@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.
- package/dest/common/debug_fn_name.js +5 -2
- package/dest/private/acvm/oracle/oracle.d.ts +3 -3
- package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.js +9 -15
- package/dest/private/acvm/oracle/typed_oracle.d.ts +3 -3
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/typed_oracle.js +6 -6
- package/dest/private/hashed_values_cache.d.ts +2 -2
- package/dest/private/hashed_values_cache.d.ts.map +1 -1
- package/dest/private/hashed_values_cache.js +5 -15
- package/dest/private/private_execution.d.ts.map +1 -1
- package/dest/private/private_execution.js +1 -3
- package/dest/private/private_execution_oracle.d.ts +9 -37
- package/dest/private/private_execution_oracle.d.ts.map +1 -1
- package/dest/private/private_execution_oracle.js +32 -92
- package/dest/private/simulator.d.ts.map +1 -1
- package/dest/private/simulator.js +12 -2
- package/dest/public/avm/fixtures/avm_simulation_tester.js +2 -2
- package/dest/public/avm/fixtures/index.d.ts +2 -1
- package/dest/public/avm/fixtures/index.d.ts.map +1 -1
- package/dest/public/avm/fixtures/index.js +7 -12
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +2 -2
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/avm/fixtures/simple_contract_data_source.js +1 -1
- package/dest/public/avm/journal/journal.d.ts +2 -2
- package/dest/public/avm/journal/journal.d.ts.map +1 -1
- package/dest/public/avm/journal/journal.js +3 -3
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +2 -2
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +27 -47
- package/dest/public/fixtures/utils.d.ts +2 -2
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +18 -22
- package/dest/public/index.d.ts +1 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_db_sources.js +1 -1
- package/dest/public/public_processor/public_processor.js +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +3 -10
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +4 -22
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +2 -3
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +20 -24
- package/dest/public/utils.d.ts +2 -4
- package/dest/public/utils.d.ts.map +1 -1
- package/dest/public/utils.js +4 -21
- package/package.json +14 -14
- package/src/common/debug_fn_name.ts +5 -5
- package/src/private/acvm/oracle/oracle.ts +13 -17
- package/src/private/acvm/oracle/typed_oracle.ts +10 -12
- package/src/private/hashed_values_cache.ts +6 -14
- package/src/private/private_execution.ts +0 -4
- package/src/private/private_execution_oracle.ts +39 -138
- package/src/private/simulator.ts +14 -2
- package/src/public/avm/fixtures/avm_simulation_tester.ts +2 -2
- package/src/public/avm/fixtures/index.ts +15 -17
- package/src/public/avm/fixtures/simple_contract_data_source.ts +2 -2
- package/src/public/avm/journal/journal.ts +6 -6
- package/src/public/fixtures/public_tx_simulation_tester.ts +31 -88
- package/src/public/fixtures/utils.ts +28 -26
- package/src/public/index.ts +1 -2
- package/src/public/public_db_sources.ts +1 -1
- package/src/public/public_processor/public_processor.ts +1 -1
- package/src/public/public_tx_simulator/public_tx_context.ts +12 -32
- package/src/public/public_tx_simulator/public_tx_simulator.ts +24 -30
- package/src/public/utils.ts +5 -21
- package/dest/public/execution.d.ts +0 -108
- package/dest/public/execution.d.ts.map +0 -1
- package/dest/public/execution.js +0 -9
- 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 {
|
|
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,
|
|
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,
|
|
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
|
|
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
|
|
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,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAO,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
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;AAEzD,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,gBAAgB,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,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,CAAC,EAAE,eAAe,CAAC;IAC/B,eAAe,EAAE,cAAc,EAAE,CAAC;CACnC,CAAC;AAEF,qBAAa,iBAAiB;IAM1B,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,kBAAkB;IAT5B,OAAO,EAAE,eAAe,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAS;gBAGV,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,iBAAiB,EAC9B,eAAe,EAAE,eAAe,EAChC,kBAAkB,GAAE,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;IAuC3B;;;;;;OAMG;YAOW,oBAAoB;IA8ClC;;;;;;;;;;;;;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"}
|
|
@@ -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.
|
|
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
|
|
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
|
|
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
|
|
204
|
+
*/ async simulateEnqueuedCall(phase, context, callRequest) {
|
|
209
205
|
const stateManager = context.state.getActiveStateManager();
|
|
210
|
-
const
|
|
211
|
-
const fnName = await getPublicFunctionDebugName(this.contractsDB,
|
|
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(
|
|
218
|
-
const result = await this.simulateEnqueuedCallInternal(context.state.getActiveStateManager(),
|
|
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 = `${
|
|
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
|
|
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,
|
|
242
|
-
const address =
|
|
243
|
-
const sender =
|
|
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,
|
|
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,
|
|
333
|
+
trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context, callRequest)=>({
|
|
338
334
|
[Attributes.TX_HASH]: context.txHash.toString(),
|
|
339
|
-
[Attributes.TARGET_ADDRESS]:
|
|
340
|
-
[Attributes.SENDER_ADDRESS]:
|
|
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,
|
|
341
|
+
trackSpan('PublicTxSimulator.simulateEnqueuedCallInternal', (_stateManager, _callRequest, _allocatedGas, _transactionFee, fnName)=>({
|
|
346
342
|
[Attributes.APP_CIRCUIT_NAME]: fnName
|
|
347
343
|
}))
|
|
348
344
|
], PublicTxSimulator.prototype, "simulateEnqueuedCallInternal", null);
|
package/dest/public/utils.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
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,
|
|
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"}
|
package/dest/public/utils.js
CHANGED
|
@@ -1,30 +1,13 @@
|
|
|
1
1
|
import { TxExecutionPhase } from '@aztec/stdlib/tx';
|
|
2
|
-
export function
|
|
2
|
+
export function getCallRequestsWithCalldataByPhase(tx, phase) {
|
|
3
3
|
switch(phase){
|
|
4
4
|
case TxExecutionPhase.SETUP:
|
|
5
|
-
return tx.
|
|
5
|
+
return tx.getNonRevertiblePublicCallRequestsWithCalldata();
|
|
6
6
|
case TxExecutionPhase.APP_LOGIC:
|
|
7
|
-
return tx.
|
|
7
|
+
return tx.getRevertiblePublicCallRequestsWithCalldata();
|
|
8
8
|
case TxExecutionPhase.TEARDOWN:
|
|
9
9
|
{
|
|
10
|
-
const request = tx.
|
|
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.
|
|
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.
|
|
64
|
-
"@aztec/foundation": "0.82.
|
|
65
|
-
"@aztec/noir-acvm_js": "0.82.
|
|
66
|
-
"@aztec/noir-noirc_abi": "0.82.
|
|
67
|
-
"@aztec/noir-protocol-circuits-types": "0.82.
|
|
68
|
-
"@aztec/noir-types": "0.82.
|
|
69
|
-
"@aztec/protocol-contracts": "0.82.
|
|
70
|
-
"@aztec/stdlib": "0.82.
|
|
71
|
-
"@aztec/telemetry-client": "0.82.
|
|
72
|
-
"@aztec/world-state": "0.82.
|
|
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.
|
|
81
|
-
"@aztec/merkle-tree": "0.82.
|
|
82
|
-
"@aztec/noir-contracts.js": "0.82.
|
|
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
|
-
|
|
14
|
-
calldata[0]
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
return [
|
|
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
|
|
323
|
+
async notifyEnqueuedPublicFunctionCall(
|
|
324
324
|
[contractAddress]: ACVMField[],
|
|
325
|
-
[
|
|
326
|
-
[argsHash]: ACVMField[],
|
|
325
|
+
[calldataHash]: ACVMField[],
|
|
327
326
|
[sideEffectCounter]: ACVMField[],
|
|
328
327
|
[isStaticCall]: ACVMField[],
|
|
329
328
|
): Promise<ACVMField[]> {
|
|
330
|
-
|
|
329
|
+
await this.typedOracle.notifyEnqueuedPublicFunctionCall(
|
|
331
330
|
AztecAddress.fromString(contractAddress),
|
|
332
|
-
|
|
333
|
-
Fr.fromString(argsHash),
|
|
331
|
+
Fr.fromString(calldataHash),
|
|
334
332
|
Fr.fromString(sideEffectCounter).toNumber(),
|
|
335
333
|
Fr.fromString(isStaticCall).toBool(),
|
|
336
334
|
);
|
|
337
|
-
return [
|
|
335
|
+
return [];
|
|
338
336
|
}
|
|
339
337
|
|
|
340
|
-
async
|
|
338
|
+
async notifySetPublicTeardownFunctionCall(
|
|
341
339
|
[contractAddress]: ACVMField[],
|
|
342
|
-
[
|
|
343
|
-
[argsHash]: ACVMField[],
|
|
340
|
+
[calldataHash]: ACVMField[],
|
|
344
341
|
[sideEffectCounter]: ACVMField[],
|
|
345
342
|
[isStaticCall]: ACVMField[],
|
|
346
343
|
): Promise<ACVMField[]> {
|
|
347
|
-
|
|
344
|
+
await this.typedOracle.notifySetPublicTeardownFunctionCall(
|
|
348
345
|
AztecAddress.fromString(contractAddress),
|
|
349
|
-
|
|
350
|
-
Fr.fromString(argsHash),
|
|
346
|
+
Fr.fromString(calldataHash),
|
|
351
347
|
Fr.fromString(sideEffectCounter).toNumber(),
|
|
352
348
|
Fr.fromString(isStaticCall).toBool(),
|
|
353
349
|
);
|
|
354
|
-
return [
|
|
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[]
|
|
51
|
-
|
|
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
|
-
|
|
183
|
+
notifyEnqueuedPublicFunctionCall(
|
|
184
184
|
_targetContractAddress: AztecAddress,
|
|
185
|
-
|
|
186
|
-
_argsHash: Fr,
|
|
185
|
+
_calldataHash: Fr,
|
|
187
186
|
_sideEffectCounter: number,
|
|
188
187
|
_isStaticCall: boolean,
|
|
189
|
-
): Promise<
|
|
190
|
-
return Promise.reject(new OracleMethodNotAvailableError('
|
|
188
|
+
): Promise<void> {
|
|
189
|
+
return Promise.reject(new OracleMethodNotAvailableError('notifyEnqueuedPublicFunctionCall'));
|
|
191
190
|
}
|
|
192
191
|
|
|
193
|
-
|
|
192
|
+
notifySetPublicTeardownFunctionCall(
|
|
194
193
|
_targetContractAddress: AztecAddress,
|
|
195
|
-
|
|
196
|
-
_argsHash: Fr,
|
|
194
|
+
_calldataHash: Fr,
|
|
197
195
|
_sideEffectCounter: number,
|
|
198
196
|
_isStaticCall: boolean,
|
|
199
|
-
): Promise<
|
|
200
|
-
return Promise.reject(new OracleMethodNotAvailableError('
|
|
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.
|
|
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
|
|
48
|
-
|
|
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
|
}
|