@aztec/simulator 0.67.0 → 0.67.1-devnet

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 (91) hide show
  1. package/dest/acvm/oracle/oracle.d.ts +1 -1
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +3 -3
  4. package/dest/acvm/oracle/typed_oracle.d.ts +1 -1
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +3 -3
  7. package/dest/avm/avm_memory_types.d.ts +1 -1
  8. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  9. package/dest/avm/avm_memory_types.js +27 -27
  10. package/dest/avm/avm_simulator.d.ts.map +1 -1
  11. package/dest/avm/avm_simulator.js +6 -3
  12. package/dest/avm/avm_tree.d.ts +2 -1
  13. package/dest/avm/avm_tree.d.ts.map +1 -1
  14. package/dest/avm/avm_tree.js +6 -2
  15. package/dest/avm/fixtures/index.d.ts +2 -0
  16. package/dest/avm/fixtures/index.d.ts.map +1 -1
  17. package/dest/avm/fixtures/index.js +4 -4
  18. package/dest/avm/journal/journal.d.ts +16 -4
  19. package/dest/avm/journal/journal.d.ts.map +1 -1
  20. package/dest/avm/journal/journal.js +32 -14
  21. package/dest/avm/opcodes/conversion.d.ts +4 -4
  22. package/dest/avm/opcodes/conversion.d.ts.map +1 -1
  23. package/dest/avm/opcodes/conversion.js +22 -18
  24. package/dest/avm/test_utils.d.ts +1 -0
  25. package/dest/avm/test_utils.d.ts.map +1 -1
  26. package/dest/avm/test_utils.js +4 -1
  27. package/dest/client/client_execution_context.d.ts.map +1 -1
  28. package/dest/client/client_execution_context.js +2 -1
  29. package/dest/client/db_oracle.d.ts +7 -3
  30. package/dest/client/db_oracle.d.ts.map +1 -1
  31. package/dest/client/index.d.ts +1 -0
  32. package/dest/client/index.d.ts.map +1 -1
  33. package/dest/client/index.js +2 -1
  34. package/dest/client/view_data_oracle.d.ts +2 -2
  35. package/dest/client/view_data_oracle.d.ts.map +1 -1
  36. package/dest/client/view_data_oracle.js +5 -4
  37. package/dest/providers/acvm_wasm.js +2 -2
  38. package/dest/providers/index.d.ts +0 -1
  39. package/dest/providers/index.d.ts.map +1 -1
  40. package/dest/providers/index.js +1 -2
  41. package/dest/public/enqueued_call_side_effect_trace.d.ts +4 -3
  42. package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
  43. package/dest/public/enqueued_call_side_effect_trace.js +6 -5
  44. package/dest/public/execution.d.ts +2 -2
  45. package/dest/public/execution.d.ts.map +1 -1
  46. package/dest/public/execution.js +1 -1
  47. package/dest/public/fee_payment.d.ts.map +1 -1
  48. package/dest/public/fee_payment.js +4 -3
  49. package/dest/public/fixtures/index.js +3 -3
  50. package/dest/public/public_db_sources.d.ts.map +1 -1
  51. package/dest/public/public_db_sources.js +7 -6
  52. package/dest/public/public_processor.d.ts +5 -4
  53. package/dest/public/public_processor.d.ts.map +1 -1
  54. package/dest/public/public_processor.js +65 -61
  55. package/dest/public/public_processor_metrics.d.ts +1 -1
  56. package/dest/public/public_processor_metrics.d.ts.map +1 -1
  57. package/dest/public/public_tx_context.d.ts.map +1 -1
  58. package/dest/public/public_tx_context.js +32 -20
  59. package/dest/public/public_tx_simulator.d.ts.map +1 -1
  60. package/dest/public/public_tx_simulator.js +12 -1
  61. package/dest/public/side_effect_trace_interface.d.ts +2 -1
  62. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  63. package/dest/public/transitional_adapters.d.ts.map +1 -1
  64. package/dest/public/transitional_adapters.js +2 -35
  65. package/package.json +9 -9
  66. package/src/acvm/oracle/oracle.ts +2 -2
  67. package/src/acvm/oracle/typed_oracle.ts +2 -2
  68. package/src/avm/avm_memory_types.ts +29 -27
  69. package/src/avm/avm_simulator.ts +4 -2
  70. package/src/avm/avm_tree.ts +6 -1
  71. package/src/avm/fixtures/index.ts +4 -2
  72. package/src/avm/journal/journal.ts +41 -8
  73. package/src/avm/opcodes/conversion.ts +21 -16
  74. package/src/avm/test_utils.ts +4 -0
  75. package/src/client/client_execution_context.ts +2 -0
  76. package/src/client/db_oracle.ts +8 -3
  77. package/src/client/index.ts +1 -0
  78. package/src/client/view_data_oracle.ts +6 -3
  79. package/src/providers/acvm_wasm.ts +2 -2
  80. package/src/providers/index.ts +0 -1
  81. package/src/public/enqueued_call_side_effect_trace.ts +8 -12
  82. package/src/public/execution.ts +1 -2
  83. package/src/public/fee_payment.ts +3 -2
  84. package/src/public/fixtures/index.ts +2 -2
  85. package/src/public/public_db_sources.ts +6 -5
  86. package/src/public/public_processor.ts +83 -78
  87. package/src/public/public_processor_metrics.ts +1 -1
  88. package/src/public/public_tx_context.ts +48 -21
  89. package/src/public/public_tx_simulator.ts +11 -0
  90. package/src/public/side_effect_trace_interface.ts +2 -1
  91. package/src/public/transitional_adapters.ts +0 -51
@@ -1,5 +1,4 @@
1
- import { Fr, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PrivateToAvmAccumulatedData, PrivateToAvmAccumulatedDataArrayLengths, PublicCallRequest, PublicDataWrite, TreeSnapshots, countAccumulatedItems, mergeAccumulatedData, } from '@aztec/circuits.js';
2
- import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
1
+ import { Fr, MAX_L2_TO_L1_MSGS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PrivateToAvmAccumulatedData, PrivateToAvmAccumulatedDataArrayLengths, PublicCallRequest, PublicDataWrite, TreeSnapshots, countAccumulatedItems, mergeAccumulatedData, } from '@aztec/circuits.js';
3
2
  import { padArrayEnd } from '@aztec/foundation/collection';
4
3
  import { assertLength } from '@aztec/foundation/serialize';
5
4
  export function generateAvmCircuitPublicInputs(trace, globalVariables, startStateReference, startGasUsed, gasSettings, feePayer, setupCallRequests, appLogicCallRequests, teardownCallRequests, nonRevertibleAccumulatedDataFromPrivate, revertibleAccumulatedDataFromPrivate, endTreeSnapshots, endGasUsed, transactionFee, revertCode) {
@@ -12,38 +11,6 @@ export function generateAvmCircuitPublicInputs(trace, globalVariables, startStat
12
11
  avmCircuitPublicInputs.previousRevertibleAccumulatedDataArrayLengths = getArrayLengths(revertibleAccumulatedDataFromPrivate);
13
12
  avmCircuitPublicInputs.previousNonRevertibleAccumulatedData = convertAccumulatedData(nonRevertibleAccumulatedDataFromPrivate);
14
13
  avmCircuitPublicInputs.previousRevertibleAccumulatedData = convertAccumulatedData(revertibleAccumulatedDataFromPrivate);
15
- const txHash = avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.nullifiers[0];
16
- // Add nonces to revertible note hashes from private. These don't have nonces since we don't know
17
- // the final position in the tx until the AVM has executed.
18
- // TODO: Use the final position in the tx
19
- for (let revertibleIndex = 0; revertibleIndex < avmCircuitPublicInputs.previousRevertibleAccumulatedData.noteHashes.length; revertibleIndex++) {
20
- const noteHash = avmCircuitPublicInputs.previousRevertibleAccumulatedData.noteHashes[revertibleIndex];
21
- if (noteHash.isZero()) {
22
- continue;
23
- }
24
- const indexInTx = revertibleIndex + avmCircuitPublicInputs.previousNonRevertibleAccumulatedDataArrayLengths.noteHashes;
25
- const nonce = computeNoteHashNonce(txHash, indexInTx);
26
- const uniqueNoteHash = computeUniqueNoteHash(nonce, noteHash);
27
- avmCircuitPublicInputs.previousRevertibleAccumulatedData.noteHashes[revertibleIndex] = uniqueNoteHash;
28
- }
29
- // merge all revertible & non-revertible side effects into output accumulated data
30
- const noteHashesFromPrivate = revertCode.isOK()
31
- ? mergeAccumulatedData(avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.noteHashes, avmCircuitPublicInputs.previousRevertibleAccumulatedData.noteHashes)
32
- : avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.noteHashes;
33
- avmCircuitPublicInputs.accumulatedData.noteHashes = assertLength(mergeAccumulatedData(noteHashesFromPrivate, avmCircuitPublicInputs.accumulatedData.noteHashes), MAX_NOTE_HASHES_PER_TX);
34
- // Silo and add nonces for note hashes emitted by the AVM
35
- const scopedNoteHashesFromPublic = trace.getSideEffects().noteHashes;
36
- for (let i = 0; i < scopedNoteHashesFromPublic.length; i++) {
37
- const scopedNoteHash = scopedNoteHashesFromPublic[i];
38
- const noteHash = scopedNoteHash.value;
39
- if (!noteHash.isZero()) {
40
- const noteHashIndexInTx = i + countAccumulatedItems(noteHashesFromPrivate);
41
- const nonce = computeNoteHashNonce(txHash, noteHashIndexInTx);
42
- const siloedNoteHash = siloNoteHash(scopedNoteHash.contractAddress, noteHash);
43
- const uniqueNoteHash = computeUniqueNoteHash(nonce, siloedNoteHash);
44
- avmCircuitPublicInputs.accumulatedData.noteHashes[noteHashIndexInTx] = uniqueNoteHash;
45
- }
46
- }
47
14
  const msgsFromPrivate = revertCode.isOK()
48
15
  ? mergeAccumulatedData(avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.l2ToL1Msgs, avmCircuitPublicInputs.previousRevertibleAccumulatedData.l2ToL1Msgs)
49
16
  : avmCircuitPublicInputs.previousNonRevertibleAccumulatedData.l2ToL1Msgs;
@@ -59,4 +26,4 @@ export function generateAvmCircuitPublicInputs(trace, globalVariables, startStat
59
26
  //console.log(`AvmCircuitPublicInputs:\n${inspect(avmCircuitPublicInputs)}`);
60
27
  return avmCircuitPublicInputs;
61
28
  }
62
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNpdGlvbmFsX2FkYXB0ZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3B1YmxpYy90cmFuc2l0aW9uYWxfYWRhcHRlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUdMLEVBQUUsRUFJRix3QkFBd0IsRUFDeEIsc0JBQXNCLEVBQ3RCLDRDQUE0Q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QUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsSUFBSSxFQUFFLEtBQUssQ0FBQyxFQUFFLEVBQUUsQ0FBQyxJQUFJLGVBQWUsQ0FBQyxJQUFJLEVBQUUsQ0FBQyxJQUFJLENBQUMsRUFBRSxLQUFLLENBQUMsQ0FBQyxFQUMvRyxlQUFlLENBQUMsS0FBSyxFQUFFLEVBQ3ZCLDRDQUE0QyxDQUM3QyxDQUFDO0lBQ0YsNkVBQTZFO0lBQzdFLE9BQU8sc0JBQXNCLENBQUM7QUFDaEMsQ0FBQyJ9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/simulator",
3
- "version": "0.67.0",
3
+ "version": "0.67.1-devnet",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -66,14 +66,14 @@
66
66
  ]
67
67
  },
68
68
  "dependencies": {
69
- "@aztec/circuit-types": "0.67.0",
70
- "@aztec/circuits.js": "0.67.0",
71
- "@aztec/foundation": "0.67.0",
72
- "@aztec/noir-protocol-circuits-types": "0.67.0",
73
- "@aztec/protocol-contracts": "0.67.0",
74
- "@aztec/telemetry-client": "0.67.0",
75
- "@aztec/types": "0.67.0",
76
- "@aztec/world-state": "0.67.0",
69
+ "@aztec/circuit-types": "0.67.1-devnet",
70
+ "@aztec/circuits.js": "0.67.1-devnet",
71
+ "@aztec/foundation": "0.67.1-devnet",
72
+ "@aztec/noir-protocol-circuits-types": "0.67.1-devnet",
73
+ "@aztec/protocol-contracts": "0.67.1-devnet",
74
+ "@aztec/telemetry-client": "0.67.1-devnet",
75
+ "@aztec/types": "0.67.1-devnet",
76
+ "@aztec/world-state": "0.67.1-devnet",
77
77
  "@noir-lang/acvm_js": "portal:../../noir/packages/acvm_js",
78
78
  "@noir-lang/noirc_abi": "portal:../../noir/packages/noirc_abi",
79
79
  "@noir-lang/types": "portal:../../noir/packages/types",
@@ -375,8 +375,8 @@ export class Oracle {
375
375
  this.typedOracle.notifySetMinRevertibleSideEffectCounter(frToNumber(fromACVMField(minRevertibleSideEffectCounter)));
376
376
  }
377
377
 
378
- async getAppTaggingSecretAsSender([sender]: ACVMField[], [recipient]: ACVMField[]): Promise<ACVMField[]> {
379
- const taggingSecret = await this.typedOracle.getAppTaggingSecretAsSender(
378
+ async getIndexedTaggingSecretAsSender([sender]: ACVMField[], [recipient]: ACVMField[]): Promise<ACVMField[]> {
379
+ const taggingSecret = await this.typedOracle.getIndexedTaggingSecretAsSender(
380
380
  AztecAddress.fromString(sender),
381
381
  AztecAddress.fromString(recipient),
382
382
  );
@@ -237,8 +237,8 @@ export abstract class TypedOracle {
237
237
  throw new OracleMethodNotAvailableError('debugLog');
238
238
  }
239
239
 
240
- getAppTaggingSecretAsSender(_sender: AztecAddress, _recipient: AztecAddress): Promise<IndexedTaggingSecret> {
241
- throw new OracleMethodNotAvailableError('getAppTaggingSecretAsSender');
240
+ getIndexedTaggingSecretAsSender(_sender: AztecAddress, _recipient: AztecAddress): Promise<IndexedTaggingSecret> {
241
+ throw new OracleMethodNotAvailableError('getIndexedTaggingSecretAsSender');
242
242
  }
243
243
 
244
244
  incrementAppTaggingSecretIndexAsSender(_sender: AztecAddress, _recipient: AztecAddress): Promise<void> {
@@ -232,13 +232,14 @@ export class TaggedMemory implements TaggedMemoryInterface {
232
232
  // Whether to track and validate memory accesses for each instruction.
233
233
  static readonly TRACK_MEMORY_ACCESSES = process.env.NODE_ENV === 'test';
234
234
 
235
- // FIXME: memory should be 2^32, but TS max array size is: 2^32 - 1
236
- static readonly MAX_MEMORY_SIZE = Number((1n << 32n) - 1n);
237
- private _mem: MemoryValue[];
235
+ // Memory is modelled by a map with key type being number.
236
+ // We however restrict the keys to be non-negative integers smaller than
237
+ // MAX_MEMORY_SIZE.
238
+ static readonly MAX_MEMORY_SIZE = Number(1n << 32n);
239
+ private _mem: Map<number, MemoryValue>;
238
240
 
239
241
  constructor() {
240
- // We do not initialize memory size here because otherwise tests blow up when diffing.
241
- this._mem = [];
242
+ this._mem = new Map<number, MemoryValue>();
242
243
  }
243
244
 
244
245
  public getMaxMemorySize(): number {
@@ -257,8 +258,9 @@ export class TaggedMemory implements TaggedMemoryInterface {
257
258
  }
258
259
 
259
260
  public getAs<T>(offset: number): T {
261
+ assert(Number.isInteger(offset));
260
262
  assert(offset < TaggedMemory.MAX_MEMORY_SIZE);
261
- const word = this._mem[offset];
263
+ const word = this._mem.get(offset);
262
264
  TaggedMemory.log.trace(`get(${offset}) = ${word}`);
263
265
  if (word === undefined) {
264
266
  TaggedMemory.log.debug(`WARNING: Memory at offset ${offset} is undefined!`);
@@ -268,46 +270,46 @@ export class TaggedMemory implements TaggedMemoryInterface {
268
270
  }
269
271
 
270
272
  public getSlice(offset: number, size: number): MemoryValue[] {
273
+ assert(Number.isInteger(offset) && Number.isInteger(size));
271
274
  assert(offset + size <= TaggedMemory.MAX_MEMORY_SIZE);
272
- const value = this._mem.slice(offset, offset + size);
273
- TaggedMemory.log.trace(`getSlice(${offset}, ${size}) = ${value}`);
274
- for (let i = 0; i < value.length; i++) {
275
- if (value[i] === undefined) {
276
- value[i] = new Field(0);
277
- }
275
+ const slice = new Array<MemoryValue>(size);
276
+
277
+ for (let i = 0; i < size; i++) {
278
+ slice[i] = this._mem.get(offset + i) ?? new Field(0);
278
279
  }
279
- assert(value.length === size, `Expected slice of size ${size}, got ${value.length}.`);
280
- return value;
280
+
281
+ TaggedMemory.log.trace(`getSlice(${offset}, ${size}) = ${slice}`);
282
+ return slice;
281
283
  }
282
284
 
283
285
  public getSliceAs<T>(offset: number, size: number): T[] {
284
- assert(offset + size <= TaggedMemory.MAX_MEMORY_SIZE);
285
286
  return this.getSlice(offset, size) as T[];
286
287
  }
287
288
 
288
289
  public getSliceTags(offset: number, size: number): TypeTag[] {
289
- assert(offset + size <= TaggedMemory.MAX_MEMORY_SIZE);
290
- return this._mem.slice(offset, offset + size).map(TaggedMemory.getTag);
290
+ return this.getSlice(offset, size).map(TaggedMemory.getTag);
291
291
  }
292
292
 
293
293
  public set(offset: number, v: MemoryValue) {
294
+ assert(Number.isInteger(offset));
294
295
  assert(offset < TaggedMemory.MAX_MEMORY_SIZE);
295
- this._mem[offset] = v;
296
+ this._mem.set(offset, v);
296
297
  TaggedMemory.log.trace(`set(${offset}, ${v})`);
297
298
  }
298
299
 
299
- public setSlice(offset: number, vs: MemoryValue[]) {
300
- assert(offset + vs.length <= TaggedMemory.MAX_MEMORY_SIZE);
301
- // We may need to extend the memory size, otherwise splice doesn't insert.
302
- if (offset + vs.length > this._mem.length) {
303
- this._mem.length = offset + vs.length;
304
- }
305
- this._mem.splice(offset, vs.length, ...vs);
306
- TaggedMemory.log.trace(`setSlice(${offset}, ${vs})`);
300
+ public setSlice(offset: number, slice: MemoryValue[]) {
301
+ assert(Number.isInteger(offset));
302
+ assert(offset + slice.length <= TaggedMemory.MAX_MEMORY_SIZE);
303
+ slice.forEach((element, idx) => {
304
+ this._mem.set(offset + idx, element);
305
+ });
306
+ TaggedMemory.log.trace(`setSlice(${offset}, ${slice})`);
307
307
  }
308
308
 
309
309
  public getTag(offset: number): TypeTag {
310
- return TaggedMemory.getTag(this._mem[offset]);
310
+ assert(Number.isInteger(offset));
311
+ assert(offset < TaggedMemory.MAX_MEMORY_SIZE);
312
+ return TaggedMemory.getTag(this._mem.get(offset));
311
313
  }
312
314
 
313
315
  /**
@@ -114,7 +114,7 @@ export class AvmSimulator {
114
114
  return new AvmContractCallResult(
115
115
  /*reverted=*/ true,
116
116
  /*output=*/ [],
117
- /*gasLeft=*/ { l2Gas: 0, daGas: 0 },
117
+ /*gasLeft=*/ { l2Gas: 0, daGas: 0 }, // consumes all allocated gas
118
118
  revertReason,
119
119
  );
120
120
  }
@@ -195,8 +195,10 @@ export class AvmSimulator {
195
195
  }
196
196
 
197
197
  const revertReason = await revertReasonFromExceptionalHalt(err, this.context);
198
+ // Exceptional halts consume all allocated gas
199
+ const noGasLeft = { l2Gas: 0, daGas: 0 };
198
200
  // Note: "exceptional halts" cannot return data, hence [].
199
- const results = new AvmContractCallResult(/*reverted=*/ true, /*output=*/ [], machineState.gasLeft, revertReason);
201
+ const results = new AvmContractCallResult(/*reverted=*/ true, /*output=*/ [], noGasLeft, revertReason);
200
202
  this.log.debug(`Context execution results: ${results.toString()}`);
201
203
 
202
204
  this.tallyPrintFunction();
@@ -1,5 +1,5 @@
1
1
  import { type IndexedTreeId, MerkleTreeId, type MerkleTreeReadOperations, getTreeHeight } from '@aztec/circuit-types';
2
- import { NullifierLeafPreimage, PublicDataTreeLeafPreimage } from '@aztec/circuits.js';
2
+ import { AppendOnlyTreeSnapshot, NullifierLeafPreimage, PublicDataTreeLeafPreimage } from '@aztec/circuits.js';
3
3
  import { poseidon2Hash } from '@aztec/foundation/crypto';
4
4
  import { Fr } from '@aztec/foundation/fields';
5
5
  import { type IndexedTreeLeafPreimage, type TreeLeafPreimage } from '@aztec/foundation/trees';
@@ -550,6 +550,11 @@ export class AvmEphemeralForest {
550
550
  const input = preimage.toHashInputs().map(x => Fr.fromBuffer(x));
551
551
  return poseidon2Hash(input);
552
552
  }
553
+
554
+ getTreeSnapshot(id: MerkleTreeId): AppendOnlyTreeSnapshot {
555
+ const tree = this.treeMap.get(id)!;
556
+ return new AppendOnlyTreeSnapshot(tree.getRoot(), Number(tree.leafCount));
557
+ }
553
558
  }
554
559
 
555
560
  /****************************************************/
@@ -1,10 +1,10 @@
1
- import { isNoirCallStackUnresolved } from '@aztec/circuit-types';
1
+ import { TxHash, isNoirCallStackUnresolved } from '@aztec/circuit-types';
2
2
  import { GasFees, GlobalVariables, MAX_L2_GAS_PER_TX_PUBLIC_PORTION } from '@aztec/circuits.js';
3
3
  import { type FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
4
4
  import { AztecAddress } from '@aztec/foundation/aztec-address';
5
5
  import { EthAddress } from '@aztec/foundation/eth-address';
6
6
  import { Fr } from '@aztec/foundation/fields';
7
- import { AvmTestContractArtifact } from '@aztec/noir-contracts.js';
7
+ import { AvmTestContractArtifact } from '@aztec/noir-contracts.js/AvmTest';
8
8
 
9
9
  import { strict as assert } from 'assert';
10
10
  import { mock } from 'jest-mock-extended';
@@ -45,6 +45,7 @@ export function initPersistableStateManager(overrides?: {
45
45
  nullifiers?: NullifierManager;
46
46
  doMerkleOperations?: boolean;
47
47
  merkleTrees?: AvmEphemeralForest;
48
+ txHash?: TxHash;
48
49
  }): AvmPersistableStateManager {
49
50
  const worldStateDB = overrides?.worldStateDB || mock<WorldStateDB>();
50
51
  return new AvmPersistableStateManager(
@@ -54,6 +55,7 @@ export function initPersistableStateManager(overrides?: {
54
55
  overrides?.nullifiers || new NullifierManager(worldStateDB),
55
56
  overrides?.doMerkleOperations || false,
56
57
  overrides?.merkleTrees || mock<AvmEphemeralForest>(),
58
+ overrides?.txHash || new TxHash(new Fr(27).toBuffer()),
57
59
  );
58
60
  }
59
61
 
@@ -1,4 +1,4 @@
1
- import { MerkleTreeId } from '@aztec/circuit-types';
1
+ import { MerkleTreeId, type TxHash } from '@aztec/circuit-types';
2
2
  import {
3
3
  AztecAddress,
4
4
  CANONICAL_AUTH_REGISTRY_ADDRESS,
@@ -12,7 +12,13 @@ import {
12
12
  ROUTER_ADDRESS,
13
13
  SerializableContractInstance,
14
14
  } from '@aztec/circuits.js';
15
- import { computePublicDataTreeLeafSlot, siloNoteHash, siloNullifier } from '@aztec/circuits.js/hash';
15
+ import {
16
+ computeNoteHashNonce,
17
+ computePublicDataTreeLeafSlot,
18
+ computeUniqueNoteHash,
19
+ siloNoteHash,
20
+ siloNullifier,
21
+ } from '@aztec/circuits.js/hash';
16
22
  import { Fr } from '@aztec/foundation/fields';
17
23
  import { jsonStringify } from '@aztec/foundation/json-rpc';
18
24
  import { createLogger } from '@aztec/foundation/log';
@@ -55,6 +61,7 @@ export class AvmPersistableStateManager {
55
61
  private readonly doMerkleOperations: boolean = false,
56
62
  /** Ephmeral forest for merkle tree operations */
57
63
  public merkleTrees: AvmEphemeralForest,
64
+ public readonly txHash: TxHash,
58
65
  ) {}
59
66
 
60
67
  /**
@@ -65,6 +72,7 @@ export class AvmPersistableStateManager {
65
72
  trace: PublicSideEffectTraceInterface,
66
73
  pendingSiloedNullifiers: Fr[],
67
74
  doMerkleOperations: boolean = false,
75
+ txHash: TxHash,
68
76
  ) {
69
77
  const parentNullifiers = NullifierManager.newWithPendingSiloedNullifiers(worldStateDB, pendingSiloedNullifiers);
70
78
  const ephemeralForest = await AvmEphemeralForest.create(worldStateDB.getMerkleInterface());
@@ -75,6 +83,7 @@ export class AvmPersistableStateManager {
75
83
  /*nullifiers=*/ parentNullifiers.fork(),
76
84
  doMerkleOperations,
77
85
  ephemeralForest,
86
+ txHash,
78
87
  );
79
88
  }
80
89
 
@@ -85,6 +94,7 @@ export class AvmPersistableStateManager {
85
94
  worldStateDB: WorldStateDB,
86
95
  trace: PublicSideEffectTraceInterface,
87
96
  doMerkleOperations: boolean = false,
97
+ txHash: TxHash,
88
98
  ) {
89
99
  const ephemeralForest = await AvmEphemeralForest.create(worldStateDB.getMerkleInterface());
90
100
  return new AvmPersistableStateManager(
@@ -94,6 +104,7 @@ export class AvmPersistableStateManager {
94
104
  /*nullifiers=*/ new NullifierManager(worldStateDB),
95
105
  /*doMerkleOperations=*/ doMerkleOperations,
96
106
  ephemeralForest,
107
+ txHash,
97
108
  );
98
109
  }
99
110
 
@@ -108,6 +119,7 @@ export class AvmPersistableStateManager {
108
119
  this.nullifiers.fork(),
109
120
  this.doMerkleOperations,
110
121
  this.merkleTrees.fork(),
122
+ this.txHash,
111
123
  );
112
124
  }
113
125
 
@@ -290,20 +302,41 @@ export class AvmPersistableStateManager {
290
302
  }
291
303
 
292
304
  /**
293
- * Write a note hash, trace the write.
305
+ * Write a raw note hash, silo it and make it unique, then trace the write.
294
306
  * @param noteHash - the unsiloed note hash to write
295
307
  */
296
308
  public writeNoteHash(contractAddress: AztecAddress, noteHash: Fr): void {
297
- this.log.debug(`noteHashes(${contractAddress}) += @${noteHash}.`);
309
+ const siloedNoteHash = siloNoteHash(contractAddress, noteHash);
310
+
311
+ this.writeSiloedNoteHash(siloedNoteHash);
312
+ }
313
+
314
+ /**
315
+ * Write a note hash, make it unique, trace the write.
316
+ * @param noteHash - the non unique note hash to write
317
+ */
318
+ public writeSiloedNoteHash(noteHash: Fr): void {
319
+ const txHash = Fr.fromBuffer(this.txHash.toBuffer());
320
+ const nonce = computeNoteHashNonce(txHash, this.trace.getNoteHashCount());
321
+ const uniqueNoteHash = computeUniqueNoteHash(nonce, noteHash);
322
+
323
+ this.writeUniqueNoteHash(uniqueNoteHash);
324
+ }
325
+
326
+ /**
327
+ * Write a note hash, trace the write.
328
+ * @param noteHash - the siloed unique hash to write
329
+ */
330
+ public writeUniqueNoteHash(noteHash: Fr): void {
331
+ this.log.debug(`noteHashes += @${noteHash}.`);
298
332
 
299
333
  if (this.doMerkleOperations) {
300
334
  // Should write a helper for this
301
335
  const leafIndex = new Fr(this.merkleTrees.treeMap.get(MerkleTreeId.NOTE_HASH_TREE)!.leafCount);
302
- const siloedNoteHash = siloNoteHash(contractAddress, noteHash);
303
- const insertionPath = this.merkleTrees.appendNoteHash(siloedNoteHash);
304
- this.trace.traceNewNoteHash(contractAddress, noteHash, leafIndex, insertionPath);
336
+ const insertionPath = this.merkleTrees.appendNoteHash(noteHash);
337
+ this.trace.traceNewNoteHash(noteHash, leafIndex, insertionPath);
305
338
  } else {
306
- this.trace.traceNewNoteHash(contractAddress, noteHash);
339
+ this.trace.traceNewNoteHash(noteHash);
307
340
  }
308
341
  }
309
342
 
@@ -12,57 +12,62 @@ export class ToRadixBE extends Instruction {
12
12
  // Informs (de)serialization. See Instruction.deserialize.
13
13
  static readonly wireFormat: OperandType[] = [
14
14
  OperandType.UINT8, // Opcode
15
- OperandType.UINT8, // Indirect
15
+ OperandType.UINT16, // Indirect
16
16
  OperandType.UINT16, // src memory address
17
- OperandType.UINT16, // dst memory address
18
17
  OperandType.UINT16, // radix memory address
19
- OperandType.UINT16, // number of limbs (Immediate)
20
- OperandType.UINT8, // output is in "bits" mode (Immediate - Uint1 still takes up a whole byte)
18
+ OperandType.UINT16, // number of limbs address
19
+ OperandType.UINT16, // output is in "bits" mode memory address (boolean/Uint1 is stored)
20
+ OperandType.UINT16, // dst memory address
21
21
  ];
22
22
 
23
23
  constructor(
24
24
  private indirect: number,
25
25
  private srcOffset: number,
26
- private dstOffset: number,
27
26
  private radixOffset: number,
28
- private numLimbs: number,
29
- private outputBits: number, // effectively a bool
27
+ private numLimbsOffset: number,
28
+ private outputBitsOffset: number,
29
+ private dstOffset: number,
30
30
  ) {
31
31
  super();
32
32
  }
33
33
 
34
34
  public async execute(context: AvmContext): Promise<void> {
35
35
  const memory = context.machineState.memory.track(this.type);
36
- const operands = [this.srcOffset, this.dstOffset, this.radixOffset];
36
+ const operands = [this.srcOffset, this.radixOffset, this.numLimbsOffset, this.outputBitsOffset, this.dstOffset];
37
37
  const addressing = Addressing.fromWire(this.indirect, operands.length);
38
- const [srcOffset, dstOffset, radixOffset] = addressing.resolve(operands, memory);
39
- context.machineState.consumeGas(this.gasCost(this.numLimbs));
38
+ const [srcOffset, radixOffset, numLimbsOffset, outputBitsOffset, dstOffset] = addressing.resolve(operands, memory);
40
39
 
41
40
  // The radix gadget only takes in a Field
42
41
  memory.checkTag(TypeTag.FIELD, srcOffset);
43
42
  memory.checkTag(TypeTag.UINT32, radixOffset);
43
+ memory.checkTag(TypeTag.UINT32, numLimbsOffset);
44
+ memory.checkTag(TypeTag.UINT1, outputBitsOffset);
45
+
46
+ const numLimbs = memory.get(numLimbsOffset).toNumber();
47
+ context.machineState.consumeGas(this.gasCost(numLimbs));
48
+ const outputBits = memory.get(outputBitsOffset).toNumber();
44
49
 
45
50
  let value: bigint = memory.get(srcOffset).toBigInt();
46
51
  const radix: bigint = memory.get(radixOffset).toBigInt();
47
- if (this.numLimbs < 1) {
48
- throw new InstructionExecutionError(`ToRadixBE instruction's numLimbs should be > 0 (was ${this.numLimbs})`);
52
+ if (numLimbs < 1) {
53
+ throw new InstructionExecutionError(`ToRadixBE instruction's numLimbs should be > 0 (was ${numLimbs})`);
49
54
  }
50
55
  if (radix > 256) {
51
56
  throw new InstructionExecutionError(`ToRadixBE instruction's radix should be <= 256 (was ${radix})`);
52
57
  }
53
58
  const radixBN: bigint = BigInt(radix);
54
- const limbArray = new Array(this.numLimbs);
59
+ const limbArray = new Array(numLimbs);
55
60
 
56
- for (let i = this.numLimbs - 1; i >= 0; i--) {
61
+ for (let i = numLimbs - 1; i >= 0; i--) {
57
62
  const limb = value % radixBN;
58
63
  limbArray[i] = limb;
59
64
  value /= radixBN;
60
65
  }
61
66
 
62
- const outputType = this.outputBits != 0 ? Uint1 : Uint8;
67
+ const outputType = outputBits != 0 ? Uint1 : Uint8;
63
68
  const res = limbArray.map(byte => new outputType(byte));
64
69
  memory.setSlice(dstOffset, res);
65
70
 
66
- memory.assert({ reads: 2, writes: this.numLimbs, addressing });
71
+ memory.assert({ reads: 4, writes: numLimbs, addressing });
67
72
  }
68
73
  }
@@ -28,6 +28,10 @@ export function mockStorageRead(worldStateDB: WorldStateDB, value: Fr) {
28
28
  (worldStateDB as jest.Mocked<WorldStateDB>).storageRead.mockResolvedValue(value);
29
29
  }
30
30
 
31
+ export function mockNoteHashCount(mockedTrace: PublicSideEffectTraceInterface, count: number) {
32
+ (mockedTrace as jest.Mocked<PublicSideEffectTraceInterface>).getNoteHashCount.mockReturnValue(count);
33
+ }
34
+
31
35
  export function mockStorageReadWithMap(worldStateDB: WorldStateDB, mockedStorage: Map<bigint, Fr>) {
32
36
  (worldStateDB as jest.Mocked<WorldStateDB>).storageRead.mockImplementation((_address, slot) =>
33
37
  Promise.resolve(mockedStorage.get(slot.toBigInt()) ?? Fr.ZERO),
@@ -565,5 +565,7 @@ export class ClientExecutionContext extends ViewDataOracle {
565
565
  for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) {
566
566
  await this.db.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient));
567
567
  }
568
+
569
+ await this.db.removeNullifiedNotes(this.contractAddress);
568
570
  }
569
571
  }
@@ -198,21 +198,21 @@ export interface DBOracle extends CommitmentsDB {
198
198
  getBlockNumber(): Promise<number>;
199
199
 
200
200
  /**
201
- * Returns the tagging secret for a given sender and recipient pair. For this to work, the ivpsk_m of the sender must be known.
201
+ * Returns the tagging secret for a given sender and recipient pair. For this to work, the ivsk_m of the sender must be known.
202
202
  * Includes the next index to be used used for tagging with this secret.
203
203
  * @param contractAddress - The contract address to silo the secret for
204
204
  * @param sender - The address sending the note
205
205
  * @param recipient - The address receiving the note
206
206
  * @returns A tagging secret that can be used to tag notes.
207
207
  */
208
- getAppTaggingSecretAsSender(
208
+ getIndexedTaggingSecretAsSender(
209
209
  contractAddress: AztecAddress,
210
210
  sender: AztecAddress,
211
211
  recipient: AztecAddress,
212
212
  ): Promise<IndexedTaggingSecret>;
213
213
 
214
214
  /**
215
- * Increments the tagging secret for a given sender and recipient pair. For this to work, the ivpsk_m of the sender must be known.
215
+ * Increments the tagging secret for a given sender and recipient pair. For this to work, the ivsk_m of the sender must be known.
216
216
  * @param contractAddress - The contract address to silo the secret for
217
217
  * @param sender - The address sending the note
218
218
  * @param recipient - The address receiving the note
@@ -242,4 +242,9 @@ export interface DBOracle extends CommitmentsDB {
242
242
  * @param recipient - The recipient of the logs.
243
243
  */
244
244
  processTaggedLogs(logs: TxScopedL2Log[], recipient: AztecAddress): Promise<void>;
245
+
246
+ /**
247
+ * Removes all of a contract's notes that have been nullified from the note database.
248
+ */
249
+ removeNullifiedNotes(contractAddress: AztecAddress): Promise<void>;
245
250
  }
@@ -3,3 +3,4 @@ export * from './db_oracle.js';
3
3
  export * from './pick_notes.js';
4
4
  export * from './execution_note_cache.js';
5
5
  export { extractPrivateCircuitPublicInputs } from './private_execution.js';
6
+ export { WASMSimulator } from '../providers/acvm_wasm.js';
@@ -296,16 +296,16 @@ export class ViewDataOracle extends TypedOracle {
296
296
  /**
297
297
  * Returns the tagging secret for a given sender and recipient pair, siloed to the current contract address.
298
298
  * Includes the next index to be used used for tagging with this secret.
299
- * For this to work, the ivpsk_m of the sender must be known.
299
+ * For this to work, the ivsk_m of the sender must be known.
300
300
  * @param sender - The address sending the note
301
301
  * @param recipient - The address receiving the note
302
302
  * @returns A tagging secret that can be used to tag notes.
303
303
  */
304
- public override async getAppTaggingSecretAsSender(
304
+ public override async getIndexedTaggingSecretAsSender(
305
305
  sender: AztecAddress,
306
306
  recipient: AztecAddress,
307
307
  ): Promise<IndexedTaggingSecret> {
308
- return await this.db.getAppTaggingSecretAsSender(this.contractAddress, sender, recipient);
308
+ return await this.db.getIndexedTaggingSecretAsSender(this.contractAddress, sender, recipient);
309
309
  }
310
310
 
311
311
  public override async syncNotes() {
@@ -314,8 +314,11 @@ export class ViewDataOracle extends TypedOracle {
314
314
  await this.aztecNode.getBlockNumber(),
315
315
  this.scopes,
316
316
  );
317
+
317
318
  for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) {
318
319
  await this.db.processTaggedLogs(taggedLogs, AztecAddress.fromString(recipient));
319
320
  }
321
+
322
+ await this.db.removeNullifiedNotes(this.contractAddress);
320
323
  }
321
324
  }
@@ -1,4 +1,4 @@
1
- import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types';
1
+ import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types/client';
2
2
  import { type NoirCompiledCircuit } from '@aztec/types/noir';
3
3
 
4
4
  import { executeCircuit } from '@noir-lang/acvm_js';
@@ -17,7 +17,7 @@ export class WASMSimulator implements SimulationProvider {
17
17
  const _witnessMap = await executeCircuit(
18
18
  decodedBytecode,
19
19
  input,
20
- foreignCallHandler, // handle calls to debug_log
20
+ foreignCallHandler, // handle calls to debug_log and evaluate_blobs mock
21
21
  );
22
22
 
23
23
  return _witnessMap;
@@ -1,4 +1,3 @@
1
1
  export * from './acvm_native.js';
2
- export * from './acvm_wasm.js';
3
2
  export * from './simulation_provider.js';
4
3
  export * from './factory.js';