@aztec/simulator 0.82.0 → 0.82.1

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 (71) hide show
  1. package/dest/common/debug_fn_name.js +5 -2
  2. package/dest/private/acvm/oracle/oracle.d.ts +3 -3
  3. package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
  4. package/dest/private/acvm/oracle/oracle.js +9 -15
  5. package/dest/private/acvm/oracle/typed_oracle.d.ts +3 -3
  6. package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
  7. package/dest/private/acvm/oracle/typed_oracle.js +6 -6
  8. package/dest/private/hashed_values_cache.d.ts +2 -2
  9. package/dest/private/hashed_values_cache.d.ts.map +1 -1
  10. package/dest/private/hashed_values_cache.js +5 -15
  11. package/dest/private/private_execution.d.ts.map +1 -1
  12. package/dest/private/private_execution.js +1 -3
  13. package/dest/private/private_execution_oracle.d.ts +9 -37
  14. package/dest/private/private_execution_oracle.d.ts.map +1 -1
  15. package/dest/private/private_execution_oracle.js +32 -92
  16. package/dest/private/simulator.d.ts.map +1 -1
  17. package/dest/private/simulator.js +12 -2
  18. package/dest/public/avm/fixtures/avm_simulation_tester.js +2 -2
  19. package/dest/public/avm/fixtures/index.d.ts +2 -1
  20. package/dest/public/avm/fixtures/index.d.ts.map +1 -1
  21. package/dest/public/avm/fixtures/index.js +7 -12
  22. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +2 -2
  23. package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -1
  24. package/dest/public/avm/fixtures/simple_contract_data_source.js +1 -1
  25. package/dest/public/avm/journal/journal.d.ts +2 -2
  26. package/dest/public/avm/journal/journal.d.ts.map +1 -1
  27. package/dest/public/avm/journal/journal.js +3 -3
  28. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +2 -2
  29. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  30. package/dest/public/fixtures/public_tx_simulation_tester.js +27 -47
  31. package/dest/public/fixtures/utils.d.ts +2 -2
  32. package/dest/public/fixtures/utils.d.ts.map +1 -1
  33. package/dest/public/fixtures/utils.js +18 -22
  34. package/dest/public/index.d.ts +1 -2
  35. package/dest/public/index.d.ts.map +1 -1
  36. package/dest/public/index.js +1 -1
  37. package/dest/public/public_db_sources.js +1 -1
  38. package/dest/public/public_processor/public_processor.js +1 -1
  39. package/dest/public/public_tx_simulator/public_tx_context.d.ts +3 -10
  40. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  41. package/dest/public/public_tx_simulator/public_tx_context.js +4 -22
  42. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +2 -3
  43. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  44. package/dest/public/public_tx_simulator/public_tx_simulator.js +20 -24
  45. package/dest/public/utils.d.ts +2 -4
  46. package/dest/public/utils.d.ts.map +1 -1
  47. package/dest/public/utils.js +4 -21
  48. package/package.json +14 -14
  49. package/src/common/debug_fn_name.ts +5 -5
  50. package/src/private/acvm/oracle/oracle.ts +13 -17
  51. package/src/private/acvm/oracle/typed_oracle.ts +10 -12
  52. package/src/private/hashed_values_cache.ts +6 -14
  53. package/src/private/private_execution.ts +0 -4
  54. package/src/private/private_execution_oracle.ts +39 -138
  55. package/src/private/simulator.ts +14 -2
  56. package/src/public/avm/fixtures/avm_simulation_tester.ts +2 -2
  57. package/src/public/avm/fixtures/index.ts +15 -17
  58. package/src/public/avm/fixtures/simple_contract_data_source.ts +2 -2
  59. package/src/public/avm/journal/journal.ts +6 -6
  60. package/src/public/fixtures/public_tx_simulation_tester.ts +31 -88
  61. package/src/public/fixtures/utils.ts +28 -26
  62. package/src/public/index.ts +1 -2
  63. package/src/public/public_db_sources.ts +1 -1
  64. package/src/public/public_processor/public_processor.ts +1 -1
  65. package/src/public/public_tx_simulator/public_tx_context.ts +12 -32
  66. package/src/public/public_tx_simulator/public_tx_simulator.ts +24 -30
  67. package/src/public/utils.ts +5 -21
  68. package/dest/public/execution.d.ts +0 -108
  69. package/dest/public/execution.d.ts.map +0 -1
  70. package/dest/public/execution.js +0 -9
  71. package/src/public/execution.ts +0 -140
@@ -14,7 +14,7 @@ import { inspect } from 'util';
14
14
  import { AvmPersistableStateManager } from '../avm/index.js';
15
15
  import { HintingPublicContractsDB } from '../hinting_db_sources.js';
16
16
  import { SideEffectArrayLengths, SideEffectTrace } from '../side_effect_trace.js';
17
- import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js';
17
+ import { getCallRequestsWithCalldataByPhase } from '../utils.js';
18
18
  /**
19
19
  * The transaction-level context for public execution.
20
20
  */ export class PublicTxContext {
@@ -28,9 +28,6 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
28
28
  setupCallRequests;
29
29
  appLogicCallRequests;
30
30
  teardownCallRequests;
31
- setupExecutionRequests;
32
- appLogicExecutionRequests;
33
- teardownExecutionRequests;
34
31
  nonRevertibleAccumulatedDataFromPrivate;
35
32
  revertibleAccumulatedDataFromPrivate;
36
33
  feePayer;
@@ -42,7 +39,7 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
42
39
  /* Entire transaction execution is done. */ halted;
43
40
  /* Where did reverts happen (if at all)? */ revertCode;
44
41
  /* What caused a revert (if one occurred)? */ revertReason;
45
- constructor(txHash, state, globalVariables, startStateReference, gasSettings, gasUsedByPrivate, gasAllocatedToPublic, setupCallRequests, appLogicCallRequests, teardownCallRequests, setupExecutionRequests, appLogicExecutionRequests, teardownExecutionRequests, nonRevertibleAccumulatedDataFromPrivate, revertibleAccumulatedDataFromPrivate, feePayer, trace, hints){
42
+ constructor(txHash, state, globalVariables, startStateReference, gasSettings, gasUsedByPrivate, gasAllocatedToPublic, setupCallRequests, appLogicCallRequests, teardownCallRequests, nonRevertibleAccumulatedDataFromPrivate, revertibleAccumulatedDataFromPrivate, feePayer, trace, hints){
46
43
  this.txHash = txHash;
47
44
  this.state = state;
48
45
  this.globalVariables = globalVariables;
@@ -53,9 +50,6 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
53
50
  this.setupCallRequests = setupCallRequests;
54
51
  this.appLogicCallRequests = appLogicCallRequests;
55
52
  this.teardownCallRequests = teardownCallRequests;
56
- this.setupExecutionRequests = setupExecutionRequests;
57
- this.appLogicExecutionRequests = appLogicExecutionRequests;
58
- this.teardownExecutionRequests = teardownExecutionRequests;
59
53
  this.nonRevertibleAccumulatedDataFromPrivate = nonRevertibleAccumulatedDataFromPrivate;
60
54
  this.revertibleAccumulatedDataFromPrivate = revertibleAccumulatedDataFromPrivate;
61
55
  this.feePayer = feePayer;
@@ -82,7 +76,7 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
82
76
  const gasUsedByPrivate = tx.data.gasUsed;
83
77
  // Gas allocated to public is "whatever's left" after private, but with some max applied.
84
78
  const gasAllocatedToPublic = applyMaxToAvailableGas(gasSettings.gasLimits.sub(gasUsedByPrivate));
85
- return new PublicTxContext(await tx.getTxHash(), new PhaseStateManager(txStateManager), globalVariables, await treesDB.getStateReference(), gasSettings, gasUsedByPrivate, gasAllocatedToPublic, getCallRequestsByPhase(tx, TxExecutionPhase.SETUP), getCallRequestsByPhase(tx, TxExecutionPhase.APP_LOGIC), getCallRequestsByPhase(tx, TxExecutionPhase.TEARDOWN), getExecutionRequestsByPhase(tx, TxExecutionPhase.SETUP), getExecutionRequestsByPhase(tx, TxExecutionPhase.APP_LOGIC), getExecutionRequestsByPhase(tx, TxExecutionPhase.TEARDOWN), tx.data.forPublic.nonRevertibleAccumulatedData, tx.data.forPublic.revertibleAccumulatedData, tx.data.feePayer, trace, hints);
79
+ 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);
86
80
  }
87
81
  /**
88
82
  * Signal that the entire transaction execution is done.
@@ -154,18 +148,6 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
154
148
  }
155
149
  }
156
150
  /**
157
- * Get the call requests for the specified phase (including actual args).
158
- */ getExecutionRequestsForPhase(phase) {
159
- switch(phase){
160
- case TxExecutionPhase.SETUP:
161
- return this.setupExecutionRequests;
162
- case TxExecutionPhase.APP_LOGIC:
163
- return this.appLogicExecutionRequests;
164
- case TxExecutionPhase.TEARDOWN:
165
- return this.teardownExecutionRequests;
166
- }
167
- }
168
- /**
169
151
  * How much gas is left as of the specified phase?
170
152
  */ getGasLeftAtPhase(phase) {
171
153
  if (phase === TxExecutionPhase.TEARDOWN) {
@@ -239,7 +221,7 @@ import { getCallRequestsByPhase, getExecutionRequestsByPhase } from '../utils.js
239
221
  const startTreeSnapshots = new TreeSnapshots(this.startStateReference.l1ToL2MessageTree, this.startStateReference.partial.noteHashTree, this.startStateReference.partial.nullifierTree, this.startStateReference.partial.publicDataTree);
240
222
  // Will be patched/padded at the end of this fn
241
223
  const endTreeSnapshots = new TreeSnapshots(endStateReference.l1ToL2MessageTree, endStateReference.partial.noteHashTree, endStateReference.partial.nullifierTree, endStateReference.partial.publicDataTree);
242
- const avmCircuitPublicInputs = this.trace.toAvmCircuitPublicInputs(this.globalVariables, startTreeSnapshots, /*startGasUsed=*/ this.gasUsedByPrivate, this.gasSettings, this.feePayer, this.setupCallRequests, this.appLogicCallRequests, /*teardownCallRequest=*/ this.teardownCallRequests.length ? this.teardownCallRequests[0] : PublicCallRequest.empty(), endTreeSnapshots, /*endGasUsed=*/ this.getTotalGasUsed(), /*transactionFee=*/ this.getTransactionFeeUnsafe(), /*reverted=*/ !this.revertCode.isOK());
224
+ 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, /*endGasUsed=*/ this.getTotalGasUsed(), /*transactionFee=*/ this.getTransactionFeeUnsafe(), /*reverted=*/ !this.revertCode.isOK());
243
225
  const getArrayLengths = (from)=>new PrivateToAvmAccumulatedDataArrayLengths(countAccumulatedItems(from.noteHashes), countAccumulatedItems(from.nullifiers), countAccumulatedItems(from.l2ToL1Msgs));
244
226
  const convertAccumulatedData = (from)=>new PrivateToAvmAccumulatedData(from.noteHashes, from.nullifiers, from.l2ToL1Msgs);
245
227
  // Temporary overrides as these entries aren't yet populated in trace
@@ -67,8 +67,7 @@ export declare class PublicTxSimulator {
67
67
  * Simulate an enqueued public call.
68
68
  * @param phase - The current phase of public execution
69
69
  * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
70
- * @param callRequest - The enqueued call to execute
71
- * @param executionRequest - The execution request (includes args)
70
+ * @param callRequest - The public function call request, including the calldata.
72
71
  * @returns The result of execution.
73
72
  */
74
73
  private simulateEnqueuedCall;
@@ -81,7 +80,7 @@ export declare class PublicTxSimulator {
81
80
  *
82
81
  * @param stateManager - The state manager for AvmSimulation
83
82
  * @param context - The context of the currently executing public transaction portion
84
- * @param executionRequest - The execution request (includes args)
83
+ * @param callRequest - The public function call request, including the calldata.
85
84
  * @param allocatedGas - The gas allocated to the enqueued call
86
85
  * @param fnName - The name of the function
87
86
  * @returns The result of execution.
@@ -1 +1 @@
1
- {"version":3,"file":"public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_simulator.ts"],"names":[],"mappings":"AAKA,OAAO,EAKL,KAAK,iBAAiB,EACtB,KAAK,UAAU,EAChB,MAAM,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E,OAAe,EACnC,kBAAkB,GAAE,OAAe,EAC3C,eAAe,GAAE,eAAsC;IAMzD,IAAI,MAAM,IAAI,MAAM,CAEnB;IACD;;;;OAIG;IACU,QAAQ,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAyFtD;;;;OAIG;YACW,kBAAkB;IAIhC;;;;OAIG;YACW,qBAAqB;IAkBnC;;;;OAIG;YACW,qBAAqB;IAoBnC;;;;;OAKG;YACW,aAAa;IA0C3B;;;;;;;OAOG;YAOW,oBAAoB;IA+ClC;;;;;;;;;;;;;OAaG;YAOW,4BAA4B;IAgD1C;;OAEG;IACU,+BAA+B,CAAC,OAAO,EAAE,eAAe;IAkBrE;;;OAGG;IACU,4BAA4B,CAAC,OAAO,EAAE,eAAe,GAAgB,OAAO,CAAC,OAAO,CAAC;YA+BpF,MAAM;IAgCpB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;CAStC"}
1
+ {"version":3,"file":"public_tx_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/public_tx_simulator/public_tx_simulator.ts"],"names":[],"mappings":"AAKA,OAAO,EAKL,KAAK,iBAAiB,EACtB,KAAK,UAAU,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAO,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EACL,KAAK,eAAe,EACpB,yBAAyB,EAEzB,EAAE,EACF,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAc,KAAK,eAAe,EAAE,KAAK,MAAM,EAAiC,MAAM,yBAAyB,CAAC;AAQvH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEz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O,EAAE,eAAe,GAAgB,OAAO,CAAC,OAAO,CAAC;YA+BpF,MAAM;IAgCpB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;CAStC"}
@@ -47,7 +47,7 @@ export class PublicTxSimulator {
47
47
  try {
48
48
  const startTime = process.hrtime.bigint();
49
49
  const txHash = await tx.getTxHash();
50
- this.log.debug(`Simulating ${tx.enqueuedPublicFunctionCalls.length} public calls for tx ${txHash}`, {
50
+ this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, {
51
51
  txHash
52
52
  });
53
53
  const context = await PublicTxContext.create(this.treesDB, this.contractsDB, tx, this.globalVariables, this.doMerkleOperations);
@@ -166,12 +166,10 @@ export class PublicTxSimulator {
166
166
  * @returns The phase result.
167
167
  */ async simulatePhase(phase, context) {
168
168
  const callRequests = context.getCallRequestsForPhase(phase);
169
- const executionRequests = context.getExecutionRequestsForPhase(phase);
170
169
  this.log.debug(`Processing phase ${TxExecutionPhase[phase]} for tx ${context.txHash}`, {
171
170
  txHash: context.txHash.toString(),
172
171
  phase: TxExecutionPhase[phase],
173
- callRequests: callRequests.length,
174
- executionRequests: executionRequests.length
172
+ callRequests: callRequests.length
175
173
  });
176
174
  const returnValues = [];
177
175
  let reverted = false;
@@ -182,8 +180,7 @@ export class PublicTxSimulator {
182
180
  break;
183
181
  }
184
182
  const callRequest = callRequests[i];
185
- const executionRequest = executionRequests[i];
186
- const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest, executionRequest);
183
+ const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest);
187
184
  returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output));
188
185
  if (enqueuedCallResult.reverted) {
189
186
  reverted = true;
@@ -202,25 +199,24 @@ export class PublicTxSimulator {
202
199
  * Simulate an enqueued public call.
203
200
  * @param phase - The current phase of public execution
204
201
  * @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
205
- * @param callRequest - The enqueued call to execute
206
- * @param executionRequest - The execution request (includes args)
202
+ * @param callRequest - The public function call request, including the calldata.
207
203
  * @returns The result of execution.
208
- */ async simulateEnqueuedCall(phase, context, callRequest, executionRequest) {
204
+ */ async simulateEnqueuedCall(phase, context, callRequest) {
209
205
  const stateManager = context.state.getActiveStateManager();
210
- const address = executionRequest.callContext.contractAddress;
211
- const fnName = await getPublicFunctionDebugName(this.contractsDB, address, executionRequest.args);
206
+ const contractAddress = callRequest.request.contractAddress;
207
+ const fnName = await getPublicFunctionDebugName(this.contractsDB, contractAddress, callRequest.calldata);
212
208
  const allocatedGas = context.getGasLeftAtPhase(phase);
213
209
  // The reason we need enqueued hints at all (and cannot just use the public inputs) is
214
210
  // because they don't have the actual calldata, just the hash of it.
215
211
  // If/when we pass the whole TX to C++, we can remove this class of hints.
216
- stateManager.traceEnqueuedCall(callRequest);
217
- context.hints.enqueuedCalls.push(new AvmEnqueuedCallHint(executionRequest.callContext.msgSender, executionRequest.callContext.contractAddress, executionRequest.args, executionRequest.callContext.isStaticCall));
218
- const result = await this.simulateEnqueuedCallInternal(context.state.getActiveStateManager(), executionRequest, allocatedGas, /*transactionFee=*/ context.getTransactionFee(phase), fnName);
212
+ stateManager.traceEnqueuedCall(callRequest.request);
213
+ context.hints.enqueuedCalls.push(new AvmEnqueuedCallHint(callRequest.request.msgSender, contractAddress, callRequest.calldata, callRequest.request.isStaticCall));
214
+ const result = await this.simulateEnqueuedCallInternal(context.state.getActiveStateManager(), callRequest, allocatedGas, /*transactionFee=*/ context.getTransactionFee(phase), fnName);
219
215
  const gasUsed = allocatedGas.sub(result.gasLeft); // by enqueued call
220
216
  context.consumeGas(phase, gasUsed);
221
217
  this.log.debug(`Simulated enqueued public call (${fnName}) consumed ${gasUsed.l2Gas} L2 gas ending with ${result.gasLeft.l2Gas} L2 gas left.`);
222
218
  if (result.reverted) {
223
- const culprit = `${executionRequest.callContext.contractAddress}:${executionRequest.callContext.functionSelector}`;
219
+ const culprit = `${contractAddress}:${callRequest.functionSelector}`;
224
220
  context.revert(phase, result.revertReason, culprit); // throws if in setup (non-revertible) phase
225
221
  }
226
222
  return result;
@@ -234,16 +230,16 @@ export class PublicTxSimulator {
234
230
  *
235
231
  * @param stateManager - The state manager for AvmSimulation
236
232
  * @param context - The context of the currently executing public transaction portion
237
- * @param executionRequest - The execution request (includes args)
233
+ * @param callRequest - The public function call request, including the calldata.
238
234
  * @param allocatedGas - The gas allocated to the enqueued call
239
235
  * @param fnName - The name of the function
240
236
  * @returns The result of execution.
241
- */ async simulateEnqueuedCallInternal(stateManager, executionRequest, allocatedGas, transactionFee, fnName) {
242
- const address = executionRequest.callContext.contractAddress;
243
- const sender = executionRequest.callContext.msgSender;
237
+ */ async simulateEnqueuedCallInternal(stateManager, { request, calldata }, allocatedGas, transactionFee, fnName) {
238
+ const address = request.contractAddress;
239
+ const sender = request.msgSender;
244
240
  this.log.debug(`Executing enqueued public call to external function ${fnName}@${address} with ${allocatedGas.l2Gas} allocated L2 gas.`);
245
241
  const timer = new Timer();
246
- const simulator = await AvmSimulator.create(stateManager, address, sender, transactionFee, this.globalVariables, executionRequest.callContext.isStaticCall, executionRequest.args, allocatedGas);
242
+ const simulator = await AvmSimulator.create(stateManager, address, sender, transactionFee, this.globalVariables, request.isStaticCall, calldata, allocatedGas);
247
243
  const avmCallResult = await simulator.execute();
248
244
  const result = avmCallResult.finalize();
249
245
  this.log.verbose(result.reverted ? `Simulation of enqueued public call ${fnName} reverted with reason ${result.revertReason}.` : `Simulation of enqueued public call ${fnName} completed successfully.`, {
@@ -334,15 +330,15 @@ export class PublicTxSimulator {
334
330
  }
335
331
  }
336
332
  _ts_decorate([
337
- trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context, _callRequest, executionRequest)=>({
333
+ trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context, callRequest)=>({
338
334
  [Attributes.TX_HASH]: context.txHash.toString(),
339
- [Attributes.TARGET_ADDRESS]: executionRequest.callContext.contractAddress.toString(),
340
- [Attributes.SENDER_ADDRESS]: executionRequest.callContext.msgSender.toString(),
335
+ [Attributes.TARGET_ADDRESS]: callRequest.request.contractAddress.toString(),
336
+ [Attributes.SENDER_ADDRESS]: callRequest.request.msgSender.toString(),
341
337
  [Attributes.SIMULATOR_PHASE]: TxExecutionPhase[phase].toString()
342
338
  }))
343
339
  ], PublicTxSimulator.prototype, "simulateEnqueuedCall", null);
344
340
  _ts_decorate([
345
- trackSpan('PublicTxSimulator.simulateEnqueuedCallInternal', (_stateManager, _executionRequest, _allocatedGas, _transactionFee, fnName)=>({
341
+ trackSpan('PublicTxSimulator.simulateEnqueuedCallInternal', (_stateManager, _callRequest, _allocatedGas, _transactionFee, fnName)=>({
346
342
  [Attributes.APP_CIRCUIT_NAME]: fnName
347
343
  }))
348
344
  ], PublicTxSimulator.prototype, "simulateEnqueuedCallInternal", null);
@@ -1,5 +1,3 @@
1
- import type { PublicCallRequest } from '@aztec/stdlib/kernel';
2
- import { type PublicExecutionRequest, type Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
3
- export declare function getExecutionRequestsByPhase(tx: Tx, phase: TxExecutionPhase): PublicExecutionRequest[];
4
- export declare function getCallRequestsByPhase(tx: Tx, phase: TxExecutionPhase): PublicCallRequest[];
1
+ import { PublicCallRequestWithCalldata, type Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
2
+ export declare function getCallRequestsWithCalldataByPhase(tx: Tx, phase: TxExecutionPhase): PublicCallRequestWithCalldata[];
5
3
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/public/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,KAAK,sBAAsB,EAAE,KAAK,EAAE,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE1F,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,gBAAgB,GAAG,sBAAsB,EAAE,CAarG;AAED,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,gBAAgB,GAAG,iBAAiB,EAAE,CAa3F"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/public/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,KAAK,EAAE,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE5F,wBAAgB,kCAAkC,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,gBAAgB,GAAG,6BAA6B,EAAE,CAanH"}
@@ -1,30 +1,13 @@
1
1
  import { TxExecutionPhase } from '@aztec/stdlib/tx';
2
- export function getExecutionRequestsByPhase(tx, phase) {
2
+ export function getCallRequestsWithCalldataByPhase(tx, phase) {
3
3
  switch(phase){
4
4
  case TxExecutionPhase.SETUP:
5
- return tx.getNonRevertiblePublicExecutionRequests();
5
+ return tx.getNonRevertiblePublicCallRequestsWithCalldata();
6
6
  case TxExecutionPhase.APP_LOGIC:
7
- return tx.getRevertiblePublicExecutionRequests();
7
+ return tx.getRevertiblePublicCallRequestsWithCalldata();
8
8
  case TxExecutionPhase.TEARDOWN:
9
9
  {
10
- const request = tx.getPublicTeardownExecutionRequest();
11
- return request ? [
12
- request
13
- ] : [];
14
- }
15
- default:
16
- throw new Error(`Unknown phase: ${phase}`);
17
- }
18
- }
19
- export function getCallRequestsByPhase(tx, phase) {
20
- switch(phase){
21
- case TxExecutionPhase.SETUP:
22
- return tx.data.getNonRevertiblePublicCallRequests();
23
- case TxExecutionPhase.APP_LOGIC:
24
- return tx.data.getRevertiblePublicCallRequests();
25
- case TxExecutionPhase.TEARDOWN:
26
- {
27
- const request = tx.data.getTeardownPublicCallRequest();
10
+ const request = tx.getTeardownPublicCallRequestWithCalldata();
28
11
  return request ? [
29
12
  request
30
13
  ] : [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/simulator",
3
- "version": "0.82.0",
3
+ "version": "0.82.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./server": "./dest/server.js",
@@ -60,16 +60,16 @@
60
60
  ]
61
61
  },
62
62
  "dependencies": {
63
- "@aztec/constants": "0.82.0",
64
- "@aztec/foundation": "0.82.0",
65
- "@aztec/noir-acvm_js": "0.82.0",
66
- "@aztec/noir-noirc_abi": "0.82.0",
67
- "@aztec/noir-protocol-circuits-types": "0.82.0",
68
- "@aztec/noir-types": "0.82.0",
69
- "@aztec/protocol-contracts": "0.82.0",
70
- "@aztec/stdlib": "0.82.0",
71
- "@aztec/telemetry-client": "0.82.0",
72
- "@aztec/world-state": "0.82.0",
63
+ "@aztec/constants": "0.82.1",
64
+ "@aztec/foundation": "0.82.1",
65
+ "@aztec/noir-acvm_js": "0.82.1",
66
+ "@aztec/noir-noirc_abi": "0.82.1",
67
+ "@aztec/noir-protocol-circuits-types": "0.82.1",
68
+ "@aztec/noir-types": "0.82.1",
69
+ "@aztec/protocol-contracts": "0.82.1",
70
+ "@aztec/stdlib": "0.82.1",
71
+ "@aztec/telemetry-client": "0.82.1",
72
+ "@aztec/world-state": "0.82.1",
73
73
  "levelup": "^5.1.1",
74
74
  "lodash.clonedeep": "^4.5.0",
75
75
  "lodash.merge": "^4.6.2",
@@ -77,9 +77,9 @@
77
77
  "tslib": "^2.4.0"
78
78
  },
79
79
  "devDependencies": {
80
- "@aztec/kv-store": "0.82.0",
81
- "@aztec/merkle-tree": "0.82.0",
82
- "@aztec/noir-contracts.js": "0.82.0",
80
+ "@aztec/kv-store": "0.82.1",
81
+ "@aztec/merkle-tree": "0.82.1",
82
+ "@aztec/noir-contracts.js": "0.82.1",
83
83
  "@jest/globals": "^29.5.0",
84
84
  "@types/jest": "^29.5.0",
85
85
  "@types/levelup": "^5.1.3",
@@ -10,9 +10,9 @@ export async function getPublicFunctionDebugName(
10
10
  calldata: Fr[],
11
11
  ): Promise<string> {
12
12
  // Public function is dispatched and therefore the target function is passed in the first argument.
13
- const targetFunction =
14
- calldata[0] !== undefined
15
- ? await db.getDebugFunctionName(contractAddress, FunctionSelector.fromField(calldata[0]))
16
- : `<calldata[0] undefined> (Contract Address: ${contractAddress})`;
17
- return `${targetFunction}`;
13
+ if (!calldata[0]) {
14
+ return `<calldata[0] undefined> (Contract Address: ${contractAddress})`;
15
+ }
16
+ const selector = FunctionSelector.fromField(calldata[0]);
17
+ return (await db.getDebugFunctionName(contractAddress, selector)) ?? selector.toString();
18
18
  }
@@ -21,9 +21,9 @@ export class Oracle {
21
21
  }
22
22
 
23
23
  // Since the argument is a slice, noir automatically adds a length field to oracle call.
24
- async storeInExecutionCache(_length: ACVMField[], values: ACVMField[]): Promise<ACVMField[]> {
25
- const hash = await this.typedOracle.storeInExecutionCache(values.map(Fr.fromString));
26
- return [toACVMField(hash)];
24
+ storeInExecutionCache(_length: ACVMField[], values: ACVMField[], [hash]: ACVMField[]): Promise<ACVMField[]> {
25
+ this.typedOracle.storeInExecutionCache(values.map(Fr.fromString), Fr.fromString(hash));
26
+ return Promise.resolve([]);
27
27
  }
28
28
 
29
29
  async loadFromExecutionCache([returnsHash]: ACVMField[]): Promise<ACVMField[][]> {
@@ -320,38 +320,34 @@ export class Oracle {
320
320
  return [[endSideEffectCounter, returnsHash].map(toACVMField)];
321
321
  }
322
322
 
323
- async enqueuePublicFunctionCall(
323
+ async notifyEnqueuedPublicFunctionCall(
324
324
  [contractAddress]: ACVMField[],
325
- [functionSelector]: ACVMField[],
326
- [argsHash]: ACVMField[],
325
+ [calldataHash]: ACVMField[],
327
326
  [sideEffectCounter]: ACVMField[],
328
327
  [isStaticCall]: ACVMField[],
329
328
  ): Promise<ACVMField[]> {
330
- const newArgsHash = await this.typedOracle.enqueuePublicFunctionCall(
329
+ await this.typedOracle.notifyEnqueuedPublicFunctionCall(
331
330
  AztecAddress.fromString(contractAddress),
332
- FunctionSelector.fromField(Fr.fromString(functionSelector)),
333
- Fr.fromString(argsHash),
331
+ Fr.fromString(calldataHash),
334
332
  Fr.fromString(sideEffectCounter).toNumber(),
335
333
  Fr.fromString(isStaticCall).toBool(),
336
334
  );
337
- return [toACVMField(newArgsHash)];
335
+ return [];
338
336
  }
339
337
 
340
- async setPublicTeardownFunctionCall(
338
+ async notifySetPublicTeardownFunctionCall(
341
339
  [contractAddress]: ACVMField[],
342
- [functionSelector]: ACVMField[],
343
- [argsHash]: ACVMField[],
340
+ [calldataHash]: ACVMField[],
344
341
  [sideEffectCounter]: ACVMField[],
345
342
  [isStaticCall]: ACVMField[],
346
343
  ): Promise<ACVMField[]> {
347
- const newArgsHash = await this.typedOracle.setPublicTeardownFunctionCall(
344
+ await this.typedOracle.notifySetPublicTeardownFunctionCall(
348
345
  AztecAddress.fromString(contractAddress),
349
- FunctionSelector.fromField(Fr.fromString(functionSelector)),
350
- Fr.fromString(argsHash),
346
+ Fr.fromString(calldataHash),
351
347
  Fr.fromString(sideEffectCounter).toNumber(),
352
348
  Fr.fromString(isStaticCall).toBool(),
353
349
  );
354
- return [toACVMField(newArgsHash)];
350
+ return [];
355
351
  }
356
352
 
357
353
  notifySetMinRevertibleSideEffectCounter([minRevertibleSideEffectCounter]: ACVMField[]): Promise<ACVMField[]> {
@@ -47,8 +47,8 @@ export abstract class TypedOracle {
47
47
  return Fr.random();
48
48
  }
49
49
 
50
- storeInExecutionCache(_values: Fr[]): Promise<Fr> {
51
- return Promise.reject(new OracleMethodNotAvailableError('storeInExecutionCache'));
50
+ storeInExecutionCache(_values: Fr[], _hash: Fr): void {
51
+ throw new OracleMethodNotAvailableError('storeInExecutionCache');
52
52
  }
53
53
 
54
54
  loadFromExecutionCache(_hash: Fr): Promise<Fr[]> {
@@ -180,24 +180,22 @@ export abstract class TypedOracle {
180
180
  return Promise.reject(new OracleMethodNotAvailableError('callPrivateFunction'));
181
181
  }
182
182
 
183
- enqueuePublicFunctionCall(
183
+ notifyEnqueuedPublicFunctionCall(
184
184
  _targetContractAddress: AztecAddress,
185
- _functionSelector: FunctionSelector,
186
- _argsHash: Fr,
185
+ _calldataHash: Fr,
187
186
  _sideEffectCounter: number,
188
187
  _isStaticCall: boolean,
189
- ): Promise<Fr> {
190
- return Promise.reject(new OracleMethodNotAvailableError('enqueuePublicFunctionCall'));
188
+ ): Promise<void> {
189
+ return Promise.reject(new OracleMethodNotAvailableError('notifyEnqueuedPublicFunctionCall'));
191
190
  }
192
191
 
193
- setPublicTeardownFunctionCall(
192
+ notifySetPublicTeardownFunctionCall(
194
193
  _targetContractAddress: AztecAddress,
195
- _functionSelector: FunctionSelector,
196
- _argsHash: Fr,
194
+ _calldataHash: Fr,
197
195
  _sideEffectCounter: number,
198
196
  _isStaticCall: boolean,
199
- ): Promise<Fr> {
200
- return Promise.reject(new OracleMethodNotAvailableError('setPublicTeardownFunctionCall'));
197
+ ): Promise<void> {
198
+ return Promise.reject(new OracleMethodNotAvailableError('notifySetPublicTeardownFunctionCall'));
201
199
  }
202
200
 
203
201
  notifySetMinRevertibleSideEffectCounter(_minRevertibleSideEffectCounter: number): void {
@@ -28,15 +28,12 @@ export class HashedValuesCache {
28
28
  * @param hash - The hash to get the preimage of.
29
29
  * @returns The preimage.
30
30
  */
31
- public getPreimage(hash: Fr): Fr[] {
32
- if (hash.equals(Fr.ZERO)) {
31
+ public getPreimage(hash: Fr): Fr[] | undefined {
32
+ if (hash.isEmpty()) {
33
33
  return [];
34
+ } else {
35
+ return this.cache.get(hash.toBigInt());
34
36
  }
35
- const hashedValues = this.cache.get(hash.toBigInt());
36
- if (!hashedValues) {
37
- throw new Error(`Preimage for hash ${hash.toString()} not found in cache`);
38
- }
39
- return hashedValues;
40
37
  }
41
38
 
42
39
  /**
@@ -44,12 +41,7 @@ export class HashedValuesCache {
44
41
  * @param values - The values to store.
45
42
  * @returns The hash of the values.
46
43
  */
47
- public async store(values: Fr[]) {
48
- if (values.length === 0) {
49
- return Fr.ZERO;
50
- }
51
- const hashedValues = await HashedValues.fromValues(values);
52
- this.cache.set(hashedValues.hash.toBigInt(), hashedValues.values);
53
- return hashedValues.hash;
44
+ public store(values: Fr[], hash: Fr) {
45
+ this.cache.set(hash.toBigInt(), values);
54
46
  }
55
47
  }
@@ -77,8 +77,6 @@ export async function executePrivateFunction(
77
77
  const newNotes = privateExecutionOracle.getNewNotes();
78
78
  const noteHashNullifierCounterMap = privateExecutionOracle.getNoteHashNullifierCounterMap();
79
79
  const nestedExecutions = privateExecutionOracle.getNestedExecutions();
80
- const enqueuedPublicFunctionCalls = privateExecutionOracle.getEnqueuedPublicFunctionCalls();
81
- const publicTeardownFunctionCall = privateExecutionOracle.getPublicTeardownFunctionCall();
82
80
 
83
81
  log.debug(`Returning from call to ${contractAddress.toString()}:${functionSelector}`);
84
82
 
@@ -92,8 +90,6 @@ export async function executePrivateFunction(
92
90
  noteHashNullifierCounterMap,
93
91
  rawReturnValues,
94
92
  nestedExecutions,
95
- enqueuedPublicFunctionCalls,
96
- publicTeardownFunctionCall,
97
93
  contractClassLogs,
98
94
  );
99
95
  }