@aztec/simulator 0.0.1-commit.3469e52 → 0.0.1-commit.3895657bc

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 (184) hide show
  1. package/README.md +4 -4
  2. package/dest/private/acvm/acvm.d.ts +4 -2
  3. package/dest/private/acvm/acvm.d.ts.map +1 -1
  4. package/dest/private/acvm/acvm.js +4 -3
  5. package/dest/private/acvm_native.d.ts +5 -3
  6. package/dest/private/acvm_native.d.ts.map +1 -1
  7. package/dest/private/acvm_native.js +8 -6
  8. package/dest/private/acvm_wasm.d.ts +4 -3
  9. package/dest/private/acvm_wasm.d.ts.map +1 -1
  10. package/dest/private/acvm_wasm.js +4 -4
  11. package/dest/private/circuit_recording/circuit_recorder.d.ts +4 -3
  12. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  13. package/dest/private/circuit_recording/circuit_recorder.js +7 -5
  14. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +3 -2
  15. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  16. package/dest/private/circuit_recording/file_circuit_recorder.js +2 -2
  17. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  18. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  19. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  20. package/dest/private/factory.d.ts +3 -3
  21. package/dest/private/factory.d.ts.map +1 -1
  22. package/dest/private/factory.js +7 -4
  23. package/dest/public/avm/avm_context.d.ts +3 -3
  24. package/dest/public/avm/avm_context.d.ts.map +1 -1
  25. package/dest/public/avm/avm_contract_call_result.d.ts +6 -6
  26. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  27. package/dest/public/avm/avm_contract_call_result.js +3 -3
  28. package/dest/public/avm/avm_execution_environment.d.ts +6 -5
  29. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  30. package/dest/public/avm/avm_gas.js +3 -3
  31. package/dest/public/avm/avm_machine_state.d.ts +6 -5
  32. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  33. package/dest/public/avm/avm_machine_state.js +3 -2
  34. package/dest/public/avm/avm_memory_types.d.ts +1 -1
  35. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  36. package/dest/public/avm/avm_memory_types.js +3 -0
  37. package/dest/public/avm/avm_simulator.d.ts +3 -2
  38. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  39. package/dest/public/avm/avm_simulator.js +5 -4
  40. package/dest/public/avm/calldata.d.ts +51 -0
  41. package/dest/public/avm/calldata.d.ts.map +1 -0
  42. package/dest/public/avm/calldata.js +63 -0
  43. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +2 -0
  44. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
  45. package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
  46. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
  47. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  48. package/dest/public/avm/fixtures/avm_simulation_tester.js +3 -2
  49. package/dest/public/avm/fixtures/initializers.d.ts +1 -1
  50. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  51. package/dest/public/avm/fixtures/initializers.js +2 -1
  52. package/dest/public/avm/opcodes/accrued_substate.d.ts +4 -5
  53. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  54. package/dest/public/avm/opcodes/accrued_substate.js +15 -16
  55. package/dest/public/avm/opcodes/contract.d.ts +1 -1
  56. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  57. package/dest/public/avm/opcodes/contract.js +4 -4
  58. package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
  59. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  60. package/dest/public/avm/opcodes/external_calls.js +7 -7
  61. package/dest/public/avm/opcodes/memory.js +1 -1
  62. package/dest/public/avm/opcodes/storage.d.ts +13 -12
  63. package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
  64. package/dest/public/avm/opcodes/storage.js +30 -20
  65. package/dest/public/avm/serialization/bytecode_serialization.js +3 -3
  66. package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
  67. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  68. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  69. package/dest/public/debug_fn_name.d.ts +4 -4
  70. package/dest/public/debug_fn_name.d.ts.map +1 -1
  71. package/dest/public/debug_fn_name.js +7 -5
  72. package/dest/public/executor_metrics.d.ts +1 -1
  73. package/dest/public/executor_metrics.d.ts.map +1 -1
  74. package/dest/public/executor_metrics.js +7 -2
  75. package/dest/public/fixtures/amm_test.js +2 -2
  76. package/dest/public/fixtures/opcode_spammer.d.ts +3 -4
  77. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
  78. package/dest/public/fixtures/opcode_spammer.js +36 -64
  79. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +6 -5
  80. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  81. package/dest/public/fixtures/public_tx_simulation_tester.js +36 -9
  82. package/dest/public/fixtures/utils.d.ts +2 -2
  83. package/dest/public/fixtures/utils.d.ts.map +1 -1
  84. package/dest/public/fixtures/utils.js +6 -6
  85. package/dest/public/fuzzing/avm_simulator_bin.js +7 -4
  86. package/dest/public/hinting_db_sources.d.ts +2 -2
  87. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  88. package/dest/public/hinting_db_sources.js +1 -1
  89. package/dest/public/public_db_sources.d.ts +4 -3
  90. package/dest/public/public_db_sources.d.ts.map +1 -1
  91. package/dest/public/public_db_sources.js +4 -4
  92. package/dest/public/public_processor/guarded_merkle_tree.d.ts +2 -2
  93. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  94. package/dest/public/public_processor/guarded_merkle_tree.js +1 -1
  95. package/dest/public/public_processor/public_processor.d.ts +8 -4
  96. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  97. package/dest/public/public_processor/public_processor.js +50 -35
  98. package/dest/public/public_processor/public_processor_metrics.d.ts +2 -2
  99. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  100. package/dest/public/public_processor/public_processor_metrics.js +20 -4
  101. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +3 -2
  102. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  103. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +2 -2
  104. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +5 -5
  105. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  106. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +10 -11
  107. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +4 -4
  108. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
  109. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +7 -7
  110. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +4 -4
  111. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
  112. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +6 -6
  113. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +3 -2
  114. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -1
  115. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +2 -2
  116. package/dest/public/public_tx_simulator/factories.d.ts +3 -2
  117. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  118. package/dest/public/public_tx_simulator/factories.js +4 -4
  119. package/dest/public/public_tx_simulator/public_tx_context.d.ts +4 -3
  120. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  121. package/dest/public/public_tx_simulator/public_tx_context.js +8 -8
  122. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +4 -3
  123. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  124. package/dest/public/public_tx_simulator/public_tx_simulator.js +11 -8
  125. package/dest/public/side_effect_trace.d.ts +4 -4
  126. package/dest/public/side_effect_trace.d.ts.map +1 -1
  127. package/dest/public/side_effect_trace.js +3 -3
  128. package/dest/public/state_manager/state_manager.d.ts +10 -4
  129. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  130. package/dest/public/state_manager/state_manager.js +12 -5
  131. package/dest/public/test_executor_metrics.d.ts +8 -2
  132. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  133. package/dest/public/test_executor_metrics.js +24 -2
  134. package/package.json +16 -16
  135. package/src/private/acvm/acvm.ts +4 -3
  136. package/src/private/acvm_native.ts +11 -5
  137. package/src/private/acvm_wasm.ts +7 -3
  138. package/src/private/circuit_recording/circuit_recorder.ts +7 -5
  139. package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
  140. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  141. package/src/private/factory.ts +7 -4
  142. package/src/public/avm/avm_context.ts +2 -2
  143. package/src/public/avm/avm_contract_call_result.ts +8 -6
  144. package/src/public/avm/avm_execution_environment.ts +9 -4
  145. package/src/public/avm/avm_gas.ts +2 -2
  146. package/src/public/avm/avm_machine_state.ts +6 -5
  147. package/src/public/avm/avm_memory_types.ts +4 -0
  148. package/src/public/avm/avm_simulator.ts +8 -5
  149. package/src/public/avm/calldata.ts +100 -0
  150. package/src/public/avm/fixtures/account_proof.json +553 -0
  151. package/src/public/avm/fixtures/account_proof_fetcher.ts +166 -0
  152. package/src/public/avm/fixtures/avm_simulation_tester.ts +8 -2
  153. package/src/public/avm/fixtures/initializers.ts +2 -1
  154. package/src/public/avm/opcodes/accrued_substate.ts +16 -19
  155. package/src/public/avm/opcodes/contract.ts +1 -4
  156. package/src/public/avm/opcodes/external_calls.ts +8 -7
  157. package/src/public/avm/opcodes/memory.ts +1 -1
  158. package/src/public/avm/opcodes/storage.ts +28 -20
  159. package/src/public/avm/serialization/bytecode_serialization.ts +2 -2
  160. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  161. package/src/public/debug_fn_name.ts +10 -8
  162. package/src/public/executor_metrics.ts +4 -1
  163. package/src/public/fixtures/amm_test.ts +2 -2
  164. package/src/public/fixtures/opcode_spammer.ts +55 -63
  165. package/src/public/fixtures/public_tx_simulation_tester.ts +51 -5
  166. package/src/public/fixtures/utils.ts +6 -5
  167. package/src/public/fuzzing/avm_fuzzer_simulator.ts +1 -1
  168. package/src/public/fuzzing/avm_simulator_bin.ts +11 -1
  169. package/src/public/hinting_db_sources.ts +1 -1
  170. package/src/public/public_db_sources.ts +15 -5
  171. package/src/public/public_processor/guarded_merkle_tree.ts +1 -1
  172. package/src/public/public_processor/public_processor.ts +75 -47
  173. package/src/public/public_processor/public_processor_metrics.ts +10 -4
  174. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +6 -3
  175. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +10 -8
  176. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +7 -5
  177. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +7 -5
  178. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +3 -1
  179. package/src/public/public_tx_simulator/factories.ts +6 -3
  180. package/src/public/public_tx_simulator/public_tx_context.ts +13 -6
  181. package/src/public/public_tx_simulator/public_tx_simulator.ts +17 -8
  182. package/src/public/side_effect_trace.ts +5 -2
  183. package/src/public/state_manager/state_manager.ts +27 -4
  184. package/src/public/test_executor_metrics.ts +27 -3
@@ -143,7 +143,7 @@
143
143
  * - `EMITNOTEHASH`: max 64 per TX
144
144
  * - `EMITNULLIFIER`: max 63 per TX (one reserved for TX nullifier)
145
145
  * - `SENDL2TOL1MSG`: max 8 per TX
146
- * - `EMITUNENCRYPTEDLOG`: limited by total log payload size
146
+ * - `EMITPUBLICLOG`: limited by total log payload size
147
147
  *
148
148
  * By having the inner contract REVERT after emitting side effects, those effects are discarded, allowing the outer contract to call it again. This enables thousands of opcode executions per TX instead of just the limit.
149
149
  *
@@ -164,7 +164,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
164
164
  import type { Bufferable } from '@aztec/foundation/serialize';
165
165
  import { type CallStackMetadata, PublicDataWrite, type PublicTxResult } from '@aztec/stdlib/avm';
166
166
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
167
- import { computePublicDataTreeLeafSlot, siloNullifier } from '@aztec/stdlib/hash';
167
+ import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
168
168
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
169
169
  import { MerkleTreeId } from '@aztec/stdlib/trees';
170
170
 
@@ -182,7 +182,7 @@ import {
182
182
  EcAdd,
183
183
  EmitNoteHash,
184
184
  EmitNullifier,
185
- EmitUnencryptedLog,
185
+ EmitPublicLog,
186
186
  Eq,
187
187
  FieldDiv,
188
188
  GetContractInstance,
@@ -295,9 +295,8 @@ export interface SpamConfigsForOpcode {
295
295
  export const WARM_NOTE_HASH = new Fr(0xdeadbeefn);
296
296
  export const WARM_L1_TO_L2_MSG = new Fr(0xcafebabedeadbeefn);
297
297
 
298
- /** Warm nullifier constants - uses a fixed address since NULLIFIEREXISTS takes address as parameter */
299
- export const WARM_NULLIFIER = new Fr(0xdeadbeef0001n);
300
- export const WARM_NULLIFIER_ADDRESS = AztecAddress.fromNumber(0xbeef);
298
+ /** Warm nullifier constant - a pre-siloed nullifier value inserted directly into the tree */
299
+ export const WARM_SILOED_NULLIFIER = new Fr(0xdeadbeef0001n);
301
300
 
302
301
  /** Warm storage constants - storage is inserted for the deployed contract's address */
303
302
  export const WARM_STORAGE_SLOT = new Fr(0xdeadbeef0002n);
@@ -331,9 +330,8 @@ export async function insertWarmTreeEntries(
331
330
  // Insert into L1 to L2 message tree
332
331
  await merkleTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [WARM_L1_TO_L2_MSG]);
333
332
 
334
- // Insert siloed nullifier into nullifier tree
335
- const siloedNullifier = await siloNullifier(WARM_NULLIFIER_ADDRESS, WARM_NULLIFIER);
336
- await merkleTrees.sequentialInsert(MerkleTreeId.NULLIFIER_TREE, [siloedNullifier.toBuffer()]);
333
+ // Insert siloed nullifier into nullifier tree (already siloed - used directly by NULLIFIEREXISTS)
334
+ await merkleTrees.sequentialInsert(MerkleTreeId.NULLIFIER_TREE, [WARM_SILOED_NULLIFIER.toBuffer()]);
337
335
 
338
336
  // Insert storage value into public data tree
339
337
  const leafSlot = await computePublicDataTreeLeafSlot(contractAddress, WARM_STORAGE_SLOT);
@@ -966,34 +964,63 @@ export const SPAM_CONFIGS: Partial<Record<Opcode, SpamConfig[]>> = {
966
964
  [Opcode.SLOAD]: [
967
965
  {
968
966
  label: 'Cold read (slot not written)',
969
- setup: [{ offset: 0, value: new Field(Fr.random()) }], // random slot
970
- targetInstructions: () => [new SLoad(/*addressing_mode=*/ 0, /*slotOffset=*/ 0, /*dstOffset=*/ 1)],
967
+ setup: [
968
+ { offset: 0, value: new Field(Fr.random()) }, // random slot
969
+ () => [
970
+ // Get current contract address into offset 1
971
+ new GetEnvVar(/*addressing_mode=*/ 0, /*dstOffset=*/ 1, /*varEnum=*/ 0).as(
972
+ Opcode.GETENVVAR_16,
973
+ GetEnvVar.wireFormat16,
974
+ ),
975
+ ],
976
+ ],
977
+ targetInstructions: () => [
978
+ new SLoad(/*addressing_mode=*/ 0, /*slotOffset=*/ 0, /*contractAddressOffset=*/ 1, /*dstOffset=*/ 2),
979
+ ],
971
980
  },
972
981
  {
973
982
  label: 'Warm read (from tree)',
974
983
  // Uses pre-inserted storage from insertWarmTreeEntries() which is called after contract deployment
975
- setup: [{ offset: 0, value: new Field(WARM_STORAGE_SLOT) }], // pre-inserted slot
976
- targetInstructions: () => [new SLoad(/*addressing_mode=*/ 0, /*slotOffset=*/ 0, /*dstOffset=*/ 1)],
984
+ setup: [
985
+ { offset: 0, value: new Field(WARM_STORAGE_SLOT) }, // pre-inserted slot
986
+ () => [
987
+ // Get current contract address into offset 1
988
+ new GetEnvVar(/*addressing_mode=*/ 0, /*dstOffset=*/ 1, /*varEnum=*/ 0).as(
989
+ Opcode.GETENVVAR_16,
990
+ GetEnvVar.wireFormat16,
991
+ ),
992
+ ],
993
+ ],
994
+ targetInstructions: () => [
995
+ new SLoad(/*addressing_mode=*/ 0, /*slotOffset=*/ 0, /*contractAddressOffset=*/ 1, /*dstOffset=*/ 2),
996
+ ],
977
997
  },
978
998
  {
979
999
  label: 'Warm read (SSTORE first, unique slot per SLOAD)',
980
- // Memory layout: slot (incremented), value, constant 1, revertSize, loaded value
1000
+ // Memory layout: slot (incremented), value, constant 1, contract address (from GETENVVAR), revertSize, loaded value
981
1001
  setup: [
982
1002
  { offset: 0, value: new Field(Fr.random()) }, // slot (will be incremented)
983
1003
  { offset: 1, value: new Field(Fr.random()) }, // value to store
984
1004
  { offset: 2, value: new Field(1n) }, // constant 1 for ADD
985
- { offset: 3, value: new Uint32(0n) }, // revertSize
1005
+ () => [
1006
+ // Get current contract address into offset 3
1007
+ new GetEnvVar(/*addressing_mode=*/ 0, /*dstOffset=*/ 3, /*varEnum=*/ 0).as(
1008
+ Opcode.GETENVVAR_16,
1009
+ GetEnvVar.wireFormat16,
1010
+ ),
1011
+ ],
1012
+ { offset: 4, value: new Uint32(0n) }, // revertSize
986
1013
  ],
987
1014
  targetInstructions: () => [
988
1015
  new SStore(/*addressing_mode=*/ 0, /*srcOffset=*/ 1, /*slotOffset=*/ 0),
989
- new SLoad(/*addressing_mode=*/ 0, /*slotOffset=*/ 0, /*dstOffset=*/ 4),
1016
+ new SLoad(/*addressing_mode=*/ 0, /*slotOffset=*/ 0, /*contractAddressOffset=*/ 3, /*dstOffset=*/ 5),
990
1017
  new Add(/*addressing_mode=*/ 0, /*aOffset=*/ 0, /*bOffset=*/ 2, /*dstOffset=*/ 0).as(
991
1018
  Opcode.ADD_8,
992
1019
  Add.wireFormat8,
993
1020
  ), // slot++
994
1021
  ],
995
1022
  cleanupInstructions: () => [
996
- new Revert(/*addressing_mode=*/ 0, /*retSizeOffset=*/ 3, /*returnOffset=*/ 0).as(
1023
+ new Revert(/*addressing_mode=*/ 0, /*retSizeOffset=*/ 4, /*returnOffset=*/ 0).as(
997
1024
  Opcode.REVERT_8,
998
1025
  Revert.wireFormat8,
999
1026
  ),
@@ -1031,56 +1058,25 @@ export const SPAM_CONFIGS: Partial<Record<Opcode, SpamConfig[]>> = {
1031
1058
  [Opcode.NULLIFIEREXISTS]: [
1032
1059
  {
1033
1060
  label: 'Non-existent nullifier',
1061
+ // NULLIFIEREXISTS now takes a siloed nullifier directly (no address parameter)
1034
1062
  setup: [
1035
- { offset: 0, value: new Field(Fr.random()) }, // random nullifier
1036
- { offset: 1, value: new Field(Fr.random()) }, // random address
1063
+ { offset: 0, value: new Field(Fr.random()) }, // random siloed nullifier (won't exist)
1037
1064
  ],
1038
1065
  targetInstructions: () => [
1039
- new NullifierExists(/*addressing_mode=*/ 0, /*nullifierOffset=*/ 0, /*addressOffset=*/ 1, /*existsOffset=*/ 2),
1066
+ new NullifierExists(/*addressing_mode=*/ 0, /*siloedNullifierOffset=*/ 0, /*existsOffset=*/ 1),
1040
1067
  ],
1041
1068
  },
1042
1069
  {
1043
1070
  label: 'Existing nullifier (warm - from tree)',
1044
- // Uses pre-inserted nullifier from insertWarmTreeEntries()
1071
+ // Uses pre-inserted siloed nullifier from insertWarmTreeEntries()
1072
+ // NULLIFIEREXISTS now takes a siloed nullifier directly
1045
1073
  setup: [
1046
- { offset: 0, value: new Field(WARM_NULLIFIER) }, // pre-inserted nullifier
1047
- { offset: 1, value: new Field(WARM_NULLIFIER_ADDRESS.toField()) }, // address it was siloed with
1074
+ { offset: 0, value: new Field(WARM_SILOED_NULLIFIER) }, // pre-inserted siloed nullifier
1048
1075
  ],
1049
1076
  targetInstructions: () => [
1050
- new NullifierExists(/*addressing_mode=*/ 0, /*nullifierOffset=*/ 0, /*addressOffset=*/ 1, /*existsOffset=*/ 2),
1077
+ new NullifierExists(/*addressing_mode=*/ 0, /*siloedNullifierOffset=*/ 0, /*existsOffset=*/ 1),
1051
1078
  ],
1052
1079
  },
1053
- {
1054
- label: 'Existing nullifier (warm - EMITNULLIFIER first)',
1055
- // Memory layout: nullifier (incremented), constant 1, current address (from GETENVVAR), revertSize, exists result
1056
- setup: [
1057
- { offset: 0, value: new Field(Fr.random()) }, // nullifier (will be incremented)
1058
- { offset: 1, value: new Field(1n) }, // constant 1 for ADD
1059
- () => [
1060
- // Get current contract address into offset 2
1061
- new GetEnvVar(/*addressing_mode=*/ 0, /*dstOffset=*/ 2, /*varEnum=*/ 0).as(
1062
- Opcode.GETENVVAR_16,
1063
- GetEnvVar.wireFormat16,
1064
- ),
1065
- ],
1066
- { offset: 3, value: new Uint32(0n) }, // revertSize
1067
- ],
1068
- targetInstructions: () => [
1069
- new EmitNullifier(/*addressing_mode=*/ 0, /*nullifierOffset=*/ 0),
1070
- new NullifierExists(/*addressing_mode=*/ 0, /*nullifierOffset=*/ 0, /*addressOffset=*/ 2, /*existsOffset=*/ 4),
1071
- new Add(/*addressing_mode=*/ 0, /*aOffset=*/ 0, /*bOffset=*/ 1, /*dstOffset=*/ 0).as(
1072
- Opcode.ADD_8,
1073
- Add.wireFormat8,
1074
- ), // nullifier++
1075
- ],
1076
- cleanupInstructions: () => [
1077
- new Revert(/*addressing_mode=*/ 0, /*retSizeOffset=*/ 3, /*returnOffset=*/ 0).as(
1078
- Opcode.REVERT_8,
1079
- Revert.wireFormat8,
1080
- ),
1081
- ],
1082
- limit: MAX_NULLIFIERS_PER_TX - 1,
1083
- },
1084
1080
  ],
1085
1081
 
1086
1082
  [Opcode.L1TOL2MSGEXISTS]: [
@@ -1246,17 +1242,15 @@ export const SPAM_CONFIGS: Partial<Record<Opcode, SpamConfig[]>> = {
1246
1242
  },
1247
1243
  ],
1248
1244
 
1249
- // EMITUNENCRYPTEDLOG - two configs: minimal (many small logs) and max-size (one large log)
1250
- [Opcode.EMITUNENCRYPTEDLOG]: [
1245
+ // EMITPUBLICLOG - two configs: minimal (many small logs) and max-size (one large log)
1246
+ [Opcode.EMITPUBLICLOG]: [
1251
1247
  {
1252
1248
  label: 'Many empty logs, revert, repeat',
1253
1249
  setup: [
1254
1250
  { offset: 0, value: new Uint32(0n) }, // logSize = 0 fields (minimal)
1255
1251
  { offset: 1, value: new Uint32(0n) }, // revertSize
1256
1252
  ],
1257
- targetInstructions: () => [
1258
- new EmitUnencryptedLog(/*addressing_mode=*/ 0, /*logSizeOffset=*/ 0, /*logOffset=*/ 1),
1259
- ], // logOffset doesn't matter when size is 0
1253
+ targetInstructions: () => [new EmitPublicLog(/*addressing_mode=*/ 0, /*logSizeOffset=*/ 0, /*logOffset=*/ 1)], // logOffset doesn't matter when size is 0
1260
1254
  cleanupInstructions: () => [
1261
1255
  new Revert(/*addressing_mode=*/ 0, /*retSizeOffset=*/ 1, /*returnOffset=*/ 0).as(
1262
1256
  Opcode.REVERT_8,
@@ -1280,9 +1274,7 @@ export const SPAM_CONFIGS: Partial<Record<Opcode, SpamConfig[]>> = {
1280
1274
  // value: new Field(0n),
1281
1275
  //})),
1282
1276
  ],
1283
- targetInstructions: () => [
1284
- new EmitUnencryptedLog(/*addressing_mode=*/ 0, /*logSizeOffset=*/ 0, /*logOffset=*/ 2),
1285
- ], // uses logOffset 2 (uninitialized Field(0))
1277
+ targetInstructions: () => [new EmitPublicLog(/*addressing_mode=*/ 0, /*logSizeOffset=*/ 0, /*logOffset=*/ 2)], // uses logOffset 2 (uninitialized Field(0))
1286
1278
  cleanupInstructions: () => [
1287
1279
  new Revert(/*addressing_mode=*/ 0, /*retSizeOffset=*/ 1, /*returnOffset=*/ 0).as(
1288
1280
  Opcode.REVERT_8,
@@ -1,4 +1,9 @@
1
- import { DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT } from '@aztec/constants';
1
+ import {
2
+ DEFAULT_TEARDOWN_DA_GAS_LIMIT,
3
+ DEFAULT_TEARDOWN_L2_GAS_LIMIT,
4
+ PUBLIC_TX_L2_GAS_OVERHEAD,
5
+ TX_DA_GAS_OVERHEAD,
6
+ } from '@aztec/constants';
2
7
  import { asyncMap } from '@aztec/foundation/async-map';
3
8
  import { BlockNumber } from '@aztec/foundation/branded-types';
4
9
  import { Fr } from '@aztec/foundation/curves/bn254';
@@ -112,6 +117,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
112
117
  feePayer: AztecAddress = sender,
113
118
  /* need some unique first nullifier for note-nonce computations */
114
119
  privateInsertions: TestPrivateInsertions = { nonRevertible: { nullifiers: [new Fr(420000 + this.txCount)] } },
120
+ gasLimits?: Gas,
115
121
  ): Promise<Tx> {
116
122
  const setupCallRequests = await asyncMap(setupCalls, call =>
117
123
  this.#createPubicCallRequestForCall(call, call.sender ?? sender),
@@ -131,9 +137,13 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
131
137
  teardownCallRequest,
132
138
  feePayer,
133
139
  /*gasUsedByPrivate*/ teardownCall
134
- ? new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT)
135
- : Gas.empty(),
140
+ ? new Gas(
141
+ DEFAULT_TEARDOWN_DA_GAS_LIMIT + TX_DA_GAS_OVERHEAD,
142
+ DEFAULT_TEARDOWN_L2_GAS_LIMIT + PUBLIC_TX_L2_GAS_OVERHEAD,
143
+ )
144
+ : new Gas(TX_DA_GAS_OVERHEAD, PUBLIC_TX_L2_GAS_OVERHEAD),
136
145
  defaultGlobals(),
146
+ gasLimits,
137
147
  );
138
148
  }
139
149
 
@@ -146,8 +156,9 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
146
156
  /* need some unique first nullifier for note-nonce computations */
147
157
  privateInsertions?: TestPrivateInsertions,
148
158
  txLabel: string = 'unlabeledTx',
159
+ gasLimits?: Gas,
149
160
  ): Promise<PublicTxResult> {
150
- const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions);
161
+ const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions, gasLimits);
151
162
 
152
163
  await this.setFeePayerBalance(feePayer);
153
164
 
@@ -161,6 +172,8 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
161
172
  }
162
173
  const avmResult = await this.simulator.simulate(tx, fullTxLabel);
163
174
 
175
+ await this.#recordBytecodeSizes(fullTxLabel, [...setupCalls, ...appCalls, ...(teardownCall ? [teardownCall] : [])]);
176
+
164
177
  // Something like this is often useful for debugging:
165
178
  //if (avmResult.revertReason) {
166
179
  // // resolve / enrich revert reason
@@ -190,8 +203,18 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
190
203
  teardownCall?: TestEnqueuedCall,
191
204
  feePayer?: AztecAddress,
192
205
  privateInsertions?: TestPrivateInsertions,
206
+ gasLimits?: Gas,
193
207
  ): Promise<PublicTxResult> {
194
- return await this.simulateTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions, txLabel);
208
+ return await this.simulateTx(
209
+ sender,
210
+ setupCalls,
211
+ appCalls,
212
+ teardownCall,
213
+ feePayer,
214
+ privateInsertions,
215
+ txLabel,
216
+ gasLimits,
217
+ );
195
218
  }
196
219
 
197
220
  /**
@@ -209,6 +232,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
209
232
  teardownCall?: TestEnqueuedCall,
210
233
  feePayer?: AztecAddress,
211
234
  privateInsertions?: TestPrivateInsertions,
235
+ gasLimits?: Gas,
212
236
  ): Promise<PublicTxResult> {
213
237
  return await this.simulateTxWithLabel(
214
238
  txLabel,
@@ -218,6 +242,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
218
242
  teardownCall,
219
243
  feePayer,
220
244
  privateInsertions,
245
+ gasLimits,
221
246
  );
222
247
  }
223
248
 
@@ -277,6 +302,27 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
277
302
 
278
303
  return new PublicCallRequestWithCalldata(request, calldata);
279
304
  }
305
+
306
+ // WARNING: Deduplicates by artifact name, so two different artifacts with the same name
307
+ // in a single tx would only record the first one's bytecode size.
308
+ async #recordBytecodeSizes(txLabel: string, calls: TestEnqueuedCall[]) {
309
+ const seenArtifactNames = new Set<string>();
310
+ for (const call of calls) {
311
+ const artifact = await this.contractDataSource.getContractArtifact(call.address);
312
+ if (!artifact || seenArtifactNames.has(artifact.name)) {
313
+ continue;
314
+ }
315
+ seenArtifactNames.add(artifact.name);
316
+ const instance = await this.contractDataSource.getContract(call.address);
317
+ if (!instance) {
318
+ continue;
319
+ }
320
+ const contractClass = await this.contractDataSource.getContractClass(instance.currentContractClassId);
321
+ if (contractClass) {
322
+ this.metrics.recordBytecodeSize(txLabel, artifact.name, contractClass.packedBytecode.length);
323
+ }
324
+ }
325
+ }
280
326
  }
281
327
 
282
328
  export function defaultGlobals() {
@@ -62,13 +62,14 @@ export async function createTxForPublicCalls(
62
62
  feePayer = AztecAddress.zero(),
63
63
  gasUsedByPrivate: Gas = Gas.empty(),
64
64
  globals: GlobalVariables = GlobalVariables.empty(),
65
+ gasLimits?: Gas,
65
66
  ): Promise<Tx> {
66
67
  assert(
67
68
  setupCallRequests.length > 0 || appCallRequests.length > 0 || teardownCallRequest !== undefined,
68
69
  "Can't create public tx with no enqueued calls",
69
70
  );
70
71
  // use max limits
71
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
72
+ gasLimits = gasLimits ?? new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
72
73
 
73
74
  const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
74
75
 
@@ -134,13 +135,13 @@ export async function createTxForPublicCalls(
134
135
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
135
136
  const header = BlockHeader.empty({ globalVariables: globals });
136
137
  const constantData = new TxConstantData(header, txContext, Fr.zero(), Fr.zero());
137
- const includeByTimestamp = 0n; // Not used in the simulator.
138
+ const expirationTimestamp = 0n; // Not used in the simulator.
138
139
 
139
140
  const txData = new PrivateKernelTailCircuitPublicInputs(
140
141
  constantData,
141
142
  /*gasUsed=*/ gasUsedByPrivate,
142
143
  feePayer,
143
- includeByTimestamp,
144
+ expirationTimestamp,
144
145
  forPublic,
145
146
  );
146
147
 
@@ -171,13 +172,13 @@ export async function createTxForPrivateOnly(
171
172
  const gasSettings = new GasSettings(gasLimits, Gas.empty(), maxFeesPerGas, GasFees.empty());
172
173
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
173
174
  const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
174
- const includeByTimestamp = 0n; // Not used in the simulator.
175
+ const expirationTimestamp = 0n; // Not used in the simulator.
175
176
 
176
177
  const txData = new PrivateKernelTailCircuitPublicInputs(
177
178
  constantData,
178
179
  /*gasUsed=*/ gasUsedByPrivate,
179
180
  feePayer,
180
- includeByTimestamp,
181
+ expirationTimestamp,
181
182
  /*forPublic=*/ undefined,
182
183
  forRollup,
183
184
  );
@@ -146,7 +146,7 @@ async function createTxFromHint(cppTx: AvmTxHint): Promise<Tx> {
146
146
  constants,
147
147
  cppTx.gasUsedByPrivate,
148
148
  cppTx.feePayer,
149
- 0n, // includeByTimestamp
149
+ 0n, // expirationTimestamp
150
150
  forPublic,
151
151
  undefined, // forRollup - not needed for public simulation
152
152
  );
@@ -3,6 +3,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
3
3
  import {
4
4
  AvmCircuitPublicInputs,
5
5
  type AvmTxHint,
6
+ PublicTxEffect,
6
7
  deserializeFromMessagePack,
7
8
  serializeWithMessagePack,
8
9
  } from '@aztec/stdlib/avm';
@@ -58,7 +59,13 @@ async function simulateWithFuzzer(
58
59
  rawPublicDataWrites: any[], // Public data tree writes to apply before simulation
59
60
  rawNoteHashes: any[], // Note hashes to apply before simulation
60
61
  protocolContracts: ProtocolContracts, // Protocol contracts mapping from C++
61
- ): Promise<{ reverted: boolean; output: Fr[]; revertReason?: string; publicInputs: AvmCircuitPublicInputs }> {
62
+ ): Promise<{
63
+ reverted: boolean;
64
+ output: Fr[];
65
+ revertReason?: string;
66
+ publicInputs: AvmCircuitPublicInputs;
67
+ publicTxEffect: PublicTxEffect;
68
+ }> {
62
69
  const worldStateService = await openExistingWorldState(dataDir, mapSizeKb);
63
70
 
64
71
  const simulator = await AvmFuzzerSimulator.create(worldStateService, globals, protocolContracts);
@@ -90,6 +97,7 @@ async function simulateWithFuzzer(
90
97
  output,
91
98
  revertReason: result.findRevertReason()?.message,
92
99
  publicInputs: result.publicInputs!,
100
+ publicTxEffect: result.publicTxEffect,
93
101
  };
94
102
  }
95
103
 
@@ -119,6 +127,7 @@ async function execute(base64Line: string): Promise<void> {
119
127
  output: result.output,
120
128
  revertReason: result.revertReason ?? '',
121
129
  endTreeSnapshots: result.publicInputs.endTreeSnapshots,
130
+ publicTxEffect: result.publicTxEffect,
122
131
  });
123
132
  const base64Response = resultBuffer.toString('base64') + '\n';
124
133
  await writeOutput(base64Response);
@@ -129,6 +138,7 @@ async function execute(base64Line: string): Promise<void> {
129
138
  output: [] as Fr[],
130
139
  revertReason: `Unexpected Error ${error.message}`,
131
140
  endTreeSnapshots: TreeSnapshots.empty(),
141
+ publicTxEffect: PublicTxEffect.empty(),
132
142
  });
133
143
  await writeOutput(errorResult.toString('base64') + '\n');
134
144
  }
@@ -572,7 +572,7 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
572
572
  return await this.db.close();
573
573
  }
574
574
 
575
- async [Symbol.dispose](): Promise<void> {
575
+ async [Symbol.asyncDispose](): Promise<void> {
576
576
  await this.close();
577
577
  }
578
578
 
@@ -5,7 +5,7 @@ import {
5
5
  PUBLIC_DATA_SUBTREE_HEIGHT,
6
6
  } from '@aztec/constants';
7
7
  import { Fr } from '@aztec/foundation/curves/bn254';
8
- import { createLogger } from '@aztec/foundation/log';
8
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
9
9
  import { Timer } from '@aztec/foundation/timer';
10
10
  import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
11
11
  import { ContractInstancePublishedEvent } from '@aztec/protocol-contracts/instance-registry';
@@ -46,9 +46,14 @@ import { L1ToL2MessageIndexOutOfRangeError, NoteHashIndexOutOfRangeError } from
46
46
  export class PublicContractsDB implements PublicContractsDBInterface {
47
47
  private contractStateStack: ContractsDbCheckpoint[] = [new ContractsDbCheckpoint()];
48
48
 
49
- private log = createLogger('simulator:contracts-data-source');
49
+ private log: Logger;
50
50
 
51
- constructor(private dataSource: ContractDataSource) {}
51
+ constructor(
52
+ private dataSource: ContractDataSource,
53
+ bindings?: LoggerBindings,
54
+ ) {
55
+ this.log = createLogger('simulator:contracts-data-source', bindings);
56
+ }
52
57
 
53
58
  public async addContracts(contractDeploymentData: ContractDeploymentData): Promise<void> {
54
59
  const currentState = this.getCurrentState();
@@ -208,9 +213,14 @@ export class PublicContractsDB implements PublicContractsDBInterface {
208
213
  * to decide whether to use hints or not (same with tracing, etc).
209
214
  */
210
215
  export class PublicTreesDB implements PublicStateDBInterface {
211
- private logger = createLogger('simulator:public-trees-db');
216
+ private logger: Logger;
212
217
 
213
- constructor(private readonly db: MerkleTreeWriteOperations) {}
218
+ constructor(
219
+ private readonly db: MerkleTreeWriteOperations,
220
+ bindings?: LoggerBindings,
221
+ ) {
222
+ this.logger = createLogger('simulator:public-trees-db', bindings);
223
+ }
214
224
 
215
225
  public async storageRead(contract: AztecAddress, slot: Fr): Promise<Fr> {
216
226
  const timer = new Timer();
@@ -82,7 +82,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
82
82
  return this.guardAndPush(() => this.target.close());
83
83
  }
84
84
 
85
- async [Symbol.dispose](): Promise<void> {
85
+ async [Symbol.asyncDispose](): Promise<void> {
86
86
  await this.close();
87
87
  }
88
88
  getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo> {