@aztec/simulator 0.0.1-commit.3fd054f6 → 0.0.1-commit.431c48d

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 (104) 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 +1 -1
  49. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  50. package/dest/public/fixtures/public_tx_simulation_tester.js +4 -2
  51. package/dest/public/fixtures/token_test.js +3 -3
  52. package/dest/public/fixtures/utils.d.ts +1 -1
  53. package/dest/public/fixtures/utils.d.ts.map +1 -1
  54. package/dest/public/fixtures/utils.js +16 -15
  55. package/dest/public/hinting_db_sources.d.ts +1 -1
  56. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  57. package/dest/public/hinting_db_sources.js +1 -1
  58. package/dest/public/public_db_sources.d.ts +5 -2
  59. package/dest/public/public_db_sources.d.ts.map +1 -1
  60. package/dest/public/public_db_sources.js +10 -4
  61. package/dest/public/public_processor/public_processor.d.ts +4 -3
  62. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  63. package/dest/public/public_processor/public_processor.js +77 -33
  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.js +4 -4
  68. package/dest/public/public_tx_simulator/public_tx_context.d.ts +7 -3
  69. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  70. package/dest/public/public_tx_simulator/public_tx_context.js +8 -10
  71. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +6 -2
  72. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  73. package/dest/public/public_tx_simulator/public_tx_simulator.js +12 -7
  74. package/dest/public/state_manager/state_manager.js +1 -1
  75. package/package.json +16 -15
  76. package/src/client.ts +0 -2
  77. package/src/private/acvm_wasm.ts +4 -1
  78. package/src/private/circuit_recording/circuit_recorder.ts +84 -78
  79. package/src/private/circuit_recording/file_circuit_recorder.ts +38 -48
  80. package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
  81. package/src/public/avm/avm_simulator.ts +1 -1
  82. package/src/public/avm/calldata.ts +3 -2
  83. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +23 -3
  84. package/src/public/avm/fixtures/utils.ts +4 -1
  85. package/src/public/avm/opcodes/contract.ts +5 -1
  86. package/src/public/avm/opcodes/ec_add.ts +12 -31
  87. package/src/public/avm/opcodes/external_calls.ts +1 -1
  88. package/src/public/contracts_db_checkpoint.ts +1 -1
  89. package/src/public/fixtures/amm_test.ts +2 -2
  90. package/src/public/fixtures/bulk_test.ts +31 -6
  91. package/src/public/fixtures/custom_bytecode_tester.ts +2 -2
  92. package/src/public/fixtures/custom_bytecode_tests.ts +209 -2
  93. package/src/public/fixtures/opcode_spammer.ts +4 -8
  94. package/src/public/fixtures/public_tx_simulation_tester.ts +4 -10
  95. package/src/public/fixtures/token_test.ts +3 -3
  96. package/src/public/fixtures/utils.ts +18 -20
  97. package/src/public/hinting_db_sources.ts +1 -0
  98. package/src/public/public_db_sources.ts +13 -4
  99. package/src/public/public_processor/public_processor.ts +97 -40
  100. package/src/public/public_processor/public_processor_metrics.ts +12 -0
  101. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +4 -4
  102. package/src/public/public_tx_simulator/public_tx_context.ts +8 -10
  103. package/src/public/public_tx_simulator/public_tx_simulator.ts +11 -7
  104. package/src/public/state_manager/state_manager.ts +1 -1
@@ -14,8 +14,8 @@ abstract class ExternalCall extends Instruction {
14
14
  OperandType.UINT16, // L2 gas offset
15
15
  OperandType.UINT16, // DA gas offset
16
16
  OperandType.UINT16, // Address offset
17
- OperandType.UINT16, // Args offset
18
17
  OperandType.UINT16, // Args size offset
18
+ OperandType.UINT16, // Args offset
19
19
  ];
20
20
 
21
21
  constructor(
@@ -31,7 +31,7 @@ export class ContractsDbCheckpoint {
31
31
  return this.bytecodeCommitments.get(classId.toString());
32
32
  }
33
33
 
34
- public deepCopy(): ContractsDbCheckpoint {
34
+ public fork(): ContractsDbCheckpoint {
35
35
  const copy = new ContractsDbCheckpoint();
36
36
  this.instances.forEach((value, key) => copy.instances.set(key, value));
37
37
  this.classes.forEach((value, key) => copy.classes.set(key, value));
@@ -25,8 +25,8 @@ export async function ammTest(
25
25
  ) {
26
26
  const timer = new Timer();
27
27
 
28
- const admin = AztecAddress.fromNumber(42);
29
- const sender = AztecAddress.fromNumber(111);
28
+ const admin = AztecAddress.fromNumberUnsafe(42);
29
+ const sender = AztecAddress.fromNumberUnsafe(111);
30
30
 
31
31
  logger.debug(`Deploying tokens`);
32
32
  const token0 = await setUpToken(tester, tokenArtifact, admin, expectToBeTrue, /*seed=*/ 0);
@@ -13,7 +13,7 @@ export async function bulkTest(
13
13
  ) {
14
14
  const timer = new Timer();
15
15
 
16
- const deployer = AztecAddress.fromNumber(42);
16
+ const deployer = AztecAddress.fromNumberUnsafe(42);
17
17
  const avmTestContract = await tester.registerAndDeployContract(
18
18
  /*constructorArgs=*/ [],
19
19
  deployer,
@@ -25,14 +25,26 @@ export async function bulkTest(
25
25
  // Register multiple different protocol contracts (to ensure we don't dedup bytecode hashing events):
26
26
  await tester.registerAuthContract();
27
27
  await tester.registerInstanceRegistryContract();
28
+ await tester.registerClassRegistryContract();
28
29
 
29
30
  // Get a deployed contract instance to pass to the contract
30
31
  // for it to use as "expected" values when testing contract instance retrieval.
31
32
  const expectContractInstance = avmTestContract;
32
33
  const argsField = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
33
- const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8].map(x => new Fr(x));
34
- argsU8.push(new Fr(2n ** 128n + 9n)); // Trigger truncation from large (> 128 bits) value (canonical decomposition event)
35
- argsU8.push(new Fr(2n ** 125n + 10n)); // Trigger truncation from small (< 128 bits) value (no canonical decomposition event)
34
+ const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
35
+ // Pinned grumpkin-Poseidon2 Schnorr signature (mirrors the C++ `pinned_test_vector_large`
36
+ // and noir-lang/schnorr v0.4.0's `pinned_vector_large`). Passing these in as calldata
37
+ // (rather than baking them into Noir as constants) keeps MSM + Poseidon2 from being folded
38
+ // by the Noir compiler.
39
+ const schnorrInputs = [
40
+ Fr.fromHexString('0x065812e335a97c2108ea8cf4ccfe2f9dd6b117a0714f5e18461575be93f61da6'), // pubkey.x
41
+ Fr.fromHexString('0x1a915003e8ec534f9a15d926a7ded478e178468ccc4f28e236e67450a55ac622'), // pubkey.y
42
+ Fr.fromHexString('0xf3bc3b7147acb9c621fd9f72dbf15ffa'), // sig_s.lo
43
+ Fr.fromHexString('0x08599f379f0301dfefdbd0272554454d'), // sig_s.hi
44
+ Fr.fromHexString('0x97065383ebbbd76620398792bd259bc2'), // sig_e.lo
45
+ Fr.fromHexString('0x2ceaee87f45b7a417f0ffb05451a8c92'), // sig_e.hi
46
+ Fr.fromHexString('0x0123456789abcdef0fedcba9876543210123456789abcdef0fedcba987654321'), // message
47
+ ];
36
48
  const args = [
37
49
  argsField,
38
50
  argsU8,
@@ -40,6 +52,8 @@ export async function bulkTest(
40
52
  /*expectedDeployer=*/ expectContractInstance.deployer,
41
53
  /*expectedClassId=*/ expectContractInstance.currentContractClassId,
42
54
  /*expectedInitializationHash=*/ expectContractInstance.initializationHash,
55
+ /*expectedImmutablesHash=*/ expectContractInstance.immutablesHash,
56
+ /*schnorrInputs=*/ schnorrInputs,
43
57
  /*skip_strictly_limited_side_effects=*/ false,
44
58
  ];
45
59
 
@@ -62,7 +76,7 @@ export async function bulkTest(
62
76
  {
63
77
  address: avmTestContract.address,
64
78
  fnName: 'assert_calldata_copy',
65
- args: [argsField.slice(3), /* with_selector: */ true],
79
+ args: [argsField.slice(0, 3), /* with_selector: */ true],
66
80
  },
67
81
  {
68
82
  address: avmTestContract.address,
@@ -100,7 +114,7 @@ export async function megaBulkTest(
100
114
  ) {
101
115
  const timer = new Timer();
102
116
 
103
- const deployer = AztecAddress.fromNumber(42);
117
+ const deployer = AztecAddress.fromNumberUnsafe(42);
104
118
  const avmTestContract = await tester.registerAndDeployContract(
105
119
  /*constructorArgs=*/ [],
106
120
  deployer,
@@ -123,6 +137,15 @@ export async function megaBulkTest(
123
137
  //const argsField7 = [15, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
124
138
  //const argsField8 = [17, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
125
139
  const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
140
+ const schnorrInputs = [
141
+ Fr.fromHexString('0x065812e335a97c2108ea8cf4ccfe2f9dd6b117a0714f5e18461575be93f61da6'), // pubkey.x
142
+ Fr.fromHexString('0x1a915003e8ec534f9a15d926a7ded478e178468ccc4f28e236e67450a55ac622'), // pubkey.y
143
+ Fr.fromHexString('0xf3bc3b7147acb9c621fd9f72dbf15ffa'), // sig_s.lo
144
+ Fr.fromHexString('0x08599f379f0301dfefdbd0272554454d'), // sig_s.hi
145
+ Fr.fromHexString('0x97065383ebbbd76620398792bd259bc2'), // sig_e.lo
146
+ Fr.fromHexString('0x2ceaee87f45b7a417f0ffb05451a8c92'), // sig_e.hi
147
+ Fr.fromHexString('0x0123456789abcdef0fedcba9876543210123456789abcdef0fedcba987654321'), // message
148
+ ];
126
149
  const genArgs = (argsField: Fr[]) => [
127
150
  argsField,
128
151
  argsU8,
@@ -130,6 +153,8 @@ export async function megaBulkTest(
130
153
  /*expectedDeployer=*/ expectContractInstance.deployer.toField(),
131
154
  /*expectedClassId=*/ expectContractInstance.currentContractClassId.toField(),
132
155
  /*expectedInitializationHash=*/ expectContractInstance.initializationHash.toField(),
156
+ /*expectedImmutablesHash=*/ expectContractInstance.immutablesHash.toField(),
157
+ /*schnorrInputs=*/ schnorrInputs,
133
158
  // Must skip strictly limited side effects (logs, messages) so we can spam the bulk test several times.
134
159
  /*skip_strictly_limited_side_effects=*/ true,
135
160
  ];
@@ -17,7 +17,7 @@ export async function deployCustomBytecode(
17
17
  bytecode: Buffer,
18
18
  tester: PublicTxSimulationTester,
19
19
  contractName: string = 'CustomBytecodeContract',
20
- deployer: AztecAddress = AztecAddress.fromNumber(42),
20
+ deployer: AztecAddress = AztecAddress.fromNumberUnsafe(42),
21
21
  ): Promise<ContractInstanceWithAddress> {
22
22
  const contractArtifact = emptyContractArtifact();
23
23
  contractArtifact.name = contractName;
@@ -75,7 +75,7 @@ export async function deployAndExecuteCustomBytecode(
75
75
  tester: PublicTxSimulationTester,
76
76
  txLabel: string = 'CustomBytecodeTest',
77
77
  contractName: string = 'CustomBytecodeContract',
78
- deployer: AztecAddress = AztecAddress.fromNumber(42),
78
+ deployer: AztecAddress = AztecAddress.fromNumberUnsafe(42),
79
79
  calldata: any[] = [],
80
80
  ): Promise<PublicTxResult> {
81
81
  const testContract = await deployCustomBytecode(bytecode, tester, contractName, deployer);
@@ -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;
@@ -137,10 +134,7 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
137
134
  teardownCallRequest,
138
135
  feePayer,
139
136
  /*gasUsedByPrivate*/ teardownCall
140
- ? new Gas(
141
- DEFAULT_TEARDOWN_DA_GAS_LIMIT + TX_DA_GAS_OVERHEAD,
142
- DEFAULT_TEARDOWN_L2_GAS_LIMIT + PUBLIC_TX_L2_GAS_OVERHEAD,
143
- )
137
+ ? new Gas(TEARDOWN_DA_GAS_LIMIT + TX_DA_GAS_OVERHEAD, TEARDOWN_L2_GAS_LIMIT + PUBLIC_TX_L2_GAS_OVERHEAD)
144
138
  : new Gas(TX_DA_GAS_OVERHEAD, PUBLIC_TX_L2_GAS_OVERHEAD),
145
139
  defaultGlobals(),
146
140
  gasLimits,
@@ -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[];
@@ -69,7 +70,7 @@ export async function createTxForPublicCalls(
69
70
  "Can't create public tx with no enqueued calls",
70
71
  );
71
72
  // use max limits
72
- gasLimits = 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);
73
74
 
74
75
  const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
75
76
 
@@ -128,9 +129,7 @@ export async function createTxForPublicCalls(
128
129
  }
129
130
 
130
131
  const maxFeesPerGas = feePayer.isZero() ? GasFees.empty() : new GasFees(10, 10);
131
- const teardownGasLimits = teardownCallRequest
132
- ? new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT)
133
- : Gas.empty();
132
+ const teardownGasLimits = teardownCallRequest ? new Gas(TEARDOWN_DA_GAS_LIMIT, TEARDOWN_L2_GAS_LIMIT) : Gas.empty();
134
133
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, maxFeesPerGas, GasFees.empty());
135
134
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
136
135
  const header = BlockHeader.empty({ globalVariables: globals });
@@ -164,7 +163,7 @@ export async function createTxForPrivateOnly(
164
163
  gasUsedByPrivate: Gas = new Gas(10, 10),
165
164
  ): Promise<Tx> {
166
165
  // use max limits
167
- 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);
168
167
 
169
168
  const forRollup = PartialPrivateTailPublicInputsForRollup.empty();
170
169
 
@@ -229,17 +228,15 @@ export async function addNewContractInstanceToTx(
229
228
  contractInstance: ContractInstanceWithAddress,
230
229
  skipNullifierInsertion = false,
231
230
  ) {
232
- // can't use publicKeys.toFields() because it includes isInfinite which
233
- // is not broadcast in such private logs
231
+ // Only ivpk_m is broadcast as a point (x, y); the other five keys are hashes.
234
232
  const publicKeysAsFields = [
235
- contractInstance.publicKeys.masterNullifierPublicKey.x,
236
- contractInstance.publicKeys.masterNullifierPublicKey.y,
237
- contractInstance.publicKeys.masterIncomingViewingPublicKey.x,
238
- contractInstance.publicKeys.masterIncomingViewingPublicKey.y,
239
- contractInstance.publicKeys.masterOutgoingViewingPublicKey.x,
240
- contractInstance.publicKeys.masterOutgoingViewingPublicKey.y,
241
- contractInstance.publicKeys.masterTaggingPublicKey.x,
242
- 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,
243
240
  ];
244
241
  const logFields = [
245
242
  CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG,
@@ -248,6 +245,7 @@ export async function addNewContractInstanceToTx(
248
245
  new Fr(contractInstance.salt),
249
246
  contractInstance.currentContractClassId,
250
247
  contractInstance.initializationHash,
248
+ contractInstance.immutablesHash,
251
249
  ...publicKeysAsFields,
252
250
  contractInstance.deployer.toField(),
253
251
  ];
@@ -257,7 +255,7 @@ export async function addNewContractInstanceToTx(
257
255
  );
258
256
 
259
257
  const contractAddressNullifier = await siloNullifier(
260
- AztecAddress.fromNumber(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS),
258
+ AztecAddress.fromNumberUnsafe(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS),
261
259
  contractInstance.address.toField(),
262
260
  );
263
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
  );
@@ -55,7 +55,8 @@ export class PublicContractsDB implements PublicContractsDBInterface {
55
55
  this.log = createLogger('simulator:contracts-data-source', bindings);
56
56
  }
57
57
 
58
- public addContracts(contractDeploymentData: ContractDeploymentData): 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
62
  this.addContractClassesFromEvents(
@@ -71,8 +72,16 @@ export class PublicContractsDB implements PublicContractsDBInterface {
71
72
 
72
73
  public addNewContracts(tx: Tx): void {
73
74
  const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
74
- this.addContracts(contractDeploymentData.getNonRevertibleContractDeploymentData());
75
- 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