@aztec/simulator 0.56.0 → 0.58.0

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 (205) hide show
  1. package/dest/acvm/oracle/oracle.d.ts +2 -5
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +7 -38
  4. package/dest/acvm/oracle/typed_oracle.d.ts +4 -8
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +1 -10
  7. package/dest/avm/avm_execution_environment.d.ts +2 -3
  8. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  9. package/dest/avm/avm_execution_environment.js +3 -4
  10. package/dest/avm/avm_gas.d.ts.map +1 -1
  11. package/dest/avm/avm_gas.js +2 -3
  12. package/dest/avm/avm_memory_types.d.ts +10 -5
  13. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  14. package/dest/avm/avm_memory_types.js +31 -16
  15. package/dest/avm/avm_simulator.d.ts.map +1 -1
  16. package/dest/avm/avm_simulator.js +5 -2
  17. package/dest/avm/errors.d.ts +1 -1
  18. package/dest/avm/errors.d.ts.map +1 -1
  19. package/dest/avm/errors.js +12 -3
  20. package/dest/avm/fixtures/index.d.ts.map +1 -1
  21. package/dest/avm/fixtures/index.js +4 -4
  22. package/dest/avm/journal/journal.d.ts +2 -1
  23. package/dest/avm/journal/journal.d.ts.map +1 -1
  24. package/dest/avm/journal/journal.js +8 -8
  25. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  26. package/dest/avm/opcodes/accrued_substate.js +54 -47
  27. package/dest/avm/opcodes/addressing_mode.d.ts +3 -2
  28. package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
  29. package/dest/avm/opcodes/addressing_mode.js +25 -21
  30. package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
  31. package/dest/avm/opcodes/arithmetic.js +7 -6
  32. package/dest/avm/opcodes/bitwise.d.ts +3 -3
  33. package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
  34. package/dest/avm/opcodes/bitwise.js +19 -16
  35. package/dest/avm/opcodes/commitment.d.ts.map +1 -1
  36. package/dest/avm/opcodes/commitment.js +6 -5
  37. package/dest/avm/opcodes/comparators.d.ts.map +1 -1
  38. package/dest/avm/opcodes/comparators.js +7 -6
  39. package/dest/avm/opcodes/contract.d.ts.map +1 -1
  40. package/dest/avm/opcodes/contract.js +8 -6
  41. package/dest/avm/opcodes/control_flow.js +7 -7
  42. package/dest/avm/opcodes/conversion.d.ts.map +1 -1
  43. package/dest/avm/opcodes/conversion.js +11 -10
  44. package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
  45. package/dest/avm/opcodes/ec_add.js +25 -15
  46. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  47. package/dest/avm/opcodes/environment_getters.js +6 -5
  48. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  49. package/dest/avm/opcodes/external_calls.js +37 -26
  50. package/dest/avm/opcodes/hashing.d.ts +1 -3
  51. package/dest/avm/opcodes/hashing.d.ts.map +1 -1
  52. package/dest/avm/opcodes/hashing.js +39 -48
  53. package/dest/avm/opcodes/instruction.d.ts +2 -6
  54. package/dest/avm/opcodes/instruction.d.ts.map +1 -1
  55. package/dest/avm/opcodes/instruction.js +3 -9
  56. package/dest/avm/opcodes/instruction_impl.d.ts +1 -2
  57. package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
  58. package/dest/avm/opcodes/instruction_impl.js +2 -5
  59. package/dest/avm/opcodes/memory.d.ts +0 -12
  60. package/dest/avm/opcodes/memory.d.ts.map +1 -1
  61. package/dest/avm/opcodes/memory.js +24 -54
  62. package/dest/avm/opcodes/misc.d.ts.map +1 -1
  63. package/dest/avm/opcodes/misc.js +10 -9
  64. package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
  65. package/dest/avm/opcodes/multi_scalar_mul.js +35 -20
  66. package/dest/avm/opcodes/storage.d.ts.map +1 -1
  67. package/dest/avm/opcodes/storage.js +13 -11
  68. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  69. package/dest/avm/serialization/bytecode_serialization.js +2 -3
  70. package/dest/avm/serialization/instruction_serialization.d.ts +32 -34
  71. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  72. package/dest/avm/serialization/instruction_serialization.js +34 -37
  73. package/dest/avm/test_utils.d.ts +1 -2
  74. package/dest/avm/test_utils.d.ts.map +1 -1
  75. package/dest/avm/test_utils.js +1 -1
  76. package/dest/client/client_execution_context.d.ts +6 -30
  77. package/dest/client/client_execution_context.d.ts.map +1 -1
  78. package/dest/client/client_execution_context.js +36 -54
  79. package/dest/client/db_oracle.d.ts +1 -2
  80. package/dest/client/db_oracle.d.ts.map +1 -1
  81. package/dest/client/db_oracle.js +1 -1
  82. package/dest/client/index.d.ts +1 -1
  83. package/dest/client/index.d.ts.map +1 -1
  84. package/dest/client/index.js +2 -2
  85. package/dest/client/private_execution.d.ts +12 -3
  86. package/dest/client/private_execution.d.ts.map +1 -1
  87. package/dest/client/private_execution.js +29 -23
  88. package/dest/client/simulator.d.ts +2 -3
  89. package/dest/client/simulator.d.ts.map +1 -1
  90. package/dest/client/simulator.js +1 -1
  91. package/dest/client/view_data_oracle.d.ts +1 -2
  92. package/dest/client/view_data_oracle.d.ts.map +1 -1
  93. package/dest/client/view_data_oracle.js +1 -1
  94. package/dest/common/debug_fn_name.d.ts +4 -0
  95. package/dest/common/debug_fn_name.d.ts.map +1 -0
  96. package/dest/common/debug_fn_name.js +15 -0
  97. package/dest/common/index.d.ts +0 -1
  98. package/dest/common/index.d.ts.map +1 -1
  99. package/dest/common/index.js +1 -2
  100. package/dest/public/db_interfaces.d.ts +1 -2
  101. package/dest/public/db_interfaces.d.ts.map +1 -1
  102. package/dest/public/dual_side_effect_trace.d.ts +76 -0
  103. package/dest/public/dual_side_effect_trace.d.ts.map +1 -0
  104. package/dest/public/dual_side_effect_trace.js +109 -0
  105. package/dest/public/enqueued_call_side_effect_trace.d.ts +114 -0
  106. package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -0
  107. package/dest/public/enqueued_call_side_effect_trace.js +314 -0
  108. package/dest/public/enqueued_call_simulator.d.ts +2 -2
  109. package/dest/public/enqueued_call_simulator.d.ts.map +1 -1
  110. package/dest/public/enqueued_call_simulator.js +20 -10
  111. package/dest/public/enqueued_calls_processor.d.ts +2 -2
  112. package/dest/public/enqueued_calls_processor.d.ts.map +1 -1
  113. package/dest/public/enqueued_calls_processor.js +3 -5
  114. package/dest/public/execution.d.ts +11 -5
  115. package/dest/public/execution.d.ts.map +1 -1
  116. package/dest/public/execution.js +13 -1
  117. package/dest/public/executor.d.ts +7 -6
  118. package/dest/public/executor.d.ts.map +1 -1
  119. package/dest/public/executor.js +24 -15
  120. package/dest/public/fee_payment.d.ts +1 -1
  121. package/dest/public/fee_payment.d.ts.map +1 -1
  122. package/dest/public/fee_payment.js +4 -7
  123. package/dest/public/hints_builder.d.ts +2 -2
  124. package/dest/public/hints_builder.d.ts.map +1 -1
  125. package/dest/public/hints_builder.js +2 -2
  126. package/dest/public/public_db_sources.d.ts +4 -5
  127. package/dest/public/public_db_sources.d.ts.map +1 -1
  128. package/dest/public/public_db_sources.js +15 -11
  129. package/dest/public/public_kernel_tail_simulator.d.ts +3 -3
  130. package/dest/public/public_kernel_tail_simulator.d.ts.map +1 -1
  131. package/dest/public/public_kernel_tail_simulator.js +1 -1
  132. package/dest/public/public_processor.d.ts +7 -10
  133. package/dest/public/public_processor.d.ts.map +1 -1
  134. package/dest/public/public_processor.js +9 -10
  135. package/dest/public/side_effect_errors.d.ts +4 -0
  136. package/dest/public/side_effect_errors.d.ts.map +1 -0
  137. package/dest/public/side_effect_errors.js +7 -0
  138. package/dest/public/side_effect_trace.d.ts +3 -4
  139. package/dest/public/side_effect_trace.d.ts.map +1 -1
  140. package/dest/public/side_effect_trace.js +54 -29
  141. package/dest/public/side_effect_trace_interface.d.ts +1 -1
  142. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  143. package/package.json +12 -9
  144. package/src/acvm/oracle/oracle.ts +8 -86
  145. package/src/acvm/oracle/typed_oracle.ts +8 -33
  146. package/src/avm/avm_execution_environment.ts +1 -3
  147. package/src/avm/avm_gas.ts +1 -2
  148. package/src/avm/avm_memory_types.ts +38 -16
  149. package/src/avm/avm_simulator.ts +7 -1
  150. package/src/avm/errors.ts +11 -3
  151. package/src/avm/fixtures/index.ts +2 -3
  152. package/src/avm/journal/journal.ts +14 -10
  153. package/src/avm/opcodes/accrued_substate.ts +53 -61
  154. package/src/avm/opcodes/addressing_mode.ts +27 -24
  155. package/src/avm/opcodes/arithmetic.ts +6 -8
  156. package/src/avm/opcodes/bitwise.ts +18 -18
  157. package/src/avm/opcodes/commitment.ts +6 -7
  158. package/src/avm/opcodes/comparators.ts +6 -8
  159. package/src/avm/opcodes/contract.ts +7 -8
  160. package/src/avm/opcodes/control_flow.ts +6 -6
  161. package/src/avm/opcodes/conversion.ts +10 -12
  162. package/src/avm/opcodes/ec_add.ts +29 -24
  163. package/src/avm/opcodes/environment_getters.ts +5 -4
  164. package/src/avm/opcodes/external_calls.ts +37 -30
  165. package/src/avm/opcodes/hashing.ts +38 -63
  166. package/src/avm/opcodes/instruction.ts +3 -10
  167. package/src/avm/opcodes/instruction_impl.ts +0 -3
  168. package/src/avm/opcodes/memory.ts +23 -67
  169. package/src/avm/opcodes/misc.ts +9 -11
  170. package/src/avm/opcodes/multi_scalar_mul.ts +31 -26
  171. package/src/avm/opcodes/storage.ts +12 -10
  172. package/src/avm/serialization/bytecode_serialization.ts +0 -2
  173. package/src/avm/serialization/instruction_serialization.ts +1 -4
  174. package/src/avm/test_utils.ts +1 -2
  175. package/src/client/client_execution_context.ts +46 -97
  176. package/src/client/db_oracle.ts +6 -2
  177. package/src/client/index.ts +1 -1
  178. package/src/client/private_execution.ts +45 -15
  179. package/src/client/simulator.ts +2 -3
  180. package/src/client/view_data_oracle.ts +1 -2
  181. package/src/common/debug_fn_name.ts +22 -0
  182. package/src/common/index.ts +0 -1
  183. package/src/public/db_interfaces.ts +5 -2
  184. package/src/public/dual_side_effect_trace.ts +173 -0
  185. package/src/public/enqueued_call_side_effect_trace.ts +552 -0
  186. package/src/public/enqueued_call_simulator.ts +35 -14
  187. package/src/public/enqueued_calls_processor.ts +4 -6
  188. package/src/public/execution.ts +15 -6
  189. package/src/public/executor.ts +42 -19
  190. package/src/public/fee_payment.ts +4 -6
  191. package/src/public/hints_builder.ts +9 -11
  192. package/src/public/public_db_sources.ts +31 -22
  193. package/src/public/public_kernel_tail_simulator.ts +3 -3
  194. package/src/public/public_processor.ts +17 -13
  195. package/src/public/side_effect_errors.ts +6 -0
  196. package/src/public/side_effect_trace.ts +74 -29
  197. package/src/public/side_effect_trace_interface.ts +2 -2
  198. package/dest/client/execution_result.d.ts +0 -104
  199. package/dest/client/execution_result.d.ts.map +0 -1
  200. package/dest/client/execution_result.js +0 -136
  201. package/dest/common/return_values.d.ts +0 -11
  202. package/dest/common/return_values.d.ts.map +0 -1
  203. package/dest/common/return_values.js +0 -13
  204. package/src/client/execution_result.ts +0 -228
  205. package/src/common/return_values.ts +0 -18
@@ -1,8 +1,7 @@
1
1
  import { MerkleTreeId, UnencryptedL2Log } from '@aztec/circuit-types';
2
- import { KeyValidationRequest } from '@aztec/circuits.js';
3
2
  import { FunctionSelector, NoteSelector } from '@aztec/foundation/abi';
4
3
  import { AztecAddress } from '@aztec/foundation/aztec-address';
5
- import { Fr, Point } from '@aztec/foundation/fields';
4
+ import { Fr } from '@aztec/foundation/fields';
6
5
 
7
6
  import { type ACVMField } from '../acvm_types.js';
8
7
  import { frToBoolean, frToNumber, fromACVMField } from '../deserialize.js';
@@ -71,7 +70,7 @@ export class Oracle {
71
70
  instance.deployer,
72
71
  instance.contractClassId,
73
72
  instance.initializationHash,
74
- instance.publicKeysHash,
73
+ ...instance.publicKeys.toFields(),
75
74
  ].map(toACVMField);
76
75
  }
77
76
 
@@ -329,72 +328,6 @@ export class Oracle {
329
328
  this.typedOracle.emitEncryptedNoteLog(+noteHashCounter, processedInput, +counter);
330
329
  }
331
330
 
332
- computeEncryptedEventLog(
333
- [contractAddress]: ACVMField[],
334
- [randomness]: ACVMField[],
335
- [eventTypeId]: ACVMField[],
336
- [ovskApp]: ACVMField[],
337
- [ovpkMX]: ACVMField[],
338
- [ovpkMY]: ACVMField[],
339
- [ovpkMIsInfinite]: ACVMField[],
340
- [ivpkMX]: ACVMField[],
341
- [ivpkMY]: ACVMField[],
342
- [ivpkMIsInfinite]: ACVMField[],
343
- [recipient]: ACVMField[],
344
- preimage: ACVMField[],
345
- ): ACVMField[] {
346
- const ovpkM = new Point(fromACVMField(ovpkMX), fromACVMField(ovpkMY), !fromACVMField(ovpkMIsInfinite).isZero());
347
- const ovKeys = new KeyValidationRequest(ovpkM, Fr.fromString(ovskApp));
348
- const ivpkM = new Point(fromACVMField(ivpkMX), fromACVMField(ivpkMY), !fromACVMField(ivpkMIsInfinite).isZero());
349
- const encLog = this.typedOracle.computeEncryptedEventLog(
350
- AztecAddress.fromString(contractAddress),
351
- Fr.fromString(randomness),
352
- Fr.fromString(eventTypeId),
353
- ovKeys,
354
- ivpkM,
355
- AztecAddress.fromString(recipient),
356
- preimage.map(fromACVMField),
357
- );
358
- const bytes: ACVMField[] = [];
359
- encLog.forEach(v => {
360
- bytes.push(toACVMField(v));
361
- });
362
- return bytes;
363
- }
364
-
365
- computeEncryptedNoteLog(
366
- [contractAddress]: ACVMField[],
367
- [storageSlot]: ACVMField[],
368
- [noteTypeId]: ACVMField[],
369
- [ovskApp]: ACVMField[],
370
- [ovpkMX]: ACVMField[],
371
- [ovpkMY]: ACVMField[],
372
- [ovpkMIsInfinite]: ACVMField[],
373
- [ivpkMX]: ACVMField[],
374
- [ivpkMY]: ACVMField[],
375
- [ivpkMIsInfinite]: ACVMField[],
376
- [recipient]: ACVMField[],
377
- preimage: ACVMField[],
378
- ): ACVMField[] {
379
- const ovpkM = new Point(fromACVMField(ovpkMX), fromACVMField(ovpkMY), !fromACVMField(ovpkMIsInfinite).isZero());
380
- const ovKeys = new KeyValidationRequest(ovpkM, Fr.fromString(ovskApp));
381
- const ivpkM = new Point(fromACVMField(ivpkMX), fromACVMField(ivpkMY), !fromACVMField(ivpkMIsInfinite).isZero());
382
- const encLog = this.typedOracle.computeEncryptedNoteLog(
383
- AztecAddress.fromString(contractAddress),
384
- Fr.fromString(storageSlot),
385
- NoteSelector.fromField(Fr.fromString(noteTypeId)),
386
- ovKeys,
387
- ivpkM,
388
- AztecAddress.fromString(recipient),
389
- preimage.map(fromACVMField),
390
- );
391
- const bytes: ACVMField[] = [];
392
- encLog.forEach(v => {
393
- bytes.push(toACVMField(v));
394
- });
395
- return bytes;
396
- }
397
-
398
331
  emitUnencryptedLog([contractAddress]: ACVMField[], message: ACVMField[], [counter]: ACVMField[]): ACVMField {
399
332
  const logPayload = Buffer.concat(message.map(fromACVMField).map(f => f.toBuffer()));
400
333
  const log = new UnencryptedL2Log(AztecAddress.fromString(contractAddress), logPayload);
@@ -447,8 +380,8 @@ export class Oracle {
447
380
  [sideEffectCounter]: ACVMField[],
448
381
  [isStaticCall]: ACVMField[],
449
382
  [isDelegateCall]: ACVMField[],
450
- ) {
451
- await this.typedOracle.enqueuePublicFunctionCall(
383
+ ): Promise<ACVMField> {
384
+ const newArgsHash = await this.typedOracle.enqueuePublicFunctionCall(
452
385
  AztecAddress.fromString(contractAddress),
453
386
  FunctionSelector.fromField(fromACVMField(functionSelector)),
454
387
  fromACVMField(argsHash),
@@ -456,6 +389,7 @@ export class Oracle {
456
389
  frToBoolean(fromACVMField(isStaticCall)),
457
390
  frToBoolean(fromACVMField(isDelegateCall)),
458
391
  );
392
+ return toACVMField(newArgsHash);
459
393
  }
460
394
 
461
395
  async setPublicTeardownFunctionCall(
@@ -465,8 +399,8 @@ export class Oracle {
465
399
  [sideEffectCounter]: ACVMField[],
466
400
  [isStaticCall]: ACVMField[],
467
401
  [isDelegateCall]: ACVMField[],
468
- ) {
469
- await this.typedOracle.setPublicTeardownFunctionCall(
402
+ ): Promise<ACVMField> {
403
+ const newArgsHash = await this.typedOracle.setPublicTeardownFunctionCall(
470
404
  AztecAddress.fromString(contractAddress),
471
405
  FunctionSelector.fromField(fromACVMField(functionSelector)),
472
406
  fromACVMField(argsHash),
@@ -474,22 +408,10 @@ export class Oracle {
474
408
  frToBoolean(fromACVMField(isStaticCall)),
475
409
  frToBoolean(fromACVMField(isDelegateCall)),
476
410
  );
411
+ return toACVMField(newArgsHash);
477
412
  }
478
413
 
479
414
  notifySetMinRevertibleSideEffectCounter([minRevertibleSideEffectCounter]: ACVMField[]) {
480
415
  this.typedOracle.notifySetMinRevertibleSideEffectCounter(frToNumber(fromACVMField(minRevertibleSideEffectCounter)));
481
416
  }
482
-
483
- aes128Encrypt(input: ACVMField[], initializationVector: ACVMField[], key: ACVMField[]): ACVMField[] {
484
- // Convert each field to a number and then to a buffer (1 byte is stored in 1 field)
485
- const processedInput = Buffer.from(input.map(fromACVMField).map(f => f.toNumber()));
486
- const processedIV = Buffer.from(initializationVector.map(fromACVMField).map(f => f.toNumber()));
487
- const processedKey = Buffer.from(key.map(fromACVMField).map(f => f.toNumber()));
488
-
489
- // Encrypt the input
490
- const ciphertext = this.typedOracle.aes128Encrypt(processedInput, processedIV, processedKey);
491
-
492
- // Convert each byte of ciphertext to a field and return it
493
- return Array.from(ciphertext).map(byte => toACVMField(byte));
494
- }
495
417
  }
@@ -5,15 +5,18 @@ import {
5
5
  type NoteStatus,
6
6
  type NullifierMembershipWitness,
7
7
  type PublicDataWitness,
8
- type PublicKey,
9
8
  type SiblingPath,
10
9
  type UnencryptedL2Log,
11
10
  } from '@aztec/circuit-types';
12
- import { type Header, type KeyValidationRequest, type L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/circuits.js';
11
+ import {
12
+ type ContractInstance,
13
+ type Header,
14
+ type KeyValidationRequest,
15
+ type L1_TO_L2_MSG_TREE_HEIGHT,
16
+ } from '@aztec/circuits.js';
13
17
  import { type FunctionSelector, type NoteSelector } from '@aztec/foundation/abi';
14
18
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
15
19
  import { Fr } from '@aztec/foundation/fields';
16
- import { type ContractInstance } from '@aztec/types/contracts';
17
20
 
18
21
  /**
19
22
  * Information about a note needed during execution.
@@ -204,30 +207,6 @@ export abstract class TypedOracle {
204
207
  throw new OracleMethodNotAvailableError('emitEncryptedNoteLog');
205
208
  }
206
209
 
207
- computeEncryptedEventLog(
208
- _contractAddress: AztecAddress,
209
- _randomness: Fr,
210
- _eventTypeId: Fr,
211
- _ovKeys: KeyValidationRequest,
212
- _ivpkM: PublicKey,
213
- _recipient: AztecAddress,
214
- _preimage: Fr[],
215
- ): Buffer {
216
- throw new OracleMethodNotAvailableError('computeEncryptedEventLog');
217
- }
218
-
219
- computeEncryptedNoteLog(
220
- _contractAddress: AztecAddress,
221
- _storageSlot: Fr,
222
- _noteTypeId: NoteSelector,
223
- _ovKeys: KeyValidationRequest,
224
- _ivpkM: PublicKey,
225
- _recipient: AztecAddress,
226
- _preimage: Fr[],
227
- ): Buffer {
228
- throw new OracleMethodNotAvailableError('computeEncryptedNoteLog');
229
- }
230
-
231
210
  emitUnencryptedLog(_log: UnencryptedL2Log, _counter: number): void {
232
211
  throw new OracleMethodNotAvailableError('emitUnencryptedLog');
233
212
  }
@@ -254,7 +233,7 @@ export abstract class TypedOracle {
254
233
  _sideEffectCounter: number,
255
234
  _isStaticCall: boolean,
256
235
  _isDelegateCall: boolean,
257
- ): Promise<void> {
236
+ ): Promise<Fr> {
258
237
  throw new OracleMethodNotAvailableError('enqueuePublicFunctionCall');
259
238
  }
260
239
 
@@ -265,7 +244,7 @@ export abstract class TypedOracle {
265
244
  _sideEffectCounter: number,
266
245
  _isStaticCall: boolean,
267
246
  _isDelegateCall: boolean,
268
- ): Promise<void> {
247
+ ): Promise<Fr> {
269
248
  throw new OracleMethodNotAvailableError('setPublicTeardownFunctionCall');
270
249
  }
271
250
 
@@ -273,10 +252,6 @@ export abstract class TypedOracle {
273
252
  throw new OracleMethodNotAvailableError('notifySetMinRevertibleSideEffectCounter');
274
253
  }
275
254
 
276
- aes128Encrypt(_input: Buffer, _initializationVector: Buffer, _key: Buffer): Buffer {
277
- throw new OracleMethodNotAvailableError('encrypt');
278
- }
279
-
280
255
  debugLog(_message: string, _fields: Fr[]): void {
281
256
  throw new OracleMethodNotAvailableError('debugLog');
282
257
  }
@@ -1,4 +1,4 @@
1
- import { FunctionSelector, type GlobalVariables, type Header } from '@aztec/circuits.js';
1
+ import { FunctionSelector, type GlobalVariables } from '@aztec/circuits.js';
2
2
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
3
3
  import { Fr } from '@aztec/foundation/fields';
4
4
 
@@ -14,7 +14,6 @@ export class AvmExecutionEnvironment {
14
14
  public readonly functionSelector: FunctionSelector, // may be temporary (#7224)
15
15
  public readonly contractCallDepth: Fr,
16
16
  public readonly transactionFee: Fr,
17
- public readonly header: Header,
18
17
  public readonly globals: GlobalVariables,
19
18
  public readonly isStaticCall: boolean,
20
19
  public readonly isDelegateCall: boolean,
@@ -35,7 +34,6 @@ export class AvmExecutionEnvironment {
35
34
  functionSelector,
36
35
  this.contractCallDepth.add(Fr.ONE),
37
36
  this.transactionFee,
38
- this.header,
39
37
  this.globals,
40
38
  isStaticCall,
41
39
  isDelegateCall,
@@ -101,7 +101,6 @@ const BASE_GAS_COSTS: Record<Opcode, Gas> = {
101
101
  [Opcode.SET_FF]: makeCost(c.AVM_SET_BASE_L2_GAS, 0),
102
102
  [Opcode.MOV_8]: makeCost(c.AVM_MOV_BASE_L2_GAS, 0),
103
103
  [Opcode.MOV_16]: makeCost(c.AVM_MOV_BASE_L2_GAS, 0),
104
- [Opcode.CMOV]: makeCost(c.AVM_CMOV_BASE_L2_GAS, 0),
105
104
  [Opcode.SLOAD]: makeCost(c.AVM_SLOAD_BASE_L2_GAS, 0),
106
105
  [Opcode.SSTORE]: makeCost(c.AVM_SSTORE_BASE_L2_GAS, c.AVM_SSTORE_BASE_DA_GAS),
107
106
  [Opcode.NOTEHASHEXISTS]: makeCost(c.AVM_NOTEHASHEXISTS_BASE_L2_GAS, 0),
@@ -181,6 +180,7 @@ export function getGasCostForTypeTag(tag: TypeTag, baseCost: Gas) {
181
180
  function getGasCostMultiplierFromTypeTag(tag: TypeTag) {
182
181
  switch (tag) {
183
182
  case TypeTag.UINT1: // same as u8
183
+ return 1;
184
184
  case TypeTag.UINT8:
185
185
  return 1;
186
186
  case TypeTag.UINT16:
@@ -194,7 +194,6 @@ function getGasCostMultiplierFromTypeTag(tag: TypeTag) {
194
194
  case TypeTag.FIELD:
195
195
  return 32;
196
196
  case TypeTag.INVALID:
197
- case TypeTag.UNINITIALIZED:
198
197
  throw new InstructionExecutionError(`Invalid tag type for gas cost multiplier: ${TypeTag[tag]}`);
199
198
  }
200
199
  }
@@ -208,21 +208,19 @@ export class Field extends MemoryValue {
208
208
  }
209
209
 
210
210
  export enum TypeTag {
211
- UNINITIALIZED,
211
+ FIELD = MEM_TAG_FF,
212
212
  UINT1 = MEM_TAG_U1,
213
213
  UINT8 = MEM_TAG_U8,
214
214
  UINT16 = MEM_TAG_U16,
215
215
  UINT32 = MEM_TAG_U32,
216
216
  UINT64 = MEM_TAG_U64,
217
217
  UINT128 = MEM_TAG_U128,
218
- FIELD = MEM_TAG_FF,
219
218
  INVALID,
220
219
  }
221
220
 
222
221
  // Lazy interface definition for tagged memory
223
222
  export type TaggedMemoryInterface = FunctionsOf<TaggedMemory>;
224
223
 
225
- // TODO: Consider automatic conversion when getting undefined values.
226
224
  export class TaggedMemory implements TaggedMemoryInterface {
227
225
  static readonly log: DebugLogger = createDebugLogger('aztec:avm_simulator:memory');
228
226
 
@@ -255,6 +253,7 @@ export class TaggedMemory implements TaggedMemoryInterface {
255
253
  TaggedMemory.log.debug(`get(${offset}) = ${word}`);
256
254
  if (word === undefined) {
257
255
  TaggedMemory.log.debug(`WARNING: Memory at offset ${offset} is undefined!`);
256
+ return new Field(0) as T;
258
257
  }
259
258
  return word as T;
260
259
  }
@@ -264,7 +263,11 @@ export class TaggedMemory implements TaggedMemoryInterface {
264
263
  assert(offset + size < TaggedMemory.MAX_MEMORY_SIZE);
265
264
  const value = this._mem.slice(offset, offset + size);
266
265
  TaggedMemory.log.debug(`getSlice(${offset}, ${size}) = ${value}`);
267
- assert(!value.some(e => e === undefined), 'Memory slice contains undefined values.');
266
+ for (let i = 0; i < value.length; i++) {
267
+ if (value[i] === undefined) {
268
+ value[i] = new Field(0);
269
+ }
270
+ }
268
271
  assert(value.length === size, `Expected slice of size ${size}, got ${value.length}.`);
269
272
  return value;
270
273
  }
@@ -332,6 +335,16 @@ export class TaggedMemory implements TaggedMemoryInterface {
332
335
  }
333
336
  }
334
337
 
338
+ /**
339
+ * Check that all tags at the given offsets are the same.
340
+ */
341
+ public checkTagsAreSame(...offsets: number[]) {
342
+ const tag = this.getTag(offsets[0]);
343
+ for (let i = 1; i < offsets.length; i++) {
344
+ this.checkTag(tag, offsets[i]);
345
+ }
346
+ }
347
+
335
348
  /**
336
349
  * Check tags for all memory in the specified range.
337
350
  */
@@ -347,7 +360,9 @@ export class TaggedMemory implements TaggedMemoryInterface {
347
360
  let tag = TypeTag.INVALID;
348
361
 
349
362
  if (v === undefined) {
350
- tag = TypeTag.UNINITIALIZED;
363
+ tag = TypeTag.FIELD; // uninitialized memory is Field(0)
364
+ } else if (v instanceof Field) {
365
+ tag = TypeTag.FIELD;
351
366
  } else if (v instanceof Uint1) {
352
367
  tag = TypeTag.UINT1;
353
368
  } else if (v instanceof Uint8) {
@@ -360,8 +375,6 @@ export class TaggedMemory implements TaggedMemoryInterface {
360
375
  tag = TypeTag.UINT64;
361
376
  } else if (v instanceof Uint128) {
362
377
  tag = TypeTag.UINT128;
363
- } else if (v instanceof Field) {
364
- tag = TypeTag.FIELD;
365
378
  }
366
379
 
367
380
  return tag;
@@ -371,6 +384,8 @@ export class TaggedMemory implements TaggedMemoryInterface {
371
384
  public static buildFromTagTruncating(v: bigint | number, tag: TypeTag): MemoryValue {
372
385
  v = BigInt(v);
373
386
  switch (tag) {
387
+ case TypeTag.FIELD:
388
+ return new Field(v);
374
389
  case TypeTag.UINT1:
375
390
  return new Uint1(v & 1n);
376
391
  case TypeTag.UINT8:
@@ -383,8 +398,6 @@ export class TaggedMemory implements TaggedMemoryInterface {
383
398
  return new Uint64(v & ((1n << 64n) - 1n));
384
399
  case TypeTag.UINT128:
385
400
  return new Uint128(v & ((1n << 128n) - 1n));
386
- case TypeTag.FIELD:
387
- return new Field(v);
388
401
  default:
389
402
  throw new Error(`${TypeTag[tag]} is not a valid tag.`);
390
403
  }
@@ -393,6 +406,8 @@ export class TaggedMemory implements TaggedMemoryInterface {
393
406
  // Does not truncate. Type constructor will check that it fits.
394
407
  public static buildFromTagOrDie(v: bigint | number, tag: TypeTag): MemoryValue {
395
408
  switch (tag) {
409
+ case TypeTag.FIELD:
410
+ return new Field(v);
396
411
  case TypeTag.UINT1:
397
412
  return new Uint1(v);
398
413
  case TypeTag.UINT8:
@@ -405,15 +420,13 @@ export class TaggedMemory implements TaggedMemoryInterface {
405
420
  return new Uint64(v);
406
421
  case TypeTag.UINT128:
407
422
  return new Uint128(v);
408
- case TypeTag.FIELD:
409
- return new Field(v);
410
423
  default:
411
424
  throw new Error(`${TypeTag[tag]} is not a valid integral type.`);
412
425
  }
413
426
  }
414
427
 
415
428
  /** No-op. Implemented here for compatibility with the MeteredTaggedMemory. */
416
- public assert(_operations: Partial<MemoryOperations & { indirect: number }>) {}
429
+ public assert(_operations: Partial<MemoryOperations & { addressing: Addressing }>) {}
417
430
  }
418
431
 
419
432
  /** Tagged memory wrapper with metering for each memory read and write operation. */
@@ -435,10 +448,15 @@ export class MeteredTaggedMemory implements TaggedMemoryInterface {
435
448
  * Asserts that the exact number of memory operations have been performed.
436
449
  * Indirect represents the flags for indirect accesses: each bit set to one counts as an extra read.
437
450
  */
438
- public assert(operations: Partial<MemoryOperations & { indirect: number }>) {
439
- const { reads: expectedReads, writes: expectedWrites, indirect } = { reads: 0, writes: 0, ...operations };
440
-
441
- const totalExpectedReads = expectedReads + Addressing.fromWire(indirect ?? 0).count(AddressingMode.INDIRECT);
451
+ public assert(operations: Partial<MemoryOperations & { addressing: Addressing }>) {
452
+ const {
453
+ reads: expectedReads,
454
+ writes: expectedWrites,
455
+ addressing,
456
+ } = { reads: 0, writes: 0, addressing: new Addressing([]), ...operations };
457
+
458
+ const totalExpectedReads =
459
+ expectedReads + addressing.count(AddressingMode.INDIRECT) + addressing.count(AddressingMode.RELATIVE);
442
460
  const { reads: actualReads, writes: actualWrites } = this.reset();
443
461
  if (actualReads !== totalExpectedReads) {
444
462
  throw new InstructionExecutionError(
@@ -506,6 +524,10 @@ export class MeteredTaggedMemory implements TaggedMemoryInterface {
506
524
  this.wrapped.checkTags(tag, ...offsets);
507
525
  }
508
526
 
527
+ public checkTagsAreSame(...offsets: number[]): void {
528
+ this.wrapped.checkTagsAreSame(...offsets);
529
+ }
530
+
509
531
  public checkTagsRange(tag: TypeTag, startOffset: number, size: number): void {
510
532
  this.wrapped.checkTagsRange(tag, startOffset, size);
511
533
  }
@@ -1,7 +1,9 @@
1
+ import { MAX_L2_GAS_PER_ENQUEUED_CALL } from '@aztec/circuits.js';
1
2
  import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
2
3
 
3
4
  import { strict as assert } from 'assert';
4
5
 
6
+ import { SideEffectLimitReachedError } from '../public/side_effect_errors.js';
5
7
  import type { AvmContext } from './avm_context.js';
6
8
  import { AvmContractCallResult } from './avm_contract_call_result.js';
7
9
  import { isAvmBytecode } from './bytecode_utils.js';
@@ -20,6 +22,10 @@ export class AvmSimulator {
20
22
  private bytecode: Buffer | undefined;
21
23
 
22
24
  constructor(private context: AvmContext) {
25
+ assert(
26
+ context.machineState.gasLeft.l2Gas <= MAX_L2_GAS_PER_ENQUEUED_CALL,
27
+ `Cannot allocate more than ${MAX_L2_GAS_PER_ENQUEUED_CALL} to the AVM for execution of an enqueued call`,
28
+ );
23
29
  this.log = createDebugLogger(`aztec:avm_simulator:core(f:${context.environment.functionSelector.toString()})`);
24
30
  }
25
31
 
@@ -98,7 +104,7 @@ export class AvmSimulator {
98
104
  return results;
99
105
  } catch (err: any) {
100
106
  this.log.verbose('Exceptional halt (revert by something other than REVERT opcode)');
101
- if (!(err instanceof AvmExecutionError)) {
107
+ if (!(err instanceof AvmExecutionError || err instanceof SideEffectLimitReachedError)) {
102
108
  this.log.verbose(`Unknown error thrown by AVM: ${err}`);
103
109
  throw err;
104
110
  }
package/src/avm/errors.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type FailingFunction, type NoirCallStack } from '@aztec/circuit-types';
2
- import { type AztecAddress, type Fr } from '@aztec/circuits.js';
2
+ import { type AztecAddress, Fr, FunctionSelector, PUBLIC_DISPATCH_SELECTOR } from '@aztec/circuits.js';
3
3
 
4
4
  import { ExecutionError } from '../common/errors.js';
5
5
  import { type AvmContext } from './avm_context.js';
@@ -109,13 +109,21 @@ export class AvmRevertReason extends ExecutionError {
109
109
  * @param nestedError - the error that caused this one (if this is not the root-cause itself)
110
110
  */
111
111
  function createRevertReason(message: string, context: AvmContext, nestedError?: AvmRevertReason): AvmRevertReason {
112
+ // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Properly fix this.
113
+ // If the function selector is the public dispatch selector, we need to extract the actual function selector from the calldata.
114
+ // We should remove this because the AVM (or public protocol) shouldn't be aware of the public dispatch calling convention.
115
+ let functionSelector = context.environment.functionSelector;
116
+ const internalCallStack = context.machineState.internalCallStack;
117
+ if (functionSelector.toField().equals(new Fr(PUBLIC_DISPATCH_SELECTOR)) && context.environment.calldata.length > 0) {
118
+ functionSelector = FunctionSelector.fromField(context.environment.calldata[0]);
119
+ }
112
120
  return new AvmRevertReason(
113
121
  message,
114
122
  /*failingFunction=*/ {
115
123
  contractAddress: context.environment.address,
116
- functionSelector: context.environment.functionSelector,
124
+ functionSelector: functionSelector,
117
125
  },
118
- /*noirCallStack=*/ [...context.machineState.internalCallStack, context.machineState.pc].map(pc => `0.${pc}`),
126
+ /*noirCallStack=*/ [...internalCallStack, context.machineState.pc].map(pc => `0.${pc}`),
119
127
  /*options=*/ { cause: nestedError },
120
128
  );
121
129
  }
@@ -1,5 +1,5 @@
1
1
  import { isNoirCallStackUnresolved } from '@aztec/circuit-types';
2
- import { GasFees, GlobalVariables, Header } from '@aztec/circuits.js';
2
+ import { GasFees, GlobalVariables, MAX_L2_GAS_PER_ENQUEUED_CALL } from '@aztec/circuits.js';
3
3
  import { FunctionSelector, getFunctionDebugMetadata } from '@aztec/foundation/abi';
4
4
  import { AztecAddress } from '@aztec/foundation/aztec-address';
5
5
  import { EthAddress } from '@aztec/foundation/eth-address';
@@ -63,7 +63,6 @@ export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnviron
63
63
  overrides?.functionSelector ?? FunctionSelector.empty(),
64
64
  overrides?.contractCallDepth ?? Fr.zero(),
65
65
  overrides?.transactionFee ?? Fr.zero(),
66
- overrides?.header ?? Header.empty(),
67
66
  overrides?.globals ?? GlobalVariables.empty(),
68
67
  overrides?.isStaticCall ?? false,
69
68
  overrides?.isDelegateCall ?? false,
@@ -92,7 +91,7 @@ export function initGlobalVariables(overrides?: Partial<GlobalVariables>): Globa
92
91
  */
93
92
  export function initMachineState(overrides?: Partial<AvmMachineState>): AvmMachineState {
94
93
  return AvmMachineState.fromState({
95
- l2GasLeft: overrides?.l2GasLeft ?? 1e8,
94
+ l2GasLeft: overrides?.l2GasLeft ?? MAX_L2_GAS_PER_ENQUEUED_CALL,
96
95
  daGasLeft: overrides?.daGasLeft ?? 1e8,
97
96
  });
98
97
  }
@@ -1,8 +1,8 @@
1
- import { AztecAddress, type FunctionSelector, type Gas } from '@aztec/circuits.js';
1
+ import { AztecAddress, type FunctionSelector, type Gas, SerializableContractInstance } from '@aztec/circuits.js';
2
2
  import { Fr } from '@aztec/foundation/fields';
3
- import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
4
- import { SerializableContractInstance } from '@aztec/types/contracts';
3
+ import { createDebugLogger } from '@aztec/foundation/log';
5
4
 
5
+ import { getPublicFunctionDebugName } from '../../common/debug_fn_name.js';
6
6
  import { type WorldStateDB } from '../../public/public_db_sources.js';
7
7
  import { type TracedContractInstance } from '../../public/side_effect_trace.js';
8
8
  import { type PublicSideEffectTraceInterface } from '../../public/side_effect_trace_interface.js';
@@ -21,7 +21,7 @@ import { PublicStorage } from './public_storage.js';
21
21
  * Manages merging of successful/reverted child state into current state.
22
22
  */
23
23
  export class AvmPersistableStateManager {
24
- private readonly log: DebugLogger = createDebugLogger('aztec:avm_simulator:state_manager');
24
+ private readonly log = createDebugLogger('aztec:avm_simulator:state_manager');
25
25
 
26
26
  constructor(
27
27
  /** Reference to node storage */
@@ -187,12 +187,13 @@ export class AvmPersistableStateManager {
187
187
 
188
188
  /**
189
189
  * Write an L2 to L1 message.
190
+ * @param contractAddress - L2 contract address that created this message
190
191
  * @param recipient - L1 contract address to send the message to.
191
192
  * @param content - Message content.
192
193
  */
193
- public writeL2ToL1Message(recipient: Fr, content: Fr) {
194
- this.log.debug(`L1Messages(${recipient}) += ${content}.`);
195
- this.trace.traceNewL2ToL1Message(recipient, content);
194
+ public writeL2ToL1Message(contractAddress: Fr, recipient: Fr, content: Fr) {
195
+ this.log.debug(`L2ToL1Messages(${contractAddress}) += (recipient: ${recipient}, content: ${content}).`);
196
+ this.trace.traceNewL2ToL1Message(contractAddress, recipient, content);
196
197
  }
197
198
 
198
199
  /**
@@ -256,9 +257,12 @@ export class AvmPersistableStateManager {
256
257
  if (!avmCallResults.reverted) {
257
258
  this.acceptNestedCallState(nestedState);
258
259
  }
259
- const functionName =
260
- (await this.worldStateDB.getDebugFunctionName(nestedEnvironment.address, nestedEnvironment.functionSelector)) ??
261
- `${nestedEnvironment.address}:${nestedEnvironment.functionSelector}`;
260
+ const functionName = await getPublicFunctionDebugName(
261
+ this.worldStateDB,
262
+ nestedEnvironment.address,
263
+ nestedEnvironment.functionSelector,
264
+ nestedEnvironment.calldata,
265
+ );
262
266
 
263
267
  this.log.verbose(`[AVM] Calling nested function ${functionName}`);
264
268