@aztec/stdlib 0.77.0-testnet-ignition.17 → 0.77.0-testnet-ignition.21

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.
Files changed (56) hide show
  1. package/dest/avm/avm.d.ts +3559 -414
  2. package/dest/avm/avm.d.ts.map +1 -1
  3. package/dest/avm/avm.js +117 -662
  4. package/dest/avm/avm_accumulated_data.d.ts +94 -0
  5. package/dest/avm/avm_accumulated_data.d.ts.map +1 -1
  6. package/dest/avm/avm_accumulated_data.js +12 -1
  7. package/dest/avm/avm_circuit_public_inputs.d.ts +1023 -0
  8. package/dest/avm/avm_circuit_public_inputs.d.ts.map +1 -1
  9. package/dest/avm/avm_circuit_public_inputs.js +30 -1
  10. package/dest/avm/avm_proving_request.d.ts +2567 -2
  11. package/dest/avm/avm_proving_request.d.ts.map +1 -1
  12. package/dest/avm/message_pack.d.ts +4 -0
  13. package/dest/avm/message_pack.d.ts.map +1 -0
  14. package/dest/avm/message_pack.js +47 -0
  15. package/dest/block/l2_block_source.d.ts +17 -0
  16. package/dest/block/l2_block_source.d.ts.map +1 -1
  17. package/dest/block/l2_block_source.js +4 -0
  18. package/dest/interfaces/proving-job.d.ts +2567 -2
  19. package/dest/interfaces/proving-job.d.ts.map +1 -1
  20. package/dest/kernel/private_to_avm_accumulated_data.d.ts +85 -0
  21. package/dest/kernel/private_to_avm_accumulated_data.d.ts.map +1 -1
  22. package/dest/kernel/private_to_avm_accumulated_data.js +17 -1
  23. package/dest/kernel/public_call_request.d.ts +26 -0
  24. package/dest/kernel/public_call_request.d.ts.map +1 -1
  25. package/dest/kernel/public_call_request.js +13 -0
  26. package/dest/messaging/l2_to_l1_message.d.ts +55 -0
  27. package/dest/messaging/l2_to_l1_message.d.ts.map +1 -1
  28. package/dest/messaging/l2_to_l1_message.js +15 -0
  29. package/dest/p2p/consensus_payload.d.ts.map +1 -1
  30. package/dest/p2p/consensus_payload.js +2 -1
  31. package/dest/tests/factories.d.ts +4 -4
  32. package/dest/tests/factories.d.ts.map +1 -1
  33. package/dest/tests/factories.js +20 -19
  34. package/dest/trees/nullifier_membership_witness.d.ts +7 -7
  35. package/dest/trees/public_data_witness.d.ts +7 -7
  36. package/dest/tx/private_execution_result.js +1 -1
  37. package/dest/tx/processed_tx.d.ts +4 -0
  38. package/dest/tx/processed_tx.d.ts.map +1 -1
  39. package/dest/tx/processed_tx.js +2 -0
  40. package/dest/tx/tree_snapshots.d.ts +94 -0
  41. package/dest/tx/tree_snapshots.d.ts.map +1 -1
  42. package/dest/tx/tree_snapshots.js +9 -0
  43. package/package.json +6 -6
  44. package/src/avm/avm.ts +208 -906
  45. package/src/avm/avm_accumulated_data.ts +27 -1
  46. package/src/avm/avm_circuit_public_inputs.ts +73 -1
  47. package/src/avm/message_pack.ts +48 -0
  48. package/src/block/l2_block_source.ts +18 -0
  49. package/src/kernel/private_to_avm_accumulated_data.ts +33 -0
  50. package/src/kernel/public_call_request.ts +16 -0
  51. package/src/messaging/l2_to_l1_message.ts +22 -0
  52. package/src/p2p/consensus_payload.ts +2 -1
  53. package/src/tests/factories.ts +38 -28
  54. package/src/tx/private_execution_result.ts +1 -1
  55. package/src/tx/processed_tx.ts +6 -0
  56. package/src/tx/tree_snapshots.ts +15 -0
package/src/avm/avm.ts CHANGED
@@ -1,86 +1,26 @@
1
- import { Fq, Fr, Point } from '@aztec/foundation/fields';
2
- import { bufferSchemaFor } from '@aztec/foundation/schemas';
3
- import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
- import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';
5
- import type { FieldsOf } from '@aztec/foundation/types';
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
3
+ import { schemas } from '@aztec/foundation/schemas';
6
4
 
7
- import { strict as assert } from 'assert';
8
- import { Encoder, addExtension } from 'msgpackr';
5
+ import { z } from 'zod';
9
6
 
10
7
  import { AztecAddress } from '../aztec-address/index.js';
11
8
  import { PublicKeys } from '../keys/public_keys.js';
12
9
  import { NullifierLeafPreimage } from '../trees/nullifier_leaf.js';
13
10
  import { PublicDataTreeLeafPreimage } from '../trees/public_data_leaf.js';
14
- import { Vector } from '../types/shared.js';
15
11
  import { AvmCircuitPublicInputs } from './avm_circuit_public_inputs.js';
12
+ import { serializeWithMessagePack } from './message_pack.js';
16
13
 
17
14
  export class AvmEnqueuedCallHint {
18
- public readonly contractAddress: AztecAddress;
19
- public readonly calldata: Vector<Fr>;
15
+ constructor(public readonly contractAddress: AztecAddress, public readonly calldata: Fr[]) {}
20
16
 
21
- constructor(contractAddress: AztecAddress, calldata: Fr[]) {
22
- this.contractAddress = contractAddress;
23
- this.calldata = new Vector(calldata);
24
- }
25
-
26
- /* Serializes the inputs to a buffer.
27
- * @returns - The inputs serialized to a buffer.
28
- */
29
- toBuffer() {
30
- return serializeToBuffer(...AvmEnqueuedCallHint.getFields(this));
31
- }
32
-
33
- /**
34
- * Serializes the inputs to a hex string.
35
- * @returns The instance serialized to a hex string.
36
- */
37
- toString() {
38
- return bufferToHex(this.toBuffer());
39
- }
40
-
41
- /**
42
- * Is the struct empty?
43
- * @returns whether all members are empty.
44
- */
45
- isEmpty(): boolean {
46
- return this.contractAddress.isZero() && this.calldata.items.length == 0;
47
- }
48
-
49
- /**
50
- * Creates a new instance from fields.
51
- * @param fields - Fields to create the instance from.
52
- * @returns A new AvmExecutionHints instance.
53
- */
54
- static from(fields: FieldsOf<AvmEnqueuedCallHint>): AvmEnqueuedCallHint {
55
- return new AvmEnqueuedCallHint(fields.contractAddress, fields.calldata.items);
56
- }
57
-
58
- /**
59
- * Extracts fields from an instance.
60
- * @param fields - Fields to create the instance from.
61
- * @returns An array of fields.
62
- */
63
- static getFields(fields: FieldsOf<AvmEnqueuedCallHint>) {
64
- return [fields.contractAddress, fields.calldata] as const;
65
- }
66
-
67
- /**
68
- * Deserializes from a buffer or reader.
69
- * @param buffer - Buffer or reader to read from.
70
- * @returns The deserialized instance.
71
- */
72
- static fromBuffer(buff: Buffer | BufferReader) {
73
- const reader = BufferReader.asReader(buff);
74
- return new AvmEnqueuedCallHint(AztecAddress.fromBuffer(reader), reader.readVector(Fr));
75
- }
76
-
77
- /**
78
- * Deserializes from a hex string.
79
- * @param str - Hex string to read from.
80
- * @returns The deserialized instance.
81
- */
82
- static fromString(str: string): AvmEnqueuedCallHint {
83
- return AvmEnqueuedCallHint.fromBuffer(hexToBuffer(str));
17
+ static get schema() {
18
+ return z
19
+ .object({
20
+ contractAddress: AztecAddress.schema,
21
+ calldata: schemas.Fr.array(),
22
+ })
23
+ .transform(({ contractAddress, calldata }) => new AvmEnqueuedCallHint(contractAddress, calldata));
84
24
  }
85
25
  }
86
26
 
@@ -94,84 +34,31 @@ export class AvmContractClassHint {
94
34
  public readonly packedBytecode: Buffer,
95
35
  ) {}
96
36
 
97
- /**
98
- * Serializes the inputs to a buffer.
99
- * @returns - The inputs serialized to a buffer.
100
- */
101
- toBuffer() {
102
- return serializeToBuffer(...AvmContractClassHint.getFields(this));
103
- }
104
-
105
- /**
106
- * Serializes the inputs to a hex string.
107
- * @returns The instance serialized to a hex string.
108
- */
109
- toString() {
110
- return bufferToHex(this.toBuffer());
111
- }
112
-
113
- /**
114
- * Is the struct empty?
115
- * @returns whether all members are empty.
116
- */
117
- isEmpty(): boolean {
118
- return (
119
- this.classId.isZero() &&
120
- !this.exists &&
121
- this.artifactHash.isZero() &&
122
- this.privateFunctionsRoot.isZero() &&
123
- this.publicBytecodeCommitment.isZero() &&
124
- this.packedBytecode.length == 0
125
- );
126
- }
127
-
128
- /**
129
- * Extracts fields from an instance.
130
- * @param fields - Fields to create the instance from.
131
- * @returns An array of fields.
132
- */
133
- static getFields(fields: FieldsOf<AvmContractClassHint>) {
134
- return [
135
- fields.classId,
136
- fields.exists,
137
- fields.artifactHash,
138
- fields.privateFunctionsRoot,
139
- fields.publicBytecodeCommitment,
140
- fields.packedBytecode.length, // we need to manually prepend the length...
141
- fields.packedBytecode,
142
- ] as const;
143
- }
144
-
145
- /**
146
- * Deserializes from a buffer or reader.
147
- * @param buffer - Buffer or reader to read from.
148
- * @returns The deserialized instance.
149
- */
150
- static fromBuffer(buff: Buffer | BufferReader): AvmContractClassHint {
151
- const reader = BufferReader.asReader(buff);
152
- return new AvmContractClassHint(
153
- Fr.fromBuffer(reader),
154
- reader.readBoolean(),
155
- Fr.fromBuffer(reader),
156
- Fr.fromBuffer(reader),
157
- Fr.fromBuffer(reader),
158
- reader.readBuffer(),
159
- );
160
- }
161
-
162
- /**
163
- * Deserializes from a hex string.
164
- * @param str - Hex string to read from.
165
- * @returns The deserialized instance.
166
- */
167
- static fromString(str: string): AvmContractClassHint {
168
- return AvmContractClassHint.fromBuffer(hexToBuffer(str));
37
+ static get schema() {
38
+ return z
39
+ .object({
40
+ classId: schemas.Fr,
41
+ exists: z.boolean(),
42
+ artifactHash: schemas.Fr,
43
+ privateFunctionsRoot: schemas.Fr,
44
+ publicBytecodeCommitment: schemas.Fr,
45
+ packedBytecode: schemas.Buffer,
46
+ })
47
+ .transform(
48
+ ({ classId, exists, artifactHash, privateFunctionsRoot, publicBytecodeCommitment, packedBytecode }) =>
49
+ new AvmContractClassHint(
50
+ classId,
51
+ exists,
52
+ artifactHash,
53
+ privateFunctionsRoot,
54
+ publicBytecodeCommitment,
55
+ packedBytecode,
56
+ ),
57
+ );
169
58
  }
170
59
  }
171
60
 
172
61
  export class AvmContractInstanceHint {
173
- public readonly updatePreimage: Vector<Fr>;
174
-
175
62
  constructor(
176
63
  public readonly address: AztecAddress,
177
64
  public readonly exists: boolean,
@@ -181,653 +68,207 @@ export class AvmContractInstanceHint {
181
68
  public readonly originalContractClassId: Fr,
182
69
  public readonly initializationHash: Fr,
183
70
  public readonly publicKeys: PublicKeys,
184
- public readonly updateMembershipHint: AvmPublicDataReadTreeHint = AvmPublicDataReadTreeHint.empty(),
185
- updatePreimage: Fr[],
186
- ) {
187
- this.updatePreimage = new Vector(updatePreimage);
188
- }
189
- /**
190
- * Serializes the inputs to a buffer.
191
- * @returns - The inputs serialized to a buffer.
192
- */
193
- toBuffer() {
194
- return serializeToBuffer(...AvmContractInstanceHint.getFields(this));
195
- }
196
-
197
- /**
198
- * Serializes the inputs to a hex string.
199
- * @returns The instance serialized to a hex string.
200
- */
201
- toString() {
202
- return bufferToHex(this.toBuffer());
203
- }
204
-
205
- /**
206
- * Is the struct empty?
207
- * @returns whether all members are empty.
208
- */
209
- isEmpty(): boolean {
210
- return (
211
- this.address.isZero() &&
212
- !this.exists &&
213
- this.salt.isZero() &&
214
- this.deployer.isZero() &&
215
- this.currentContractClassId.isZero() &&
216
- this.originalContractClassId.isZero() &&
217
- this.initializationHash.isZero() &&
218
- this.publicKeys.isEmpty() &&
219
- this.updateMembershipHint.isEmpty() &&
220
- this.updatePreimage.items.length == 0
221
- );
222
- }
223
-
224
- /**
225
- * Extracts fields from an instance.
226
- * @param fields - Fields to create the instance from.
227
- * @returns An array of fields.
228
- */
229
- static getFields(fields: FieldsOf<AvmContractInstanceHint>) {
230
- return [
231
- fields.address,
232
- fields.exists,
233
- fields.salt,
234
- fields.deployer,
235
- fields.currentContractClassId,
236
- fields.originalContractClassId,
237
- fields.initializationHash,
238
- fields.publicKeys,
239
- fields.updateMembershipHint,
240
- fields.updatePreimage,
241
- ] as const;
242
- }
243
-
244
- /**
245
- * Deserializes from a buffer or reader.
246
- * @param buffer - Buffer or reader to read from.
247
- * @returns The deserialized instance.
248
- */
249
- static fromBuffer(buff: Buffer | BufferReader): AvmContractInstanceHint {
250
- const reader = BufferReader.asReader(buff);
251
- return new AvmContractInstanceHint(
252
- AztecAddress.fromBuffer(reader),
253
- reader.readBoolean(),
254
- Fr.fromBuffer(reader),
255
- AztecAddress.fromBuffer(reader),
256
- Fr.fromBuffer(reader),
257
- Fr.fromBuffer(reader),
258
- Fr.fromBuffer(reader),
259
- PublicKeys.fromBuffer(reader),
260
- AvmPublicDataReadTreeHint.fromBuffer(reader),
261
- reader.readVector(Fr),
262
- );
263
- }
71
+ // public readonly updateMembershipHint: AvmPublicDataReadTreeHint = AvmPublicDataReadTreeHint.empty(),
72
+ public readonly updateMembershipHint: AvmPublicDataReadTreeHint,
73
+ public readonly updatePreimage: Fr[] = [],
74
+ ) {}
264
75
 
265
- /**
266
- * Deserializes from a hex string.
267
- * @param str - Hex string to read from.
268
- * @returns The deserialized instance.
269
- */
270
- static fromString(str: string): AvmContractInstanceHint {
271
- return AvmContractInstanceHint.fromBuffer(hexToBuffer(str));
76
+ static get schema() {
77
+ return z
78
+ .object({
79
+ address: AztecAddress.schema,
80
+ exists: z.boolean(),
81
+ salt: schemas.Fr,
82
+ deployer: AztecAddress.schema,
83
+ currentContractClassId: schemas.Fr,
84
+ originalContractClassId: schemas.Fr,
85
+ initializationHash: schemas.Fr,
86
+ publicKeys: PublicKeys.schema,
87
+ updateMembershipHint: AvmPublicDataReadTreeHint.schema,
88
+ updatePreimage: schemas.Fr.array(),
89
+ })
90
+ .transform(
91
+ ({
92
+ address,
93
+ exists,
94
+ salt,
95
+ deployer,
96
+ currentContractClassId,
97
+ originalContractClassId,
98
+ initializationHash,
99
+ publicKeys,
100
+ updateMembershipHint,
101
+ updatePreimage,
102
+ }) =>
103
+ new AvmContractInstanceHint(
104
+ address,
105
+ exists,
106
+ salt,
107
+ deployer,
108
+ currentContractClassId,
109
+ originalContractClassId,
110
+ initializationHash,
111
+ publicKeys,
112
+ updateMembershipHint,
113
+ updatePreimage,
114
+ ),
115
+ );
272
116
  }
273
117
  }
274
118
 
275
119
  export class AvmAppendTreeHint {
276
- readonly siblingPath: Vector<Fr>;
277
- /*
278
- * @param bytecode the contract bytecode
279
- * @param contractInstance the contract instance of the nested call, used to derive the contract address
280
- * @param contractClassPreimage the contract class preimage of the nested call, used to derive the class id
281
- * */
282
- constructor(public readonly leafIndex: Fr, public readonly value: Fr, readonly _siblingPath: Fr[]) {
283
- this.siblingPath = new Vector(_siblingPath);
284
- }
120
+ constructor(public readonly leafIndex: Fr, public readonly value: Fr, public readonly siblingPath: Fr[]) {}
285
121
 
286
- /**
287
- * Serializes the inputs to a buffer.
288
- * @returns - The inputs serialized to a buffer.
289
- */
290
- toBuffer() {
291
- return serializeToBuffer(...AvmAppendTreeHint.getFields(this));
292
- }
293
-
294
- /**
295
- * Serializes the inputs to a hex string.
296
- * @returns The instance serialized to a hex string.
297
- */
298
- toString() {
299
- return this.toBuffer().toString('hex');
300
- }
301
-
302
- /**
303
- * Is the struct empty?
304
- * @returns whether all members are empty.
305
- */
306
- isEmpty(): boolean {
307
- return this.value.isZero() && this.siblingPath.items.length == 0;
308
- }
309
-
310
- /**
311
- * Creates a new instance from fields.
312
- * @param fields - Fields to create the instance from.
313
- * @returns A new AvmHint instance.
314
- */
315
- static from(fields: FieldsOf<AvmAppendTreeHint>): AvmAppendTreeHint {
316
- return new AvmAppendTreeHint(fields.leafIndex, fields.value, fields.siblingPath.items);
317
- }
318
-
319
- /**
320
- * Extracts fields from an instance.
321
- * @param fields - Fields to create the instance from.
322
- * @returns An array of fields.
323
- */
324
- static getFields(fields: FieldsOf<AvmAppendTreeHint>) {
325
- return [fields.leafIndex, fields.value, fields.siblingPath] as const;
326
- }
327
-
328
- /**
329
- * Deserializes from a buffer or reader.
330
- * @param buffer - Buffer or reader to read from.
331
- * @returns The deserialized instance.
332
- */
333
- static fromBuffer(buff: Buffer | BufferReader): AvmAppendTreeHint {
334
- return new AvmAppendTreeHint(Fr.fromBuffer(buff), Fr.fromBuffer(buff), BufferReader.asReader(buff).readVector(Fr));
335
- }
336
-
337
- /**
338
- * Deserializes from a hex string.
339
- * @param str - Hex string to read from.
340
- * @returns The deserialized instance.
341
- */
342
- static fromString(str: string): AvmAppendTreeHint {
343
- return AvmAppendTreeHint.fromBuffer(Buffer.from(str, 'hex'));
122
+ static get schema() {
123
+ return z
124
+ .object({
125
+ leafIndex: schemas.Fr,
126
+ value: schemas.Fr,
127
+ siblingPath: schemas.Fr.array(),
128
+ })
129
+ .transform(({ leafIndex, value, siblingPath }) => new AvmAppendTreeHint(leafIndex, value, siblingPath));
344
130
  }
345
131
  }
346
132
 
347
133
  export class AvmNullifierWriteTreeHint {
348
- readonly insertionPath: Vector<Fr>;
349
- /*
350
- * @param bytecode the contract bytecode
351
- * @param contractInstance the contract instance of the nested call, used to derive the contract address
352
- * @param contractClassPreimage the contract class preimage of the nested call, used to derive the class id
353
- * */
354
- constructor(public lowLeafRead: AvmNullifierReadTreeHint, public _insertionPath: Fr[]) {
355
- this.insertionPath = new Vector(_insertionPath);
356
- }
357
-
358
- /**
359
- * Serializes the inputs to a buffer.
360
- * @returns - The inputs serialized to a buffer.
361
- */
362
- toBuffer() {
363
- return serializeToBuffer(...AvmNullifierWriteTreeHint.getFields(this));
364
- }
365
-
366
- /**
367
- * Serializes the inputs to a hex string.
368
- * @returns The instance serialized to a hex string.
369
- */
370
- toString() {
371
- return this.toBuffer().toString('hex');
372
- }
373
-
374
- /**
375
- * Is the struct empty?
376
- * @returns whether all members are empty.
377
- */
378
- isEmpty(): boolean {
379
- return this.insertionPath.items.length == 0;
380
- }
134
+ constructor(public lowLeafRead: AvmNullifierReadTreeHint, public readonly insertionPath: Fr[]) {}
381
135
 
382
- /**
383
- * Creates a new instance from fields.
384
- * @param fields - Fields to create the instance from.
385
- * @returns A new AvmHint instance.
386
- */
387
- static from(fields: FieldsOf<AvmNullifierWriteTreeHint>): AvmNullifierWriteTreeHint {
388
- return new AvmNullifierWriteTreeHint(fields.lowLeafRead, fields.insertionPath.items);
389
- }
390
-
391
- /**
392
- * Extracts fields from an instance.
393
- * @param fields - Fields to create the instance from.
394
- * @returns An array of fields.
395
- */
396
- static getFields(fields: FieldsOf<AvmNullifierWriteTreeHint>) {
397
- return [...AvmNullifierReadTreeHint.getFields(fields.lowLeafRead), fields.insertionPath] as const;
398
- }
399
-
400
- /**
401
- * Deserializes from a buffer or reader.
402
- * @param buffer - Buffer or reader to read from.
403
- * @returns The deserialized instance.
404
- */
405
- static fromBuffer(buff: Buffer | BufferReader): AvmNullifierWriteTreeHint {
406
- const reader = BufferReader.asReader(buff);
407
- const lowLeafRead = AvmNullifierReadTreeHint.fromBuffer(reader);
408
- const insertionPath = reader.readVector(Fr);
409
- return new AvmNullifierWriteTreeHint(lowLeafRead, insertionPath);
410
- }
411
-
412
- /**
413
- * Deserializes from a hex string.
414
- * @param str - Hex string to read from.
415
- * @returns The deserialized instance.
416
- */
417
- static fromString(str: string): AvmNullifierWriteTreeHint {
418
- return AvmNullifierWriteTreeHint.fromBuffer(Buffer.from(str, 'hex'));
136
+ static get schema() {
137
+ return z
138
+ .object({
139
+ lowLeafRead: AvmNullifierReadTreeHint.schema,
140
+ insertionPath: schemas.Fr.array(),
141
+ })
142
+ .transform(({ lowLeafRead, insertionPath }) => new AvmNullifierWriteTreeHint(lowLeafRead, insertionPath));
419
143
  }
420
144
  }
421
145
 
422
146
  export class AvmNullifierReadTreeHint {
423
- readonly lowLeafSiblingPath: Vector<Fr>;
424
-
425
147
  constructor(
426
148
  public readonly lowLeafPreimage: NullifierLeafPreimage,
427
149
  public readonly lowLeafIndex: Fr,
428
- public _lowLeafSiblingPath: Fr[],
429
- ) {
430
- this.lowLeafSiblingPath = new Vector(_lowLeafSiblingPath);
431
- }
432
-
433
- /**
434
- * Serializes the inputs to a buffer.
435
- * @returns - The inputs serialized to a buffer.
436
- */
437
- toBuffer() {
438
- return serializeToBuffer(...AvmNullifierReadTreeHint.getFields(this));
439
- }
440
-
441
- /**
442
- * Serializes the inputs to a hex string.
443
- * @returns The instance serialized to a hex string.
444
- */
445
- toString() {
446
- return this.toBuffer().toString('hex');
447
- }
448
-
449
- /**
450
- * Is the struct empty?
451
- * @returns whether all members are empty.
452
- */
453
- isEmpty(): boolean {
454
- return this.lowLeafSiblingPath.items.length == 0;
455
- }
456
-
457
- /**
458
- * Creates a new instance from fields.
459
- * @param fields - Fields to create the instance from.
460
- * @returns A new AvmHint instance.
461
- */
462
- static from(fields: FieldsOf<AvmNullifierReadTreeHint>): AvmNullifierReadTreeHint {
463
- return new AvmNullifierReadTreeHint(fields.lowLeafPreimage, fields.lowLeafIndex, fields.lowLeafSiblingPath.items);
464
- }
465
-
466
- static empty(): AvmNullifierReadTreeHint {
467
- return new AvmNullifierReadTreeHint(NullifierLeafPreimage.empty(), Fr.ZERO, []);
468
- }
469
-
470
- /**
471
- * Extracts fields from an instance.
472
- * @param fields - Fields to create the instance from.
473
- * @returns An array of fields.
474
- */
475
- static getFields(fields: FieldsOf<AvmNullifierReadTreeHint>) {
476
- return [
477
- fields.lowLeafPreimage.nullifier,
478
- fields.lowLeafPreimage.nextNullifier,
479
- new Fr(fields.lowLeafPreimage.nextIndex),
480
- fields.lowLeafIndex,
481
- fields.lowLeafSiblingPath,
482
- ] as const;
483
- }
484
-
485
- /**
486
- * Deserializes from a buffer or reader.
487
- * @param buffer - Buffer or reader to read from.
488
- * @returns The deserialized instance.
489
- */
490
- static fromBuffer(buff: Buffer | BufferReader): AvmNullifierReadTreeHint {
491
- const reader = BufferReader.asReader(buff);
492
- const lowLeafPreimage = reader.readObject<NullifierLeafPreimage>(NullifierLeafPreimage);
493
- const lowLeafIndex = Fr.fromBuffer(reader);
494
- const lowSiblingPath = reader.readVector(Fr);
495
-
496
- return new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowSiblingPath);
497
- }
150
+ public readonly lowLeafSiblingPath: Fr[],
151
+ ) {}
498
152
 
499
- /**
500
- * Deserializes from a hex string.
501
- * @param str - Hex string to read from.
502
- * @returns The deserialized instance.
503
- */
504
- static fromString(str: string): AvmNullifierReadTreeHint {
505
- return AvmNullifierReadTreeHint.fromBuffer(Buffer.from(str, 'hex'));
153
+ static get schema() {
154
+ return z
155
+ .object({
156
+ lowLeafPreimage: NullifierLeafPreimage.schema,
157
+ lowLeafIndex: schemas.Fr,
158
+ lowLeafSiblingPath: schemas.Fr.array(),
159
+ })
160
+ .transform(
161
+ ({ lowLeafPreimage, lowLeafIndex, lowLeafSiblingPath }) =>
162
+ new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafSiblingPath),
163
+ );
506
164
  }
507
165
  }
508
166
 
509
167
  export class AvmPublicDataReadTreeHint {
510
- siblingPath: Vector<Fr>;
511
-
512
168
  constructor(
513
169
  public readonly leafPreimage: PublicDataTreeLeafPreimage,
514
170
  public readonly leafIndex: Fr,
515
- public readonly _siblingPath: Fr[],
516
- ) {
517
- this.siblingPath = new Vector(_siblingPath);
518
- }
519
-
520
- /**
521
- * Serializes the inputs to a buffer.
522
- * @returns - The inputs serialized to a buffer.
523
- */
524
- toBuffer() {
525
- return serializeToBuffer(...AvmPublicDataReadTreeHint.getFields(this));
526
- }
527
-
528
- /**
529
- * Serializes the inputs to a hex string.
530
- * @returns The instance serialized to a hex string.
531
- */
532
- toString() {
533
- return this.toBuffer().toString('hex');
534
- }
171
+ public readonly siblingPath: Fr[],
172
+ ) {}
535
173
 
536
- static empty(): AvmPublicDataReadTreeHint {
174
+ static empty() {
537
175
  return new AvmPublicDataReadTreeHint(PublicDataTreeLeafPreimage.empty(), Fr.ZERO, []);
538
176
  }
539
177
 
540
- /**
541
- * Is the struct empty?
542
- * @returns whether all members are empty.
543
- */
544
- isEmpty(): boolean {
545
- return this.siblingPath.items.length == 0;
546
- }
547
-
548
- /**
549
- * Creates a new instance from fields.
550
- * @param fields - Fields to create the instance from.
551
- * @returns A new AvmHint instance.
552
- */
553
- static from(fields: FieldsOf<AvmPublicDataReadTreeHint>): AvmPublicDataReadTreeHint {
554
- return new AvmPublicDataReadTreeHint(fields.leafPreimage, fields.leafIndex, fields.siblingPath.items);
555
- }
556
-
557
- /**
558
- * Extracts fields from an instance.
559
- * @param fields - Fields to create the instance from.
560
- * @returns An array of fields.
561
- */
562
- static getFields(fields: FieldsOf<AvmPublicDataReadTreeHint>) {
563
- return [
564
- fields.leafPreimage.slot,
565
- fields.leafPreimage.value,
566
- new Fr(fields.leafPreimage.nextIndex),
567
- fields.leafPreimage.nextSlot,
568
- fields.leafIndex,
569
- fields.siblingPath,
570
- ] as const;
571
- }
572
-
573
- /**
574
- * Deserializes from a buffer or reader.
575
- * @param buffer - Buffer or reader to read from.
576
- * @returns The deserialized instance.
577
- */
578
- static fromBuffer(buff: Buffer | BufferReader): AvmPublicDataReadTreeHint {
579
- const reader = BufferReader.asReader(buff);
580
- const lowLeafPreimage = reader.readObject<PublicDataTreeLeafPreimage>(PublicDataTreeLeafPreimage);
581
- const lowLeafIndex = Fr.fromBuffer(reader);
582
- const lowSiblingPath = reader.readVector(Fr);
583
-
584
- return new AvmPublicDataReadTreeHint(lowLeafPreimage, lowLeafIndex, lowSiblingPath);
585
- }
586
-
587
- /**
588
- * Deserializes from a hex string.
589
- * @param str - Hex string to read from.
590
- * @returns The deserialized instance.
591
- */
592
- static fromString(str: string): AvmPublicDataReadTreeHint {
593
- return AvmPublicDataReadTreeHint.fromBuffer(Buffer.from(str, 'hex'));
178
+ static get schema() {
179
+ return z
180
+ .object({
181
+ leafPreimage: PublicDataTreeLeafPreimage.schema,
182
+ leafIndex: schemas.Fr,
183
+ siblingPath: schemas.Fr.array(),
184
+ })
185
+ .transform(
186
+ ({ leafPreimage, leafIndex, siblingPath }) =>
187
+ new AvmPublicDataReadTreeHint(leafPreimage, leafIndex, siblingPath),
188
+ );
594
189
  }
595
190
  }
596
191
 
597
192
  export class AvmPublicDataWriteTreeHint {
598
- insertionPath: Vector<Fr>;
599
-
600
193
  constructor(
601
194
  // To check the current slot has been written to
602
195
  public readonly lowLeafRead: AvmPublicDataReadTreeHint,
603
196
  public readonly newLeafPreimage: PublicDataTreeLeafPreimage,
604
- public readonly _insertionPath: Fr[],
605
- ) {
606
- this.insertionPath = new Vector(_insertionPath);
607
- }
608
-
609
- /**
610
- * Serializes the inputs to a buffer.
611
- * @returns - The inputs serialized to a buffer.
612
- */
613
- toBuffer() {
614
- return serializeToBuffer(...AvmPublicDataWriteTreeHint.getFields(this));
615
- }
616
-
617
- /**
618
- * Serializes the inputs to a hex string.
619
- * @returns The instance serialized to a hex string.
620
- */
621
- toString() {
622
- return this.toBuffer().toString('hex');
623
- }
624
-
625
- /**
626
- * Is the struct empty?
627
- * @returns whether all members are empty.
628
- */
629
- isEmpty(): boolean {
630
- return this.insertionPath.items.length == 0;
631
- }
632
-
633
- /**
634
- * Creates a new instance from fields.
635
- * @param fields - Fields to create the instance from.
636
- * @returns A new AvmHint instance.
637
- */
638
- static from(fields: FieldsOf<AvmPublicDataWriteTreeHint>): AvmPublicDataWriteTreeHint {
639
- return new AvmPublicDataWriteTreeHint(fields.lowLeafRead, fields.newLeafPreimage, fields.insertionPath.items);
640
- }
641
-
642
- /**
643
- * Extracts fields from an instance.
644
- * @param fields - Fields to create the instance from.
645
- * @returns An array of fields.
646
- */
647
- static getFields(fields: FieldsOf<AvmPublicDataWriteTreeHint>) {
648
- return [
649
- ...AvmPublicDataReadTreeHint.getFields(fields.lowLeafRead),
650
- fields.newLeafPreimage.slot,
651
- fields.newLeafPreimage.value,
652
- new Fr(fields.newLeafPreimage.nextIndex),
653
- fields.newLeafPreimage.nextSlot,
654
- fields.insertionPath,
655
- ] as const;
656
- }
657
-
658
- /**
659
- * Deserializes from a buffer or reader.
660
- * @param buffer - Buffer or reader to read from.
661
- * @returns The deserialized instance.
662
- */
663
- static fromBuffer(buff: Buffer | BufferReader): AvmPublicDataWriteTreeHint {
664
- const reader = BufferReader.asReader(buff);
665
- const lowLeafPreimage = reader.readObject<AvmPublicDataReadTreeHint>(AvmPublicDataReadTreeHint);
666
- const newLeafPreimage = reader.readObject<PublicDataTreeLeafPreimage>(PublicDataTreeLeafPreimage);
667
- const lowSiblingPath = reader.readVector(Fr);
668
-
669
- return new AvmPublicDataWriteTreeHint(lowLeafPreimage, newLeafPreimage, lowSiblingPath);
670
- }
197
+ public readonly insertionPath: Fr[],
198
+ ) {}
671
199
 
672
- /**
673
- * Deserializes from a hex string.
674
- * @param str - Hex string to read from.
675
- * @returns The deserialized instance.
676
- */
677
- static fromString(str: string): AvmPublicDataWriteTreeHint {
678
- return AvmPublicDataWriteTreeHint.fromBuffer(Buffer.from(str, 'hex'));
200
+ static get schema() {
201
+ return z
202
+ .object({
203
+ lowLeafRead: AvmPublicDataReadTreeHint.schema,
204
+ newLeafPreimage: PublicDataTreeLeafPreimage.schema,
205
+ insertionPath: schemas.Fr.array(),
206
+ })
207
+ .transform(
208
+ ({ lowLeafRead, newLeafPreimage, insertionPath }) =>
209
+ new AvmPublicDataWriteTreeHint(lowLeafRead, newLeafPreimage, insertionPath),
210
+ );
679
211
  }
680
212
  }
681
213
 
682
214
  export class AvmExecutionHints {
683
- public readonly enqueuedCalls: Vector<AvmEnqueuedCallHint>;
684
-
685
- public readonly contractInstances: Vector<AvmContractInstanceHint>;
686
- public readonly contractClasses: Vector<AvmContractClassHint>;
687
-
688
- public readonly publicDataReads: Vector<AvmPublicDataReadTreeHint>;
689
- public readonly publicDataWrites: Vector<AvmPublicDataWriteTreeHint>;
690
- public readonly nullifierReads: Vector<AvmNullifierReadTreeHint>;
691
- public readonly nullifierWrites: Vector<AvmNullifierWriteTreeHint>;
692
- public readonly noteHashReads: Vector<AvmAppendTreeHint>;
693
- public readonly noteHashWrites: Vector<AvmAppendTreeHint>;
694
- public readonly l1ToL2MessageReads: Vector<AvmAppendTreeHint>;
695
-
696
215
  constructor(
697
- enqueuedCalls: AvmEnqueuedCallHint[],
698
- contractInstances: AvmContractInstanceHint[],
699
- contractClasses: AvmContractClassHint[],
700
- publicDataReads: AvmPublicDataReadTreeHint[],
701
- publicDataWrites: AvmPublicDataWriteTreeHint[],
702
- nullifierReads: AvmNullifierReadTreeHint[],
703
- nullifierWrites: AvmNullifierWriteTreeHint[],
704
- noteHashReads: AvmAppendTreeHint[],
705
- noteHashWrites: AvmAppendTreeHint[],
706
- l1ToL2MessageReads: AvmAppendTreeHint[],
707
- ) {
708
- this.enqueuedCalls = new Vector(enqueuedCalls);
709
- this.contractInstances = new Vector(contractInstances);
710
- this.contractClasses = new Vector(contractClasses);
711
- this.publicDataReads = new Vector(publicDataReads);
712
- this.publicDataWrites = new Vector(publicDataWrites);
713
- this.nullifierReads = new Vector(nullifierReads);
714
- this.nullifierWrites = new Vector(nullifierWrites);
715
- this.noteHashReads = new Vector(noteHashReads);
716
- this.noteHashWrites = new Vector(noteHashWrites);
717
- this.l1ToL2MessageReads = new Vector(l1ToL2MessageReads);
718
- }
216
+ public readonly enqueuedCalls: AvmEnqueuedCallHint[],
217
+ public readonly contractInstances: AvmContractInstanceHint[],
218
+ public readonly contractClasses: AvmContractClassHint[],
219
+ public readonly publicDataReads: AvmPublicDataReadTreeHint[],
220
+ public readonly publicDataWrites: AvmPublicDataWriteTreeHint[],
221
+ public readonly nullifierReads: AvmNullifierReadTreeHint[],
222
+ public readonly nullifierWrites: AvmNullifierWriteTreeHint[],
223
+ public readonly noteHashReads: AvmAppendTreeHint[],
224
+ public readonly noteHashWrites: AvmAppendTreeHint[],
225
+ public readonly l1ToL2MessageReads: AvmAppendTreeHint[],
226
+ ) {}
719
227
 
720
- /**
721
- * Return an empty instance.
722
- * @returns an empty instance.
723
- */
724
228
  static empty() {
725
229
  return new AvmExecutionHints([], [], [], [], [], [], [], [], [], []);
726
230
  }
727
231
 
728
- /**
729
- * Serializes the inputs to a buffer.
730
- * @returns - The inputs serialized to a buffer.
731
- */
732
- toBuffer() {
733
- return serializeToBuffer(...AvmExecutionHints.getFields(this));
734
- }
735
-
736
- /**
737
- * Serializes the inputs to a hex string.
738
- * @returns The instance serialized to a hex string.
739
- */
740
- toString() {
741
- return bufferToHex(this.toBuffer());
742
- }
743
-
744
- /**
745
- * Is the struct empty?
746
- * @returns whether all members are empty.
747
- */
748
- isEmpty(): boolean {
749
- return (
750
- this.enqueuedCalls.items.length == 0 &&
751
- this.contractInstances.items.length == 0 &&
752
- this.contractClasses.items.length == 0 &&
753
- this.publicDataReads.items.length == 0 &&
754
- this.publicDataWrites.items.length == 0 &&
755
- this.nullifierReads.items.length == 0 &&
756
- this.nullifierWrites.items.length == 0 &&
757
- this.noteHashReads.items.length == 0 &&
758
- this.noteHashWrites.items.length == 0 &&
759
- this.l1ToL2MessageReads.items.length == 0
760
- );
761
- }
762
-
763
- /**
764
- * Creates a new instance from fields.
765
- * @param fields - Fields to create the instance from.
766
- * @returns A new AvmExecutionHints instance.
767
- */
768
- static from(fields: FieldsOf<AvmExecutionHints>): AvmExecutionHints {
769
- return new AvmExecutionHints(
770
- fields.enqueuedCalls.items,
771
- fields.contractInstances.items,
772
- fields.contractClasses.items,
773
- fields.publicDataReads.items,
774
- fields.publicDataWrites.items,
775
- fields.nullifierReads.items,
776
- fields.nullifierWrites.items,
777
- fields.noteHashReads.items,
778
- fields.noteHashWrites.items,
779
- fields.l1ToL2MessageReads.items,
780
- );
781
- }
782
-
783
- /**
784
- * Extracts fields from an instance.
785
- * @param fields - Fields to create the instance from.
786
- * @returns An array of fields.
787
- */
788
- static getFields(fields: FieldsOf<AvmExecutionHints>) {
789
- return [
790
- fields.enqueuedCalls,
791
- fields.contractInstances,
792
- fields.contractClasses,
793
- fields.publicDataReads,
794
- fields.publicDataWrites,
795
- fields.nullifierReads,
796
- fields.nullifierWrites,
797
- fields.noteHashReads,
798
- fields.noteHashWrites,
799
- fields.l1ToL2MessageReads,
800
- ] as const;
801
- }
802
-
803
- /**
804
- * Deserializes from a buffer or reader.
805
- * @param buffer - Buffer or reader to read from.
806
- * @returns The deserialized instance.
807
- */
808
- static fromBuffer(buff: Buffer | BufferReader): AvmExecutionHints {
809
- const reader = BufferReader.asReader(buff);
810
- return new AvmExecutionHints(
811
- reader.readVector(AvmEnqueuedCallHint),
812
- reader.readVector(AvmContractInstanceHint),
813
- reader.readVector(AvmContractClassHint),
814
- reader.readVector(AvmPublicDataReadTreeHint),
815
- reader.readVector(AvmPublicDataWriteTreeHint),
816
- reader.readVector(AvmNullifierReadTreeHint),
817
- reader.readVector(AvmNullifierWriteTreeHint),
818
- reader.readVector(AvmAppendTreeHint),
819
- reader.readVector(AvmAppendTreeHint),
820
- reader.readVector(AvmAppendTreeHint),
821
- );
822
- }
823
-
824
- /**
825
- * Deserializes from a hex string.
826
- * @param str - Hex string to read from.
827
- * @returns The deserialized instance.
828
- */
829
- static fromString(str: string): AvmCircuitInputs {
830
- return AvmCircuitInputs.fromBuffer(hexToBuffer(str));
232
+ static get schema() {
233
+ return z
234
+ .object({
235
+ enqueuedCalls: AvmEnqueuedCallHint.schema.array(),
236
+ contractInstances: AvmContractInstanceHint.schema.array(),
237
+ contractClasses: AvmContractClassHint.schema.array(),
238
+ publicDataReads: AvmPublicDataReadTreeHint.schema.array(),
239
+ publicDataWrites: AvmPublicDataWriteTreeHint.schema.array(),
240
+ nullifierReads: AvmNullifierReadTreeHint.schema.array(),
241
+ nullifierWrites: AvmNullifierWriteTreeHint.schema.array(),
242
+ noteHashReads: AvmAppendTreeHint.schema.array(),
243
+ noteHashWrites: AvmAppendTreeHint.schema.array(),
244
+ l1ToL2MessageReads: AvmAppendTreeHint.schema.array(),
245
+ })
246
+ .transform(
247
+ ({
248
+ enqueuedCalls,
249
+ contractInstances,
250
+ contractClasses,
251
+ publicDataReads,
252
+ publicDataWrites,
253
+ nullifierReads,
254
+ nullifierWrites,
255
+ noteHashReads,
256
+ noteHashWrites,
257
+ l1ToL2MessageReads,
258
+ }) =>
259
+ new AvmExecutionHints(
260
+ enqueuedCalls,
261
+ contractInstances,
262
+ contractClasses,
263
+ publicDataReads,
264
+ publicDataWrites,
265
+ nullifierReads,
266
+ nullifierWrites,
267
+ noteHashReads,
268
+ noteHashWrites,
269
+ l1ToL2MessageReads,
270
+ ),
271
+ );
831
272
  }
832
273
  }
833
274
 
@@ -835,176 +276,37 @@ export class AvmCircuitInputs {
835
276
  constructor(
836
277
  public readonly functionName: string, // only informational
837
278
  public readonly calldata: Fr[],
838
- public readonly avmHints: AvmExecutionHints,
839
- public publicInputs: AvmCircuitPublicInputs, // This should replace the above `publicInputs` eventually.
279
+ public readonly hints: AvmExecutionHints,
280
+ public publicInputs: AvmCircuitPublicInputs,
840
281
  ) {}
841
282
 
842
- /**
843
- * Serializes the inputs to a buffer.
844
- * @returns - The inputs serialized to a buffer.
845
- */
846
- toBuffer() {
847
- const functionNameBuffer = Buffer.from(this.functionName);
848
- return serializeToBuffer(
849
- functionNameBuffer.length,
850
- functionNameBuffer,
851
- this.calldata.length,
852
- this.calldata,
853
- this.avmHints.toBuffer(),
854
- this.publicInputs,
855
- );
856
- }
857
-
858
- /**
859
- * Serializes the inputs to a hex string.
860
- * @returns The instance serialized to a hex string.
861
- */
862
- toString() {
863
- return bufferToHex(this.toBuffer());
864
- }
865
-
866
- static empty(): AvmCircuitInputs {
283
+ static empty() {
867
284
  return new AvmCircuitInputs('', [], AvmExecutionHints.empty(), AvmCircuitPublicInputs.empty());
868
285
  }
869
286
 
870
- /**
871
- * Creates a new instance from fields.
872
- * @param fields - Fields to create the instance from.
873
- * @returns A new AvmCircuitInputs instance.
874
- */
875
- static from(fields: FieldsOf<AvmCircuitInputs>): AvmCircuitInputs {
876
- return new AvmCircuitInputs(...AvmCircuitInputs.getFields(fields));
877
- }
878
-
879
- /**
880
- * Extracts fields from an instance.
881
- * @param fields - Fields to create the instance from.
882
- * @returns An array of fields.
883
- */
884
- static getFields(fields: FieldsOf<AvmCircuitInputs>) {
885
- return [fields.functionName, fields.calldata, fields.avmHints, fields.publicInputs] as const;
886
- }
887
-
888
- /**
889
- * Deserializes from a buffer or reader.
890
- * @param buffer - Buffer or reader to read from.
891
- * @returns The deserialized instance.
892
- */
893
- static fromBuffer(buff: Buffer | BufferReader): AvmCircuitInputs {
894
- const reader = BufferReader.asReader(buff);
895
- return new AvmCircuitInputs(
896
- /*functionName=*/ reader.readBuffer().toString(),
897
- /*calldata=*/ reader.readVector(Fr),
898
- AvmExecutionHints.fromBuffer(reader),
899
- AvmCircuitPublicInputs.fromBuffer(reader),
900
- );
901
- }
902
-
903
- /**
904
- * Deserializes from a hex string.
905
- * @param str - Hex string to read from.
906
- * @returns The deserialized instance.
907
- */
908
- static fromString(str: string): AvmCircuitInputs {
909
- return AvmCircuitInputs.fromBuffer(hexToBuffer(str));
287
+ static get schema() {
288
+ return z
289
+ .object({
290
+ functionName: z.string(),
291
+ calldata: schemas.Fr.array(),
292
+ hints: AvmExecutionHints.schema,
293
+ publicInputs: AvmCircuitPublicInputs.schema,
294
+ })
295
+ .transform(
296
+ ({ functionName, calldata, hints, publicInputs }) =>
297
+ new AvmCircuitInputs(functionName, calldata, hints, publicInputs),
298
+ );
910
299
  }
911
300
 
912
- /** Returns a buffer representation for JSON serialization. */
913
- toJSON() {
914
- return this.toBuffer();
301
+ public serializeWithMessagePack(): Buffer {
302
+ return serializeWithMessagePack(this);
915
303
  }
916
304
 
917
- /** Creates an instance from a hex string. */
918
- static get schema() {
919
- return bufferSchemaFor(AvmCircuitInputs);
305
+ // These are used by the prover to generate an id, and also gcs_proof_store.ts.
306
+ public toBuffer(): Buffer {
307
+ return Buffer.from(jsonStringify(this));
920
308
  }
921
-
922
- /** Serializes in format for the Avm2 */
923
- serializeForAvm2(): Buffer {
924
- // logger(`original: ${inspect(input)}`);
925
- // logger.verbose(`original: ${inspect(this.avmHints.enqueuedCalls.items)}`);
926
- // Convert the inputs to something that works with vm2 and messagepack.
927
- // const inputSubset = {
928
- // ffs: [new Fr(0x123456789), new Fr(0x987654321)],
929
- // affine: new Point(new Fr(0x123456789), new Fr(0x987654321), false),
930
- // fq: new Fq(0x123456789),
931
- // addr: AztecAddress.fromBigInt(0x123456789n),
932
- // contract_instance_hints: this.avmHints.contractInstances,
933
- // };
934
- const hints = {
935
- contractInstances: [] as any[],
936
- contractClasses: [] as any[],
937
- initialTreeRoots: {
938
- publicDataTree: this.publicInputs.startTreeSnapshots.publicDataTree.root,
939
- nullifierTree: this.publicInputs.startTreeSnapshots.nullifierTree.root,
940
- noteHashTree: this.publicInputs.startTreeSnapshots.noteHashTree.root,
941
- l1ToL2MessageTree: this.publicInputs.startTreeSnapshots.l1ToL2MessageTree.root,
942
- },
943
- };
944
- const inputs = {
945
- hints: hints,
946
- enqueuedCalls: [] as any[],
947
- // Placeholder for now.
948
- publicInputs: {
949
- dummy: [] as any[],
950
- },
951
- };
952
- hints.contractInstances = this.avmHints.contractInstances.items;
953
- hints.contractClasses = this.avmHints.contractClasses.items;
954
-
955
- // TODO: for now I only convert app logic requests?
956
- for (const enqueuedCall of this.avmHints.enqueuedCalls.items) {
957
- inputs.enqueuedCalls.push({
958
- contractAddress: enqueuedCall.contractAddress,
959
- sender: new Fr(0), // FIXME
960
- args: enqueuedCall.calldata.items,
961
- isStatic: false, // FIXME
962
- });
963
- }
964
-
965
- const inputsBuffer = serializeWithMessagePack(inputs);
966
-
967
- return inputsBuffer;
309
+ static fromBuffer(buf: Buffer) {
310
+ return jsonParseWithSchema(buf.toString(), this.schema);
968
311
  }
969
312
  }
970
-
971
- export function serializeWithMessagePack(obj: any): Buffer {
972
- setUpMessagePackExtensions();
973
- const encoder = new Encoder({
974
- // always encode JS objects as MessagePack maps
975
- // this makes it compatible with other MessagePack decoders
976
- useRecords: false,
977
- int64AsType: 'bigint',
978
- });
979
- return encoder.encode(obj);
980
- }
981
-
982
- function setUpMessagePackExtensions() {
983
- // C++ Fr and Fq classes work well with the buffer serialization.
984
- addExtension({
985
- Class: Fr,
986
- write: (fr: Fr) => fr.toBuffer(),
987
- });
988
- addExtension({
989
- Class: Fq,
990
- write: (fq: Fq) => fq.toBuffer(),
991
- });
992
- // AztecAddress is a class that has a field in TS, but just a field in C++.
993
- addExtension({
994
- Class: AztecAddress,
995
- write: (addr: AztecAddress) => addr.toField(),
996
- });
997
- // If we find a vector, we just use the underlying list.
998
- addExtension({
999
- Class: Vector,
1000
- write: v => v.items,
1001
- });
1002
- // Affine points are a mess, we do our best.
1003
- addExtension({
1004
- Class: Point,
1005
- write: (p: Point) => {
1006
- assert(!p.inf, 'Cannot serialize infinity');
1007
- return { x: new Fq(p.x.toBigInt()), y: new Fq(p.y.toBigInt()) };
1008
- },
1009
- });
1010
- }