@aztec/simulator 0.85.0 → 0.86.0

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 (133) hide show
  1. package/dest/private/providers/acvm_native.d.ts +1 -1
  2. package/dest/private/providers/acvm_native.d.ts.map +1 -1
  3. package/dest/private/providers/acvm_native.js +4 -3
  4. package/dest/private/providers/acvm_wasm.d.ts +2 -1
  5. package/dest/private/providers/acvm_wasm.d.ts.map +1 -1
  6. package/dest/private/providers/acvm_wasm.js +6 -1
  7. package/dest/private/providers/acvm_wasm_with_blobs.d.ts +2 -1
  8. package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +1 -1
  9. package/dest/private/providers/acvm_wasm_with_blobs.js +6 -1
  10. package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts +2 -1
  11. package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts.map +1 -1
  12. package/dest/private/providers/simulation_provider.d.ts +2 -1
  13. package/dest/private/providers/simulation_provider.d.ts.map +1 -1
  14. package/dest/public/avm/avm_context.d.ts +2 -2
  15. package/dest/public/avm/avm_context.d.ts.map +1 -1
  16. package/dest/public/avm/avm_simulator.d.ts +2 -1
  17. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  18. package/dest/public/avm/avm_simulator.js +2 -1
  19. package/dest/public/avm/avm_simulator_interface.d.ts +11 -0
  20. package/dest/public/avm/avm_simulator_interface.d.ts.map +1 -0
  21. package/dest/public/avm/avm_simulator_interface.js +3 -0
  22. package/dest/public/avm/errors.d.ts +1 -16
  23. package/dest/public/avm/errors.d.ts.map +1 -1
  24. package/dest/public/avm/errors.js +0 -37
  25. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
  26. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  27. package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -1
  28. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -1
  29. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  30. package/dest/public/avm/fixtures/index.d.ts +2 -85
  31. package/dest/public/avm/fixtures/index.d.ts.map +1 -1
  32. package/dest/public/avm/fixtures/index.js +2 -174
  33. package/dest/public/avm/fixtures/initializers.d.ts +42 -0
  34. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -0
  35. package/dest/public/avm/fixtures/initializers.js +42 -0
  36. package/dest/public/avm/fixtures/utils.d.ts +46 -0
  37. package/dest/public/avm/fixtures/utils.d.ts.map +1 -0
  38. package/dest/public/avm/fixtures/utils.js +136 -0
  39. package/dest/public/avm/index.d.ts +0 -1
  40. package/dest/public/avm/index.d.ts.map +1 -1
  41. package/dest/public/avm/index.js +0 -1
  42. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  43. package/dest/public/avm/opcodes/accrued_substate.js +1 -1
  44. package/dest/public/avm/opcodes/external_calls.d.ts +3 -2
  45. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  46. package/dest/public/avm/opcodes/external_calls.js +14 -9
  47. package/dest/public/avm/opcodes/instruction.d.ts +5 -5
  48. package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
  49. package/dest/public/avm/opcodes/instruction.js +6 -6
  50. package/dest/public/avm/revert_reason.d.ts +18 -0
  51. package/dest/public/avm/revert_reason.d.ts.map +1 -0
  52. package/dest/public/avm/revert_reason.js +38 -0
  53. package/dest/public/avm/serialization/bytecode_serialization.d.ts +2 -4
  54. package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  55. package/dest/public/avm/serialization/bytecode_serialization.js +70 -69
  56. package/dest/{common → public}/debug_fn_name.d.ts +1 -1
  57. package/dest/{common → public}/debug_fn_name.d.ts.map +1 -1
  58. package/dest/public/fixtures/index.d.ts +1 -0
  59. package/dest/public/fixtures/index.d.ts.map +1 -1
  60. package/dest/public/fixtures/index.js +1 -0
  61. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +1 -1
  62. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  63. package/dest/public/fixtures/public_tx_simulation_tester.js +3 -4
  64. package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -0
  65. package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.js +1 -1
  66. package/dest/public/hinting_db_sources.d.ts +15 -5
  67. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  68. package/dest/public/hinting_db_sources.js +65 -27
  69. package/dest/public/index.d.ts +2 -6
  70. package/dest/public/index.d.ts.map +1 -1
  71. package/dest/public/index.js +2 -6
  72. package/dest/public/public_db_sources.d.ts +19 -52
  73. package/dest/public/public_db_sources.d.ts.map +1 -1
  74. package/dest/public/public_db_sources.js +96 -107
  75. package/dest/public/public_processor/public_processor.d.ts +6 -6
  76. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  77. package/dest/public/public_processor/public_processor.js +24 -26
  78. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +3 -2
  79. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  80. package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +2 -2
  81. package/dest/public/public_tx_simulator/public_tx_context.d.ts +3 -4
  82. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  83. package/dest/public/public_tx_simulator/public_tx_context.js +11 -21
  84. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +5 -4
  85. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  86. package/dest/public/public_tx_simulator/public_tx_simulator.js +21 -10
  87. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +3 -2
  88. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  89. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +2 -2
  90. package/dest/public/side_effect_trace.d.ts +1 -3
  91. package/dest/public/side_effect_trace.d.ts.map +1 -1
  92. package/dest/public/side_effect_trace.js +3 -2
  93. package/dest/public/state_manager/state_manager.d.ts +6 -4
  94. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  95. package/dest/public/state_manager/state_manager.js +20 -41
  96. package/package.json +14 -16
  97. package/src/private/providers/acvm_native.ts +5 -4
  98. package/src/private/providers/acvm_wasm.ts +5 -2
  99. package/src/private/providers/acvm_wasm_with_blobs.ts +5 -3
  100. package/src/private/providers/circuit_recording/simulation_provider_recorder_wrapper.ts +3 -2
  101. package/src/private/providers/simulation_provider.ts +2 -1
  102. package/src/public/avm/avm_context.ts +2 -2
  103. package/src/public/avm/avm_simulator.ts +4 -8
  104. package/src/public/avm/avm_simulator_interface.ts +8 -0
  105. package/src/public/avm/errors.ts +1 -53
  106. package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
  107. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
  108. package/src/public/avm/fixtures/index.ts +2 -308
  109. package/src/public/avm/fixtures/initializers.ts +101 -0
  110. package/src/public/avm/fixtures/utils.ts +213 -0
  111. package/src/public/avm/index.ts +0 -1
  112. package/src/public/avm/opcodes/accrued_substate.ts +1 -5
  113. package/src/public/avm/opcodes/external_calls.ts +17 -11
  114. package/src/public/avm/opcodes/instruction.ts +9 -8
  115. package/src/public/avm/revert_reason.ts +55 -0
  116. package/src/public/avm/serialization/bytecode_serialization.ts +72 -74
  117. package/src/{common → public}/debug_fn_name.ts +1 -1
  118. package/src/public/fixtures/index.ts +1 -0
  119. package/src/public/fixtures/public_tx_simulation_tester.ts +3 -5
  120. package/src/public/{avm/fixtures → fixtures}/simple_contract_data_source.ts +1 -1
  121. package/src/public/hinting_db_sources.ts +104 -39
  122. package/src/public/index.ts +2 -6
  123. package/src/public/public_db_sources.ts +111 -164
  124. package/src/public/public_processor/public_processor.ts +27 -29
  125. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +4 -3
  126. package/src/public/public_tx_simulator/public_tx_context.ts +10 -47
  127. package/src/public/public_tx_simulator/public_tx_simulator.ts +25 -10
  128. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +4 -3
  129. package/src/public/side_effect_trace.ts +2 -4
  130. package/src/public/state_manager/state_manager.ts +24 -50
  131. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +0 -1
  132. /package/dest/{common → public}/debug_fn_name.js +0 -0
  133. /package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.d.ts +0 -0
@@ -3,7 +3,7 @@ import { padArrayEnd } from '@aztec/foundation/collection';
3
3
  import { Fr } from '@aztec/foundation/fields';
4
4
  import { createLogger } from '@aztec/foundation/log';
5
5
  import { assertLength } from '@aztec/foundation/serialize';
6
- import { AvmExecutionHints, AvmTxHint, PublicDataWrite, RevertCode } from '@aztec/stdlib/avm';
6
+ import { PublicDataWrite, RevertCode } from '@aztec/stdlib/avm';
7
7
  import { computeTransactionFee } from '@aztec/stdlib/fees';
8
8
  import { Gas } from '@aztec/stdlib/gas';
9
9
  import { PrivateToAvmAccumulatedData, PrivateToAvmAccumulatedDataArrayLengths, PublicCallRequest, countAccumulatedItems, mergeAccumulatedData } from '@aztec/stdlib/kernel';
@@ -11,7 +11,6 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
11
11
  import { TreeSnapshots, TxExecutionPhase } from '@aztec/stdlib/tx';
12
12
  import { strict as assert } from 'assert';
13
13
  import { inspect } from 'util';
14
- import { HintingPublicContractsDB, HintingPublicTreesDB } from '../hinting_db_sources.js';
15
14
  import { SideEffectArrayLengths, SideEffectTrace } from '../side_effect_trace.js';
16
15
  import { PublicPersistableStateManager } from '../state_manager/state_manager.js';
17
16
  import { getCallRequestsWithCalldataByPhase } from '../utils.js';
@@ -20,8 +19,8 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
20
19
  */ export class PublicTxContext {
21
20
  txHash;
22
21
  state;
22
+ startTreeSnapshots;
23
23
  globalVariables;
24
- startStateReference;
25
24
  gasSettings;
26
25
  gasUsedByPrivate;
27
26
  gasAllocatedToPublic;
@@ -32,18 +31,17 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
32
31
  revertibleAccumulatedDataFromPrivate;
33
32
  feePayer;
34
33
  trace;
35
- hints;
36
34
  log;
37
35
  /* Gas used including private, teardown gas _limit_, setup and app logic */ gasUsedByPublic;
38
36
  /* Gas actually used during teardown (different from limit) */ teardownGasUsed;
39
37
  /* Entire transaction execution is done. */ halted;
40
38
  /* Where did reverts happen (if at all)? */ revertCode;
41
39
  /* What caused a revert (if one occurred)? */ revertReason;
42
- constructor(txHash, state, globalVariables, startStateReference, gasSettings, gasUsedByPrivate, gasAllocatedToPublic, setupCallRequests, appLogicCallRequests, teardownCallRequests, nonRevertibleAccumulatedDataFromPrivate, revertibleAccumulatedDataFromPrivate, feePayer, trace, hints){
40
+ constructor(txHash, state, startTreeSnapshots, globalVariables, gasSettings, gasUsedByPrivate, gasAllocatedToPublic, setupCallRequests, appLogicCallRequests, teardownCallRequests, nonRevertibleAccumulatedDataFromPrivate, revertibleAccumulatedDataFromPrivate, feePayer, trace){
43
41
  this.txHash = txHash;
44
42
  this.state = state;
43
+ this.startTreeSnapshots = startTreeSnapshots;
45
44
  this.globalVariables = globalVariables;
46
- this.startStateReference = startStateReference;
47
45
  this.gasSettings = gasSettings;
48
46
  this.gasUsedByPrivate = gasUsedByPrivate;
49
47
  this.gasAllocatedToPublic = gasAllocatedToPublic;
@@ -54,7 +52,6 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
54
52
  this.revertibleAccumulatedDataFromPrivate = revertibleAccumulatedDataFromPrivate;
55
53
  this.feePayer = feePayer;
56
54
  this.trace = trace;
57
- this.hints = hints;
58
55
  this.gasUsedByPublic = Gas.empty();
59
56
  this.teardownGasUsed = Gas.empty();
60
57
  this.halted = false;
@@ -66,19 +63,13 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
66
63
  const previousAccumulatedDataArrayLengths = new SideEffectArrayLengths(/*publicDataWrites*/ 0, /*protocolPublicDataWrites*/ 0, /*noteHashes*/ 0, /*nullifiers=*/ 0, countAccumulatedItems(nonRevertibleAccumulatedDataFromPrivate.l2ToL1Msgs), /*publicLogs*/ 0);
67
64
  const trace = new SideEffectTrace(/*startSideEffectCounter=*/ 0, previousAccumulatedDataArrayLengths);
68
65
  const firstNullifier = nonRevertibleAccumulatedDataFromPrivate.nullifiers[0];
69
- // We wrap the DB to collect AVM hints.
70
- const hints = new AvmExecutionHints(await AvmTxHint.fromTx(tx));
71
- const hintingContractsDB = new HintingPublicContractsDB(contractsDB, hints);
72
- const hintingTreesDB = new HintingPublicTreesDB(treesDB, hints);
73
- const startStateReference = await treesDB.getStateReference();
74
- hints.startingTreeRoots = new TreeSnapshots(startStateReference.l1ToL2MessageTree, startStateReference.partial.noteHashTree, startStateReference.partial.nullifierTree, startStateReference.partial.publicDataTree);
75
66
  // Transaction level state manager that will be forked for revertible phases.
76
- const txStateManager = PublicPersistableStateManager.create(hintingTreesDB, hintingContractsDB, trace, doMerkleOperations, firstNullifier, globalVariables.blockNumber.toNumber());
67
+ const txStateManager = PublicPersistableStateManager.create(treesDB, contractsDB, trace, doMerkleOperations, firstNullifier, globalVariables.blockNumber.toNumber());
77
68
  const gasSettings = tx.data.constants.txContext.gasSettings;
78
69
  const gasUsedByPrivate = tx.data.gasUsed;
79
70
  // Gas allocated to public is "whatever's left" after private, but with some max applied.
80
71
  const gasAllocatedToPublic = applyMaxToAvailableGas(gasSettings.gasLimits.sub(gasUsedByPrivate));
81
- return new PublicTxContext(await tx.getTxHash(), new PhaseStateManager(txStateManager), globalVariables, await treesDB.getStateReference(), gasSettings, gasUsedByPrivate, gasAllocatedToPublic, getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP), getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.APP_LOGIC), getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.TEARDOWN), tx.data.forPublic.nonRevertibleAccumulatedData, tx.data.forPublic.revertibleAccumulatedData, tx.data.feePayer, trace, hints);
72
+ return new PublicTxContext(await tx.getTxHash(), new PhaseStateManager(txStateManager), await txStateManager.getTreeSnapshots(), globalVariables, gasSettings, gasUsedByPrivate, gasAllocatedToPublic, getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP), getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.APP_LOGIC), getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.TEARDOWN), tx.data.forPublic.nonRevertibleAccumulatedData, tx.data.forPublic.revertibleAccumulatedData, tx.data.feePayer, trace);
82
73
  }
83
74
  /**
84
75
  * Signal that the entire transaction execution is done.
@@ -220,12 +211,12 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
220
211
  */ async generateAvmCircuitPublicInputs() {
221
212
  assert(this.halted, 'Can only get AvmCircuitPublicInputs after tx execution ends');
222
213
  const stateManager = this.state.getActiveStateManager();
223
- const startTreeSnapshots = new TreeSnapshots(this.startStateReference.l1ToL2MessageTree, this.startStateReference.partial.noteHashTree, this.startStateReference.partial.nullifierTree, this.startStateReference.partial.publicDataTree);
224
214
  // FIXME: We are first creating the PIs with the wrong endTreeSnapshots, then patching them.
225
215
  // This is because we need to know the lengths of the accumulated data arrays to pad them.
226
216
  // We should refactor this to avoid this hack.
227
217
  // We should just get the info we need from the trace, and create the rest of the PIs here.
228
- const avmCircuitPublicInputs = this.trace.toAvmCircuitPublicInputs(this.globalVariables, startTreeSnapshots, /*startGasUsed=*/ this.gasUsedByPrivate, this.gasSettings, this.feePayer, this.setupCallRequests.map((r)=>r.request), this.appLogicCallRequests.map((r)=>r.request), /*teardownCallRequest=*/ this.teardownCallRequests.length ? this.teardownCallRequests[0].request : PublicCallRequest.empty(), /*endTreeSnapshots=*/ TreeSnapshots.empty(), /*endGasUsed=*/ this.getTotalGasUsed(), /*transactionFee=*/ this.getTransactionFeeUnsafe(), /*reverted=*/ !this.revertCode.isOK());
218
+ const avmCircuitPublicInputs = this.trace.toAvmCircuitPublicInputs(this.globalVariables, /*startGasUsed=*/ this.gasUsedByPrivate, this.gasSettings, this.feePayer, this.setupCallRequests.map((r)=>r.request), this.appLogicCallRequests.map((r)=>r.request), /*teardownCallRequest=*/ this.teardownCallRequests.length ? this.teardownCallRequests[0].request : PublicCallRequest.empty(), /*endTreeSnapshots=*/ TreeSnapshots.empty(), /*endGasUsed=*/ this.getTotalGasUsed(), /*transactionFee=*/ this.getTransactionFeeUnsafe(), /*reverted=*/ !this.revertCode.isOK());
219
+ avmCircuitPublicInputs.startTreeSnapshots = this.startTreeSnapshots;
229
220
  const getArrayLengths = (from)=>new PrivateToAvmAccumulatedDataArrayLengths(countAccumulatedItems(from.noteHashes), countAccumulatedItems(from.nullifiers), countAccumulatedItems(from.l2ToL1Msgs));
230
221
  const convertAccumulatedData = (from)=>new PrivateToAvmAccumulatedData(from.noteHashes, from.nullifiers, from.l2ToL1Msgs);
231
222
  // Temporary overrides as these entries aren't yet populated in trace
@@ -244,11 +235,10 @@ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
244
235
  }
245
236
  avmCircuitPublicInputs.accumulatedData.publicDataWrites = padArrayEnd(Array.from(squashedPublicDataWrites.entries()).map(([slot, value])=>new PublicDataWrite(new Fr(slot), value)), PublicDataWrite.empty(), MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX);
246
237
  const numNoteHashesToPad = MAX_NOTE_HASHES_PER_TX - countAccumulatedItems(avmCircuitPublicInputs.accumulatedData.noteHashes);
247
- await stateManager.deprecatedGetTreesForPIGeneration().padTree(MerkleTreeId.NOTE_HASH_TREE, numNoteHashesToPad);
238
+ await stateManager.padTree(MerkleTreeId.NOTE_HASH_TREE, numNoteHashesToPad);
248
239
  const numNullifiersToPad = MAX_NULLIFIERS_PER_TX - countAccumulatedItems(avmCircuitPublicInputs.accumulatedData.nullifiers);
249
- await stateManager.deprecatedGetTreesForPIGeneration().padTree(MerkleTreeId.NULLIFIER_TREE, numNullifiersToPad);
250
- const paddedState = await stateManager.deprecatedGetTreesForPIGeneration().getStateReference();
251
- avmCircuitPublicInputs.endTreeSnapshots = new TreeSnapshots(paddedState.l1ToL2MessageTree, paddedState.partial.noteHashTree, paddedState.partial.nullifierTree, paddedState.partial.publicDataTree);
240
+ await stateManager.padTree(MerkleTreeId.NULLIFIER_TREE, numNullifiersToPad);
241
+ avmCircuitPublicInputs.endTreeSnapshots = await stateManager.getTreeSnapshots();
252
242
  return avmCircuitPublicInputs;
253
243
  }
254
244
  }
@@ -3,9 +3,10 @@ import { type Logger } from '@aztec/foundation/log';
3
3
  import { type AvmProvingRequest, type RevertCode } from '@aztec/stdlib/avm';
4
4
  import { SimulationError } from '@aztec/stdlib/errors';
5
5
  import type { Gas, GasUsed } from '@aztec/stdlib/gas';
6
+ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
6
7
  import { type GlobalVariables, NestedProcessReturnValues, PublicCallRequestWithCalldata, Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
7
8
  import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
8
- import type { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
9
+ import { type PublicContractsDB } from '../public_db_sources.js';
9
10
  import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
10
11
  import { PublicTxContext } from './public_tx_context.js';
11
12
  export type ProcessedPhase = {
@@ -25,13 +26,13 @@ export type PublicTxResult = {
25
26
  processedPhases: ProcessedPhase[];
26
27
  };
27
28
  export declare class PublicTxSimulator {
28
- private treesDB;
29
- protected contractsDB: PublicContractsDB;
29
+ private merkleTree;
30
+ private contractsDB;
30
31
  private globalVariables;
31
32
  private doMerkleOperations;
32
33
  private skipFeeEnforcement;
33
34
  protected log: Logger;
34
- constructor(treesDB: PublicTreesDB, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations?: boolean, skipFeeEnforcement?: boolean);
35
+ constructor(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations?: boolean, skipFeeEnforcement?: boolean);
35
36
  /**
36
37
  * Simulate a transaction's public portion including all of its phases.
37
38
  * @param tx - The transaction to simulate.
@@ -1 +1 @@
1
- {"version":3,"file":"public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,UAAU,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EACL,KAAK,eAAe,EACpB,yBAAyB,EACzB,6BAA6B,EAC7B,EAAE,EACF,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAK1B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAEjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEhF,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,gBAAgB,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,yBAAyB,EAAE,CAAC;IAC1C,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,eAAe,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,+CAA+C;IAC/C,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,UAAU,CAAC;IACvB,4BAA4B;IAC5B,YAAY,C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O,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE;IA2BhF;;;OAGG;cACa,4BAA4B,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE,GAAgB,OAAO,CAAC,OAAO,CAAC;YAsC/F,MAAM;IAgCpB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;CAStC"}
@@ -1,24 +1,26 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
2
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
3
  import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
4
- import { AvmCircuitInputs } from '@aztec/stdlib/avm';
4
+ import { AvmCircuitInputs, AvmExecutionHints, AvmTxHint } from '@aztec/stdlib/avm';
5
5
  import { SimulationError } from '@aztec/stdlib/errors';
6
6
  import { ProvingRequestType } from '@aztec/stdlib/proofs';
7
7
  import { NestedProcessReturnValues, TxExecutionPhase } from '@aztec/stdlib/tx';
8
8
  import { strict as assert } from 'assert';
9
- import { getPublicFunctionDebugName } from '../../common/debug_fn_name.js';
10
9
  import { AvmSimulator } from '../avm/index.js';
10
+ import { getPublicFunctionDebugName } from '../debug_fn_name.js';
11
+ import { HintingMerkleWriteOperations, HintingPublicContractsDB } from '../hinting_db_sources.js';
12
+ import { PublicTreesDB } from '../public_db_sources.js';
11
13
  import { NullifierCollisionError } from '../state_manager/nullifiers.js';
12
14
  import { PublicTxContext } from './public_tx_context.js';
13
15
  export class PublicTxSimulator {
14
- treesDB;
16
+ merkleTree;
15
17
  contractsDB;
16
18
  globalVariables;
17
19
  doMerkleOperations;
18
20
  skipFeeEnforcement;
19
21
  log;
20
- constructor(treesDB, contractsDB, globalVariables, doMerkleOperations = false, skipFeeEnforcement = false){
21
- this.treesDB = treesDB;
22
+ constructor(merkleTree, contractsDB, globalVariables, doMerkleOperations = false, skipFeeEnforcement = false){
23
+ this.merkleTree = merkleTree;
22
24
  this.contractsDB = contractsDB;
23
25
  this.globalVariables = globalVariables;
24
26
  this.doMerkleOperations = doMerkleOperations;
@@ -35,7 +37,12 @@ export class PublicTxSimulator {
35
37
  this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, {
36
38
  txHash
37
39
  });
38
- const context = await PublicTxContext.create(this.treesDB, this.contractsDB, tx, this.globalVariables, this.doMerkleOperations);
40
+ // Create hinting DBs.
41
+ const hints = new AvmExecutionHints(await AvmTxHint.fromTx(tx));
42
+ const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
43
+ const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
44
+ const hintingContractsDB = new HintingPublicContractsDB(this.contractsDB, hints);
45
+ const context = await PublicTxContext.create(hintingTreesDB, hintingContractsDB, tx, this.globalVariables, this.doMerkleOperations);
39
46
  await this.insertNonRevertiblesFromPrivate(context, tx);
40
47
  const processedPhases = [];
41
48
  if (context.hasPhase(TxExecutionPhase.SETUP)) {
@@ -59,7 +66,7 @@ export class PublicTxSimulator {
59
66
  await context.halt();
60
67
  await this.payFee(context);
61
68
  const publicInputs = await context.generateAvmCircuitPublicInputs();
62
- const avmProvingRequest = PublicTxSimulator.generateProvingRequest(publicInputs, context.hints);
69
+ const avmProvingRequest = PublicTxSimulator.generateProvingRequest(publicInputs, hints);
63
70
  const revertCode = context.getFinalRevertCode();
64
71
  if (!revertCode.isOK()) {
65
72
  await tx.filterRevertedLogs();
@@ -184,7 +191,7 @@ export class PublicTxSimulator {
184
191
  const fnName = await getPublicFunctionDebugName(this.contractsDB, contractAddress, callRequest.calldata);
185
192
  const allocatedGas = context.getGasLeftAtPhase(phase);
186
193
  stateManager.traceEnqueuedCall(callRequest.request);
187
- const result = await this.simulateEnqueuedCallInternal(context.state.getActiveStateManager(), callRequest, allocatedGas, /*transactionFee=*/ context.getTransactionFee(phase), fnName);
194
+ const result = await this.simulateEnqueuedCallInternal(stateManager, callRequest, allocatedGas, /*transactionFee=*/ context.getTransactionFee(phase), fnName);
188
195
  const gasUsed = allocatedGas.sub(result.gasLeft); // by enqueued call
189
196
  context.consumeGas(phase, gasUsed);
190
197
  this.log.debug(`Simulated enqueued public call (${fnName}) consumed ${gasUsed.l2Gas} L2 gas ending with ${result.gasLeft.l2Gas} L2 gas left.`);
@@ -219,7 +226,9 @@ export class PublicTxSimulator {
219
226
  */ async insertNonRevertiblesFromPrivate(context, tx) {
220
227
  const stateManager = context.state.getActiveStateManager();
221
228
  try {
222
- await stateManager.writeSiloedNullifiersFromPrivate(context.nonRevertibleAccumulatedDataFromPrivate.nullifiers);
229
+ for (const siloedNullifier of context.nonRevertibleAccumulatedDataFromPrivate.nullifiers.filter((n)=>!n.isEmpty())){
230
+ await stateManager.writeSiloedNullifier(siloedNullifier);
231
+ }
223
232
  } catch (e) {
224
233
  if (e instanceof NullifierCollisionError) {
225
234
  throw new NullifierCollisionError(`Nullifier collision encountered when inserting non-revertible nullifiers from private.\nDetails: ${e.message}\nStack:${e.stack}`);
@@ -244,7 +253,9 @@ export class PublicTxSimulator {
244
253
  await context.state.fork();
245
254
  const stateManager = context.state.getActiveStateManager();
246
255
  try {
247
- await stateManager.writeSiloedNullifiersFromPrivate(context.revertibleAccumulatedDataFromPrivate.nullifiers);
256
+ for (const siloedNullifier of context.revertibleAccumulatedDataFromPrivate.nullifiers.filter((n)=>!n.isEmpty())){
257
+ await stateManager.writeSiloedNullifier(siloedNullifier);
258
+ }
248
259
  } catch (e) {
249
260
  if (e instanceof NullifierCollisionError) {
250
261
  // Instead of throwing, revert the app_logic phase
@@ -1,9 +1,10 @@
1
1
  import type { Fr } from '@aztec/foundation/fields';
2
2
  import type { Gas } from '@aztec/stdlib/gas';
3
+ import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
3
4
  import { type GlobalVariables, PublicCallRequestWithCalldata, TxExecutionPhase } from '@aztec/stdlib/tx';
4
5
  import { type TelemetryClient, type Tracer } from '@aztec/telemetry-client';
5
6
  import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
6
- import type { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
7
+ import type { PublicContractsDB } from '../public_db_sources.js';
7
8
  import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
8
9
  import { MeasuredPublicTxSimulator } from './measured_public_tx_simulator.js';
9
10
  import { PublicTxContext } from './public_tx_context.js';
@@ -12,7 +13,7 @@ import { PublicTxContext } from './public_tx_context.js';
12
13
  */
13
14
  export declare class TelemetryPublicTxSimulator extends MeasuredPublicTxSimulator {
14
15
  readonly tracer: Tracer;
15
- constructor(treesDB: PublicTreesDB, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations?: boolean, skipFeeEnforcement?: boolean, telemetryClient?: TelemetryClient);
16
+ constructor(merkleTree: MerkleTreeWriteOperations, contractsDB: PublicContractsDB, globalVariables: GlobalVariables, doMerkleOperations?: boolean, skipFeeEnforcement?: boolean, telemetryClient?: TelemetryClient);
16
17
  protected simulateEnqueuedCall(phase: TxExecutionPhase, context: PublicTxContext, callRequest: PublicCallRequestWithCalldata): Promise<AvmFinalizedCallResult>;
17
18
  protected simulateEnqueuedCallInternal(stateManager: PublicPersistableStateManager, callRequest: PublicCallRequestWithCalldata, allocatedGas: Gas, transactionFee: Fr, fnName: string): Promise<AvmFinalizedCallResult>;
18
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry_public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/telemetry_public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,KAAK,eAAe,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzG,OAAO,EAAc,KAAK,eAAe,EAAE,KAAK,MAAM,EAAiC,MAAM,yBAAyB,CAAC;AAEvH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAEjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,yBAAyB;IAEvE,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAG7B,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,GAAE,OAAe,EACnC,kBAAkB,GAAE,OAAe,EACnC,eAAe,GAAE,eAAsC;cAahC,oBAAoB,CAC3C,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,6BAA6B,GACzC,OAAO,CAAC,sBAAsB,CAAC;cAUT,4BAA4B,CACnD,YAAY,EAAE,6BAA6B,EAC3C,WAAW,EAAE,6BAA6B,EAC1C,YAAY,EAAE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC;CAGnC"}
1
+ {"version":3,"file":"telemetry_public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/telemetry_public_tx_simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,KAAK,eAAe,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzG,OAAO,EAAc,KAAK,eAAe,EAAE,KAAK,MAAM,EAAiC,MAAM,yBAAyB,CAAC;AAEvH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAEjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,yBAAyB;IAEvE,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAG7B,UAAU,EAAE,yBAAyB,EACrC,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,GAAE,OAAe,EACnC,kBAAkB,GAAE,OAAe,EACnC,eAAe,GAAE,eAAsC;cAahC,oBAAoB,CAC3C,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,6BAA6B,GACzC,OAAO,CAAC,sBAAsB,CAAC;cAUT,4BAA4B,CACnD,YAAY,EAAE,6BAA6B,EAC3C,WAAW,EAAE,6BAA6B,EAC1C,YAAY,EAAE,GAAG,EACjB,cAAc,EAAE,EAAE,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,sBAAsB,CAAC;CAGnC"}
@@ -12,9 +12,9 @@ import { MeasuredPublicTxSimulator } from './measured_public_tx_simulator.js';
12
12
  * A public tx simulator that tracks runtime/production metrics with telemetry.
13
13
  */ export class TelemetryPublicTxSimulator extends MeasuredPublicTxSimulator {
14
14
  /* tracer needed by trackSpans */ tracer;
15
- constructor(treesDB, contractsDB, globalVariables, doMerkleOperations = false, skipFeeEnforcement = false, telemetryClient = getTelemetryClient()){
15
+ constructor(merkleTree, contractsDB, globalVariables, doMerkleOperations = false, skipFeeEnforcement = false, telemetryClient = getTelemetryClient()){
16
16
  const metrics = new ExecutorMetrics(telemetryClient, 'PublicTxSimulator');
17
- super(treesDB, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, metrics);
17
+ super(merkleTree, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, metrics);
18
18
  this.tracer = metrics.tracer;
19
19
  }
20
20
  async simulateEnqueuedCall(phase, context, callRequest) {
@@ -5,7 +5,7 @@ import type { Gas, GasSettings } from '@aztec/stdlib/gas';
5
5
  import { NoteHash, Nullifier, PublicCallRequest } from '@aztec/stdlib/kernel';
6
6
  import { PublicLog } from '@aztec/stdlib/logs';
7
7
  import { ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
8
- import type { GlobalVariables, TreeSnapshots } from '@aztec/stdlib/tx';
8
+ import { type GlobalVariables, TreeSnapshots } from '@aztec/stdlib/tx';
9
9
  import type { PublicSideEffectTraceInterface } from './side_effect_trace_interface.js';
10
10
  import { UniqueClassIds } from './unique_class_ids.js';
11
11
  /**
@@ -85,8 +85,6 @@ export declare class SideEffectTrace implements PublicSideEffectTraceInterface {
85
85
  toAvmCircuitPublicInputs(
86
86
  /** Globals. */
87
87
  globalVariables: GlobalVariables,
88
- /** Start tree snapshots. */
89
- startTreeSnapshots: TreeSnapshots,
90
88
  /** Gas used at start of TX. */
91
89
  startGasUsed: Gas,
92
90
  /** How much gas was available for this public execution. */
@@ -1 +1 @@
1
- {"version":3,"file":"side_effect_trace.d.ts","sourceRoot":"","sources":["../../src/public/side_effect_trace.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EAEL,sBAAsB,EACtB,uBAAuB,EAExB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EACL,QAAQ,EACR,SAAS,EAGT,iBAAiB,EAClB,MAAM,sBAAsB,CAA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edData, PrivateToAvmAccumulatedDataArrayLengths, PublicCallRequest } from '@aztec/stdlib/kernel';
9
9
  import { PublicLog } from '@aztec/stdlib/logs';
10
10
  import { L2ToL1Message, ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
11
+ import { TreeSnapshots } from '@aztec/stdlib/tx';
11
12
  import { strict as assert } from 'assert';
12
13
  import { SideEffectLimitReachedError } from './side_effect_errors.js';
13
14
  import { UniqueClassIds } from './unique_class_ids.js';
@@ -175,11 +176,11 @@ export class SideEffectArrayLengths {
175
176
  publicLogs: this.publicLogs
176
177
  };
177
178
  }
178
- toAvmCircuitPublicInputs(/** Globals. */ globalVariables, /** Start tree snapshots. */ startTreeSnapshots, /** Gas used at start of TX. */ startGasUsed, /** How much gas was available for this public execution. */ gasLimits, /** Address of the fee payer. */ feePayer, /** Call requests for setup phase. */ publicSetupCallRequests, /** Call requests for app logic phase. */ publicAppLogicCallRequests, /** Call request for teardown phase. */ publicTeardownCallRequest, /** End tree snapshots. */ endTreeSnapshots, /**
179
+ toAvmCircuitPublicInputs(/** Globals. */ globalVariables, /** Gas used at start of TX. */ startGasUsed, /** How much gas was available for this public execution. */ gasLimits, /** Address of the fee payer. */ feePayer, /** Call requests for setup phase. */ publicSetupCallRequests, /** Call requests for app logic phase. */ publicAppLogicCallRequests, /** Call request for teardown phase. */ publicTeardownCallRequest, /** End tree snapshots. */ endTreeSnapshots, /**
179
180
  * Gas used by the whole transaction, assuming entire teardown limit is used.
180
181
  * This is the gas used when computing transaction fee.
181
182
  */ endGasUsed, /** Transaction fee. */ transactionFee, /** The call's results */ reverted) {
182
- return new AvmCircuitPublicInputs(globalVariables, startTreeSnapshots, startGasUsed, gasLimits, feePayer, padArrayEnd(publicSetupCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX), padArrayEnd(publicAppLogicCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX), publicTeardownCallRequest, /*previousNonRevertibleAccumulatedDataArrayLengths=*/ PrivateToAvmAccumulatedDataArrayLengths.empty(), /*previousRevertibleAccumulatedDataArrayLengths=*/ PrivateToAvmAccumulatedDataArrayLengths.empty(), /*previousNonRevertibleAccumulatedDataArray=*/ PrivateToAvmAccumulatedData.empty(), /*previousRevertibleAccumulatedDataArray=*/ PrivateToAvmAccumulatedData.empty(), endTreeSnapshots, endGasUsed, /*accumulatedData=*/ this.getAvmAccumulatedData(), transactionFee, reverted);
183
+ return new AvmCircuitPublicInputs(globalVariables, TreeSnapshots.empty(), startGasUsed, gasLimits, feePayer, padArrayEnd(publicSetupCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX), padArrayEnd(publicAppLogicCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX), publicTeardownCallRequest, /*previousNonRevertibleAccumulatedDataArrayLengths=*/ PrivateToAvmAccumulatedDataArrayLengths.empty(), /*previousRevertibleAccumulatedDataArrayLengths=*/ PrivateToAvmAccumulatedDataArrayLengths.empty(), /*previousNonRevertibleAccumulatedDataArray=*/ PrivateToAvmAccumulatedData.empty(), /*previousRevertibleAccumulatedDataArray=*/ PrivateToAvmAccumulatedData.empty(), endTreeSnapshots, endGasUsed, /*accumulatedData=*/ this.getAvmAccumulatedData(), transactionFee, reverted);
183
184
  }
184
185
  getPublicLogs() {
185
186
  return this.publicLogs;
@@ -5,8 +5,10 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import type { ContractClassPublicWithCommitment } from '@aztec/stdlib/contract';
6
6
  import { SerializableContractInstance } from '@aztec/stdlib/contract';
7
7
  import type { PublicCallRequest } from '@aztec/stdlib/kernel';
8
- import type { PublicContractsDBInterface } from '../../server.js';
8
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
9
+ import type { TreeSnapshots } from '@aztec/stdlib/tx';
9
10
  import type { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
11
+ import type { PublicContractsDBInterface } from '../db_interfaces.js';
10
12
  import type { PublicTreesDB } from '../public_db_sources.js';
11
13
  import type { PublicSideEffectTraceInterface } from '../side_effect_trace_interface.js';
12
14
  import { NullifierManager } from './nullifiers.js';
@@ -39,7 +41,6 @@ export declare class PublicPersistableStateManager {
39
41
  * Create a new state manager
40
42
  */
41
43
  static create(treesDB: PublicTreesDB, contractsDB: PublicContractsDBInterface, trace: PublicSideEffectTraceInterface, doMerkleOperations: boolean | undefined, firstNullifier: Fr, blockNumber: number): PublicPersistableStateManager;
42
- deprecatedGetTreesForPIGeneration(): PublicTreesDB;
43
44
  /**
44
45
  * Create a new state manager forked from this one
45
46
  */
@@ -111,14 +112,13 @@ export declare class PublicPersistableStateManager {
111
112
  * @param siloedNullifier - the siloed nullifier to write
112
113
  */
113
114
  writeSiloedNullifier(siloedNullifier: Fr): Promise<void>;
114
- writeSiloedNullifiersFromPrivate(siloedNullifiers: Fr[]): Promise<void>;
115
115
  /**
116
116
  * Check if an L1 to L2 message exists, trace the check.
117
117
  * @param msgHash - the message hash to check existence of
118
118
  * @param msgLeafIndex - the message leaf index to use in the check
119
119
  * @returns exists - whether the message exists in the L1 to L2 Messages tree
120
120
  */
121
- checkL1ToL2MessageExists(contractAddress: AztecAddress, msgHash: Fr, msgLeafIndex: Fr): Promise<boolean>;
121
+ checkL1ToL2MessageExists(msgHash: Fr, msgLeafIndex: Fr): Promise<boolean>;
122
122
  /**
123
123
  * Write an L2 to L1 message.
124
124
  * @param contractAddress - L2 contract address that created this message
@@ -151,5 +151,7 @@ export declare class PublicPersistableStateManager {
151
151
  getBytecode(contractAddress: AztecAddress): Promise<Buffer | undefined>;
152
152
  traceEnqueuedCall(publicCallRequest: PublicCallRequest): void;
153
153
  getPublicFunctionDebugName(avmEnvironment: AvmExecutionEnvironment): Promise<string>;
154
+ padTree(treeId: MerkleTreeId, leavesToInsert: number): Promise<void>;
155
+ getTreeSnapshots(): Promise<TreeSnapshots>;
154
156
  }
155
157
  //# sourceMappingURL=state_manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3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;;;;;OAKG;IACU,wBAAwB,CAAC,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAStF;;;;;OAKG;IACI,kBAAkB,CAAC,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE;IAKnF;;;;OAIG;IACI,cAAc,CAAC,eAAe,EAAE,YAAY,EAAE,GAAG,EAAE,EAAE,EAAE;IAK9D;;;;OAIG;IACU,mBAAmB,CAAC,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC,4BAA4B,GAAG,SAAS,CAAC;YAkCpG,8BAA8B;IAwD5C;;;;OAIG;IACU,gBAAgB,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,iCAAiC,GAAG,SAAS,CAAC;IA4BlG;;OAEG;IACU,WAAW,CAAC,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAiB7E,iBAAiB,CAAC,iBAAiB,EAAE,iBAAiB;IAIhD,0BAA0B,CAAC,cAAc,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIpF,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpE,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC;CAGxD"}
@@ -1,17 +1,14 @@
1
1
  import { CANONICAL_AUTH_REGISTRY_ADDRESS, DEPLOYER_CONTRACT_ADDRESS, FEE_JUICE_ADDRESS, MULTI_CALL_ENTRYPOINT_ADDRESS, REGISTERER_CONTRACT_ADDRESS, ROUTER_ADDRESS } from '@aztec/constants';
2
2
  import { poseidon2Hash } from '@aztec/foundation/crypto';
3
- import { Fr } from '@aztec/foundation/fields';
4
3
  import { jsonStringify } from '@aztec/foundation/json-rpc';
5
4
  import { createLogger } from '@aztec/foundation/log';
6
5
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
7
- import { PublicDataWrite } from '@aztec/stdlib/avm';
8
6
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
9
7
  import { SerializableContractInstance } from '@aztec/stdlib/contract';
10
- import { computeNoteHashNonce, computePublicDataTreeLeafSlot, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
8
+ import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
11
9
  import { SharedMutableValues, SharedMutableValuesWithHash } from '@aztec/stdlib/shared-mutable';
12
- import { MerkleTreeId } from '@aztec/stdlib/trees';
13
10
  import { strict as assert } from 'assert';
14
- import { getPublicFunctionDebugName } from '../../common/debug_fn_name.js';
11
+ import { getPublicFunctionDebugName } from '../debug_fn_name.js';
15
12
  import { NullifierCollisionError, NullifierManager } from './nullifiers.js';
16
13
  import { PublicStorage } from './public_storage.js';
17
14
  /**
@@ -50,11 +47,6 @@ import { PublicStorage } from './public_storage.js';
50
47
  */ static create(treesDB, contractsDB, trace, doMerkleOperations = false, firstNullifier, blockNumber) {
51
48
  return new PublicPersistableStateManager(treesDB, contractsDB, trace, firstNullifier, blockNumber, doMerkleOperations);
52
49
  }
53
- // DO NOT USE!
54
- // FIXME(fcarreiro): refactor and remove this.
55
- deprecatedGetTreesForPIGeneration() {
56
- return this.treesDB;
57
- }
58
50
  /**
59
51
  * Create a new state manager forked from this one
60
52
  */ async fork() {
@@ -79,10 +71,8 @@ import { PublicStorage } from './public_storage.js';
79
71
  this.nullifiers.acceptAndMerge(forkedState.nullifiers);
80
72
  this.trace.merge(forkedState.trace, reverted);
81
73
  if (reverted) {
74
+ this.log.trace('Reverting forked state...');
82
75
  await this.treesDB.revertCheckpoint();
83
- if (this.doMerkleOperations) {
84
- this.log.trace(`Rolled back nullifier tree to root ${new Fr((await this.treesDB.getTreeInfo(MerkleTreeId.NULLIFIER_TREE)).root)}`);
85
- }
86
76
  } else {
87
77
  this.log.trace('Merging forked state into parent...');
88
78
  await this.treesDB.commitCheckpoint();
@@ -95,16 +85,10 @@ import { PublicStorage } from './public_storage.js';
95
85
  * @param slot - the slot in the contract's storage being written to
96
86
  * @param value - the value being written to the slot
97
87
  */ async writeStorage(contractAddress, slot, value, protocolWrite = false) {
98
- const leafSlot = await computePublicDataTreeLeafSlot(contractAddress, slot);
99
- this.log.trace(`Storage write (address=${contractAddress}, slot=${slot}): value=${value}, leafSlot=${leafSlot}`);
88
+ this.log.trace(`Storage write (address=${contractAddress}, slot=${slot}): value=${value}`);
100
89
  if (this.doMerkleOperations) {
101
90
  // write to native merkle trees
102
- const publicDataWrite = new PublicDataWrite(leafSlot, value);
103
- const result = await this.treesDB.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [
104
- publicDataWrite.toBuffer()
105
- ]);
106
- assert(result !== undefined, 'Public data tree insertion error. You might want to disable doMerkleOperations.');
107
- this.log.trace(`Inserted public data tree leaf at leafSlot ${leafSlot}, value: ${value}`);
91
+ await this.treesDB.storageWrite(contractAddress, slot, value);
108
92
  } else {
109
93
  // Cache storage writes for later reference/reads
110
94
  this.publicStorage.write(contractAddress, slot, value);
@@ -119,8 +103,7 @@ import { PublicStorage } from './public_storage.js';
119
103
  * @returns the latest value written to slot, or 0 if never written to before
120
104
  */ async readStorage(contractAddress, slot) {
121
105
  if (this.doMerkleOperations) {
122
- const value = await this.treesDB.storageRead(contractAddress, slot);
123
- return value;
106
+ return await this.treesDB.storageRead(contractAddress, slot);
124
107
  } else {
125
108
  // TODO(fcarreiro): I don't get this. PublicStorage CAN end up reading the tree. Why is it in the "dont do merkle operations" branch?
126
109
  const read = await this.publicStorage.read(contractAddress, slot);
@@ -137,8 +120,8 @@ import { PublicStorage } from './public_storage.js';
137
120
  * @param leafIndex - the leaf index being checked
138
121
  * @returns true if the note hash exists at the given leaf index, false otherwise
139
122
  */ async checkNoteHashExists(contractAddress, noteHash, leafIndex) {
140
- const gotLeafValue = await this.treesDB.getNoteHash(leafIndex.toBigInt()) ?? Fr.ZERO;
141
- const exists = gotLeafValue.equals(noteHash);
123
+ const gotLeafValue = await this.treesDB.getNoteHash(leafIndex.toBigInt());
124
+ const exists = gotLeafValue !== undefined && gotLeafValue.equals(noteHash);
142
125
  this.log.trace(`noteHashes(${contractAddress})@${noteHash} ?? leafIndex: ${leafIndex} | gotLeafValue: ${gotLeafValue}, exists: ${exists}.`);
143
126
  return Promise.resolve(exists);
144
127
  }
@@ -164,9 +147,7 @@ import { PublicStorage } from './public_storage.js';
164
147
  */ async writeUniqueNoteHash(uniqueNoteHash) {
165
148
  this.log.trace(`noteHashes += @${uniqueNoteHash}.`);
166
149
  if (this.doMerkleOperations) {
167
- await this.treesDB.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, [
168
- uniqueNoteHash
169
- ]);
150
+ await this.treesDB.writeNoteHash(uniqueNoteHash);
170
151
  }
171
152
  this.trace.traceNewNoteHash(uniqueNoteHash);
172
153
  }
@@ -183,7 +164,6 @@ import { PublicStorage } from './public_storage.js';
183
164
  this.log.trace(`Checked siloed nullifier ${siloedNullifier} (exists=${exists})`);
184
165
  return Promise.resolve(exists);
185
166
  } else {
186
- // TODO: same here, this CAN hit the db.
187
167
  const { exists, cacheHit } = await this.nullifiers.checkExists(siloedNullifier);
188
168
  this.log.trace(`Checked siloed nullifier ${siloedNullifier} (exists=${exists}), cacheHit=${cacheHit}`);
189
169
  return Promise.resolve(exists);
@@ -209,9 +189,7 @@ import { PublicStorage } from './public_storage.js';
209
189
  this.log.verbose(`Siloed nullifier ${siloedNullifier} already present in tree!`);
210
190
  throw new NullifierCollisionError(`Siloed nullifier ${siloedNullifier} already exists in parent cache or host.`);
211
191
  } else {
212
- await this.treesDB.sequentialInsert(MerkleTreeId.NULLIFIER_TREE, [
213
- siloedNullifier.toBuffer()
214
- ]);
192
+ await this.treesDB.writeNullifier(siloedNullifier);
215
193
  }
216
194
  } else {
217
195
  // Cache pending nullifiers for later access
@@ -219,19 +197,14 @@ import { PublicStorage } from './public_storage.js';
219
197
  }
220
198
  this.trace.traceNewNullifier(siloedNullifier);
221
199
  }
222
- async writeSiloedNullifiersFromPrivate(siloedNullifiers) {
223
- for (const siloedNullifier of siloedNullifiers.filter((n)=>!n.isEmpty())){
224
- await this.writeSiloedNullifier(siloedNullifier);
225
- }
226
- }
227
200
  /**
228
201
  * Check if an L1 to L2 message exists, trace the check.
229
202
  * @param msgHash - the message hash to check existence of
230
203
  * @param msgLeafIndex - the message leaf index to use in the check
231
204
  * @returns exists - whether the message exists in the L1 to L2 Messages tree
232
- */ async checkL1ToL2MessageExists(contractAddress, msgHash, msgLeafIndex) {
233
- const valueAtIndex = await this.treesDB.getL1ToL2LeafValue(msgLeafIndex.toBigInt()) ?? Fr.ZERO;
234
- const exists = valueAtIndex.equals(msgHash);
205
+ */ async checkL1ToL2MessageExists(msgHash, msgLeafIndex) {
206
+ const valueAtIndex = await this.treesDB.getL1ToL2LeafValue(msgLeafIndex.toBigInt());
207
+ const exists = valueAtIndex !== undefined && valueAtIndex.equals(msgHash);
235
208
  this.log.trace(`l1ToL2Messages(@${msgLeafIndex}) ?? exists: ${exists}, expected: ${msgHash}, found: ${valueAtIndex}.`);
236
209
  return Promise.resolve(exists);
237
210
  }
@@ -272,7 +245,7 @@ import { PublicStorage } from './public_storage.js';
272
245
  }
273
246
  // This will decide internally whether to check the nullifier tree or not depending on doMerkleOperations.
274
247
  const nullifierExistsInTree = await this.checkNullifierExists(AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS), contractAddress.toField());
275
- assert(exists == nullifierExistsInTree, 'treesDB contains contract instance, but nullifier tree does not contain contract address (or vice versa).... This is a bug!');
248
+ assert(exists == nullifierExistsInTree, `Contract instance for address ${contractAddress} in DB: ${exists} != nullifier tree: ${nullifierExistsInTree}. This is a bug!`);
276
249
  // All that is left is tocheck that the contract updatability information is correct.
277
250
  // That is, that the current and original contract class ids are correct.
278
251
  await this.checkContractUpdateInformation(instanceWithAddress);
@@ -358,6 +331,12 @@ import { PublicStorage } from './public_storage.js';
358
331
  async getPublicFunctionDebugName(avmEnvironment) {
359
332
  return await getPublicFunctionDebugName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
360
333
  }
334
+ async padTree(treeId, leavesToInsert) {
335
+ await this.treesDB.padTree(treeId, leavesToInsert);
336
+ }
337
+ async getTreeSnapshots() {
338
+ return await this.treesDB.getTreeSnapshots();
339
+ }
361
340
  }
362
341
  function contractAddressIsCanonical(contractAddress) {
363
342
  return contractAddress.equals(AztecAddress.fromNumber(CANONICAL_AUTH_REGISTRY_ADDRESS)) || contractAddress.equals(AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS)) || contractAddress.equals(AztecAddress.fromNumber(REGISTERER_CONTRACT_ADDRESS)) || contractAddress.equals(AztecAddress.fromNumber(MULTI_CALL_ENTRYPOINT_ADDRESS)) || contractAddress.equals(AztecAddress.fromNumber(FEE_JUICE_ADDRESS)) || contractAddress.equals(AztecAddress.fromNumber(ROUTER_ADDRESS));