@aztec/simulator 0.0.1-commit.1142ef1 → 0.0.1-commit.11bf3dd6e

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 (246) hide show
  1. package/README.md +6 -4
  2. package/dest/common/errors.d.ts +7 -1
  3. package/dest/common/errors.d.ts.map +1 -1
  4. package/dest/private/acvm/acvm.d.ts +4 -2
  5. package/dest/private/acvm/acvm.d.ts.map +1 -1
  6. package/dest/private/acvm/acvm.js +4 -3
  7. package/dest/private/acvm_native.d.ts +5 -3
  8. package/dest/private/acvm_native.d.ts.map +1 -1
  9. package/dest/private/acvm_native.js +8 -6
  10. package/dest/private/acvm_wasm.d.ts +4 -3
  11. package/dest/private/acvm_wasm.d.ts.map +1 -1
  12. package/dest/private/acvm_wasm.js +4 -4
  13. package/dest/private/circuit_recording/circuit_recorder.d.ts +4 -3
  14. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  15. package/dest/private/circuit_recording/circuit_recorder.js +7 -5
  16. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +3 -2
  17. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  18. package/dest/private/circuit_recording/file_circuit_recorder.js +2 -2
  19. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  20. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  21. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  22. package/dest/private/factory.d.ts +3 -3
  23. package/dest/private/factory.d.ts.map +1 -1
  24. package/dest/private/factory.js +7 -4
  25. package/dest/public/avm/avm_context.d.ts +3 -3
  26. package/dest/public/avm/avm_context.d.ts.map +1 -1
  27. package/dest/public/avm/avm_contract_call_result.d.ts +6 -6
  28. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  29. package/dest/public/avm/avm_contract_call_result.js +3 -3
  30. package/dest/public/avm/avm_execution_environment.d.ts +6 -5
  31. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  32. package/dest/public/avm/avm_gas.js +3 -3
  33. package/dest/public/avm/avm_machine_state.d.ts +6 -5
  34. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  35. package/dest/public/avm/avm_machine_state.js +3 -2
  36. package/dest/public/avm/avm_memory_types.d.ts +1 -1
  37. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  38. package/dest/public/avm/avm_memory_types.js +3 -0
  39. package/dest/public/avm/avm_simulator.d.ts +3 -2
  40. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  41. package/dest/public/avm/avm_simulator.js +6 -5
  42. package/dest/public/avm/calldata.d.ts +51 -0
  43. package/dest/public/avm/calldata.d.ts.map +1 -0
  44. package/dest/public/avm/calldata.js +64 -0
  45. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +2 -0
  46. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
  47. package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
  48. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
  49. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  50. package/dest/public/avm/fixtures/avm_simulation_tester.js +3 -2
  51. package/dest/public/avm/fixtures/initializers.d.ts +1 -1
  52. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  53. package/dest/public/avm/fixtures/initializers.js +2 -1
  54. package/dest/public/avm/opcodes/accrued_substate.d.ts +17 -18
  55. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  56. package/dest/public/avm/opcodes/accrued_substate.js +41 -42
  57. package/dest/public/avm/opcodes/arithmetic.d.ts +8 -8
  58. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  59. package/dest/public/avm/opcodes/arithmetic.js +1 -1
  60. package/dest/public/avm/opcodes/bitwise.d.ts +7 -7
  61. package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
  62. package/dest/public/avm/opcodes/bitwise.js +5 -5
  63. package/dest/public/avm/opcodes/comparators.d.ts +4 -4
  64. package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
  65. package/dest/public/avm/opcodes/comparators.js +1 -1
  66. package/dest/public/avm/opcodes/contract.d.ts +3 -3
  67. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  68. package/dest/public/avm/opcodes/contract.js +8 -8
  69. package/dest/public/avm/opcodes/control_flow.d.ts +3 -3
  70. package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
  71. package/dest/public/avm/opcodes/control_flow.js +4 -4
  72. package/dest/public/avm/opcodes/conversion.d.ts +3 -3
  73. package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
  74. package/dest/public/avm/opcodes/conversion.js +4 -4
  75. package/dest/public/avm/opcodes/ec_add.d.ts +4 -4
  76. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
  77. package/dest/public/avm/opcodes/ec_add.js +15 -6
  78. package/dest/public/avm/opcodes/environment_getters.d.ts +3 -3
  79. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  80. package/dest/public/avm/opcodes/environment_getters.js +4 -4
  81. package/dest/public/avm/opcodes/external_calls.d.ts +9 -9
  82. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  83. package/dest/public/avm/opcodes/external_calls.js +23 -23
  84. package/dest/public/avm/opcodes/hashing.d.ts +8 -8
  85. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  86. package/dest/public/avm/opcodes/hashing.js +12 -12
  87. package/dest/public/avm/opcodes/instruction_impl.d.ts +4 -4
  88. package/dest/public/avm/opcodes/instruction_impl.d.ts.map +1 -1
  89. package/dest/public/avm/opcodes/instruction_impl.js +4 -4
  90. package/dest/public/avm/opcodes/memory.d.ts +14 -14
  91. package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
  92. package/dest/public/avm/opcodes/memory.js +25 -25
  93. package/dest/public/avm/opcodes/misc.d.ts +3 -3
  94. package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
  95. package/dest/public/avm/opcodes/misc.js +4 -4
  96. package/dest/public/avm/opcodes/storage.d.ts +16 -15
  97. package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
  98. package/dest/public/avm/opcodes/storage.js +34 -24
  99. package/dest/public/avm/serialization/bytecode_serialization.js +3 -3
  100. package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
  101. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  102. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  103. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  104. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  105. package/dest/public/contracts_db_checkpoint.js +1 -1
  106. package/dest/public/debug_fn_name.d.ts +4 -4
  107. package/dest/public/debug_fn_name.d.ts.map +1 -1
  108. package/dest/public/debug_fn_name.js +7 -5
  109. package/dest/public/executor_metrics.d.ts +1 -1
  110. package/dest/public/executor_metrics.d.ts.map +1 -1
  111. package/dest/public/executor_metrics.js +7 -2
  112. package/dest/public/fixtures/amm_test.js +2 -2
  113. package/dest/public/fixtures/bulk_test.d.ts +3 -3
  114. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  115. package/dest/public/fixtures/bulk_test.js +4 -4
  116. package/dest/public/fixtures/custom_bytecode_tests.d.ts +11 -11
  117. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  118. package/dest/public/fixtures/custom_bytecode_tests.js +18 -18
  119. package/dest/public/fixtures/minimal_public_tx.js +2 -2
  120. package/dest/public/fixtures/opcode_spammer.d.ts +3 -4
  121. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
  122. package/dest/public/fixtures/opcode_spammer.js +99 -127
  123. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +6 -5
  124. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  125. package/dest/public/fixtures/public_tx_simulation_tester.js +37 -10
  126. package/dest/public/fixtures/utils.d.ts +2 -2
  127. package/dest/public/fixtures/utils.d.ts.map +1 -1
  128. package/dest/public/fixtures/utils.js +10 -10
  129. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +21 -7
  130. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
  131. package/dest/public/fuzzing/avm_fuzzer_simulator.js +42 -10
  132. package/dest/public/fuzzing/avm_simulator_bin.js +15 -8
  133. package/dest/public/hinting_db_sources.d.ts +5 -5
  134. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  135. package/dest/public/hinting_db_sources.js +7 -6
  136. package/dest/public/public_db_sources.d.ts +6 -5
  137. package/dest/public/public_db_sources.d.ts.map +1 -1
  138. package/dest/public/public_db_sources.js +14 -14
  139. package/dest/public/public_processor/guarded_merkle_tree.d.ts +5 -5
  140. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  141. package/dest/public/public_processor/guarded_merkle_tree.js +5 -5
  142. package/dest/public/public_processor/public_processor.d.ts +8 -4
  143. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  144. package/dest/public/public_processor/public_processor.js +62 -47
  145. package/dest/public/public_processor/public_processor_metrics.d.ts +2 -2
  146. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  147. package/dest/public/public_processor/public_processor_metrics.js +20 -4
  148. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +3 -2
  149. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  150. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +4 -3
  151. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +5 -5
  152. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  153. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +10 -10
  154. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +4 -4
  155. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
  156. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +7 -7
  157. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +4 -4
  158. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
  159. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +6 -6
  160. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +3 -2
  161. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -1
  162. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +2 -2
  163. package/dest/public/public_tx_simulator/factories.d.ts +3 -2
  164. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  165. package/dest/public/public_tx_simulator/factories.js +4 -4
  166. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +1 -1
  167. package/dest/public/public_tx_simulator/public_tx_context.d.ts +10 -5
  168. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  169. package/dest/public/public_tx_simulator/public_tx_context.js +16 -18
  170. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +11 -5
  171. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  172. package/dest/public/public_tx_simulator/public_tx_simulator.js +26 -16
  173. package/dest/public/side_effect_trace.d.ts +5 -4
  174. package/dest/public/side_effect_trace.d.ts.map +1 -1
  175. package/dest/public/side_effect_trace.js +3 -3
  176. package/dest/public/state_manager/state_manager.d.ts +10 -4
  177. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  178. package/dest/public/state_manager/state_manager.js +14 -7
  179. package/dest/public/test_executor_metrics.d.ts +8 -2
  180. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  181. package/dest/public/test_executor_metrics.js +24 -2
  182. package/package.json +16 -17
  183. package/src/private/acvm/acvm.ts +4 -3
  184. package/src/private/acvm_native.ts +11 -5
  185. package/src/private/acvm_wasm.ts +7 -3
  186. package/src/private/circuit_recording/circuit_recorder.ts +7 -5
  187. package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
  188. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  189. package/src/private/factory.ts +7 -4
  190. package/src/public/avm/avm_context.ts +2 -2
  191. package/src/public/avm/avm_contract_call_result.ts +8 -6
  192. package/src/public/avm/avm_execution_environment.ts +9 -4
  193. package/src/public/avm/avm_gas.ts +2 -2
  194. package/src/public/avm/avm_machine_state.ts +6 -5
  195. package/src/public/avm/avm_memory_types.ts +4 -0
  196. package/src/public/avm/avm_simulator.ts +9 -6
  197. package/src/public/avm/calldata.ts +101 -0
  198. package/src/public/avm/fixtures/account_proof.json +553 -0
  199. package/src/public/avm/fixtures/account_proof_fetcher.ts +166 -0
  200. package/src/public/avm/fixtures/avm_simulation_tester.ts +8 -2
  201. package/src/public/avm/fixtures/initializers.ts +2 -1
  202. package/src/public/avm/opcodes/accrued_substate.ts +30 -33
  203. package/src/public/avm/opcodes/arithmetic.ts +1 -1
  204. package/src/public/avm/opcodes/bitwise.ts +3 -3
  205. package/src/public/avm/opcodes/comparators.ts +1 -1
  206. package/src/public/avm/opcodes/contract.ts +4 -7
  207. package/src/public/avm/opcodes/control_flow.ts +2 -2
  208. package/src/public/avm/opcodes/conversion.ts +3 -3
  209. package/src/public/avm/opcodes/ec_add.ts +13 -4
  210. package/src/public/avm/opcodes/environment_getters.ts +3 -3
  211. package/src/public/avm/opcodes/external_calls.ts +18 -17
  212. package/src/public/avm/opcodes/hashing.ts +6 -6
  213. package/src/public/avm/opcodes/instruction_impl.ts +2 -2
  214. package/src/public/avm/opcodes/memory.ts +19 -19
  215. package/src/public/avm/opcodes/misc.ts +2 -2
  216. package/src/public/avm/opcodes/storage.ts +30 -22
  217. package/src/public/avm/serialization/bytecode_serialization.ts +2 -2
  218. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  219. package/src/public/contracts_db_checkpoint.ts +1 -1
  220. package/src/public/debug_fn_name.ts +10 -8
  221. package/src/public/executor_metrics.ts +4 -1
  222. package/src/public/fixtures/amm_test.ts +2 -2
  223. package/src/public/fixtures/bulk_test.ts +2 -4
  224. package/src/public/fixtures/custom_bytecode_tests.ts +27 -18
  225. package/src/public/fixtures/minimal_public_tx.ts +2 -2
  226. package/src/public/fixtures/opcode_spammer.ts +196 -117
  227. package/src/public/fixtures/public_tx_simulation_tester.ts +47 -6
  228. package/src/public/fixtures/utils.ts +17 -12
  229. package/src/public/fuzzing/avm_fuzzer_simulator.ts +61 -13
  230. package/src/public/fuzzing/avm_simulator_bin.ts +26 -4
  231. package/src/public/hinting_db_sources.ts +9 -7
  232. package/src/public/public_db_sources.ts +27 -19
  233. package/src/public/public_processor/guarded_merkle_tree.ts +6 -6
  234. package/src/public/public_processor/public_processor.ts +87 -60
  235. package/src/public/public_processor/public_processor_metrics.ts +10 -4
  236. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +8 -4
  237. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +11 -8
  238. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +7 -5
  239. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +7 -5
  240. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +3 -1
  241. package/src/public/public_tx_simulator/factories.ts +6 -3
  242. package/src/public/public_tx_simulator/public_tx_context.ts +21 -16
  243. package/src/public/public_tx_simulator/public_tx_simulator.ts +32 -17
  244. package/src/public/side_effect_trace.ts +5 -2
  245. package/src/public/state_manager/state_manager.ts +29 -20
  246. package/src/public/test_executor_metrics.ts +27 -3
@@ -7,7 +7,7 @@ import {
7
7
  } from '@aztec/constants';
8
8
  import { padArrayEnd } from '@aztec/foundation/collection';
9
9
  import { Fr } from '@aztec/foundation/curves/bn254';
10
- import { type Logger, createLogger } from '@aztec/foundation/log';
10
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
11
11
  import {
12
12
  AvmAccumulatedData,
13
13
  AvmAccumulatedDataArrayLengths,
@@ -87,8 +87,9 @@ export class PublicTxContext {
87
87
  public readonly revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
88
88
  public readonly feePayer: AztecAddress,
89
89
  private readonly trace: SideEffectTrace,
90
+ bindings?: LoggerBindings,
90
91
  ) {
91
- this.log = createLogger(`simulator:public_tx_context`);
92
+ this.log = createLogger(`simulator:public_tx_context`, bindings);
92
93
  }
93
94
 
94
95
  public static async create(
@@ -98,13 +99,14 @@ export class PublicTxContext {
98
99
  globalVariables: GlobalVariables,
99
100
  protocolContracts: ProtocolContracts,
100
101
  proverId: Fr,
102
+ bindings?: LoggerBindings,
101
103
  ) {
102
104
  const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
103
105
  const nonRevertibleContractDeploymentData = contractDeploymentData.getNonRevertibleContractDeploymentData();
104
106
  const revertibleContractDeploymentData = contractDeploymentData.getRevertibleContractDeploymentData();
105
107
  const nonRevertibleAccumulatedDataFromPrivate = tx.data.forPublic!.nonRevertibleAccumulatedData;
106
108
 
107
- const trace = new SideEffectTrace();
109
+ const trace = new SideEffectTrace(0, bindings);
108
110
 
109
111
  const firstNullifier = nonRevertibleAccumulatedDataFromPrivate.nullifiers[0];
110
112
 
@@ -115,6 +117,7 @@ export class PublicTxContext {
115
117
  trace,
116
118
  firstNullifier,
117
119
  globalVariables.timestamp,
120
+ bindings,
118
121
  );
119
122
 
120
123
  const gasSettings = tx.data.constants.txContext.gasSettings;
@@ -124,7 +127,7 @@ export class PublicTxContext {
124
127
 
125
128
  return new PublicTxContext(
126
129
  tx.getTxHash(),
127
- new PhaseStateManager(txStateManager),
130
+ new PhaseStateManager(txStateManager, bindings),
128
131
  await txStateManager.getTreeSnapshots(),
129
132
  globalVariables,
130
133
  protocolContracts,
@@ -142,6 +145,7 @@ export class PublicTxContext {
142
145
  tx.data.forPublic!.revertibleAccumulatedData,
143
146
  tx.data.feePayer,
144
147
  trace,
148
+ bindings,
145
149
  );
146
150
  }
147
151
 
@@ -170,14 +174,8 @@ export class PublicTxContext {
170
174
  }
171
175
  if (phase === TxExecutionPhase.SETUP) {
172
176
  this.log.warn(`Setup phase reverted! The transaction will be thrown out.`);
173
- } else if (phase === TxExecutionPhase.APP_LOGIC) {
174
- this.revertCode = RevertCode.APP_LOGIC_REVERTED;
175
- } else if (phase === TxExecutionPhase.TEARDOWN) {
176
- if (this.revertCode.equals(RevertCode.APP_LOGIC_REVERTED)) {
177
- this.revertCode = RevertCode.BOTH_REVERTED;
178
- } else {
179
- this.revertCode = RevertCode.TEARDOWN_REVERTED;
180
- }
177
+ } else if (phase === TxExecutionPhase.APP_LOGIC || phase === TxExecutionPhase.TEARDOWN) {
178
+ this.revertCode = RevertCode.REVERTED;
181
179
  }
182
180
  }
183
181
 
@@ -243,8 +241,12 @@ export class PublicTxContext {
243
241
  }
244
242
 
245
243
  /**
246
- * The gasUsed by public and private,
247
- * as if the entire teardown gas limit was consumed.
244
+ * The gasUsed by public and private, as if the entire teardown gas limit was consumed.
245
+ *
246
+ * This is intentional: teardown is used for gas accounting and refunds, so the transaction
247
+ * fee must be deterministic _before_ teardown executes. If fees depended on teardown's actual
248
+ * consumption there would be a circular dependency. Billing the full teardown gas limit
249
+ * (set by the user) makes the fee known in advance and available to the teardown function.
248
250
  */
249
251
  getTotalGasUsed(): Gas {
250
252
  return this.gasUsedByPrivate.add(this.gasUsedByPublic);
@@ -441,8 +443,11 @@ class PhaseStateManager {
441
443
 
442
444
  private currentlyActiveStateManager: PublicPersistableStateManager | undefined;
443
445
 
444
- constructor(private readonly txStateManager: PublicPersistableStateManager) {
445
- this.log = createLogger(`simulator:public_phase_state_manager`);
446
+ constructor(
447
+ private readonly txStateManager: PublicPersistableStateManager,
448
+ bindings?: LoggerBindings,
449
+ ) {
450
+ this.log = createLogger(`simulator:public_phase_state_manager`, bindings);
446
451
  }
447
452
 
448
453
  async fork() {
@@ -1,6 +1,6 @@
1
- import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
1
+ import { MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { type Logger, createLogger } from '@aztec/foundation/log';
3
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
4
4
  import { ProtocolContractAddress, ProtocolContractsList } from '@aztec/protocol-contracts';
5
5
  import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
6
6
  import { AvmExecutionHints, AvmTxHint, PublicSimulatorConfig, PublicTxEffect, PublicTxResult } from '@aztec/stdlib/avm';
@@ -10,6 +10,7 @@ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
10
10
  import {
11
11
  type GlobalVariables,
12
12
  NestedProcessReturnValues,
13
+ ProtocolContracts,
13
14
  PublicCallRequestWithCalldata,
14
15
  Tx,
15
16
  TxExecutionPhase,
@@ -18,6 +19,7 @@ import {
18
19
  import { strict as assert } from 'assert';
19
20
 
20
21
  import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
22
+ import { CallDataArray } from '../avm/calldata.js';
21
23
  import { AvmSimulator } from '../avm/index.js';
22
24
  import { getPublicFunctionDebugName } from '../debug_fn_name.js';
23
25
  import { HintingMerkleWriteOperations, HintingPublicContractsDB } from '../hinting_db_sources.js';
@@ -25,7 +27,6 @@ import { type PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
25
27
  import {
26
28
  L2ToL1MessageLimitReachedError,
27
29
  NoteHashLimitReachedError,
28
- NullifierCollisionError,
29
30
  NullifierLimitReachedError,
30
31
  } from '../side_effect_errors.js';
31
32
  import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
@@ -79,15 +80,19 @@ type ProcessedPhase = {
79
80
  export class PublicTxSimulator implements PublicTxSimulatorInterface {
80
81
  protected log: Logger;
81
82
  protected readonly config: PublicSimulatorConfig;
83
+ protected readonly bindings?: LoggerBindings;
82
84
 
83
85
  constructor(
84
86
  protected merkleTree: MerkleTreeWriteOperations,
85
87
  protected contractsDB: PublicContractsDB,
86
88
  protected globalVariables: GlobalVariables,
87
89
  config?: Partial<PublicSimulatorConfig>,
90
+ protected protocolContracts: ProtocolContracts = ProtocolContractsList,
91
+ bindings?: LoggerBindings,
88
92
  ) {
89
93
  this.config = PublicSimulatorConfig.from(config ?? {});
90
- this.log = createLogger(`simulator:public_tx_simulator`);
94
+ this.bindings = bindings;
95
+ this.log = createLogger(`simulator:public_tx_simulator`, bindings);
91
96
  }
92
97
 
93
98
  /**
@@ -103,7 +108,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
103
108
  const hints = new AvmExecutionHints(
104
109
  this.globalVariables,
105
110
  AvmTxHint.fromTx(tx, this.globalVariables.gasFees),
106
- ProtocolContractsList, // imported from file
111
+ this.protocolContracts,
107
112
  );
108
113
  const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
109
114
  const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
@@ -114,8 +119,9 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
114
119
  hintingContractsDB,
115
120
  tx,
116
121
  this.globalVariables,
117
- ProtocolContractsList, // imported from file
122
+ this.protocolContracts,
118
123
  this.config.proverId,
124
+ this.bindings,
119
125
  );
120
126
 
121
127
  // This will throw if there is a nullifier collision.
@@ -140,7 +146,8 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
140
146
  hintingContractsDB.createCheckpoint();
141
147
 
142
148
  try {
143
- // This will throw if there is a nullifier collision or other insertion error (limit reached).
149
+ // This may throw: a side-effect limit error triggers a soft revert (caught below), while a
150
+ // nullifier collision is unrecoverable and propagates out of simulate() to throw out the tx.
144
151
  await this.insertRevertiblesFromPrivate(context);
145
152
 
146
153
  // Only proceed with app logic if there was no revert during revertible insertion.
@@ -192,8 +199,8 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
192
199
 
193
200
  // Such transactions should be filtered by GasTxValidator.
194
201
  assert(
195
- context.getActualGasUsed().l2Gas <= AVM_MAX_PROCESSABLE_L2_GAS,
196
- `Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the AVM maximum processable gas of ${AVM_MAX_PROCESSABLE_L2_GAS}`,
202
+ context.getActualGasUsed().l2Gas <= MAX_PROCESSABLE_L2_GAS,
203
+ `Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the maximum processable gas of ${MAX_PROCESSABLE_L2_GAS}`,
197
204
  );
198
205
  await this.payFee(context);
199
206
 
@@ -265,7 +272,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
265
272
 
266
273
  const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest);
267
274
 
268
- returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output));
275
+ returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output.bestEffortReadAll()));
269
276
 
270
277
  if (enqueuedCallResult.reverted) {
271
278
  reverted = true;
@@ -295,7 +302,11 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
295
302
  ): Promise<AvmFinalizedCallResult> {
296
303
  const stateManager = context.state.getActiveStateManager();
297
304
  const contractAddress = callRequest.request.contractAddress;
298
- const fnName = await getPublicFunctionDebugName(this.contractsDB, contractAddress, callRequest.calldata);
305
+ const fnName = await getPublicFunctionDebugName(
306
+ this.contractsDB,
307
+ contractAddress,
308
+ new CallDataArray(callRequest.calldata),
309
+ );
299
310
 
300
311
  const allocatedGas = context.getGasLeftAtPhase(phase);
301
312
 
@@ -355,7 +366,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
355
366
  transactionFee,
356
367
  this.globalVariables,
357
368
  request.isStaticCall,
358
- calldata,
369
+ new CallDataArray(calldata),
359
370
  allocatedGas,
360
371
  this.config,
361
372
  );
@@ -390,7 +401,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
390
401
  // However, things work as expected because later calls to getters on the hintingContractsDB
391
402
  // will pick up the new contracts and will generate the necessary hints.
392
403
  // So, a consumer of the hints will always see the new contracts.
393
- await this.contractsDB.addContracts(context.nonRevertibleContractDeploymentData);
404
+ this.contractsDB.addContracts(context.nonRevertibleContractDeploymentData);
394
405
  }
395
406
 
396
407
  /**
@@ -398,9 +409,13 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
398
409
  * Throws TxSimRevertibleInsertionsRevert if there is some checked error during revertible insertions.
399
410
  * This function checks for the following errors:
400
411
  * - NullifierLimitReachedError
401
- * - NullifierCollisionError
402
412
  * - NoteHashLimitReachedError
403
413
  * - L2ToL1MessageLimitReachedError
414
+ *
415
+ * Note: NullifierCollisionError is intentionally NOT caught here. A nullifier collision
416
+ * during revertible insertions is unprovable (the nullifier originated from private, so
417
+ * a collision indicates the tx should never have been proposed). It propagates as-is to
418
+ * make the transaction unrecoverable, matching the AVM circuit behavior.
404
419
  */
405
420
  protected async insertRevertiblesFromPrivate(context: PublicTxContext) {
406
421
  const stateManager = context.state.getActiveStateManager();
@@ -410,7 +425,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
410
425
  await stateManager.writeSiloedNullifier(siloedNullifier);
411
426
  }
412
427
  } catch (e: any) {
413
- if (e instanceof NullifierLimitReachedError || e instanceof NullifierCollisionError) {
428
+ if (e instanceof NullifierLimitReachedError) {
414
429
  context.revert(
415
430
  TxExecutionPhase.APP_LOGIC,
416
431
  new SimulationError(
@@ -420,7 +435,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
420
435
  );
421
436
  throw new TxSimRevertibleInsertionsRevert();
422
437
  } else {
423
- // Unchecked/unknown error - re-throw as-is
438
+ // Unchecked/unknown error or NullifierCollisionError (unrecoverable) - re-throw as-is
424
439
  throw e;
425
440
  }
426
441
  }
@@ -475,7 +490,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
475
490
  // However, things work as expected because later calls to getters on the hintingContractsDB
476
491
  // will pick up the new contracts and will generate the necessary hints.
477
492
  // So, a consumer of the hints will always see the new contracts.
478
- await this.contractsDB.addContracts(context.revertibleContractDeploymentData);
493
+ this.contractsDB.addContracts(context.revertibleContractDeploymentData);
479
494
  }
480
495
 
481
496
  private async payFee(context: PublicTxContext) {
@@ -9,7 +9,7 @@ import {
9
9
  } from '@aztec/constants';
10
10
  import { Fr } from '@aztec/foundation/curves/bn254';
11
11
  import { EthAddress } from '@aztec/foundation/eth-address';
12
- import { type LogLevel, createLogger } from '@aztec/foundation/log';
12
+ import { type LogLevel, type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
13
13
  import { PublicDataUpdateRequest } from '@aztec/stdlib/avm';
14
14
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
15
15
  import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
@@ -61,7 +61,7 @@ export class SideEffectArrayLengths {
61
61
  * Trace side effects for an enqueued public call's execution.
62
62
  */
63
63
  export class SideEffectTrace implements PublicSideEffectTraceInterface {
64
- public log = createLogger('simulator:side_effect_trace');
64
+ public log: Logger;
65
65
 
66
66
  /** The side effect counter increments with every call to the trace. */
67
67
  private sideEffectCounter: number;
@@ -79,6 +79,7 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
79
79
  constructor(
80
80
  /** The counter of this trace's first side effect. */
81
81
  public readonly startSideEffectCounter: number = 0,
82
+ bindings?: LoggerBindings,
82
83
  /** Track parent's (or previous kernel's) lengths so the AVM can properly enforce TX-wide limits,
83
84
  * otherwise the public kernel can fail to prove because TX limits are breached.
84
85
  */
@@ -90,11 +91,13 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
90
91
  private debugLogMemoryReads: number = 0,
91
92
  ) {
92
93
  this.sideEffectCounter = startSideEffectCounter;
94
+ this.log = createLogger('simulator:side_effect_trace', bindings);
93
95
  }
94
96
 
95
97
  public fork() {
96
98
  return new SideEffectTrace(
97
99
  this.sideEffectCounter,
100
+ this.log.getBindings(),
98
101
  new SideEffectArrayLengths(
99
102
  this.previousSideEffectArrayLengths.publicDataWrites + this.userPublicDataWritesLength,
100
103
  this.previousSideEffectArrayLengths.protocolPublicDataWrites + this.protocolPublicDataWritesLength,
@@ -1,15 +1,8 @@
1
- import {
2
- CANONICAL_AUTH_REGISTRY_ADDRESS,
3
- CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS,
4
- CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
5
- FEE_JUICE_ADDRESS,
6
- MULTI_CALL_ENTRYPOINT_ADDRESS,
7
- ROUTER_ADDRESS,
8
- } from '@aztec/constants';
1
+ import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, MAX_PROTOCOL_CONTRACTS } from '@aztec/constants';
9
2
  import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
10
3
  import { Fr } from '@aztec/foundation/curves/bn254';
11
4
  import { jsonStringify } from '@aztec/foundation/json-rpc';
12
- import { type LogLevel, createLogger } from '@aztec/foundation/log';
5
+ import { type LogLevel, type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
13
6
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
14
7
  import { FunctionSelector } from '@aztec/stdlib/abi';
15
8
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -49,7 +42,7 @@ import { PublicStorage } from './public_storage.js';
49
42
  * Manages merging of successful/reverted child state into current state.
50
43
  */
51
44
  export class PublicPersistableStateManager {
52
- private readonly log = createLogger('simulator:state_manager');
45
+ private readonly log: Logger;
53
46
 
54
47
  /** Make sure a forked state is never merged twice. */
55
48
  private alreadyMergedIntoParent = false;
@@ -63,7 +56,10 @@ export class PublicPersistableStateManager {
63
56
  private readonly doMerkleOperations: boolean = true,
64
57
  private readonly publicStorage: PublicStorage = new PublicStorage(treesDB),
65
58
  private readonly nullifiers: NullifierManager = new NullifierManager(treesDB),
66
- ) {}
59
+ bindings?: LoggerBindings,
60
+ ) {
61
+ this.log = createLogger('simulator:state_manager', bindings);
62
+ }
67
63
 
68
64
  /**
69
65
  * Create a new state manager
@@ -74,8 +70,19 @@ export class PublicPersistableStateManager {
74
70
  trace: PublicSideEffectTraceInterface,
75
71
  firstNullifier: Fr,
76
72
  timestamp: UInt64,
73
+ bindings?: LoggerBindings,
77
74
  ): PublicPersistableStateManager {
78
- return new PublicPersistableStateManager(treesDB, contractsDB, trace, firstNullifier, timestamp);
75
+ return new PublicPersistableStateManager(
76
+ treesDB,
77
+ contractsDB,
78
+ trace,
79
+ firstNullifier,
80
+ timestamp,
81
+ undefined,
82
+ undefined,
83
+ undefined,
84
+ bindings,
85
+ );
79
86
  }
80
87
 
81
88
  /**
@@ -92,6 +99,7 @@ export class PublicPersistableStateManager {
92
99
  this.doMerkleOperations,
93
100
  this.publicStorage.fork(),
94
101
  this.nullifiers.fork(),
102
+ this.log.getBindings(),
95
103
  );
96
104
  }
97
105
 
@@ -240,7 +248,15 @@ export class PublicPersistableStateManager {
240
248
  public async checkNullifierExists(contractAddress: AztecAddress, nullifier: Fr): Promise<boolean> {
241
249
  this.log.trace(`Checking existence of nullifier (address=${contractAddress}, nullifier=${nullifier})`);
242
250
  const siloedNullifier = await siloNullifier(contractAddress, nullifier);
251
+ return this.checkSiloedNullifierExists(siloedNullifier);
252
+ }
243
253
 
254
+ /**
255
+ * Check if a siloed nullifier exists.
256
+ * @param siloedNullifier - the siloed nullifier to check
257
+ * @returns exists - whether the nullifier exists in the nullifier set
258
+ */
259
+ public async checkSiloedNullifierExists(siloedNullifier: Fr): Promise<boolean> {
244
260
  if (this.doMerkleOperations) {
245
261
  const exists = await this.treesDB.checkNullifierExists(siloedNullifier);
246
262
  this.log.trace(`Checked siloed nullifier ${siloedNullifier} (exists=${exists})`);
@@ -549,12 +565,5 @@ export class PublicPersistableStateManager {
549
565
  }
550
566
 
551
567
  function contractAddressIsCanonical(contractAddress: AztecAddress): boolean {
552
- return (
553
- contractAddress.equals(AztecAddress.fromNumber(CANONICAL_AUTH_REGISTRY_ADDRESS)) ||
554
- contractAddress.equals(AztecAddress.fromNumber(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS)) ||
555
- contractAddress.equals(AztecAddress.fromNumber(CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS)) ||
556
- contractAddress.equals(AztecAddress.fromNumber(MULTI_CALL_ENTRYPOINT_ADDRESS)) ||
557
- contractAddress.equals(AztecAddress.fromNumber(FEE_JUICE_ADDRESS)) ||
558
- contractAddress.equals(AztecAddress.fromNumber(ROUTER_ADDRESS))
559
- );
568
+ return contractAddress.toBigInt() >= 1 && contractAddress.toBigInt() <= MAX_PROTOCOL_CONTRACTS;
560
569
  }
@@ -1,5 +1,5 @@
1
1
  import { sum } from '@aztec/foundation/collection';
2
- import { type Logger, createLogger } from '@aztec/foundation/log';
2
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
4
  import type { RevertCode } from '@aztec/stdlib/avm';
5
5
  import type { GasUsed } from '@aztec/stdlib/gas';
@@ -21,6 +21,7 @@ export interface PublicTxMetrics {
21
21
  totalDurationMs: number;
22
22
  manaUsed: number | undefined;
23
23
  totalInstructionsExecuted: number;
24
+ bytecodeSizes: { contractName: string; sizeBytes: number }[];
24
25
  nonRevertiblePrivateInsertionsUs: number | undefined;
25
26
  revertiblePrivateInsertionsUs: number | undefined;
26
27
  enqueuedCalls: PublicEnqueuedCallMetrics[];
@@ -62,6 +63,7 @@ function createEmptyTxMetrics(): PublicTxMetrics {
62
63
  totalDurationMs: 0,
63
64
  manaUsed: 0,
64
65
  totalInstructionsExecuted: 0,
66
+ bytecodeSizes: [],
65
67
  nonRevertiblePrivateInsertionsUs: undefined,
66
68
  revertiblePrivateInsertionsUs: undefined,
67
69
  enqueuedCalls: [],
@@ -88,8 +90,8 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
88
90
  private currentTxLabel: string | undefined;
89
91
  private txTimer: Timer | undefined;
90
92
 
91
- constructor() {
92
- this.logger = createLogger(`simulator:test_executor_metrics`);
93
+ constructor(bindings?: LoggerBindings) {
94
+ this.logger = createLogger(`simulator:test_executor_metrics`, bindings);
93
95
  }
94
96
 
95
97
  startRecordingTxSimulation(txLabel: string) {
@@ -172,6 +174,12 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
172
174
  }
173
175
  }
174
176
 
177
+ recordBytecodeSize(txLabel: string, contractName: string, sizeBytes: number) {
178
+ const txMetrics = this.txMetrics.get(txLabel);
179
+ assert(txMetrics, `Cannot record bytecode size for unknown tx label: ${txLabel}`);
180
+ txMetrics.bytecodeSizes.push({ contractName, sizeBytes });
181
+ }
182
+
175
183
  recordProverMetrics(txLabel: string, metrics: Partial<PublicTxMetrics>) {
176
184
  if (!this.txMetrics.has(txLabel)) {
177
185
  this.txMetrics.set(txLabel, createEmptyTxMetrics());
@@ -216,6 +224,15 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
216
224
  ) {
217
225
  pretty += `${INDENT0}Total instructions executed: ${fmtNum(txMetrics.totalInstructionsExecuted)}\n`;
218
226
  }
227
+ if (
228
+ (filter === PublicTxMetricsFilter.TOTALS || filter === PublicTxMetricsFilter.ALL) &&
229
+ txMetrics.bytecodeSizes.length > 0
230
+ ) {
231
+ pretty += `${INDENT0}Bytecode sizes:\n`;
232
+ for (const { contractName, sizeBytes } of txMetrics.bytecodeSizes) {
233
+ pretty += `${INDENT1}${contractName}: ${fmtNum(sizeBytes, 'bytes')}\n`;
234
+ }
235
+ }
219
236
  if (filter === PublicTxMetricsFilter.DURATIONS || filter === PublicTxMetricsFilter.ALL) {
220
237
  pretty += `${INDENT0}Private insertions:\n`;
221
238
  pretty += `${INDENT1}Non-revertible: ${fmtNum(txMetrics.nonRevertiblePrivateInsertionsUs! / 1_000, 'ms')}\n`;
@@ -387,6 +404,13 @@ export class TestExecutorMetrics implements ExecutorMetricsInterface {
387
404
  });
388
405
  }
389
406
  }
407
+ for (const { contractName, sizeBytes } of txMetrics.bytecodeSizes) {
408
+ data.push({
409
+ name: `${txLabel}/bytecodeSizeBytes/${contractName}`,
410
+ value: sizeBytes,
411
+ unit: 'bytes',
412
+ });
413
+ }
390
414
  }
391
415
  return JSON.stringify(data, null, indent);
392
416
  }