@aztec/simulator 0.0.1-commit.f504929 → 0.0.1-commit.f5a9928

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 (110) hide show
  1. package/dest/client.d.ts +1 -3
  2. package/dest/client.d.ts.map +1 -1
  3. package/dest/client.js +0 -2
  4. package/dest/private/acvm_wasm.d.ts +1 -1
  5. package/dest/private/acvm_wasm.d.ts.map +1 -1
  6. package/dest/private/acvm_wasm.js +3 -1
  7. package/dest/private/circuit_recording/circuit_recorder.d.ts +36 -23
  8. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  9. package/dest/private/circuit_recording/circuit_recorder.js +65 -69
  10. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +7 -19
  11. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  12. package/dest/private/circuit_recording/file_circuit_recorder.js +38 -42
  13. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
  14. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
  15. package/dest/private/circuit_recording/simulator_recorder_wrapper.js +11 -14
  16. package/dest/public/avm/avm_simulator.js +1 -1
  17. package/dest/public/avm/calldata.d.ts +1 -1
  18. package/dest/public/avm/calldata.d.ts.map +1 -1
  19. package/dest/public/avm/calldata.js +3 -2
  20. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +2 -1
  21. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  22. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +18 -3
  23. package/dest/public/avm/fixtures/utils.d.ts +1 -1
  24. package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
  25. package/dest/public/avm/fixtures/utils.js +4 -1
  26. package/dest/public/avm/opcodes/contract.d.ts +3 -2
  27. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  28. package/dest/public/avm/opcodes/contract.js +5 -1
  29. package/dest/public/avm/opcodes/ec_add.d.ts +2 -4
  30. package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
  31. package/dest/public/avm/opcodes/ec_add.js +13 -27
  32. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  33. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  34. package/dest/public/contracts_db_checkpoint.js +1 -1
  35. package/dest/public/fixtures/amm_test.js +2 -2
  36. package/dest/public/fixtures/bulk_test.d.ts +1 -1
  37. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  38. package/dest/public/fixtures/bulk_test.js +33 -6
  39. package/dest/public/fixtures/custom_bytecode_tester.d.ts +1 -1
  40. package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
  41. package/dest/public/fixtures/custom_bytecode_tester.js +2 -2
  42. package/dest/public/fixtures/custom_bytecode_tests.d.ts +8 -1
  43. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  44. package/dest/public/fixtures/custom_bytecode_tests.js +91 -2
  45. package/dest/public/fixtures/opcode_spammer.d.ts +1 -1
  46. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
  47. package/dest/public/fixtures/opcode_spammer.js +2 -10
  48. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +6 -5
  49. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  50. package/dest/public/fixtures/public_tx_simulation_tester.js +11 -9
  51. package/dest/public/fixtures/token_test.js +3 -3
  52. package/dest/public/fixtures/utils.d.ts +2 -2
  53. package/dest/public/fixtures/utils.d.ts.map +1 -1
  54. package/dest/public/fixtures/utils.js +17 -16
  55. package/dest/public/hinting_db_sources.d.ts +4 -4
  56. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  57. package/dest/public/hinting_db_sources.js +7 -6
  58. package/dest/public/public_db_sources.d.ts +6 -3
  59. package/dest/public/public_db_sources.d.ts.map +1 -1
  60. package/dest/public/public_db_sources.js +16 -10
  61. package/dest/public/public_processor/guarded_merkle_tree.d.ts +4 -4
  62. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  63. package/dest/public/public_processor/guarded_merkle_tree.js +4 -4
  64. package/dest/public/public_processor/public_processor.d.ts +5 -4
  65. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  66. package/dest/public/public_processor/public_processor.js +107 -63
  67. package/dest/public/public_processor/public_processor_metrics.d.ts +4 -1
  68. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  69. package/dest/public/public_processor/public_processor_metrics.js +8 -0
  70. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -1
  71. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  72. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +5 -4
  73. package/dest/public/public_tx_simulator/public_tx_context.d.ts +7 -3
  74. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  75. package/dest/public/public_tx_simulator/public_tx_context.js +8 -10
  76. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +6 -2
  77. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  78. package/dest/public/public_tx_simulator/public_tx_simulator.js +12 -7
  79. package/dest/public/state_manager/state_manager.js +1 -1
  80. package/package.json +16 -16
  81. package/src/client.ts +0 -2
  82. package/src/private/acvm_wasm.ts +4 -1
  83. package/src/private/circuit_recording/circuit_recorder.ts +84 -78
  84. package/src/private/circuit_recording/file_circuit_recorder.ts +38 -48
  85. package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
  86. package/src/public/avm/avm_simulator.ts +1 -1
  87. package/src/public/avm/calldata.ts +3 -2
  88. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +23 -3
  89. package/src/public/avm/fixtures/utils.ts +4 -1
  90. package/src/public/avm/opcodes/contract.ts +5 -1
  91. package/src/public/avm/opcodes/ec_add.ts +12 -31
  92. package/src/public/avm/opcodes/external_calls.ts +1 -1
  93. package/src/public/contracts_db_checkpoint.ts +1 -1
  94. package/src/public/fixtures/amm_test.ts +2 -2
  95. package/src/public/fixtures/bulk_test.ts +31 -6
  96. package/src/public/fixtures/custom_bytecode_tester.ts +2 -2
  97. package/src/public/fixtures/custom_bytecode_tests.ts +209 -2
  98. package/src/public/fixtures/opcode_spammer.ts +4 -8
  99. package/src/public/fixtures/public_tx_simulation_tester.ts +21 -12
  100. package/src/public/fixtures/token_test.ts +3 -3
  101. package/src/public/fixtures/utils.ts +19 -20
  102. package/src/public/hinting_db_sources.ts +9 -6
  103. package/src/public/public_db_sources.ts +21 -14
  104. package/src/public/public_processor/guarded_merkle_tree.ts +5 -5
  105. package/src/public/public_processor/public_processor.ts +138 -77
  106. package/src/public/public_processor/public_processor_metrics.ts +12 -0
  107. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +5 -4
  108. package/src/public/public_tx_simulator/public_tx_context.ts +8 -10
  109. package/src/public/public_tx_simulator/public_tx_simulator.ts +11 -7
  110. package/src/public/state_manager/state_manager.ts +1 -1
@@ -1,8 +1,10 @@
1
+ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
2
+
1
3
  import { strict as assert } from 'assert';
2
4
 
3
5
  import { TypeTag } from '../avm/avm_memory_types.js';
4
6
  import { Addressing, AddressingMode } from '../avm/opcodes/addressing_mode.js';
5
- import { Add, CalldataCopy, Jump, Return, Set } from '../avm/opcodes/index.js';
7
+ import { Add, Call, CalldataCopy, Cast, Jump, Return, Set, Sha256Compression, Xor } from '../avm/opcodes/index.js';
6
8
  import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
7
9
  import {
8
10
  MAX_OPCODE_VALUE,
@@ -10,7 +12,7 @@ import {
10
12
  OperandType,
11
13
  getOperandSize,
12
14
  } from '../avm/serialization/instruction_serialization.js';
13
- import { deployAndExecuteCustomBytecode } from './custom_bytecode_tester.js';
15
+ import { deployAndExecuteCustomBytecode, deployCustomBytecode } from './custom_bytecode_tester.js';
14
16
  import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
15
17
 
16
18
  // First instruction resolved a base address (offset 0) which is uninitialized and therefore
@@ -208,6 +210,144 @@ export async function invalidTagValueAndInstructionTruncatedTest(tester: PublicT
208
210
  return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
209
211
  }
210
212
 
213
+ // Exercise SET truncation: set values whose widths exceed the target tag and
214
+ // rely on `buildFromTagTruncating` to truncate to the low bits of the tag.
215
+ // Covers sources larger than 128 bits (via SET_FF) and sources in (32, 128]
216
+ // bits (via SET_64) against destination tags U1/U8/U16/U32/U64/U128.
217
+ export async function setTruncationTest(tester: PublicTxSimulationTester) {
218
+ // 200-bit value: forces truncation for every target tag up to U128.
219
+ const LARGE_FIELD_VALUE = (1n << 200n) + 0x1234567890abcdef1234567890abcdefn;
220
+ // 40-bit value: forces truncation for target tags up to U32.
221
+ const LARGE_U64_VALUE = (1n << 40n) + 0xdeadbeefn;
222
+
223
+ const bytecode = encodeToBytecode([
224
+ // Zero U32 at offset 0 — used as the Return copy-size slot.
225
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
226
+
227
+ // Source >128 bits (via SET_FF) truncated to smaller target tags.
228
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT128, LARGE_FIELD_VALUE).as(
229
+ Opcode.SET_FF,
230
+ Set.wireFormatFF,
231
+ ),
232
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 2, TypeTag.UINT64, LARGE_FIELD_VALUE).as(
233
+ Opcode.SET_FF,
234
+ Set.wireFormatFF,
235
+ ),
236
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 3, TypeTag.UINT32, LARGE_FIELD_VALUE).as(
237
+ Opcode.SET_FF,
238
+ Set.wireFormatFF,
239
+ ),
240
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 4, TypeTag.UINT16, LARGE_FIELD_VALUE).as(
241
+ Opcode.SET_FF,
242
+ Set.wireFormatFF,
243
+ ),
244
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 5, TypeTag.UINT8, LARGE_FIELD_VALUE).as(
245
+ Opcode.SET_FF,
246
+ Set.wireFormatFF,
247
+ ),
248
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 6, TypeTag.UINT1, LARGE_FIELD_VALUE).as(
249
+ Opcode.SET_FF,
250
+ Set.wireFormatFF,
251
+ ),
252
+
253
+ // Source in (32, 128] bits (via SET_64) truncated to smaller target tags.
254
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 7, TypeTag.UINT32, LARGE_U64_VALUE).as(
255
+ Opcode.SET_64,
256
+ Set.wireFormat64,
257
+ ),
258
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 8, TypeTag.UINT16, LARGE_U64_VALUE).as(
259
+ Opcode.SET_64,
260
+ Set.wireFormat64,
261
+ ),
262
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 9, TypeTag.UINT8, LARGE_U64_VALUE).as(
263
+ Opcode.SET_64,
264
+ Set.wireFormat64,
265
+ ),
266
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 10, TypeTag.UINT1, LARGE_U64_VALUE).as(
267
+ Opcode.SET_64,
268
+ Set.wireFormat64,
269
+ ),
270
+
271
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
272
+ ]);
273
+
274
+ const txLabel = 'SetTruncation';
275
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
276
+ }
277
+
278
+ // Exercise CAST truncation: store a wide source value in memory then CAST it
279
+ // to smaller destination tags. Covers sources larger than 128 bits (FIELD
280
+ // source) and sources in (32, 128] bits (UINT64 source) against destination
281
+ // tags U1/U8/U16/U32/U64/U128.
282
+ export async function castTruncationTest(tester: PublicTxSimulationTester) {
283
+ // 200-bit source: stored as FIELD so that CASTs to any integer tag truncate.
284
+ const LARGE_FIELD_VALUE = (1n << 200n) + 0x1234567890abcdef1234567890abcdefn;
285
+ // 40-bit source: stored as UINT64 so CASTs to U1/U8/U16/U32 truncate.
286
+ const LARGE_U64_VALUE = (1n << 40n) + 0xdeadbeefn;
287
+
288
+ const bytecode = encodeToBytecode([
289
+ // Zero U32 at offset 0 — used as the Return copy-size slot.
290
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
291
+
292
+ // Store wide FIELD source at offset 10, then CAST to smaller tags.
293
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 10, TypeTag.FIELD, LARGE_FIELD_VALUE).as(
294
+ Opcode.SET_FF,
295
+ Set.wireFormatFF,
296
+ ),
297
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 11, TypeTag.UINT128).as(
298
+ Opcode.CAST_8,
299
+ Cast.wireFormat8,
300
+ ),
301
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 12, TypeTag.UINT64).as(
302
+ Opcode.CAST_8,
303
+ Cast.wireFormat8,
304
+ ),
305
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 13, TypeTag.UINT32).as(
306
+ Opcode.CAST_8,
307
+ Cast.wireFormat8,
308
+ ),
309
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 14, TypeTag.UINT16).as(
310
+ Opcode.CAST_8,
311
+ Cast.wireFormat8,
312
+ ),
313
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 15, TypeTag.UINT8).as(
314
+ Opcode.CAST_8,
315
+ Cast.wireFormat8,
316
+ ),
317
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 16, TypeTag.UINT1).as(
318
+ Opcode.CAST_8,
319
+ Cast.wireFormat8,
320
+ ),
321
+
322
+ // Store UINT64 source at offset 20, then CAST to smaller integer tags.
323
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 20, TypeTag.UINT64, LARGE_U64_VALUE).as(
324
+ Opcode.SET_64,
325
+ Set.wireFormat64,
326
+ ),
327
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 21, TypeTag.UINT32).as(
328
+ Opcode.CAST_8,
329
+ Cast.wireFormat8,
330
+ ),
331
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 22, TypeTag.UINT16).as(
332
+ Opcode.CAST_8,
333
+ Cast.wireFormat8,
334
+ ),
335
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 23, TypeTag.UINT8).as(
336
+ Opcode.CAST_8,
337
+ Cast.wireFormat8,
338
+ ),
339
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 24, TypeTag.UINT1).as(
340
+ Opcode.CAST_8,
341
+ Cast.wireFormat8,
342
+ ),
343
+
344
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
345
+ ]);
346
+
347
+ const txLabel = 'CastTruncation';
348
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
349
+ }
350
+
211
351
  /**
212
352
  * Returns the offset of the tag in an instruction.
213
353
  * @details Loops over the wire format operand type entries until it finds the tag.
@@ -226,3 +366,70 @@ function getTagOffsetInInstruction(wireFormat: OperandType[]): number {
226
366
  }
227
367
  return offset;
228
368
  }
369
+
370
+ export async function deployBitwiseSha256ErrorRowCollisionContracts(
371
+ tester: PublicTxSimulationTester,
372
+ ): Promise<{ innerContract: ContractInstanceWithAddress; outerContract: ContractInstanceWithAddress }> {
373
+ const innerBytecode = encodeToBytecode([
374
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
375
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT16, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
376
+ new Xor(/*addressing_mode=*/ 0, /*aOffset=*/ 0, /*bOffset=*/ 1, /*dstOffset=*/ 2).as(Opcode.XOR_8, Xor.wireFormat8),
377
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
378
+ ]);
379
+
380
+ const outerInstructions = [
381
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
382
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT32, /*value=*/ 1).as(Opcode.SET_8, Set.wireFormat8),
383
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 2, TypeTag.UINT32, /*value=*/ 100_000).as(
384
+ Opcode.SET_32,
385
+ Set.wireFormat32,
386
+ ),
387
+ new CalldataCopy(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 1, /*cdStartOffset=*/ 0, /*dstOffset=*/ 3),
388
+ new Call(
389
+ /*addressing_mode=*/ 0,
390
+ /*l2GasOffset=*/ 2,
391
+ /*daGasOffset=*/ 2,
392
+ /*addrOffset=*/ 3,
393
+ /*argsSizeOffset=*/ 0,
394
+ /*argsOffset=*/ 0,
395
+ ),
396
+ ];
397
+
398
+ for (let i = 0; i < 8; i++) {
399
+ outerInstructions.push(
400
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 10 + i, TypeTag.UINT32, /*value=*/ 0).as(
401
+ Opcode.SET_8,
402
+ Set.wireFormat8,
403
+ ),
404
+ );
405
+ }
406
+
407
+ outerInstructions.push(
408
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 18, TypeTag.UINT32, /*value=*/ 0x61626364).as(
409
+ Opcode.SET_32,
410
+ Set.wireFormat32,
411
+ ),
412
+ );
413
+
414
+ for (let i = 0; i < 15; i++) {
415
+ outerInstructions.push(
416
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 19 + i, TypeTag.UINT32, /*value=*/ 0).as(
417
+ Opcode.SET_8,
418
+ Set.wireFormat8,
419
+ ),
420
+ );
421
+ }
422
+
423
+ outerInstructions.push(
424
+ new Sha256Compression(/*addressing_mode=*/ 0, /*outputOffset=*/ 34, /*stateOffset=*/ 10, /*inputsOffset=*/ 18),
425
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
426
+ );
427
+
428
+ const innerContract = await deployCustomBytecode(innerBytecode, tester, 'BitwiseSha256CollisionInner');
429
+ const outerContract = await deployCustomBytecode(
430
+ encodeToBytecode(outerInstructions),
431
+ tester,
432
+ 'BitwiseSha256CollisionOuter',
433
+ );
434
+ return { innerContract, outerContract };
435
+ }
@@ -1339,20 +1339,16 @@ export const SPAM_CONFIGS: Partial<Record<Opcode, SpamConfig[]>> = {
1339
1339
  setup: [
1340
1340
  { offset: 0, value: new Field(Grumpkin.generator.x) }, // p1X = G.x
1341
1341
  { offset: 1, value: new Field(Grumpkin.generator.y) }, // p1Y = G.y
1342
- { offset: 2, value: new Uint1(0n) }, // p1IsInfinite = false
1343
- { offset: 3, value: new Field(Grumpkin.generator.x) }, // p2X = G.x
1344
- { offset: 4, value: new Field(Grumpkin.generator.y) }, // p2Y = G.y
1345
- { 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
1346
1344
  ],
1347
1345
  targetInstructions: () => [
1348
1346
  new EcAdd(
1349
1347
  /*addressing_mode=*/ 0,
1350
1348
  /*p1XOffset=*/ 0,
1351
1349
  /*p1YOffset=*/ 1,
1352
- /*p1IsInfiniteOffset=*/ 2,
1353
- /*p2XOffset=*/ 3,
1354
- /*p2YOffset=*/ 4,
1355
- /*p2IsInfiniteOffset=*/ 5,
1350
+ /*p2XOffset=*/ 2,
1351
+ /*p2YOffset=*/ 3,
1356
1352
  /*dstOffset=*/ 0,
1357
1353
  ),
1358
1354
  ],
@@ -1,9 +1,4 @@
1
- import {
2
- DEFAULT_TEARDOWN_DA_GAS_LIMIT,
3
- DEFAULT_TEARDOWN_L2_GAS_LIMIT,
4
- PUBLIC_TX_L2_GAS_OVERHEAD,
5
- TX_DA_GAS_OVERHEAD,
6
- } from '@aztec/constants';
1
+ import { PUBLIC_TX_L2_GAS_OVERHEAD, TX_DA_GAS_OVERHEAD } from '@aztec/constants';
7
2
  import { asyncMap } from '@aztec/foundation/async-map';
8
3
  import { BlockNumber } from '@aztec/foundation/branded-types';
9
4
  import { Fr } from '@aztec/foundation/curves/bn254';
@@ -32,6 +27,8 @@ import { SimpleContractDataSource } from './simple_contract_data_source.js';
32
27
  import { type TestPrivateInsertions, createTxForPublicCalls } from './utils.js';
33
28
 
34
29
  const DEFAULT_GAS_FEES = new GasFees(2, 3);
30
+ const TEARDOWN_DA_GAS_LIMIT = 98_304;
31
+ const TEARDOWN_L2_GAS_LIMIT = 817_500;
35
32
 
36
33
  export type TestEnqueuedCall = {
37
34
  sender?: AztecAddress;
@@ -117,6 +114,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
117
114
  feePayer: AztecAddress = sender,
118
115
  /* need some unique first nullifier for note-nonce computations */
119
116
  privateInsertions: TestPrivateInsertions = { nonRevertible: { nullifiers: [new Fr(420000 + this.txCount)] } },
117
+ gasLimits?: Gas,
120
118
  ): Promise<Tx> {
121
119
  const setupCallRequests = await asyncMap(setupCalls, call =>
122
120
  this.#createPubicCallRequestForCall(call, call.sender ?? sender),
@@ -136,12 +134,10 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
136
134
  teardownCallRequest,
137
135
  feePayer,
138
136
  /*gasUsedByPrivate*/ teardownCall
139
- ? new Gas(
140
- DEFAULT_TEARDOWN_DA_GAS_LIMIT + TX_DA_GAS_OVERHEAD,
141
- DEFAULT_TEARDOWN_L2_GAS_LIMIT + PUBLIC_TX_L2_GAS_OVERHEAD,
142
- )
137
+ ? new Gas(TEARDOWN_DA_GAS_LIMIT + TX_DA_GAS_OVERHEAD, TEARDOWN_L2_GAS_LIMIT + PUBLIC_TX_L2_GAS_OVERHEAD)
143
138
  : new Gas(TX_DA_GAS_OVERHEAD, PUBLIC_TX_L2_GAS_OVERHEAD),
144
139
  defaultGlobals(),
140
+ gasLimits,
145
141
  );
146
142
  }
147
143
 
@@ -154,8 +150,9 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
154
150
  /* need some unique first nullifier for note-nonce computations */
155
151
  privateInsertions?: TestPrivateInsertions,
156
152
  txLabel: string = 'unlabeledTx',
153
+ gasLimits?: Gas,
157
154
  ): Promise<PublicTxResult> {
158
- const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions);
155
+ const tx = await this.createTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions, gasLimits);
159
156
 
160
157
  await this.setFeePayerBalance(feePayer);
161
158
 
@@ -200,8 +197,18 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
200
197
  teardownCall?: TestEnqueuedCall,
201
198
  feePayer?: AztecAddress,
202
199
  privateInsertions?: TestPrivateInsertions,
200
+ gasLimits?: Gas,
203
201
  ): Promise<PublicTxResult> {
204
- return await this.simulateTx(sender, setupCalls, appCalls, teardownCall, feePayer, privateInsertions, txLabel);
202
+ return await this.simulateTx(
203
+ sender,
204
+ setupCalls,
205
+ appCalls,
206
+ teardownCall,
207
+ feePayer,
208
+ privateInsertions,
209
+ txLabel,
210
+ gasLimits,
211
+ );
205
212
  }
206
213
 
207
214
  /**
@@ -219,6 +226,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
219
226
  teardownCall?: TestEnqueuedCall,
220
227
  feePayer?: AztecAddress,
221
228
  privateInsertions?: TestPrivateInsertions,
229
+ gasLimits?: Gas,
222
230
  ): Promise<PublicTxResult> {
223
231
  return await this.simulateTxWithLabel(
224
232
  txLabel,
@@ -228,6 +236,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
228
236
  teardownCall,
229
237
  feePayer,
230
238
  privateInsertions,
239
+ gasLimits,
231
240
  );
232
241
  }
233
242
 
@@ -21,9 +21,9 @@ export async function tokenTest(
21
21
  ) {
22
22
  const timer = new Timer();
23
23
 
24
- const admin = AztecAddress.fromNumber(42);
25
- const sender = AztecAddress.fromNumber(111);
26
- const receiver = AztecAddress.fromNumber(222);
24
+ const admin = AztecAddress.fromNumberUnsafe(42);
25
+ const sender = AztecAddress.fromNumberUnsafe(111);
26
+ const receiver = AztecAddress.fromNumberUnsafe(222);
27
27
 
28
28
  const token = await setUpToken(tester, tokenArtifact, admin, expectToBeTrue);
29
29
 
@@ -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';
@@ -38,6 +36,9 @@ import {
38
36
 
39
37
  import { strict as assert } from 'assert';
40
38
 
39
+ const TEARDOWN_DA_GAS_LIMIT = 98_304;
40
+ const TEARDOWN_L2_GAS_LIMIT = 817_500;
41
+
41
42
  export type TestPrivateInsertions = {
42
43
  revertible?: {
43
44
  nullifiers?: Fr[];
@@ -62,13 +63,14 @@ export async function createTxForPublicCalls(
62
63
  feePayer = AztecAddress.zero(),
63
64
  gasUsedByPrivate: Gas = Gas.empty(),
64
65
  globals: GlobalVariables = GlobalVariables.empty(),
66
+ gasLimits?: Gas,
65
67
  ): Promise<Tx> {
66
68
  assert(
67
69
  setupCallRequests.length > 0 || appCallRequests.length > 0 || teardownCallRequest !== undefined,
68
70
  "Can't create public tx with no enqueued calls",
69
71
  );
70
72
  // use max limits
71
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
73
+ gasLimits = gasLimits ?? new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
72
74
 
73
75
  const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
74
76
 
@@ -127,9 +129,7 @@ export async function createTxForPublicCalls(
127
129
  }
128
130
 
129
131
  const maxFeesPerGas = feePayer.isZero() ? GasFees.empty() : new GasFees(10, 10);
130
- const teardownGasLimits = teardownCallRequest
131
- ? new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT)
132
- : Gas.empty();
132
+ const teardownGasLimits = teardownCallRequest ? new Gas(TEARDOWN_DA_GAS_LIMIT, TEARDOWN_L2_GAS_LIMIT) : Gas.empty();
133
133
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, maxFeesPerGas, GasFees.empty());
134
134
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
135
135
  const header = BlockHeader.empty({ globalVariables: globals });
@@ -163,7 +163,7 @@ export async function createTxForPrivateOnly(
163
163
  gasUsedByPrivate: Gas = new Gas(10, 10),
164
164
  ): Promise<Tx> {
165
165
  // use max limits
166
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
166
+ const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
167
167
 
168
168
  const forRollup = PartialPrivateTailPublicInputsForRollup.empty();
169
169
 
@@ -228,17 +228,15 @@ export async function addNewContractInstanceToTx(
228
228
  contractInstance: ContractInstanceWithAddress,
229
229
  skipNullifierInsertion = false,
230
230
  ) {
231
- // can't use publicKeys.toFields() because it includes isInfinite which
232
- // is not broadcast in such private logs
231
+ // Only ivpk_m is broadcast as a point (x, y); the other five keys are hashes.
233
232
  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,
233
+ contractInstance.publicKeys.npkMHash,
234
+ contractInstance.publicKeys.ivpkM.x,
235
+ contractInstance.publicKeys.ivpkM.y,
236
+ contractInstance.publicKeys.ovpkMHash,
237
+ contractInstance.publicKeys.tpkMHash,
238
+ contractInstance.publicKeys.mspkMHash,
239
+ contractInstance.publicKeys.fbpkMHash,
242
240
  ];
243
241
  const logFields = [
244
242
  CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG,
@@ -247,6 +245,7 @@ export async function addNewContractInstanceToTx(
247
245
  new Fr(contractInstance.salt),
248
246
  contractInstance.currentContractClassId,
249
247
  contractInstance.initializationHash,
248
+ contractInstance.immutablesHash,
250
249
  ...publicKeysAsFields,
251
250
  contractInstance.deployer.toField(),
252
251
  ];
@@ -256,7 +255,7 @@ export async function addNewContractInstanceToTx(
256
255
  );
257
256
 
258
257
  const contractAddressNullifier = await siloNullifier(
259
- AztecAddress.fromNumber(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS),
258
+ AztecAddress.fromNumberUnsafe(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS),
260
259
  contractInstance.address.toField(),
261
260
  );
262
261
 
@@ -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> {
@@ -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(
@@ -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,