@aztec/simulator 3.0.0-nightly.20251208 → 3.0.0-nightly.20251210

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 (185) 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.js +1 -1
  10. package/dest/public/avm/avm_context.d.ts +2 -2
  11. package/dest/public/avm/avm_context.d.ts.map +1 -1
  12. package/dest/public/avm/avm_contract_call_result.d.ts +2 -2
  13. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  14. package/dest/public/avm/avm_execution_environment.d.ts +2 -2
  15. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  16. package/dest/public/avm/avm_execution_environment.js +1 -1
  17. package/dest/public/avm/avm_gas.d.ts +1 -1
  18. package/dest/public/avm/avm_gas.d.ts.map +1 -1
  19. package/dest/public/avm/avm_machine_state.d.ts +2 -2
  20. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  21. package/dest/public/avm/avm_memory_types.d.ts +2 -2
  22. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  23. package/dest/public/avm/avm_memory_types.js +1 -1
  24. package/dest/public/avm/avm_simulator.d.ts +2 -2
  25. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  26. package/dest/public/avm/avm_simulator.js +1 -1
  27. package/dest/public/avm/errors.d.ts +2 -2
  28. package/dest/public/avm/errors.d.ts.map +1 -1
  29. package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -1
  30. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -2
  31. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  32. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +1 -1
  33. package/dest/public/avm/fixtures/initializers.d.ts +2 -2
  34. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  35. package/dest/public/avm/fixtures/initializers.js +1 -1
  36. package/dest/public/avm/fixtures/utils.d.ts +2 -2
  37. package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
  38. package/dest/public/avm/fixtures/utils.js +1 -1
  39. package/dest/public/avm/opcodes/arithmetic.d.ts +3 -1
  40. package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
  41. package/dest/public/avm/opcodes/arithmetic.js +11 -1
  42. package/dest/public/avm/opcodes/ec_add.js +2 -2
  43. package/dest/public/avm/opcodes/hashing.d.ts +1 -1
  44. package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
  45. package/dest/public/avm/opcodes/hashing.js +3 -1
  46. package/dest/public/avm/opcodes/memory.js +1 -1
  47. package/dest/public/avm/revert_reason.d.ts +2 -2
  48. package/dest/public/avm/revert_reason.d.ts.map +1 -1
  49. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  50. package/dest/public/avm/test_utils.d.ts +2 -2
  51. package/dest/public/avm/test_utils.d.ts.map +1 -1
  52. package/dest/public/avm/test_utils.js +1 -1
  53. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  54. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  55. package/dest/public/db_interfaces.d.ts +2 -2
  56. package/dest/public/db_interfaces.d.ts.map +1 -1
  57. package/dest/public/debug_fn_name.d.ts +2 -2
  58. package/dest/public/debug_fn_name.d.ts.map +1 -1
  59. package/dest/public/fixtures/amm_test.js +2 -2
  60. package/dest/public/fixtures/bulk_test.js +1 -1
  61. package/dest/public/fixtures/custom_bytecode_tests.d.ts +2 -1
  62. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  63. package/dest/public/fixtures/custom_bytecode_tests.js +21 -0
  64. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +1 -1
  65. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  66. package/dest/public/fixtures/public_tx_simulation_tester.js +2 -1
  67. package/dest/public/fixtures/simple_contract_data_source.d.ts +10 -2
  68. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -1
  69. package/dest/public/fixtures/simple_contract_data_source.js +35 -0
  70. package/dest/public/fixtures/token_test.js +1 -1
  71. package/dest/public/fixtures/utils.d.ts +2 -2
  72. package/dest/public/fixtures/utils.d.ts.map +1 -1
  73. package/dest/public/fixtures/utils.js +1 -1
  74. package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
  75. package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
  76. package/dest/public/fuzzing/avm_simulator_bin.js +123 -0
  77. package/dest/public/fuzzing/helpers.d.ts +14 -0
  78. package/dest/public/fuzzing/helpers.d.ts.map +1 -0
  79. package/dest/public/fuzzing/helpers.js +75 -0
  80. package/dest/public/hinting_db_sources.d.ts +2 -2
  81. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  82. package/dest/public/hinting_db_sources.js +2 -2
  83. package/dest/public/index.d.ts +2 -2
  84. package/dest/public/index.d.ts.map +1 -1
  85. package/dest/public/index.js +1 -1
  86. package/dest/public/public_db_sources.d.ts +2 -2
  87. package/dest/public/public_db_sources.d.ts.map +1 -1
  88. package/dest/public/public_db_sources.js +1 -1
  89. package/dest/public/public_processor/public_processor.d.ts +1 -1
  90. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  91. package/dest/public/public_processor/public_processor.js +5 -3
  92. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -13
  93. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  94. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +3 -42
  95. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +1 -1
  96. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
  97. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +4 -4
  98. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +22 -0
  99. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -0
  100. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +52 -0
  101. package/dest/public/public_tx_simulator/factories.d.ts +13 -0
  102. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
  103. package/dest/public/public_tx_simulator/factories.js +28 -0
  104. package/dest/public/public_tx_simulator/index.d.ts +3 -1
  105. package/dest/public/public_tx_simulator/index.d.ts.map +1 -1
  106. package/dest/public/public_tx_simulator/index.js +2 -0
  107. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +2 -2
  108. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  109. package/dest/public/public_tx_simulator/public_tx_context.d.ts +2 -2
  110. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  111. package/dest/public/public_tx_simulator/public_tx_context.js +1 -1
  112. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +2 -2
  113. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  114. package/dest/public/public_tx_simulator/public_tx_simulator.js +5 -3
  115. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +2 -2
  116. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  117. package/dest/public/side_effect_trace.d.ts +2 -2
  118. package/dest/public/side_effect_trace.d.ts.map +1 -1
  119. package/dest/public/side_effect_trace.js +1 -1
  120. package/dest/public/side_effect_trace_interface.d.ts +2 -2
  121. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  122. package/dest/public/state_manager/nullifiers.d.ts +2 -2
  123. package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
  124. package/dest/public/state_manager/public_storage.d.ts +2 -2
  125. package/dest/public/state_manager/public_storage.d.ts.map +1 -1
  126. package/dest/public/state_manager/public_storage.js +1 -1
  127. package/dest/public/state_manager/state_manager.d.ts +2 -2
  128. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  129. package/dest/public/state_manager/state_manager.js +1 -1
  130. package/package.json +17 -17
  131. package/src/common/errors.ts +1 -1
  132. package/src/private/acvm/deserialize.ts +1 -1
  133. package/src/private/acvm/serialize.ts +1 -1
  134. package/src/private/circuit_recording/circuit_recorder.ts +1 -1
  135. package/src/public/avm/avm_context.ts +1 -1
  136. package/src/public/avm/avm_contract_call_result.ts +1 -1
  137. package/src/public/avm/avm_execution_environment.ts +1 -1
  138. package/src/public/avm/avm_gas.ts +3 -3
  139. package/src/public/avm/avm_machine_state.ts +1 -1
  140. package/src/public/avm/avm_memory_types.ts +1 -1
  141. package/src/public/avm/avm_simulator.ts +1 -1
  142. package/src/public/avm/errors.ts +1 -1
  143. package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
  144. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
  145. package/src/public/avm/fixtures/initializers.ts +1 -1
  146. package/src/public/avm/fixtures/utils.ts +1 -1
  147. package/src/public/avm/opcodes/arithmetic.ts +13 -1
  148. package/src/public/avm/opcodes/ec_add.ts +2 -2
  149. package/src/public/avm/opcodes/hashing.ts +3 -1
  150. package/src/public/avm/opcodes/memory.ts +1 -1
  151. package/src/public/avm/revert_reason.ts +1 -1
  152. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  153. package/src/public/avm/test_utils.ts +1 -1
  154. package/src/public/contracts_db_checkpoint.ts +1 -1
  155. package/src/public/db_interfaces.ts +1 -1
  156. package/src/public/debug_fn_name.ts +1 -1
  157. package/src/public/fixtures/amm_test.ts +2 -2
  158. package/src/public/fixtures/bulk_test.ts +1 -1
  159. package/src/public/fixtures/custom_bytecode_tests.ts +24 -0
  160. package/src/public/fixtures/minimal_public_tx.ts +1 -1
  161. package/src/public/fixtures/public_tx_simulation_tester.ts +2 -1
  162. package/src/public/fixtures/simple_contract_data_source.ts +40 -1
  163. package/src/public/fixtures/token_test.ts +1 -1
  164. package/src/public/fixtures/utils.ts +1 -1
  165. package/src/public/fuzzing/avm_simulator_bin.ts +157 -0
  166. package/src/public/fuzzing/helpers.ts +154 -0
  167. package/src/public/hinting_db_sources.ts +2 -2
  168. package/src/public/index.ts +2 -0
  169. package/src/public/public_db_sources.ts +1 -1
  170. package/src/public/public_processor/public_processor.ts +8 -3
  171. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +3 -49
  172. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +1 -1
  173. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +4 -8
  174. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +81 -0
  175. package/src/public/public_tx_simulator/factories.ts +41 -0
  176. package/src/public/public_tx_simulator/index.ts +2 -0
  177. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +1 -1
  178. package/src/public/public_tx_simulator/public_tx_context.ts +1 -1
  179. package/src/public/public_tx_simulator/public_tx_simulator.ts +14 -3
  180. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +1 -1
  181. package/src/public/side_effect_trace.ts +1 -1
  182. package/src/public/side_effect_trace_interface.ts +1 -1
  183. package/src/public/state_manager/nullifiers.ts +1 -1
  184. package/src/public/state_manager/public_storage.ts +1 -1
  185. package/src/public/state_manager/state_manager.ts +2 -2
@@ -0,0 +1,154 @@
1
+ import {
2
+ CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
3
+ MAX_ENQUEUED_CALLS_PER_TX,
4
+ MAX_L2_TO_L1_MSGS_PER_TX,
5
+ MAX_NOTE_HASHES_PER_TX,
6
+ MAX_NULLIFIERS_PER_TX,
7
+ MAX_PRIVATE_LOGS_PER_TX,
8
+ } from '@aztec/constants';
9
+ import { padArrayEnd } from '@aztec/foundation/collection';
10
+ import { Fr } from '@aztec/foundation/curves/bn254';
11
+ import type { AvmTxHint } from '@aztec/stdlib/avm';
12
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
+ import { siloNullifier } from '@aztec/stdlib/hash';
14
+ import {
15
+ PartialPrivateTailPublicInputsForPublic,
16
+ PrivateKernelTailCircuitPublicInputs,
17
+ PrivateToPublicAccumulatedData,
18
+ PublicCallRequest,
19
+ } from '@aztec/stdlib/kernel';
20
+ import { PrivateLog } from '@aztec/stdlib/logs';
21
+ import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
22
+ import { ChonkProof } from '@aztec/stdlib/proofs';
23
+ import { MerkleTreeId, type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
24
+ import { BlockHeader, HashedValues, Tx, TxConstantData, TxContext, TxHash } from '@aztec/stdlib/tx';
25
+
26
+ // Registers a contract by inserting its address nullifier into the nullifier tree
27
+ export async function registerContract(
28
+ merkleTrees: MerkleTreeWriteOperations,
29
+ contractAddress: AztecAddress,
30
+ ): Promise<void> {
31
+ const contractAddressNullifier = await siloNullifier(
32
+ AztecAddress.fromNumber(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS),
33
+ contractAddress.toField(),
34
+ );
35
+ await merkleTrees.sequentialInsert(MerkleTreeId.NULLIFIER_TREE, [contractAddressNullifier.toBuffer()]);
36
+ }
37
+
38
+ /**
39
+ * Creates a TypeScript Tx object from a deserialized C++ Tx (AvmTxHint-like structure).
40
+ * This allows using PublicTxSimulator.simulate() with fuzzer-generated transactions.
41
+ *
42
+ * @param cppTx - Deserialized C++ Tx from msgpack (matches AvmTxHint structure)
43
+ * @returns A TypeScript Tx suitable for PublicTxSimulator
44
+ */
45
+ export async function createFuzzerTx(cppTx: AvmTxHint): Promise<Tx> {
46
+ // Create TxHash from the C++ tx hash string
47
+ if (!cppTx.hash) {
48
+ throw new Error(`cppTx.hash is undefined. Keys: ${Object.keys(cppTx || {}).join(', ')}`);
49
+ }
50
+ const txHash = TxHash.fromString(cppTx.hash);
51
+
52
+ // Extract PublicCallRequest instances from enqueued calls
53
+ const setupCallRequests = cppTx.setupEnqueuedCalls.map(call => call.request);
54
+ const paddedSetupCalls = padArrayEnd(setupCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX);
55
+
56
+ const appLogicCallRequests = cppTx.appLogicEnqueuedCalls.map(call => call.request);
57
+ const paddedAppLogicCalls = padArrayEnd(appLogicCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX);
58
+
59
+ // Build non-revertible accumulated data from C++ tx
60
+ const emptyNonRevertible = PrivateToPublicAccumulatedData.empty();
61
+ const nonRevertibleAccumulatedData = new PrivateToPublicAccumulatedData(
62
+ padArrayEnd(cppTx.nonRevertibleAccumulatedData.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
63
+ padArrayEnd(cppTx.nonRevertibleAccumulatedData.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX),
64
+ padArrayEnd(
65
+ cppTx.nonRevertibleAccumulatedData.l2ToL1Messages,
66
+ ScopedL2ToL1Message.empty(),
67
+ MAX_L2_TO_L1_MSGS_PER_TX,
68
+ ),
69
+ padArrayEnd(cppTx.nonRevertibleContractDeploymentData.privateLogs, PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX),
70
+ emptyNonRevertible.contractClassLogsHashes,
71
+ paddedSetupCalls,
72
+ );
73
+
74
+ // Build revertible accumulated data from C++ tx
75
+ const emptyRevertible = PrivateToPublicAccumulatedData.empty();
76
+ const revertibleAccumulatedData = new PrivateToPublicAccumulatedData(
77
+ padArrayEnd(cppTx.revertibleAccumulatedData.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
78
+ padArrayEnd(cppTx.revertibleAccumulatedData.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX),
79
+ padArrayEnd(cppTx.revertibleAccumulatedData.l2ToL1Messages, ScopedL2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_TX),
80
+ padArrayEnd(cppTx.revertibleContractDeploymentData.privateLogs, PrivateLog.empty(), MAX_PRIVATE_LOGS_PER_TX),
81
+ emptyRevertible.contractClassLogsHashes,
82
+ paddedAppLogicCalls,
83
+ );
84
+
85
+ // Build teardown call request (if exists)
86
+ const teardownCallRequest = cppTx.teardownEnqueuedCall?.request ?? PublicCallRequest.empty();
87
+
88
+ // Create forPublic structure
89
+ const forPublic = new PartialPrivateTailPublicInputsForPublic(
90
+ nonRevertibleAccumulatedData,
91
+ revertibleAccumulatedData,
92
+ teardownCallRequest,
93
+ );
94
+
95
+ // Build TxContext - gasSettings is already a proper GasSettings after AvmTxHint.fromPlainObject
96
+ const txContext = new TxContext(
97
+ Fr.ZERO, // chainId - this is fine because simulation actually reads from globalVariables not here
98
+ Fr.ZERO, // version - this is fine because simulation actually reads from globalVariables not here
99
+ cppTx.gasSettings,
100
+ );
101
+
102
+ // Build TxConstantData
103
+ const constants = new TxConstantData(
104
+ BlockHeader.empty(), // anchorBlockHeader (unused in simulation)
105
+ txContext,
106
+ Fr.ZERO, // vkTreeRoot - not needed for public simulation
107
+ Fr.ZERO, // protocolContractsHash - not needed for public simulation
108
+ );
109
+
110
+ const data = new PrivateKernelTailCircuitPublicInputs(
111
+ constants,
112
+ cppTx.gasUsedByPrivate,
113
+ cppTx.feePayer,
114
+ 0n, // includeByTimestamp
115
+ forPublic,
116
+ undefined, // forRollup - not needed for public simulation
117
+ );
118
+
119
+ // todo(ilyas): I don't think we need to construct this, but keeping for now - the hashing could get costly with
120
+ // large number of enqueued calls or large calldata so keep an eye on this!
121
+ // Build publicFunctionCalldata from all enqueued calls
122
+ // Calldata is already Fr[] after AvmTxHint.fromPlainObject
123
+ const publicFunctionCalldata: HashedValues[] = [];
124
+
125
+ // Add setup calls
126
+ for (const call of cppTx.setupEnqueuedCalls || []) {
127
+ publicFunctionCalldata.push(await HashedValues.fromCalldata(call.calldata));
128
+ }
129
+
130
+ // Add app logic calls
131
+ for (const call of cppTx.appLogicEnqueuedCalls || []) {
132
+ publicFunctionCalldata.push(await HashedValues.fromCalldata(call.calldata));
133
+ }
134
+
135
+ // Add teardown call if present
136
+ if (cppTx.teardownEnqueuedCall) {
137
+ publicFunctionCalldata.push(await HashedValues.fromCalldata(cppTx.teardownEnqueuedCall.calldata));
138
+ }
139
+
140
+ // Extract contract class log fields from ContractDeploymentData
141
+ const contractClassLogFields = [
142
+ ...cppTx.nonRevertibleContractDeploymentData.contractClassLogs.map(log => log.fields),
143
+ ...cppTx.revertibleContractDeploymentData.contractClassLogs.map(log => log.fields),
144
+ ];
145
+
146
+ // Create the Tx
147
+ return new Tx(
148
+ txHash,
149
+ data,
150
+ ChonkProof.empty(), // No real proof needed for simulation
151
+ contractClassLogFields,
152
+ publicFunctionCalldata,
153
+ );
154
+ }
@@ -1,6 +1,6 @@
1
1
  import type { BlockNumber } from '@aztec/foundation/branded-types';
2
- import { sha256Trunc } from '@aztec/foundation/crypto';
3
- import { Fr } from '@aztec/foundation/fields';
2
+ import { sha256Trunc } from '@aztec/foundation/crypto/sha256';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import { type Logger, createLogger } from '@aztec/foundation/log';
5
5
  import type { IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
6
6
  import type { FunctionSelector } from '@aztec/stdlib/abi';
@@ -3,6 +3,8 @@ export { GuardedMerkleTreeOperations } from './public_processor/guarded_merkle_t
3
3
  export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
4
4
  export {
5
5
  CppPublicTxSimulator,
6
+ createPublicTxSimulatorForBlockBuilding,
7
+ DumpingCppPublicTxSimulator,
6
8
  type PublicTxSimulatorInterface,
7
9
  TelemetryCppPublicTxSimulator,
8
10
  } from './public_tx_simulator/index.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,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';
@@ -523,7 +523,7 @@ export class PublicProcessor implements Traceable {
523
523
 
524
524
  const result = await this.publicTxSimulator.simulate(tx);
525
525
  // TODO: use the callStackMetadata here to extract more data about public execution
526
- const { hints, publicInputs, gasUsed, revertCode /*callStackMetadata*/ } = result;
526
+ const { hints, publicInputs, publicTxEffect, gasUsed, revertCode /*callStackMetadata*/ } = result;
527
527
 
528
528
  const contractClassLogs = revertCode.isOK()
529
529
  ? tx.getContractClassLogs()
@@ -542,10 +542,15 @@ export class PublicProcessor implements Traceable {
542
542
  const appLogicReturnValues: NestedProcessReturnValues[] = result.getAppLogicReturnValues();
543
543
  // Extract the revert reason from the call stack metadata.
544
544
  const revertReason = result.findRevertReason();
545
+ // Create proving request if we have hints and public inputs.
546
+ const avmProvingRequest =
547
+ hints && publicInputs ? PublicProcessor.generateProvingRequest(publicInputs, hints) : undefined;
545
548
 
546
549
  const processedTx = makeProcessedTxFromTxWithPublicCalls(
547
550
  tx,
548
- PublicProcessor.generateProvingRequest(publicInputs, hints),
551
+ this.globalVariables,
552
+ avmProvingRequest,
553
+ publicTxEffect,
549
554
  gasUsed,
550
555
  revertCode,
551
556
  revertReason,
@@ -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';
@@ -55,8 +54,8 @@ export class ContractProviderForCpp implements ContractProvider {
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
61
  this.log.debug(`Calling contractsDB.addContracts`);
@@ -114,49 +113,4 @@ export class ContractProviderForCpp implements ContractProvider {
114
113
  this.log.debug(`Contract provider callback: revertCheckpoint`);
115
114
  return Promise.resolve(this.contractsDB.revertCheckpoint());
116
115
  };
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
116
  }
@@ -64,7 +64,7 @@ export class CppPublicTxSimulatorHintedDbs extends PublicTxSimulator implements
64
64
  this.log.debug(`TS simulation succeeded for tx ${txHash}`);
65
65
 
66
66
  // Extract the full AvmCircuitInputs from the TS result
67
- const avmCircuitInputs = new AvmCircuitInputs(tsResult.hints!, tsResult.publicInputs);
67
+ const avmCircuitInputs = new AvmCircuitInputs(tsResult.hints!, tsResult.publicInputs!);
68
68
 
69
69
  // Second, run C++ simulation with hinted DBs
70
70
  this.log.debug(`Running C++ simulation with hinted DBs for tx ${txHash}`);
@@ -1,5 +1,4 @@
1
1
  import { type Logger, createLogger, logLevel } from '@aztec/foundation/log';
2
- import { writeTestData } from '@aztec/foundation/testing/files';
3
2
  import { avmSimulate } from '@aztec/native';
4
3
  import { ProtocolContractsList } from '@aztec/protocol-contracts';
5
4
  import {
@@ -126,12 +125,6 @@ export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements Publi
126
125
  // Deserialize the msgpack result
127
126
  this.log.debug(`Deserializing C++ from buffer (size: ${resultBuffer.length})...`);
128
127
  const cppResultJSON: object = deserializeFromMessagePack(resultBuffer);
129
- // Write testdata if AZTEC_WRITE_TESTDATA=1.
130
- writeTestData(
131
- `barretenberg/cpp/src/barretenberg/vm2/testing/tx_result_${txHash}.testdata.bin`,
132
- resultBuffer,
133
- /*raw=*/ true,
134
- );
135
128
  this.log.debug(`Deserializing C++ result to PublicTxResult...`);
136
129
  const cppResult = PublicTxResult.fromPlainObject(cppResultJSON);
137
130
  this.log.debug(`Done.`);
@@ -140,7 +133,10 @@ export class CppVsTsPublicTxSimulator extends PublicTxSimulator implements Publi
140
133
  assert(cppResult.gasUsed.publicGas.equals(tsResult.gasUsed.publicGas));
141
134
  assert(cppResult.gasUsed.teardownGas.equals(tsResult.gasUsed.teardownGas));
142
135
  assert(cppResult.gasUsed.billedGas.equals(tsResult.gasUsed.billedGas));
143
- assert(cppResult.publicInputs.toBuffer().equals(tsResult.publicInputs.toBuffer()));
136
+ assert(cppResult.publicTxEffect.equals(tsResult.publicTxEffect));
137
+ if (cppResult.publicInputs !== undefined) {
138
+ assert(cppResult.publicInputs!.toBuffer().equals(tsResult.publicInputs!.toBuffer()));
139
+ }
144
140
 
145
141
  // TODO(fcarreiro): complete this.
146
142
  // Check that C++ hints are a strict subset of TS hints.
@@ -0,0 +1,81 @@
1
+ import {
2
+ AvmCircuitInputs,
3
+ AvmCircuitPublicInputs,
4
+ AvmExecutionHints,
5
+ type PublicSimulatorConfig,
6
+ PublicTxResult,
7
+ serializeWithMessagePack,
8
+ } from '@aztec/stdlib/avm';
9
+ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
10
+ import type { GlobalVariables, Tx, TxHash } from '@aztec/stdlib/tx';
11
+
12
+ import { strict as assert } from 'assert';
13
+ import { mkdirSync, writeFileSync } from 'fs';
14
+ import { join } from 'path';
15
+
16
+ import type { PublicContractsDB } from '../public_db_sources.js';
17
+ import { CppPublicTxSimulator } from './cpp_public_tx_simulator.js';
18
+
19
+ /**
20
+ * A C++ public tx simulator that dumps AVM circuit inputs to disk after simulation.
21
+ * Used during nightly CI runs to collect circuit inputs for benchmarking.
22
+ */
23
+ export class DumpingCppPublicTxSimulator extends CppPublicTxSimulator {
24
+ private readonly outputDir: string;
25
+
26
+ constructor(
27
+ merkleTree: MerkleTreeWriteOperations,
28
+ contractsDB: PublicContractsDB,
29
+ globalVariables: GlobalVariables,
30
+ config: Partial<PublicSimulatorConfig>,
31
+ outputDir: string,
32
+ ) {
33
+ super(merkleTree, contractsDB, globalVariables, config);
34
+ assert(config.collectHints === true, 'collectHints must be enabled to dump AVM circuit inputs');
35
+ assert(config.collectPublicInputs === true, 'collectPublicInputs must be enabled to dump AVM circuit inputs');
36
+ this.outputDir = outputDir;
37
+ }
38
+
39
+ public override async simulate(tx: Tx): Promise<PublicTxResult> {
40
+ const result = await super.simulate(tx);
41
+
42
+ // Dump the circuit inputs after successful simulation
43
+ const txHash = this.computeTxHash(tx);
44
+ this.dumpAvmCircuitInputs(result, txHash);
45
+
46
+ return result;
47
+ }
48
+
49
+ /**
50
+ * Dumps AVM circuit inputs to disk.
51
+ *
52
+ * @param result - The simulation result containing hints and public inputs
53
+ * @param txHash - The transaction hash to use in the filename
54
+ */
55
+ private dumpAvmCircuitInputs(result: PublicTxResult, txHash: TxHash): void {
56
+ try {
57
+ // Ensure the output directory exists
58
+ mkdirSync(this.outputDir, { recursive: true });
59
+
60
+ // Generate filename using transaction hash
61
+ const filename = `avm-circuit-inputs-tx-${txHash.toString()}.bin`;
62
+ const filepath = join(this.outputDir, filename);
63
+
64
+ // Create circuit inputs from the result
65
+ const hints = result.hints ?? AvmExecutionHints.empty();
66
+ const publicInputs = result.publicInputs ?? AvmCircuitPublicInputs.empty();
67
+ const avmCircuitInputs = new AvmCircuitInputs(hints, publicInputs);
68
+
69
+ // Serialize the circuit inputs using MessagePack
70
+ const serialized = serializeWithMessagePack(avmCircuitInputs);
71
+
72
+ // Write to disk
73
+ writeFileSync(filepath, serialized);
74
+
75
+ this.log.debug(`Dumped AVM circuit inputs to ${filepath}`);
76
+ } catch (error) {
77
+ // Non-blocking error handling - log but don't interrupt processing
78
+ this.log.warn(`Failed to dump AVM circuit inputs for tx ${txHash.toString()}: ${error}`);
79
+ }
80
+ }
81
+ }
@@ -0,0 +1,41 @@
1
+ import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
2
+ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
3
+ import type { GlobalVariables } from '@aztec/stdlib/tx';
4
+ import type { TelemetryClient } from '@aztec/telemetry-client';
5
+
6
+ import type { PublicContractsDB } from '../public_db_sources.js';
7
+ import { TelemetryCppPublicTxSimulator } from './cpp_public_tx_simulator.js';
8
+ import { DumpingCppPublicTxSimulator } from './dumping_cpp_public_tx_simulator.js';
9
+
10
+ /**
11
+ * Creates a public tx simulator for block building.
12
+ * Uses DumpingCppPublicTxSimulator if DUMP_AVM_INPUTS_TO_DIR env var is set (for CI/testing avm circuit),
13
+ * otherwise uses TelemetryCppPublicTxSimulator (for production).
14
+ */
15
+ export function createPublicTxSimulatorForBlockBuilding(
16
+ merkleTree: MerkleTreeWriteOperations,
17
+ contractsDB: PublicContractsDB,
18
+ globalVariables: GlobalVariables,
19
+ telemetryClient: TelemetryClient,
20
+ ) {
21
+ const config = PublicSimulatorConfig.from({
22
+ skipFeeEnforcement: false,
23
+ collectDebugLogs: false,
24
+ collectHints: false,
25
+ collectPublicInputs: false,
26
+ collectStatistics: false,
27
+ collectCallMetadata: false,
28
+ });
29
+
30
+ const dumpDir = process.env.DUMP_AVM_INPUTS_TO_DIR;
31
+ if (dumpDir) {
32
+ // must collect hints and PIs for dumping
33
+ const dumpingConfig = {
34
+ ...config,
35
+ collectHints: true,
36
+ collectPublicInputs: true,
37
+ };
38
+ return new DumpingCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, dumpingConfig, dumpDir);
39
+ }
40
+ return new TelemetryCppPublicTxSimulator(merkleTree, contractsDB, globalVariables, telemetryClient, config);
41
+ }
@@ -1,5 +1,7 @@
1
1
  export * from './public_tx_simulator.js';
2
2
  export { CppPublicTxSimulator, TelemetryCppPublicTxSimulator } from './cpp_public_tx_simulator.js';
3
+ export { DumpingCppPublicTxSimulator } from './dumping_cpp_public_tx_simulator.js';
4
+ export { createPublicTxSimulatorForBlockBuilding } from './factories.js';
3
5
  export type { PublicTxSimulatorInterface } from './public_tx_simulator_interface.js';
4
6
  export { TelemetryPublicTxSimulator } from './telemetry_public_tx_simulator.js';
5
7
  export type { PublicTxResult, PublicSimulatorConfig as PublicTxSimulatorConfig } from '@aztec/stdlib/avm';
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { Timer } from '@aztec/foundation/timer';
3
3
  import type { PublicSimulatorConfig, PublicTxResult } from '@aztec/stdlib/avm';
4
4
  import type { Gas } from '@aztec/stdlib/gas';
@@ -6,7 +6,7 @@ import {
6
6
  MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
7
7
  } from '@aztec/constants';
8
8
  import { padArrayEnd } from '@aztec/foundation/collection';
9
- import { Fr } from '@aztec/foundation/fields';
9
+ import { Fr } from '@aztec/foundation/curves/bn254';
10
10
  import { type Logger, createLogger } from '@aztec/foundation/log';
11
11
  import {
12
12
  AvmAccumulatedData,
@@ -1,9 +1,9 @@
1
1
  import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { type Logger, 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
- import { AvmExecutionHints, AvmTxHint, PublicSimulatorConfig, PublicTxResult } from '@aztec/stdlib/avm';
6
+ import { AvmExecutionHints, AvmTxHint, PublicSimulatorConfig, PublicTxEffect, PublicTxResult } from '@aztec/stdlib/avm';
7
7
  import { SimulationError } from '@aztec/stdlib/errors';
8
8
  import { Gas } from '@aztec/stdlib/gas';
9
9
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
@@ -209,6 +209,16 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
209
209
  (appLogicReturnValues as any).revertReason = context.revertReason;
210
210
  }
211
211
 
212
+ // Create PublicTxEffect from PublicInputs.
213
+ const publicTxEffect = new PublicTxEffect(
214
+ publicInputs.transactionFee,
215
+ publicInputs.accumulatedData.noteHashes.filter(h => !h.isEmpty()),
216
+ publicInputs.accumulatedData.nullifiers.filter(n => !n.isEmpty()),
217
+ publicInputs.accumulatedData.l2ToL1Msgs.filter(m => !m.isEmpty()),
218
+ publicInputs.accumulatedData.publicLogs.toLogs(),
219
+ publicInputs.accumulatedData.publicDataWrites.filter(w => !w.isEmpty()),
220
+ );
221
+
212
222
  return new PublicTxResult(
213
223
  /*gasUsed=*/ {
214
224
  totalGas: context.getActualGasUsed(),
@@ -217,6 +227,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
217
227
  billedGas: context.getTotalGasUsed(),
218
228
  },
219
229
  /*revertCode=*/ revertCode,
230
+ /*publicTxEffect=*/ publicTxEffect,
220
231
  /*callStackMetadata=*/ appLogicReturnValues,
221
232
  /*logs=*/ context.state.getActiveStateManager().getLogs(),
222
233
  /*hints=*/ hints,
@@ -303,7 +314,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
303
314
  );
304
315
 
305
316
  if (result.reverted) {
306
- const culprit = `${contractAddress}:${callRequest.functionSelector}`;
317
+ const culprit = `${contractAddress}:${fnName}`;
307
318
  context.revert(phase, result.revertReason, culprit);
308
319
  }
309
320
 
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { PublicSimulatorConfig } from '@aztec/stdlib/avm';
3
3
  import type { Gas } from '@aztec/stdlib/gas';
4
4
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
@@ -7,8 +7,8 @@ import {
7
7
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
8
8
  PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
9
9
  } from '@aztec/constants';
10
+ import { Fr } from '@aztec/foundation/curves/bn254';
10
11
  import { EthAddress } from '@aztec/foundation/eth-address';
11
- import { Fr } from '@aztec/foundation/fields';
12
12
  import { type LogLevel, createLogger } from '@aztec/foundation/log';
13
13
  import { PublicDataUpdateRequest } from '@aztec/stdlib/avm';
14
14
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { LogLevel } from '@aztec/foundation/log';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { DebugLog } from '@aztec/stdlib/logs';
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
 
3
3
  import type { PublicTreesDB } from '../public_db_sources.js';
4
4
  import { NullifierCollisionError } from '../side_effect_errors.js';
@@ -1,4 +1,4 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
 
4
4
  import type { PublicStateDBInterface } from '../db_interfaces.js';
@@ -6,8 +6,8 @@ import {
6
6
  MULTI_CALL_ENTRYPOINT_ADDRESS,
7
7
  ROUTER_ADDRESS,
8
8
  } from '@aztec/constants';
9
- import { poseidon2Hash } from '@aztec/foundation/crypto';
10
- import { Fr } from '@aztec/foundation/fields';
9
+ import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
10
+ import { Fr } from '@aztec/foundation/curves/bn254';
11
11
  import { jsonStringify } from '@aztec/foundation/json-rpc';
12
12
  import { type LogLevel, createLogger } from '@aztec/foundation/log';
13
13
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';