@aztec/stdlib 5.0.0-nightly.20260416 → 5.0.0-nightly.20260418

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,4 +13,4 @@ export declare function encodeArguments(abi: FunctionAbi, args: any[]): Fr[];
13
13
  * @returns The size of the arguments.
14
14
  */
15
15
  export declare function countArgumentsSize(abi: FunctionAbi): number;
16
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW5jb2Rlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2FiaS9lbmNvZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUVwRCxPQUFPLEtBQUssRUFBVyxXQUFXLEVBQUUsTUFBTSxVQUFVLENBQUM7QUE2UXJEOzs7OztHQUtHO0FBQ0gsd0JBQWdCLGVBQWUsQ0FBQyxHQUFHLEVBQUUsV0FBVyxFQUFFLElBQUksRUFBRSxHQUFHLEVBQUUsUUFFNUQ7QUFFRDs7OztHQUlHO0FBQ0gsd0JBQWdCLGtCQUFrQixDQUFDLEdBQUcsRUFBRSxXQUFXLFVBRWxEIn0=
16
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW5jb2Rlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2FiaS9lbmNvZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUVwRCxPQUFPLEtBQUssRUFBVyxXQUFXLEVBQUUsTUFBTSxVQUFVLENBQUM7QUFpVHJEOzs7OztHQUtHO0FBQ0gsd0JBQWdCLGVBQWUsQ0FBQyxHQUFHLEVBQUUsV0FBVyxFQUFFLElBQUksRUFBRSxHQUFHLEVBQUUsUUFFNUQ7QUFFRDs7OztHQUlHO0FBQ0gsd0JBQWdCLGtCQUFrQixDQUFDLEdBQUcsRUFBRSxXQUFXLFVBRWxEIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../src/abi/encoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,UAAU,CAAC;AA6QrD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,QAE5D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,WAAW,UAElD"}
1
+ {"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../src/abi/encoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,UAAU,CAAC;AAiTrD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,QAE5D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,WAAW,UAElD"}
@@ -91,13 +91,24 @@ import { isAddressStruct, isBoundedVecStruct, isFunctionSelectorStruct, isOption
91
91
  this.flattened.push(new Fr(arg ? 1n : 0n));
92
92
  break;
93
93
  case 'array':
94
+ if (!Array.isArray(arg)) {
95
+ throw new Error(`Expected array for '${name ?? 'unnamed'}' but received ${typeof arg}`);
96
+ }
97
+ if (arg.length !== abiType.length) {
98
+ throw new Error(`Expected array of length ${abiType.length} for '${name ?? 'unnamed'}' but received length ${arg.length}`);
99
+ }
94
100
  for(let i = 0; i < abiType.length; i += 1){
95
101
  this.encodeArgument(abiType.type, arg[i], `${name}[${i}]`);
96
102
  }
97
103
  break;
98
104
  case 'string':
105
+ if (typeof arg !== 'string') {
106
+ throw new Error(`Expected string for '${name ?? 'unnamed'}' but received ${typeof arg}`);
107
+ }
108
+ if (arg.length > abiType.length) {
109
+ throw new Error(`Expected string of max length ${abiType.length} for '${name ?? 'unnamed'}' but received length ${arg.length}`);
110
+ }
99
111
  for(let i = 0; i < abiType.length; i += 1){
100
- // If the string is shorter than the defined length, pad it with 0s.
101
112
  const toInsert = i < arg.length ? BigInt(arg.charCodeAt(i)) : 0n;
102
113
  this.flattened.push(new Fr(toInsert));
103
114
  }
@@ -152,12 +163,24 @@ import { isAddressStruct, isBoundedVecStruct, isFunctionSelectorStruct, isOption
152
163
  case 'integer':
153
164
  {
154
165
  const value = BigInt(arg);
155
- if (abiType.sign === 'signed' && value < 0n) {
156
- // Convert negative values to two's complement representation
157
- const twosComplement = value + (1n << BigInt(abiType.width));
158
- this.flattened.push(new Fr(twosComplement));
159
- } else {
166
+ if (abiType.sign === 'unsigned') {
167
+ const maxValue = (1n << BigInt(abiType.width)) - 1n;
168
+ if (value < 0n || value > maxValue) {
169
+ throw new Error(`Value ${value} does not fit in u${abiType.width} for '${name ?? 'unnamed'}' (valid range: 0 to ${maxValue})`);
170
+ }
160
171
  this.flattened.push(new Fr(value));
172
+ } else {
173
+ const minValue = -(1n << BigInt(abiType.width - 1));
174
+ const maxValue = (1n << BigInt(abiType.width - 1)) - 1n;
175
+ if (value < minValue || value > maxValue) {
176
+ throw new Error(`Value ${value} does not fit in i${abiType.width} for '${name ?? 'unnamed'}' (valid range: ${minValue} to ${maxValue})`);
177
+ }
178
+ if (value < 0n) {
179
+ const twosComplement = value + (1n << BigInt(abiType.width));
180
+ this.flattened.push(new Fr(twosComplement));
181
+ } else {
182
+ this.flattened.push(new Fr(value));
183
+ }
161
184
  }
162
185
  break;
163
186
  }
@@ -169,6 +192,9 @@ import { isAddressStruct, isBoundedVecStruct, isFunctionSelectorStruct, isOption
169
192
  * Encodes all the arguments for the given function ABI.
170
193
  * @returns The encoded arguments.
171
194
  */ encode() {
195
+ if (this.args.length !== this.abi.parameters.length) {
196
+ throw new Error(`Function '${this.abi.name}' expects ${this.abi.parameters.length} argument(s) but received ${this.args.length}`);
197
+ }
172
198
  for(let i = 0; i < this.abi.parameters.length; i += 1){
173
199
  const parameterAbi = this.abi.parameters[i];
174
200
  this.encodeArgument(parameterAbi.type, this.args[i], parameterAbi.name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/stdlib",
3
- "version": "5.0.0-nightly.20260416",
3
+ "version": "5.0.0-nightly.20260418",
4
4
  "type": "module",
5
5
  "inherits": [
6
6
  "../package.common.json",
@@ -92,13 +92,13 @@
92
92
  },
93
93
  "dependencies": {
94
94
  "@aws-sdk/client-s3": "^3.892.0",
95
- "@aztec/bb.js": "5.0.0-nightly.20260416",
96
- "@aztec/blob-lib": "5.0.0-nightly.20260416",
97
- "@aztec/constants": "5.0.0-nightly.20260416",
98
- "@aztec/ethereum": "5.0.0-nightly.20260416",
99
- "@aztec/foundation": "5.0.0-nightly.20260416",
100
- "@aztec/l1-artifacts": "5.0.0-nightly.20260416",
101
- "@aztec/noir-noirc_abi": "5.0.0-nightly.20260416",
95
+ "@aztec/bb.js": "5.0.0-nightly.20260418",
96
+ "@aztec/blob-lib": "5.0.0-nightly.20260418",
97
+ "@aztec/constants": "5.0.0-nightly.20260418",
98
+ "@aztec/ethereum": "5.0.0-nightly.20260418",
99
+ "@aztec/foundation": "5.0.0-nightly.20260418",
100
+ "@aztec/l1-artifacts": "5.0.0-nightly.20260418",
101
+ "@aztec/noir-noirc_abi": "5.0.0-nightly.20260418",
102
102
  "@google-cloud/storage": "^7.15.0",
103
103
  "axios": "^1.13.5",
104
104
  "json-stringify-deterministic": "1.0.12",
@@ -106,13 +106,28 @@ class ArgumentEncoder {
106
106
  this.flattened.push(new Fr(arg ? 1n : 0n));
107
107
  break;
108
108
  case 'array':
109
+ if (!Array.isArray(arg)) {
110
+ throw new Error(`Expected array for '${name ?? 'unnamed'}' but received ${typeof arg}`);
111
+ }
112
+ if (arg.length !== abiType.length) {
113
+ throw new Error(
114
+ `Expected array of length ${abiType.length} for '${name ?? 'unnamed'}' but received length ${arg.length}`,
115
+ );
116
+ }
109
117
  for (let i = 0; i < abiType.length; i += 1) {
110
118
  this.encodeArgument(abiType.type, arg[i], `${name}[${i}]`);
111
119
  }
112
120
  break;
113
121
  case 'string':
122
+ if (typeof arg !== 'string') {
123
+ throw new Error(`Expected string for '${name ?? 'unnamed'}' but received ${typeof arg}`);
124
+ }
125
+ if (arg.length > abiType.length) {
126
+ throw new Error(
127
+ `Expected string of max length ${abiType.length} for '${name ?? 'unnamed'}' but received length ${arg.length}`,
128
+ );
129
+ }
114
130
  for (let i = 0; i < abiType.length; i += 1) {
115
- // If the string is shorter than the defined length, pad it with 0s.
116
131
  const toInsert = i < arg.length ? BigInt((arg as string).charCodeAt(i)) : 0n;
117
132
  this.flattened.push(new Fr(toInsert));
118
133
  }
@@ -157,12 +172,28 @@ class ArgumentEncoder {
157
172
  }
158
173
  case 'integer': {
159
174
  const value = BigInt(arg);
160
- if (abiType.sign === 'signed' && value < 0n) {
161
- // Convert negative values to two's complement representation
162
- const twosComplement = value + (1n << BigInt(abiType.width));
163
- this.flattened.push(new Fr(twosComplement));
164
- } else {
175
+ if (abiType.sign === 'unsigned') {
176
+ const maxValue = (1n << BigInt(abiType.width)) - 1n;
177
+ if (value < 0n || value > maxValue) {
178
+ throw new Error(
179
+ `Value ${value} does not fit in u${abiType.width} for '${name ?? 'unnamed'}' (valid range: 0 to ${maxValue})`,
180
+ );
181
+ }
165
182
  this.flattened.push(new Fr(value));
183
+ } else {
184
+ const minValue = -(1n << BigInt(abiType.width - 1));
185
+ const maxValue = (1n << BigInt(abiType.width - 1)) - 1n;
186
+ if (value < minValue || value > maxValue) {
187
+ throw new Error(
188
+ `Value ${value} does not fit in i${abiType.width} for '${name ?? 'unnamed'}' (valid range: ${minValue} to ${maxValue})`,
189
+ );
190
+ }
191
+ if (value < 0n) {
192
+ const twosComplement = value + (1n << BigInt(abiType.width));
193
+ this.flattened.push(new Fr(twosComplement));
194
+ } else {
195
+ this.flattened.push(new Fr(value));
196
+ }
166
197
  }
167
198
  break;
168
199
  }
@@ -176,6 +207,11 @@ class ArgumentEncoder {
176
207
  * @returns The encoded arguments.
177
208
  */
178
209
  public encode() {
210
+ if (this.args.length !== this.abi.parameters.length) {
211
+ throw new Error(
212
+ `Function '${this.abi.name}' expects ${this.abi.parameters.length} argument(s) but received ${this.args.length}`,
213
+ );
214
+ }
179
215
  for (let i = 0; i < this.abi.parameters.length; i += 1) {
180
216
  const parameterAbi = this.abi.parameters[i];
181
217
  this.encodeArgument(parameterAbi.type, this.args[i], parameterAbi.name);