@aztec/simulator 0.0.1-commit.023c3e5 → 0.0.1-commit.031e54b

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 (123) hide show
  1. package/README.md +4 -4
  2. package/dest/private/acvm_wasm.d.ts +1 -1
  3. package/dest/private/acvm_wasm.d.ts.map +1 -1
  4. package/dest/private/acvm_wasm.js +3 -1
  5. package/dest/private/circuit_recording/circuit_recorder.js +2 -2
  6. package/dest/public/avm/avm_gas.js +3 -3
  7. package/dest/public/avm/avm_simulator.js +1 -1
  8. package/dest/public/avm/calldata.d.ts +1 -1
  9. package/dest/public/avm/calldata.d.ts.map +1 -1
  10. package/dest/public/avm/calldata.js +3 -2
  11. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +2 -0
  12. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
  13. package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
  14. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -1
  15. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  16. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +17 -2
  17. package/dest/public/avm/fixtures/utils.d.ts +1 -1
  18. package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
  19. package/dest/public/avm/fixtures/utils.js +3 -0
  20. package/dest/public/avm/opcodes/accrued_substate.d.ts +2 -2
  21. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  22. package/dest/public/avm/opcodes/accrued_substate.js +3 -4
  23. package/dest/public/avm/opcodes/contract.d.ts +3 -2
  24. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  25. package/dest/public/avm/opcodes/contract.js +5 -1
  26. package/dest/public/avm/opcodes/ec_add.d.ts +2 -4
  27. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
  28. package/dest/public/avm/opcodes/ec_add.js +13 -27
  29. package/dest/public/avm/serialization/bytecode_serialization.js +3 -3
  30. package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
  31. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  32. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  33. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  34. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  35. package/dest/public/contracts_db_checkpoint.js +1 -1
  36. package/dest/public/fixtures/amm_test.js +2 -2
  37. package/dest/public/fixtures/bulk_test.d.ts +1 -1
  38. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  39. package/dest/public/fixtures/bulk_test.js +31 -4
  40. package/dest/public/fixtures/custom_bytecode_tests.d.ts +3 -1
  41. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  42. package/dest/public/fixtures/custom_bytecode_tests.js +61 -1
  43. package/dest/public/fixtures/opcode_spammer.d.ts +1 -1
  44. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
  45. package/dest/public/fixtures/opcode_spammer.js +8 -16
  46. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +6 -5
  47. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  48. package/dest/public/fixtures/public_tx_simulation_tester.js +37 -10
  49. package/dest/public/fixtures/utils.d.ts +2 -2
  50. package/dest/public/fixtures/utils.d.ts.map +1 -1
  51. package/dest/public/fixtures/utils.js +19 -20
  52. package/dest/public/hinting_db_sources.d.ts +5 -5
  53. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  54. package/dest/public/hinting_db_sources.js +8 -7
  55. package/dest/public/public_db_sources.d.ts +6 -3
  56. package/dest/public/public_db_sources.d.ts.map +1 -1
  57. package/dest/public/public_db_sources.js +16 -10
  58. package/dest/public/public_processor/guarded_merkle_tree.d.ts +5 -5
  59. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  60. package/dest/public/public_processor/guarded_merkle_tree.js +5 -5
  61. package/dest/public/public_processor/public_processor.d.ts +8 -5
  62. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  63. package/dest/public/public_processor/public_processor.js +107 -72
  64. package/dest/public/public_processor/public_processor_metrics.d.ts +4 -1
  65. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  66. package/dest/public/public_processor/public_processor_metrics.js +8 -0
  67. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -1
  68. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  69. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +3 -2
  70. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +1 -1
  71. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  72. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +2 -3
  73. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +1 -1
  74. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
  75. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +2 -2
  76. package/dest/public/public_tx_simulator/factories.d.ts +2 -2
  77. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  78. package/dest/public/public_tx_simulator/factories.js +2 -2
  79. package/dest/public/public_tx_simulator/public_tx_context.d.ts +7 -3
  80. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  81. package/dest/public/public_tx_simulator/public_tx_context.js +8 -10
  82. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +6 -2
  83. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  84. package/dest/public/public_tx_simulator/public_tx_simulator.js +14 -9
  85. package/dest/public/test_executor_metrics.d.ts +6 -1
  86. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  87. package/dest/public/test_executor_metrics.js +22 -0
  88. package/package.json +16 -16
  89. package/src/private/acvm_wasm.ts +4 -1
  90. package/src/private/circuit_recording/circuit_recorder.ts +2 -2
  91. package/src/public/avm/avm_gas.ts +2 -2
  92. package/src/public/avm/avm_simulator.ts +1 -1
  93. package/src/public/avm/calldata.ts +3 -2
  94. package/src/public/avm/fixtures/account_proof.json +553 -0
  95. package/src/public/avm/fixtures/account_proof_fetcher.ts +166 -0
  96. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +22 -2
  97. package/src/public/avm/fixtures/utils.ts +3 -0
  98. package/src/public/avm/opcodes/accrued_substate.ts +3 -4
  99. package/src/public/avm/opcodes/contract.ts +5 -1
  100. package/src/public/avm/opcodes/ec_add.ts +12 -31
  101. package/src/public/avm/opcodes/external_calls.ts +1 -1
  102. package/src/public/avm/serialization/bytecode_serialization.ts +2 -2
  103. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  104. package/src/public/contracts_db_checkpoint.ts +1 -1
  105. package/src/public/fixtures/amm_test.ts +2 -2
  106. package/src/public/fixtures/bulk_test.ts +29 -4
  107. package/src/public/fixtures/custom_bytecode_tests.ts +139 -1
  108. package/src/public/fixtures/opcode_spammer.ts +10 -18
  109. package/src/public/fixtures/public_tx_simulation_tester.ts +47 -6
  110. package/src/public/fixtures/utils.ts +26 -22
  111. package/src/public/fuzzing/avm_fuzzer_simulator.ts +1 -1
  112. package/src/public/hinting_db_sources.ts +10 -7
  113. package/src/public/public_db_sources.ts +21 -14
  114. package/src/public/public_processor/guarded_merkle_tree.ts +6 -6
  115. package/src/public/public_processor/public_processor.ts +140 -91
  116. package/src/public/public_processor/public_processor_metrics.ts +12 -0
  117. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +3 -2
  118. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +2 -3
  119. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +2 -2
  120. package/src/public/public_tx_simulator/factories.ts +2 -1
  121. package/src/public/public_tx_simulator/public_tx_context.ts +8 -10
  122. package/src/public/public_tx_simulator/public_tx_simulator.ts +14 -10
  123. package/src/public/test_executor_metrics.ts +24 -0
@@ -143,7 +143,7 @@
143
143
  * - `EMITNOTEHASH`: max 64 per TX
144
144
  * - `EMITNULLIFIER`: max 63 per TX (one reserved for TX nullifier)
145
145
  * - `SENDL2TOL1MSG`: max 8 per TX
146
- * - `EMITUNENCRYPTEDLOG`: limited by total log payload size
146
+ * - `EMITPUBLICLOG`: limited by total log payload size
147
147
  *
148
148
  * By having the inner contract REVERT after emitting side effects, those effects are discarded, allowing the outer contract to call it again. This enables thousands of opcode executions per TX instead of just the limit.
149
149
  *
@@ -182,7 +182,7 @@ import {
182
182
  EcAdd,
183
183
  EmitNoteHash,
184
184
  EmitNullifier,
185
- EmitUnencryptedLog,
185
+ EmitPublicLog,
186
186
  Eq,
187
187
  FieldDiv,
188
188
  GetContractInstance,
@@ -1242,17 +1242,15 @@ export const SPAM_CONFIGS: Partial<Record<Opcode, SpamConfig[]>> = {
1242
1242
  },
1243
1243
  ],
1244
1244
 
1245
- // EMITUNENCRYPTEDLOG - two configs: minimal (many small logs) and max-size (one large log)
1246
- [Opcode.EMITUNENCRYPTEDLOG]: [
1245
+ // EMITPUBLICLOG - two configs: minimal (many small logs) and max-size (one large log)
1246
+ [Opcode.EMITPUBLICLOG]: [
1247
1247
  {
1248
1248
  label: 'Many empty logs, revert, repeat',
1249
1249
  setup: [
1250
1250
  { offset: 0, value: new Uint32(0n) }, // logSize = 0 fields (minimal)
1251
1251
  { offset: 1, value: new Uint32(0n) }, // revertSize
1252
1252
  ],
1253
- targetInstructions: () => [
1254
- new EmitUnencryptedLog(/*addressing_mode=*/ 0, /*logSizeOffset=*/ 0, /*logOffset=*/ 1),
1255
- ], // logOffset doesn't matter when size is 0
1253
+ targetInstructions: () => [new EmitPublicLog(/*addressing_mode=*/ 0, /*logSizeOffset=*/ 0, /*logOffset=*/ 1)], // logOffset doesn't matter when size is 0
1256
1254
  cleanupInstructions: () => [
1257
1255
  new Revert(/*addressing_mode=*/ 0, /*retSizeOffset=*/ 1, /*returnOffset=*/ 0).as(
1258
1256
  Opcode.REVERT_8,
@@ -1276,9 +1274,7 @@ export const SPAM_CONFIGS: Partial<Record<Opcode, SpamConfig[]>> = {
1276
1274
  // value: new Field(0n),
1277
1275
  //})),
1278
1276
  ],
1279
- targetInstructions: () => [
1280
- new EmitUnencryptedLog(/*addressing_mode=*/ 0, /*logSizeOffset=*/ 0, /*logOffset=*/ 2),
1281
- ], // uses logOffset 2 (uninitialized Field(0))
1277
+ targetInstructions: () => [new EmitPublicLog(/*addressing_mode=*/ 0, /*logSizeOffset=*/ 0, /*logOffset=*/ 2)], // uses logOffset 2 (uninitialized Field(0))
1282
1278
  cleanupInstructions: () => [
1283
1279
  new Revert(/*addressing_mode=*/ 0, /*retSizeOffset=*/ 1, /*returnOffset=*/ 0).as(
1284
1280
  Opcode.REVERT_8,
@@ -1343,20 +1339,16 @@ export const SPAM_CONFIGS: Partial<Record<Opcode, SpamConfig[]>> = {
1343
1339
  setup: [
1344
1340
  { offset: 0, value: new Field(Grumpkin.generator.x) }, // p1X = G.x
1345
1341
  { offset: 1, value: new Field(Grumpkin.generator.y) }, // p1Y = G.y
1346
- { offset: 2, value: new Uint1(0n) }, // p1IsInfinite = false
1347
- { offset: 3, value: new Field(Grumpkin.generator.x) }, // p2X = G.x
1348
- { offset: 4, value: new Field(Grumpkin.generator.y) }, // p2Y = G.y
1349
- { offset: 5, value: new Uint1(0n) }, // p2IsInfinite = false
1342
+ { offset: 2, value: new Field(Grumpkin.generator.x) }, // p2X = G.x
1343
+ { offset: 3, value: new Field(Grumpkin.generator.y) }, // p2Y = G.y
1350
1344
  ],
1351
1345
  targetInstructions: () => [
1352
1346
  new EcAdd(
1353
1347
  /*addressing_mode=*/ 0,
1354
1348
  /*p1XOffset=*/ 0,
1355
1349
  /*p1YOffset=*/ 1,
1356
- /*p1IsInfiniteOffset=*/ 2,
1357
- /*p2XOffset=*/ 3,
1358
- /*p2YOffset=*/ 4,
1359
- /*p2IsInfiniteOffset=*/ 5,
1350
+ /*p2XOffset=*/ 2,
1351
+ /*p2YOffset=*/ 3,
1360
1352
  /*dstOffset=*/ 0,
1361
1353
  ),
1362
1354
  ],
@@ -1,11 +1,11 @@
1
- import { DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT } from '@aztec/constants';
1
+ import { PUBLIC_TX_L2_GAS_OVERHEAD, TX_DA_GAS_OVERHEAD } from '@aztec/constants';
2
2
  import { asyncMap } from '@aztec/foundation/async-map';
3
3
  import { BlockNumber } from '@aztec/foundation/branded-types';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { type ContractArtifact, encodeArguments } from '@aztec/stdlib/abi';
6
6
  import { PublicSimulatorConfig, type PublicTxResult } from '@aztec/stdlib/avm';
7
7
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
8
- import { Gas, GasFees } from '@aztec/stdlib/gas';
8
+ import { FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT, Gas, GasFees } from '@aztec/stdlib/gas';
9
9
  import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
10
10
  import { PublicCallRequest } from '@aztec/stdlib/kernel';
11
11
  import { GlobalVariables, PublicCallRequestWithCalldata, type Tx } from '@aztec/stdlib/tx';
@@ -112,6 +112,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
112
112
  feePayer: AztecAddress = sender,
113
113
  /* need some unique first nullifier for note-nonce computations */
114
114
  privateInsertions: TestPrivateInsertions = { nonRevertible: { nullifiers: [new Fr(420000 + this.txCount)] } },
115
+ gasLimits?: Gas,
115
116
  ): Promise<Tx> {
116
117
  const setupCallRequests = await asyncMap(setupCalls, call =>
117
118
  this.#createPubicCallRequestForCall(call, call.sender ?? sender),
@@ -131,9 +132,13 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
131
132
  teardownCallRequest,
132
133
  feePayer,
133
134
  /*gasUsedByPrivate*/ teardownCall
134
- ? new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT)
135
- : Gas.empty(),
135
+ ? new Gas(
136
+ FALLBACK_TEARDOWN_DA_GAS_LIMIT + TX_DA_GAS_OVERHEAD,
137
+ FALLBACK_TEARDOWN_L2_GAS_LIMIT + PUBLIC_TX_L2_GAS_OVERHEAD,
138
+ )
139
+ : new Gas(TX_DA_GAS_OVERHEAD, PUBLIC_TX_L2_GAS_OVERHEAD),
136
140
  defaultGlobals(),
141
+ gasLimits,
137
142
  );
138
143
  }
139
144
 
@@ -146,8 +151,9 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
146
151
  /* need some unique first nullifier for note-nonce computations */
147
152
  privateInsertions?: TestPrivateInsertions,
148
153
  txLabel: string = 'unlabeledTx',
154
+ gasLimits?: Gas,
149
155
  ): Promise<PublicTxResult> {
150
- const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions);
156
+ const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions, gasLimits);
151
157
 
152
158
  await this.setFeePayerBalance(feePayer);
153
159
 
@@ -161,6 +167,8 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
161
167
  }
162
168
  const avmResult = await this.simulator.simulate(tx, fullTxLabel);
163
169
 
170
+ await this.#recordBytecodeSizes(fullTxLabel, [...setupCalls, ...appCalls, ...(teardownCall ? [teardownCall] : [])]);
171
+
164
172
  // Something like this is often useful for debugging:
165
173
  //if (avmResult.revertReason) {
166
174
  // // resolve / enrich revert reason
@@ -190,8 +198,18 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
190
198
  teardownCall?: TestEnqueuedCall,
191
199
  feePayer?: AztecAddress,
192
200
  privateInsertions?: TestPrivateInsertions,
201
+ gasLimits?: Gas,
193
202
  ): Promise<PublicTxResult> {
194
- return await this.simulateTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions, txLabel);
203
+ return await this.simulateTx(
204
+ sender,
205
+ setupCalls,
206
+ appCalls,
207
+ teardownCall,
208
+ feePayer,
209
+ privateInsertions,
210
+ txLabel,
211
+ gasLimits,
212
+ );
195
213
  }
196
214
 
197
215
  /**
@@ -209,6 +227,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
209
227
  teardownCall?: TestEnqueuedCall,
210
228
  feePayer?: AztecAddress,
211
229
  privateInsertions?: TestPrivateInsertions,
230
+ gasLimits?: Gas,
212
231
  ): Promise<PublicTxResult> {
213
232
  return await this.simulateTxWithLabel(
214
233
  txLabel,
@@ -218,6 +237,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
218
237
  teardownCall,
219
238
  feePayer,
220
239
  privateInsertions,
240
+ gasLimits,
221
241
  );
222
242
  }
223
243
 
@@ -277,6 +297,27 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
277
297
 
278
298
  return new PublicCallRequestWithCalldata(request, calldata);
279
299
  }
300
+
301
+ // WARNING: Deduplicates by artifact name, so two different artifacts with the same name
302
+ // in a single tx would only record the first one's bytecode size.
303
+ async #recordBytecodeSizes(txLabel: string, calls: TestEnqueuedCall[]) {
304
+ const seenArtifactNames = new Set<string>();
305
+ for (const call of calls) {
306
+ const artifact = await this.contractDataSource.getContractArtifact(call.address);
307
+ if (!artifact || seenArtifactNames.has(artifact.name)) {
308
+ continue;
309
+ }
310
+ seenArtifactNames.add(artifact.name);
311
+ const instance = await this.contractDataSource.getContract(call.address);
312
+ if (!instance) {
313
+ continue;
314
+ }
315
+ const contractClass = await this.contractDataSource.getContractClass(instance.currentContractClassId);
316
+ if (contractClass) {
317
+ this.metrics.recordBytecodeSize(txLabel, artifact.name, contractClass.packedBytecode.length);
318
+ }
319
+ }
320
+ }
280
321
  }
281
322
 
282
323
  export function defaultGlobals() {
@@ -2,10 +2,8 @@ import {
2
2
  CONTRACT_CLASS_PUBLISHED_MAGIC_VALUE,
3
3
  CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS,
4
4
  CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
5
- DEFAULT_DA_GAS_LIMIT,
6
- DEFAULT_L2_GAS_LIMIT,
7
- DEFAULT_TEARDOWN_DA_GAS_LIMIT,
8
- DEFAULT_TEARDOWN_L2_GAS_LIMIT,
5
+ MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT,
6
+ MAX_PROCESSABLE_L2_GAS,
9
7
  PRIVATE_LOG_SIZE_IN_FIELDS,
10
8
  } from '@aztec/constants';
11
9
  import { padArrayEnd } from '@aztec/foundation/collection';
@@ -14,7 +12,13 @@ import { CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG } from '@aztec/protocol-contracts
14
12
  import { bufferAsFields } from '@aztec/stdlib/abi';
15
13
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
16
14
  import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
17
- import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
15
+ import {
16
+ FALLBACK_TEARDOWN_DA_GAS_LIMIT,
17
+ FALLBACK_TEARDOWN_L2_GAS_LIMIT,
18
+ Gas,
19
+ GasFees,
20
+ GasSettings,
21
+ } from '@aztec/stdlib/gas';
18
22
  import { siloNullifier } from '@aztec/stdlib/hash';
19
23
  import {
20
24
  LogHash,
@@ -62,13 +66,14 @@ export async function createTxForPublicCalls(
62
66
  feePayer = AztecAddress.zero(),
63
67
  gasUsedByPrivate: Gas = Gas.empty(),
64
68
  globals: GlobalVariables = GlobalVariables.empty(),
69
+ gasLimits?: Gas,
65
70
  ): Promise<Tx> {
66
71
  assert(
67
72
  setupCallRequests.length > 0 || appCallRequests.length > 0 || teardownCallRequest !== undefined,
68
73
  "Can't create public tx with no enqueued calls",
69
74
  );
70
75
  // use max limits
71
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
76
+ gasLimits = gasLimits ?? new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
72
77
 
73
78
  const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
74
79
 
@@ -128,19 +133,19 @@ export async function createTxForPublicCalls(
128
133
 
129
134
  const maxFeesPerGas = feePayer.isZero() ? GasFees.empty() : new GasFees(10, 10);
130
135
  const teardownGasLimits = teardownCallRequest
131
- ? new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT)
136
+ ? new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT)
132
137
  : Gas.empty();
133
138
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, maxFeesPerGas, GasFees.empty());
134
139
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
135
140
  const header = BlockHeader.empty({ globalVariables: globals });
136
141
  const constantData = new TxConstantData(header, txContext, Fr.zero(), Fr.zero());
137
- const includeByTimestamp = 0n; // Not used in the simulator.
142
+ const expirationTimestamp = 0n; // Not used in the simulator.
138
143
 
139
144
  const txData = new PrivateKernelTailCircuitPublicInputs(
140
145
  constantData,
141
146
  /*gasUsed=*/ gasUsedByPrivate,
142
147
  feePayer,
143
- includeByTimestamp,
148
+ expirationTimestamp,
144
149
  forPublic,
145
150
  );
146
151
 
@@ -163,7 +168,7 @@ export async function createTxForPrivateOnly(
163
168
  gasUsedByPrivate: Gas = new Gas(10, 10),
164
169
  ): Promise<Tx> {
165
170
  // use max limits
166
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
171
+ const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
167
172
 
168
173
  const forRollup = PartialPrivateTailPublicInputsForRollup.empty();
169
174
 
@@ -171,13 +176,13 @@ export async function createTxForPrivateOnly(
171
176
  const gasSettings = new GasSettings(gasLimits, Gas.empty(), maxFeesPerGas, GasFees.empty());
172
177
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
173
178
  const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
174
- const includeByTimestamp = 0n; // Not used in the simulator.
179
+ const expirationTimestamp = 0n; // Not used in the simulator.
175
180
 
176
181
  const txData = new PrivateKernelTailCircuitPublicInputs(
177
182
  constantData,
178
183
  /*gasUsed=*/ gasUsedByPrivate,
179
184
  feePayer,
180
- includeByTimestamp,
185
+ expirationTimestamp,
181
186
  /*forPublic=*/ undefined,
182
187
  forRollup,
183
188
  );
@@ -228,17 +233,15 @@ export async function addNewContractInstanceToTx(
228
233
  contractInstance: ContractInstanceWithAddress,
229
234
  skipNullifierInsertion = false,
230
235
  ) {
231
- // can't use publicKeys.toFields() because it includes isInfinite which
232
- // is not broadcast in such private logs
236
+ // Only ivpk_m is broadcast as a point (x, y); the other five keys are hashes.
233
237
  const publicKeysAsFields = [
234
- contractInstance.publicKeys.masterNullifierPublicKey.x,
235
- contractInstance.publicKeys.masterNullifierPublicKey.y,
236
- contractInstance.publicKeys.masterIncomingViewingPublicKey.x,
237
- contractInstance.publicKeys.masterIncomingViewingPublicKey.y,
238
- contractInstance.publicKeys.masterOutgoingViewingPublicKey.x,
239
- contractInstance.publicKeys.masterOutgoingViewingPublicKey.y,
240
- contractInstance.publicKeys.masterTaggingPublicKey.x,
241
- contractInstance.publicKeys.masterTaggingPublicKey.y,
238
+ contractInstance.publicKeys.npkMHash,
239
+ contractInstance.publicKeys.ivpkM.x,
240
+ contractInstance.publicKeys.ivpkM.y,
241
+ contractInstance.publicKeys.ovpkMHash,
242
+ contractInstance.publicKeys.tpkMHash,
243
+ contractInstance.publicKeys.mspkMHash,
244
+ contractInstance.publicKeys.fbpkMHash,
242
245
  ];
243
246
  const logFields = [
244
247
  CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG,
@@ -247,6 +250,7 @@ export async function addNewContractInstanceToTx(
247
250
  new Fr(contractInstance.salt),
248
251
  contractInstance.currentContractClassId,
249
252
  contractInstance.initializationHash,
253
+ contractInstance.immutablesHash,
250
254
  ...publicKeysAsFields,
251
255
  contractInstance.deployer.toField(),
252
256
  ];
@@ -146,7 +146,7 @@ async function createTxFromHint(cppTx: AvmTxHint): Promise<Tx> {
146
146
  constants,
147
147
  cppTx.gasUsedByPrivate,
148
148
  cppTx.feePayer,
149
- 0n, // includeByTimestamp
149
+ 0n, // expirationTimestamp
150
150
  forPublic,
151
151
  undefined, // forRollup - not needed for public simulation
152
152
  );
@@ -83,6 +83,7 @@ export class HintingPublicContractsDB implements PublicContractsDBInterface {
83
83
  instance.currentContractClassId,
84
84
  instance.originalContractClassId,
85
85
  instance.initializationHash,
86
+ instance.immutablesHash,
86
87
  instance.publicKeys,
87
88
  ),
88
89
  );
@@ -410,12 +411,12 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
410
411
  }
411
412
  }
412
413
 
413
- public async createCheckpoint(): Promise<void> {
414
+ public async createCheckpoint(): Promise<number> {
414
415
  const actionCounter = this.checkpointActionCounter++;
415
416
  const oldCheckpointId = this.getCurrentCheckpointId();
416
417
  const treesStateHash = await this.getTreesStateHash();
417
418
 
418
- await this.db.createCheckpoint();
419
+ const depth = await this.db.createCheckpoint();
419
420
  this.checkpointStack.push(this.nextCheckpointId++);
420
421
  const newCheckpointId = this.getCurrentCheckpointId();
421
422
 
@@ -424,14 +425,16 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
424
425
  HintingMerkleWriteOperations.log.trace(
425
426
  `[createCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
426
427
  );
428
+
429
+ return depth;
427
430
  }
428
431
 
429
- public commitAllCheckpoints(): Promise<void> {
430
- throw new Error('commitAllCheckpoints is not supported in HintingMerkleWriteOperations.');
432
+ public commitAllCheckpointsTo(_depth: number): Promise<void> {
433
+ throw new Error('commitAllCheckpointsTo is not supported in HintingMerkleWriteOperations.');
431
434
  }
432
435
 
433
- public revertAllCheckpoints(): Promise<void> {
434
- throw new Error('revertAllCheckpoints is not supported in HintingMerkleWriteOperations.');
436
+ public revertAllCheckpointsTo(_depth: number): Promise<void> {
437
+ throw new Error('revertAllCheckpointsTo is not supported in HintingMerkleWriteOperations.');
435
438
  }
436
439
 
437
440
  public async commitCheckpoint(): Promise<void> {
@@ -572,7 +575,7 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
572
575
  return await this.db.close();
573
576
  }
574
577
 
575
- async [Symbol.dispose](): Promise<void> {
578
+ async [Symbol.asyncDispose](): Promise<void> {
576
579
  await this.close();
577
580
  }
578
581
 
@@ -55,10 +55,11 @@ export class PublicContractsDB implements PublicContractsDBInterface {
55
55
  this.log = createLogger('simulator:contracts-data-source', bindings);
56
56
  }
57
57
 
58
- public async addContracts(contractDeploymentData: ContractDeploymentData): Promise<void> {
58
+ /** Parses raw log data from the C++/NAPI bridge and inserts the resulting contracts into the current checkpoint. */
59
+ public addContractsFromLogs(contractDeploymentData: ContractDeploymentData): void {
59
60
  const currentState = this.getCurrentState();
60
61
 
61
- await this.addContractClassesFromEvents(
62
+ this.addContractClassesFromEvents(
62
63
  ContractClassPublishedEvent.extractContractClassEvents(contractDeploymentData.getContractClassLogs()),
63
64
  currentState,
64
65
  );
@@ -69,10 +70,18 @@ export class PublicContractsDB implements PublicContractsDBInterface {
69
70
  );
70
71
  }
71
72
 
72
- public async addNewContracts(tx: Tx): Promise<void> {
73
+ public addNewContracts(tx: Tx): void {
73
74
  const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
74
- await this.addContracts(contractDeploymentData.getNonRevertibleContractDeploymentData());
75
- await this.addContracts(contractDeploymentData.getRevertibleContractDeploymentData());
75
+ this.addContractsFromLogs(contractDeploymentData.getNonRevertibleContractDeploymentData());
76
+ this.addContractsFromLogs(contractDeploymentData.getRevertibleContractDeploymentData());
77
+ }
78
+
79
+ /** Inserts typed contract instances directly into the current checkpoint. */
80
+ public addContracts(contractInstances?: ContractInstanceWithAddress[]): void {
81
+ const currentState = this.getCurrentState();
82
+ for (const instance of contractInstances ?? []) {
83
+ currentState.addInstance(instance.address, instance);
84
+ }
76
85
  }
77
86
 
78
87
  /**
@@ -81,7 +90,7 @@ export class PublicContractsDB implements PublicContractsDBInterface {
81
90
  */
82
91
  public createCheckpoint(): void {
83
92
  const currentState = this.getCurrentState();
84
- const newState = currentState.deepCopy();
93
+ const newState = currentState.fork();
85
94
  this.contractStateStack.push(newState);
86
95
  }
87
96
 
@@ -174,17 +183,15 @@ export class PublicContractsDB implements PublicContractsDBInterface {
174
183
  return await this.dataSource.getDebugFunctionName(address, selector);
175
184
  }
176
185
 
177
- private async addContractClassesFromEvents(
186
+ private addContractClassesFromEvents(
178
187
  contractClassEvents: ContractClassPublishedEvent[],
179
188
  state: ContractsDbCheckpoint,
180
189
  ) {
181
- await Promise.all(
182
- contractClassEvents.map(async (event: ContractClassPublishedEvent) => {
183
- this.log.debug(`Adding class ${event.contractClassId.toString()} to contract state`);
184
- const contractClass = await event.toContractClassPublic();
185
- state.addClass(event.contractClassId, contractClass);
186
- }),
187
- );
190
+ for (const event of contractClassEvents) {
191
+ this.log.debug(`Adding class ${event.contractClassId.toString()} to contract state`);
192
+ const contractClass = event.toContractClassPublic();
193
+ state.addClass(event.contractClassId, contractClass);
194
+ }
188
195
  }
189
196
 
190
197
  private addContractInstancesFromEvents(
@@ -82,7 +82,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
82
82
  return this.guardAndPush(() => this.target.close());
83
83
  }
84
84
 
85
- async [Symbol.dispose](): Promise<void> {
85
+ async [Symbol.asyncDispose](): Promise<void> {
86
86
  await this.close();
87
87
  }
88
88
  getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo> {
@@ -134,7 +134,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
134
134
  ): Promise<(BlockNumber | undefined)[]> {
135
135
  return this.guardAndPush(() => this.target.getBlockNumbersForLeafIndices(treeId, leafIndices));
136
136
  }
137
- createCheckpoint(): Promise<void> {
137
+ createCheckpoint(): Promise<number> {
138
138
  return this.guardAndPush(() => this.target.createCheckpoint());
139
139
  }
140
140
  commitCheckpoint(): Promise<void> {
@@ -143,11 +143,11 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
143
143
  revertCheckpoint(): Promise<void> {
144
144
  return this.guardAndPush(() => this.target.revertCheckpoint());
145
145
  }
146
- commitAllCheckpoints(): Promise<void> {
147
- return this.guardAndPush(() => this.target.commitAllCheckpoints());
146
+ commitAllCheckpointsTo(depth: number): Promise<void> {
147
+ return this.guardAndPush(() => this.target.commitAllCheckpointsTo(depth));
148
148
  }
149
- revertAllCheckpoints(): Promise<void> {
150
- return this.guardAndPush(() => this.target.revertAllCheckpoints());
149
+ revertAllCheckpointsTo(depth: number): Promise<void> {
150
+ return this.guardAndPush(() => this.target.revertAllCheckpointsTo(depth));
151
151
  }
152
152
  findSiblingPaths<ID extends MerkleTreeId>(
153
153
  treeId: ID,