@aztec/simulator 0.0.1-commit.5476d83 → 0.0.1-commit.6230efd

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 (229) hide show
  1. package/dest/common/errors.d.ts +2 -2
  2. package/dest/common/errors.d.ts.map +1 -1
  3. package/dest/private/acvm/deserialize.d.ts +2 -2
  4. package/dest/private/acvm/deserialize.d.ts.map +1 -1
  5. package/dest/private/acvm/deserialize.js +1 -1
  6. package/dest/private/acvm/serialize.d.ts +2 -2
  7. package/dest/private/acvm/serialize.d.ts.map +1 -1
  8. package/dest/private/acvm/serialize.js +1 -1
  9. package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
  10. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  11. package/dest/private/circuit_recording/circuit_recorder.js +16 -15
  12. package/dest/public/avm/avm_context.d.ts +2 -2
  13. package/dest/public/avm/avm_context.d.ts.map +1 -1
  14. package/dest/public/avm/avm_contract_call_result.d.ts +2 -2
  15. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  16. package/dest/public/avm/avm_execution_environment.d.ts +2 -2
  17. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  18. package/dest/public/avm/avm_execution_environment.js +1 -1
  19. package/dest/public/avm/avm_gas.d.ts +1 -1
  20. package/dest/public/avm/avm_gas.d.ts.map +1 -1
  21. package/dest/public/avm/avm_machine_state.d.ts +2 -2
  22. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  23. package/dest/public/avm/avm_memory_types.d.ts +2 -2
  24. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  25. package/dest/public/avm/avm_memory_types.js +1 -1
  26. package/dest/public/avm/avm_simulator.d.ts +2 -2
  27. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  28. package/dest/public/avm/avm_simulator.js +6 -5
  29. package/dest/public/avm/errors.d.ts +8 -2
  30. package/dest/public/avm/errors.d.ts.map +1 -1
  31. package/dest/public/avm/errors.js +14 -2
  32. package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -1
  33. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -2
  34. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  35. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +1 -1
  36. package/dest/public/avm/fixtures/initializers.d.ts +2 -2
  37. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  38. package/dest/public/avm/fixtures/initializers.js +3 -3
  39. package/dest/public/avm/fixtures/utils.d.ts +4 -3
  40. package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
  41. package/dest/public/avm/fixtures/utils.js +3 -2
  42. package/dest/public/avm/opcodes/addressing_mode.js +2 -2
  43. package/dest/public/avm/opcodes/arithmetic.d.ts +3 -1
  44. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  45. package/dest/public/avm/opcodes/arithmetic.js +11 -1
  46. package/dest/public/avm/opcodes/ec_add.js +2 -2
  47. package/dest/public/avm/opcodes/hashing.d.ts +1 -1
  48. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  49. package/dest/public/avm/opcodes/hashing.js +9 -4
  50. package/dest/public/avm/opcodes/memory.js +1 -1
  51. package/dest/public/avm/opcodes/misc.js +2 -2
  52. package/dest/public/avm/revert_reason.d.ts +2 -2
  53. package/dest/public/avm/revert_reason.d.ts.map +1 -1
  54. package/dest/public/avm/revert_reason.js +3 -2
  55. package/dest/public/avm/serialization/bytecode_serialization.d.ts +1 -1
  56. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  57. package/dest/public/avm/serialization/bytecode_serialization.js +9 -6
  58. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  59. package/dest/public/avm/test_utils.d.ts +2 -2
  60. package/dest/public/avm/test_utils.d.ts.map +1 -1
  61. package/dest/public/avm/test_utils.js +1 -1
  62. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  63. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  64. package/dest/public/db_interfaces.d.ts +2 -2
  65. package/dest/public/db_interfaces.d.ts.map +1 -1
  66. package/dest/public/debug_fn_name.d.ts +15 -2
  67. package/dest/public/debug_fn_name.d.ts.map +1 -1
  68. package/dest/public/debug_fn_name.js +28 -2
  69. package/dest/public/fixtures/amm_test.js +2 -2
  70. package/dest/public/fixtures/bulk_test.js +4 -52
  71. package/dest/public/fixtures/custom_bytecode_tester.d.ts +28 -6
  72. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  73. package/dest/public/fixtures/custom_bytecode_tester.js +36 -12
  74. package/dest/public/fixtures/custom_bytecode_tests.d.ts +4 -1
  75. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  76. package/dest/public/fixtures/custom_bytecode_tests.js +74 -9
  77. package/dest/public/fixtures/index.d.ts +4 -2
  78. package/dest/public/fixtures/index.d.ts.map +1 -1
  79. package/dest/public/fixtures/index.js +3 -1
  80. package/dest/public/fixtures/minimal_public_tx.d.ts +2 -7
  81. package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -1
  82. package/dest/public/fixtures/minimal_public_tx.js +2 -12
  83. package/dest/public/fixtures/opcode_spammer.d.ts +123 -0
  84. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -0
  85. package/dest/public/fixtures/opcode_spammer.js +1681 -0
  86. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +22 -3
  87. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  88. package/dest/public/fixtures/public_tx_simulation_tester.js +50 -13
  89. package/dest/public/fixtures/simple_contract_data_source.d.ts +5 -4
  90. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  91. package/dest/public/fixtures/simple_contract_data_source.js +4 -4
  92. package/dest/public/fixtures/token_test.d.ts +6 -2
  93. package/dest/public/fixtures/token_test.d.ts.map +1 -1
  94. package/dest/public/fixtures/token_test.js +13 -11
  95. package/dest/public/fixtures/utils.d.ts +2 -2
  96. package/dest/public/fixtures/utils.d.ts.map +1 -1
  97. package/dest/public/fixtures/utils.js +4 -3
  98. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +46 -0
  99. package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
  100. package/dest/public/fuzzing/avm_fuzzer_simulator.js +139 -0
  101. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  102. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  103. package/dest/public/fuzzing/avm_simulator_bin.js +100 -0
  104. package/dest/public/hinting_db_sources.d.ts +5 -3
  105. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  106. package/dest/public/hinting_db_sources.js +5 -2
  107. package/dest/public/index.d.ts +2 -2
  108. package/dest/public/index.d.ts.map +1 -1
  109. package/dest/public/index.js +1 -1
  110. package/dest/public/public_db_sources.d.ts +2 -2
  111. package/dest/public/public_db_sources.d.ts.map +1 -1
  112. package/dest/public/public_db_sources.js +1 -1
  113. package/dest/public/public_processor/guarded_merkle_tree.d.ts +4 -2
  114. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  115. package/dest/public/public_processor/guarded_merkle_tree.js +3 -0
  116. package/dest/public/public_processor/public_processor.d.ts +5 -5
  117. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  118. package/dest/public/public_processor/public_processor.js +35 -22
  119. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -13
  120. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  121. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +18 -53
  122. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +21 -34
  123. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  124. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +60 -139
  125. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +42 -0
  126. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -0
  127. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +86 -0
  128. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +30 -0
  129. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -0
  130. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +171 -0
  131. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +22 -0
  132. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
  133. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
  134. package/dest/public/public_tx_simulator/factories.d.ts +13 -0
  135. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  136. package/dest/public/public_tx_simulator/factories.js +28 -0
  137. package/dest/public/public_tx_simulator/index.d.ts +4 -1
  138. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  139. package/dest/public/public_tx_simulator/index.js +3 -0
  140. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +2 -2
  141. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  142. package/dest/public/public_tx_simulator/public_tx_context.d.ts +2 -2
  143. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  144. package/dest/public/public_tx_simulator/public_tx_context.js +1 -1
  145. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +3 -3
  146. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  147. package/dest/public/public_tx_simulator/public_tx_simulator.js +11 -5
  148. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +24 -1
  149. package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -1
  150. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +2 -2
  151. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  152. package/dest/public/side_effect_trace.d.ts +2 -2
  153. package/dest/public/side_effect_trace.d.ts.map +1 -1
  154. package/dest/public/side_effect_trace.js +1 -1
  155. package/dest/public/side_effect_trace_interface.d.ts +2 -2
  156. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  157. package/dest/public/state_manager/nullifiers.d.ts +2 -2
  158. package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
  159. package/dest/public/state_manager/public_storage.d.ts +2 -2
  160. package/dest/public/state_manager/public_storage.d.ts.map +1 -1
  161. package/dest/public/state_manager/public_storage.js +1 -1
  162. package/dest/public/state_manager/state_manager.d.ts +7 -2
  163. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  164. package/dest/public/state_manager/state_manager.js +5 -2
  165. package/package.json +19 -19
  166. package/src/common/errors.ts +1 -1
  167. package/src/private/acvm/deserialize.ts +1 -1
  168. package/src/private/acvm/serialize.ts +1 -1
  169. package/src/private/circuit_recording/circuit_recorder.ts +17 -16
  170. package/src/public/avm/avm_context.ts +1 -1
  171. package/src/public/avm/avm_contract_call_result.ts +1 -1
  172. package/src/public/avm/avm_execution_environment.ts +1 -1
  173. package/src/public/avm/avm_gas.ts +3 -3
  174. package/src/public/avm/avm_machine_state.ts +1 -1
  175. package/src/public/avm/avm_memory_types.ts +1 -1
  176. package/src/public/avm/avm_simulator.ts +8 -5
  177. package/src/public/avm/errors.ts +17 -3
  178. package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
  179. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
  180. package/src/public/avm/fixtures/initializers.ts +3 -3
  181. package/src/public/avm/fixtures/utils.ts +3 -2
  182. package/src/public/avm/opcodes/addressing_mode.ts +2 -2
  183. package/src/public/avm/opcodes/arithmetic.ts +13 -1
  184. package/src/public/avm/opcodes/ec_add.ts +2 -2
  185. package/src/public/avm/opcodes/hashing.ts +10 -4
  186. package/src/public/avm/opcodes/memory.ts +1 -1
  187. package/src/public/avm/opcodes/misc.ts +2 -2
  188. package/src/public/avm/revert_reason.ts +6 -3
  189. package/src/public/avm/serialization/bytecode_serialization.ts +17 -6
  190. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  191. package/src/public/avm/test_utils.ts +1 -1
  192. package/src/public/contracts_db_checkpoint.ts +1 -1
  193. package/src/public/db_interfaces.ts +1 -1
  194. package/src/public/debug_fn_name.ts +35 -3
  195. package/src/public/fixtures/amm_test.ts +2 -2
  196. package/src/public/fixtures/bulk_test.ts +7 -7
  197. package/src/public/fixtures/custom_bytecode_tester.ts +53 -19
  198. package/src/public/fixtures/custom_bytecode_tests.ts +93 -9
  199. package/src/public/fixtures/index.ts +7 -1
  200. package/src/public/fixtures/minimal_public_tx.ts +4 -13
  201. package/src/public/fixtures/opcode_spammer.ts +1638 -0
  202. package/src/public/fixtures/public_tx_simulation_tester.ts +69 -13
  203. package/src/public/fixtures/simple_contract_data_source.ts +8 -9
  204. package/src/public/fixtures/token_test.ts +18 -9
  205. package/src/public/fixtures/utils.ts +2 -3
  206. package/src/public/fuzzing/avm_fuzzer_simulator.ts +240 -0
  207. package/src/public/fuzzing/avm_simulator_bin.ts +140 -0
  208. package/src/public/hinting_db_sources.ts +8 -3
  209. package/src/public/index.ts +7 -1
  210. package/src/public/public_db_sources.ts +1 -1
  211. package/src/public/public_processor/guarded_merkle_tree.ts +6 -1
  212. package/src/public/public_processor/public_processor.ts +43 -27
  213. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +19 -60
  214. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +68 -174
  215. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +132 -0
  216. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +237 -0
  217. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
  218. package/src/public/public_tx_simulator/factories.ts +41 -0
  219. package/src/public/public_tx_simulator/index.ts +3 -0
  220. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +1 -1
  221. package/src/public/public_tx_simulator/public_tx_context.ts +1 -1
  222. package/src/public/public_tx_simulator/public_tx_simulator.ts +24 -9
  223. package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +23 -0
  224. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +1 -1
  225. package/src/public/side_effect_trace.ts +1 -1
  226. package/src/public/side_effect_trace_interface.ts +1 -1
  227. package/src/public/state_manager/nullifiers.ts +1 -1
  228. package/src/public/state_manager/public_storage.ts +1 -1
  229. package/src/public/state_manager/state_manager.ts +10 -3
@@ -1,5 +1,6 @@
1
- import { sha256Trunc } from '@aztec/foundation/crypto';
2
- import { Fr } from '@aztec/foundation/fields';
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { sha256Trunc } from '@aztec/foundation/crypto/sha256';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { type Logger, createLogger } from '@aztec/foundation/log';
4
5
  import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
5
6
  import type { FunctionSelector } from '@aztec/stdlib/abi';
@@ -571,6 +572,10 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
571
572
  return await this.db.close();
572
573
  }
573
574
 
575
+ async [Symbol.dispose](): Promise<void> {
576
+ await this.close();
577
+ }
578
+
574
579
  public async findLeafIndices<ID extends MerkleTreeId>(
575
580
  treeId: ID,
576
581
  values: MerkleTreeLeafType<ID>[],
@@ -596,7 +601,7 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
596
601
  public async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
597
602
  treeId: ID,
598
603
  leafIndices: bigint[],
599
- ): Promise<(bigint | undefined)[]> {
604
+ ): Promise<(BlockNumber | undefined)[]> {
600
605
  return await this.db.getBlockNumbersForLeafIndices(treeId, leafIndices);
601
606
  }
602
607
  }
@@ -1,6 +1,12 @@
1
1
  export { PublicContractsDB } from './public_db_sources.js';
2
2
  export { GuardedMerkleTreeOperations } from './public_processor/guarded_merkle_tree.js';
3
3
  export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
4
- export { PublicTxSimulator, TelemetryPublicTxSimulator } from './public_tx_simulator/index.js';
4
+ export {
5
+ CppPublicTxSimulator,
6
+ createPublicTxSimulatorForBlockBuilding,
7
+ DumpingCppPublicTxSimulator,
8
+ type PublicTxSimulatorInterface,
9
+ TelemetryCppPublicTxSimulator,
10
+ } from './public_tx_simulator/index.js';
5
11
  export type { PublicTxResult, PublicSimulatorConfig as PublicTxSimulatorConfig } from '@aztec/stdlib/avm';
6
12
  export { getCallRequestsWithCalldataByPhase } from './utils.js';
@@ -4,7 +4,7 @@ import {
4
4
  NULLIFIER_SUBTREE_HEIGHT,
5
5
  PUBLIC_DATA_SUBTREE_HEIGHT,
6
6
  } from '@aztec/constants';
7
- import { Fr } from '@aztec/foundation/fields';
7
+ import { Fr } from '@aztec/foundation/curves/bn254';
8
8
  import { createLogger } from '@aztec/foundation/log';
9
9
  import { Timer } from '@aztec/foundation/timer';
10
10
  import { ContractClassPublishedEvent } from '@aztec/protocol-contracts/class-registry';
@@ -1,3 +1,4 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { SerialQueue } from '@aztec/foundation/queue';
2
3
  import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
3
4
  import type {
@@ -80,6 +81,10 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
80
81
  close(): Promise<void> {
81
82
  return this.guardAndPush(() => this.target.close());
82
83
  }
84
+
85
+ async [Symbol.dispose](): Promise<void> {
86
+ await this.close();
87
+ }
83
88
  getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo> {
84
89
  return this.guardAndPush(() => this.target.getTreeInfo(treeId));
85
90
  }
@@ -126,7 +131,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
126
131
  getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
127
132
  treeId: ID,
128
133
  leafIndices: bigint[],
129
- ): Promise<(bigint | undefined)[]> {
134
+ ): Promise<(BlockNumber | undefined)[]> {
130
135
  return this.guardAndPush(() => this.target.getBlockNumbersForLeafIndices(treeId, leafIndices));
131
136
  }
132
137
  createCheckpoint(): Promise<void> {
@@ -1,6 +1,6 @@
1
1
  import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT } from '@aztec/constants';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
- import { Fr } from '@aztec/foundation/fields';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import { createLogger } from '@aztec/foundation/log';
5
5
  import { sleep } from '@aztec/foundation/sleep';
6
6
  import { DateProvider, Timer, elapsed, executeTimeout } from '@aztec/foundation/timer';
@@ -51,9 +51,9 @@ import { AssertionError } from 'assert';
51
51
 
52
52
  import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
53
53
  import {
54
- type PublicTxSimulator,
55
54
  type PublicTxSimulatorConfig,
56
- TelemetryPublicTxSimulator,
55
+ type PublicTxSimulatorInterface,
56
+ TelemetryCppPublicTxSimulator,
57
57
  } from '../public_tx_simulator/index.js';
58
58
  import { GuardedMerkleTreeOperations } from './guarded_merkle_tree.js';
59
59
  import { PublicProcessorMetrics } from './public_processor_metrics.js';
@@ -99,8 +99,8 @@ export class PublicProcessorFactory {
99
99
  contractsDB: PublicContractsDB,
100
100
  globalVariables: GlobalVariables,
101
101
  config?: Partial<PublicTxSimulatorConfig>,
102
- ): PublicTxSimulator {
103
- return new TelemetryPublicTxSimulator(merkleTree, contractsDB, globalVariables, this.telemetryClient, config);
102
+ ): PublicTxSimulatorInterface {
103
+ return new TelemetryCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, this.telemetryClient, config);
104
104
  }
105
105
  }
106
106
 
@@ -122,11 +122,11 @@ export class PublicProcessor implements Traceable {
122
122
  protected globalVariables: GlobalVariables,
123
123
  private guardedMerkleTree: GuardedMerkleTreeOperations,
124
124
  protected contractsDB: PublicContractsDB,
125
- protected publicTxSimulator: PublicTxSimulator,
125
+ protected publicTxSimulator: PublicTxSimulatorInterface,
126
126
  private dateProvider: DateProvider,
127
127
  telemetryClient: TelemetryClient = getTelemetryClient(),
128
128
  private log = createLogger('simulator:public-processor'),
129
- private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs'> = {},
129
+ private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs' | 'fakeThrowAfterProcessingTxCount'> = {},
130
130
  ) {
131
131
  this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
132
132
  }
@@ -160,7 +160,7 @@ export class PublicProcessor implements Traceable {
160
160
  let totalBlockGas = new Gas(0, 0);
161
161
  let totalBlobFields = 0;
162
162
 
163
- for await (const origTx of txs) {
163
+ for await (const tx of txs) {
164
164
  // Only process up to the max tx limit
165
165
  if (maxTransactions !== undefined && result.length >= maxTransactions) {
166
166
  this.log.debug(`Stopping tx processing due to reaching the max tx limit.`);
@@ -174,8 +174,8 @@ export class PublicProcessor implements Traceable {
174
174
  }
175
175
 
176
176
  // Skip this tx if it'd exceed max block size
177
- const txHash = origTx.getTxHash().toString();
178
- const preTxSizeInBytes = origTx.getEstimatedPrivateTxEffectsSize();
177
+ const txHash = tx.getTxHash().toString();
178
+ const preTxSizeInBytes = tx.getEstimatedPrivateTxEffectsSize();
179
179
  if (maxBlockSize !== undefined && totalSizeInBytes + preTxSizeInBytes > maxBlockSize) {
180
180
  this.log.warn(`Skipping processing of tx ${txHash} sized ${preTxSizeInBytes} bytes due to block size limit`, {
181
181
  txHash,
@@ -187,7 +187,7 @@ export class PublicProcessor implements Traceable {
187
187
  }
188
188
 
189
189
  // Skip this tx if its gas limit would exceed the block gas limit
190
- const txGasLimit = origTx.data.constants.txContext.gasSettings.gasLimits;
190
+ const txGasLimit = tx.data.constants.txContext.gasSettings.gasLimits;
191
191
  if (maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
192
192
  this.log.warn(`Skipping processing of tx ${txHash} due to block gas limit`, {
193
193
  txHash,
@@ -198,9 +198,6 @@ export class PublicProcessor implements Traceable {
198
198
  continue;
199
199
  }
200
200
 
201
- // The processor modifies the tx objects in place, so we need to clone them.
202
- const tx = Tx.clone(origTx);
203
-
204
201
  // We validate the tx before processing it, to avoid unnecessary work.
205
202
  if (preprocessValidator) {
206
203
  const result = await preprocessValidator.validateTx(tx);
@@ -233,6 +230,12 @@ export class PublicProcessor implements Traceable {
233
230
  try {
234
231
  const [processedTx, returnValues] = await this.processTx(tx, deadline);
235
232
 
233
+ // Inject a fake processing failure after N txs if requested
234
+ const fakeThrowAfter = this.opts.fakeThrowAfterProcessingTxCount;
235
+ if (fakeThrowAfter !== undefined && result.length + failed.length + 1 >= fakeThrowAfter) {
236
+ throw new Error(`Fake error after processing ${fakeThrowAfter} txs`);
237
+ }
238
+
236
239
  const txBlobFields = processedTx.txEffect.getNumBlobFields();
237
240
 
238
241
  // If the actual size of this tx would exceed block size, skip it
@@ -282,7 +285,15 @@ export class PublicProcessor implements Traceable {
282
285
  if (err?.name === 'PublicProcessorTimeoutError') {
283
286
  this.log.warn(`Stopping tx processing due to timeout.`);
284
287
  // We hit the transaction execution deadline.
285
- // There may still be a transaction executing. We stop the guarded fork to prevent any further access to the world state.
288
+ // There may still be a transaction executing on a worker thread (C++ via NAPI).
289
+ // Signal cancellation AND WAIT for the simulation to actually stop.
290
+ // This is critical because C++ might be in the middle of a slow operation (e.g., pad_trees)
291
+ // and won't check the cancellation flag until that operation completes.
292
+ // Without waiting, we'd proceed to revert checkpoints while C++ is still writing to state.
293
+ // Wait for C++ to stop gracefully.
294
+ await this.publicTxSimulator.cancel?.();
295
+
296
+ // Now stop the guarded fork to prevent any further TS-side access to the world state.
286
297
  await this.guardedMerkleTree.stop();
287
298
 
288
299
  // We now know there can't be any further access to world state. The fork is in a state where there is:
@@ -521,13 +532,9 @@ export class PublicProcessor implements Traceable {
521
532
  private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
522
533
  const timer = new Timer();
523
534
 
524
- const { hints, publicInputs, gasUsed, revertCode, revertReason, appLogicReturnValues } =
525
- await this.publicTxSimulator.simulate(tx);
526
-
527
- if (!hints) {
528
- this.metrics.recordFailedTx();
529
- throw new Error('Avm proving result was not generated.');
530
- }
535
+ const result = await this.publicTxSimulator.simulate(tx);
536
+ // TODO: use the callStackMetadata here to extract more data about public execution
537
+ const { hints, publicInputs, publicTxEffect, gasUsed, revertCode /*callStackMetadata*/ } = result;
531
538
 
532
539
  const contractClassLogs = revertCode.isOK()
533
540
  ? tx.getContractClassLogs()
@@ -539,19 +546,28 @@ export class PublicProcessor implements Traceable {
539
546
  );
540
547
 
541
548
  // TODO(fcarreiro): remove phase count metric.
542
- const phaseCount = 1;
543
549
  const durationMs = timer.ms();
544
- this.metrics.recordTx(phaseCount, durationMs, gasUsed.publicGas);
550
+ this.metrics.recordTx(/*phaseCount=*/ 1, durationMs, gasUsed.publicGas);
551
+
552
+ // Extract the return values from the call stack metadata.
553
+ const appLogicReturnValues: NestedProcessReturnValues[] = result.getAppLogicReturnValues();
554
+ // Extract the revert reason from the call stack metadata.
555
+ const revertReason = result.findRevertReason();
556
+ // Create proving request if we have hints and public inputs.
557
+ const avmProvingRequest =
558
+ hints && publicInputs ? PublicProcessor.generateProvingRequest(publicInputs, hints) : undefined;
545
559
 
546
560
  const processedTx = makeProcessedTxFromTxWithPublicCalls(
547
561
  tx,
548
- PublicProcessor.generateProvingRequest(publicInputs, hints),
562
+ this.globalVariables,
563
+ avmProvingRequest,
564
+ publicTxEffect,
549
565
  gasUsed,
550
566
  revertCode,
551
567
  revertReason,
552
568
  );
553
569
 
554
- return [processedTx, appLogicReturnValues ?? []];
570
+ return [processedTx, appLogicReturnValues];
555
571
  }
556
572
 
557
573
  /**
@@ -559,7 +575,7 @@ export class PublicProcessor implements Traceable {
559
575
  */
560
576
  private static generateProvingRequest(
561
577
  publicInputs: AvmCircuitPublicInputs,
562
- hints: AvmExecutionHints,
578
+ hints: AvmExecutionHints = AvmExecutionHints.empty(),
563
579
  ): AvmProvingRequest {
564
580
  return {
565
581
  type: ProvingRequestType.PUBLIC_VM,
@@ -1,11 +1,10 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
3
  import type { ContractProvider } from '@aztec/native';
4
4
  import { FunctionSelector } from '@aztec/stdlib/abi';
5
5
  import { deserializeFromMessagePack, serializeWithMessagePack } from '@aztec/stdlib/avm';
6
6
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
7
7
  import { ContractDeploymentData } from '@aztec/stdlib/contract';
8
- import { ContractClassLog, ContractClassLogFields, PrivateLog } from '@aztec/stdlib/logs';
9
8
  import type { GlobalVariables } from '@aztec/stdlib/tx';
10
9
 
11
10
  import type { PublicContractsDB } from '../public_db_sources.js';
@@ -19,7 +18,7 @@ export class ContractProviderForCpp implements ContractProvider {
19
18
  ) {}
20
19
 
21
20
  public getContractInstance = async (address: string): Promise<Buffer | undefined> => {
22
- this.log.debug(`Contract provider callback: getContractInstance(${address})`);
21
+ this.log.trace(`Contract provider callback: getContractInstance(${address})`);
23
22
 
24
23
  const aztecAddr = AztecAddress.fromString(address);
25
24
 
@@ -34,7 +33,7 @@ export class ContractProviderForCpp implements ContractProvider {
34
33
  };
35
34
 
36
35
  public getContractClass = async (classId: string): Promise<Buffer | undefined> => {
37
- this.log.debug(`Contract provider callback: getContractClass(${classId})`);
36
+ this.log.trace(`Contract provider callback: getContractClass(${classId})`);
38
37
 
39
38
  // Parse classId string to Fr
40
39
  const classIdFr = Fr.fromString(classId);
@@ -51,20 +50,20 @@ export class ContractProviderForCpp implements ContractProvider {
51
50
  };
52
51
 
53
52
  public addContracts = async (contractDeploymentDataBuffer: Buffer): Promise<void> => {
54
- this.log.debug(`Contract provider callback: addContracts`);
53
+ this.log.trace(`Contract provider callback: addContracts`);
55
54
 
56
55
  const rawData: any = deserializeFromMessagePack(contractDeploymentDataBuffer);
57
56
 
58
- // Construct class instances using the from method
59
- const contractDeploymentData = this.reconstructContractDeploymentData(rawData);
57
+ // Construct ContractDeploymentData from plain object.
58
+ const contractDeploymentData = ContractDeploymentData.fromPlainObject(rawData);
60
59
 
61
60
  // Add contracts to the contracts DB
62
- this.log.debug(`Calling contractsDB.addContracts`);
61
+ this.log.trace(`Calling contractsDB.addContracts`);
63
62
  await this.contractsDB.addContracts(contractDeploymentData);
64
63
  };
65
64
 
66
65
  public getBytecodeCommitment = async (classId: string): Promise<Buffer | undefined> => {
67
- this.log.debug(`Contract provider callback: getBytecodeCommitment(${classId})`);
66
+ this.log.trace(`Contract provider callback: getBytecodeCommitment(${classId})`);
68
67
 
69
68
  // Parse classId string to Fr
70
69
  const classIdFr = Fr.fromString(classId);
@@ -82,18 +81,23 @@ export class ContractProviderForCpp implements ContractProvider {
82
81
  };
83
82
 
84
83
  public getDebugFunctionName = async (address: string, selector: string): Promise<string | undefined> => {
85
- this.log.debug(`Contract provider callback: getDebugFunctionName(${address}, ${selector})`);
84
+ this.log.trace(`Contract provider callback: getDebugFunctionName(${address}, ${selector})`);
86
85
 
87
86
  // Parse address and selector strings
88
87
  const aztecAddr = AztecAddress.fromString(address);
89
88
  const selectorFr = Fr.fromString(selector);
90
- const functionSelector = FunctionSelector.fromField(selectorFr);
89
+ const functionSelector = FunctionSelector.fromFieldOrUndefined(selectorFr);
90
+
91
+ if (!functionSelector) {
92
+ this.log.trace(`calldata[0] is not a function selector: ${selector}`);
93
+ return undefined;
94
+ }
91
95
 
92
96
  // Fetch debug function name from the contracts DB
93
97
  const name = await this.contractsDB.getDebugFunctionName(aztecAddr, functionSelector);
94
98
 
95
99
  if (!name) {
96
- this.log.debug(`Debug function name not found for ${address}:${selector}`);
100
+ this.log.trace(`Debug function name not found for ${address}:${selector}`);
97
101
  return undefined;
98
102
  }
99
103
 
@@ -101,62 +105,17 @@ export class ContractProviderForCpp implements ContractProvider {
101
105
  };
102
106
 
103
107
  public createCheckpoint = (): Promise<void> => {
104
- this.log.debug(`Contract provider callback: createCheckpoint`);
108
+ this.log.trace(`Contract provider callback: createCheckpoint`);
105
109
  return Promise.resolve(this.contractsDB.createCheckpoint());
106
110
  };
107
111
 
108
112
  public commitCheckpoint = (): Promise<void> => {
109
- this.log.debug(`Contract provider callback: commitCheckpoint`);
113
+ this.log.trace(`Contract provider callback: commitCheckpoint`);
110
114
  return Promise.resolve(this.contractsDB.commitCheckpoint());
111
115
  };
112
116
 
113
117
  public revertCheckpoint = (): Promise<void> => {
114
- this.log.debug(`Contract provider callback: revertCheckpoint`);
118
+ this.log.trace(`Contract provider callback: revertCheckpoint`);
115
119
  return Promise.resolve(this.contractsDB.revertCheckpoint());
116
120
  };
117
-
118
- /**
119
- * Reconstruct ContractDeploymentData from plain msgpack-deserialized objects.
120
- *
121
- * msgpackr does not automatically apply extensions to nested fields, so we need to
122
- * manually reconstruct ContractClassLog and PrivateLog instances with proper types.
123
- *
124
- * TODO(dbanks12): we really shouldn't have to do this.... We need to for now because
125
- * msgpack deserialization doesn't give us actual typed objects, but rather just JSON.
126
- * It would be easier if all types matched between languages (like AztecAddress which is just
127
- * FF in C++).
128
- */
129
- private reconstructContractDeploymentData(rawData: any): ContractDeploymentData {
130
- // Helper to ensure a value is an Fr instance
131
- const toFr = (value: any): Fr => {
132
- if (value instanceof Fr) {
133
- return value;
134
- }
135
- if (Buffer.isBuffer(value)) {
136
- return Fr.fromBuffer(value);
137
- }
138
- return new Fr(value);
139
- };
140
-
141
- // Reconstruct ContractClassLogs
142
- const contractClassLogs = (rawData.contractClassLogs || []).map((log: any) => {
143
- // Convert contractAddress to TS AztecAddress
144
- const addressFr = toFr(log.contractAddress);
145
- const address = AztecAddress.fromField(addressFr);
146
-
147
- // Ensure all fields are Fr instances
148
- const fields = (log.fields.fields || []).map((field: any) => toFr(field));
149
-
150
- // Create proper ContractClassLog instance
151
- return new ContractClassLog(address, new ContractClassLogFields(fields), log.emittedLength);
152
- });
153
-
154
- // Reconstruct PrivateLogs - ensure fields are Fr instances
155
- const privateLogs = (rawData.privateLogs || []).map((log: any) => {
156
- const fields = (log.fields || []).map((field: any) => toFr(field));
157
- return new PrivateLog(fields as any, log.emittedLength);
158
- });
159
-
160
- return new ContractDeploymentData(contractClassLogs, privateLogs);
161
- }
162
121
  }