@aztec/simulator 0.81.0 → 0.82.1-alpha-testnet.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/db_interfaces.d.ts +6 -12
- package/dest/common/db_interfaces.d.ts.map +1 -1
- package/dest/common/db_interfaces.js +1 -1
- package/dest/common/debug_fn_name.js +5 -2
- package/dest/common/message_load_oracle_inputs.d.ts +4 -0
- package/dest/common/message_load_oracle_inputs.d.ts.map +1 -1
- package/dest/common/message_load_oracle_inputs.js +9 -0
- package/dest/private/acvm/acvm.d.ts +6 -1
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/acvm.js +7 -13
- package/dest/private/acvm/deserialize.d.ts +0 -18
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.js +3 -24
- package/dest/private/acvm/oracle/oracle.d.ts +34 -34
- package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.js +116 -82
- package/dest/private/acvm/oracle/typed_oracle.d.ts +4 -4
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/typed_oracle.js +8 -8
- package/dest/private/execution_data_provider.d.ts +3 -9
- package/dest/private/execution_data_provider.d.ts.map +1 -1
- 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 +2 -2
- package/dest/private/private_execution.d.ts.map +1 -1
- package/dest/private/private_execution.js +4 -7
- 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/providers/acvm_native.d.ts +6 -4
- package/dest/private/providers/acvm_native.d.ts.map +1 -1
- package/dest/private/providers/acvm_native.js +6 -3
- package/dest/private/providers/acvm_wasm.d.ts +6 -7
- package/dest/private/providers/acvm_wasm.d.ts.map +1 -1
- package/dest/private/providers/acvm_wasm.js +13 -15
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts +5 -5
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +1 -1
- package/dest/private/providers/acvm_wasm_with_blobs.js +7 -9
- package/dest/private/providers/circuit_recording/circuit_recorder.d.ts +90 -0
- package/dest/private/providers/circuit_recording/circuit_recorder.d.ts.map +1 -0
- package/dest/private/providers/circuit_recording/circuit_recorder.js +246 -0
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts +18 -0
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts.map +1 -0
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.js +39 -0
- package/dest/private/providers/simulation_provider.d.ts +21 -7
- package/dest/private/providers/simulation_provider.d.ts.map +1 -1
- package/dest/private/simulator.d.ts +3 -2
- package/dest/private/simulator.d.ts.map +1 -1
- package/dest/private/simulator.js +14 -4
- package/dest/private/unconstrained_execution.d.ts +2 -2
- package/dest/private/unconstrained_execution.d.ts.map +1 -1
- package/dest/private/unconstrained_execution.js +1 -2
- package/dest/private/unconstrained_execution_oracle.d.ts +1 -1
- package/dest/private/unconstrained_execution_oracle.d.ts.map +1 -1
- package/dest/private/unconstrained_execution_oracle.js +3 -3
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +0 -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 +4 -4
- package/dest/public/avm/test_utils.js +1 -1
- 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.d.ts +1 -1
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +4 -4
- 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/dest/testing.d.ts +2 -0
- package/dest/testing.d.ts.map +1 -0
- package/dest/testing.js +1 -0
- package/package.json +15 -14
- package/src/common/db_interfaces.ts +6 -13
- package/src/common/debug_fn_name.ts +5 -5
- package/src/common/message_load_oracle_inputs.ts +8 -0
- package/src/private/acvm/acvm.ts +8 -24
- package/src/private/acvm/deserialize.ts +3 -30
- package/src/private/acvm/oracle/oracle.ts +148 -144
- package/src/private/acvm/oracle/typed_oracle.ts +12 -14
- package/src/private/execution_data_provider.ts +6 -10
- package/src/private/hashed_values_cache.ts +6 -14
- package/src/private/private_execution.ts +11 -11
- package/src/private/private_execution_oracle.ts +39 -138
- package/src/private/providers/acvm_native.ts +17 -6
- package/src/private/providers/acvm_wasm.ts +27 -20
- package/src/private/providers/acvm_wasm_with_blobs.ts +15 -12
- package/src/private/providers/circuit_recording/circuit_recorder.ts +283 -0
- package/src/private/providers/circuit_recording/simulation_provider_recorder_wrapper.ts +82 -0
- package/src/private/providers/simulation_provider.ts +30 -5
- package/src/private/simulator.ts +19 -5
- package/src/private/unconstrained_execution.ts +8 -4
- package/src/private/unconstrained_execution_oracle.ts +3 -6
- package/src/public/avm/avm_simulator.ts +0 -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 +7 -7
- package/src/public/avm/test_utils.ts +1 -1
- 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 +4 -4
- 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/src/testing.ts +1 -0
- package/dest/public/avm/bytecode_utils.d.ts +0 -5
- package/dest/public/avm/bytecode_utils.d.ts.map +0 -1
- package/dest/public/avm/bytecode_utils.js +0 -17
- 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/avm/bytecode_utils.ts +0 -17
- package/src/public/execution.ts +0 -140
|
@@ -28,7 +28,7 @@ export function mockStorageReadWithMap(worldStateDB: PublicTreesDB, mockedStorag
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function mockNoteHashExists(worldStateDB: PublicTreesDB, _leafIndex: Fr, value?: Fr) {
|
|
31
|
-
(worldStateDB as jest.Mocked<PublicTreesDB>).
|
|
31
|
+
(worldStateDB as jest.Mocked<PublicTreesDB>).getNoteHash.mockImplementation((index: bigint) => {
|
|
32
32
|
if (index == _leafIndex.toBigInt()) {
|
|
33
33
|
return Promise.resolve(value);
|
|
34
34
|
} else {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { asyncMap } from '@aztec/foundation/async-map';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { type ContractArtifact,
|
|
3
|
+
import { type ContractArtifact, encodeArguments } from '@aztec/stdlib/abi';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
6
6
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
8
|
+
import { GlobalVariables, PublicCallRequestWithCalldata, type Tx } from '@aztec/stdlib/tx';
|
|
9
9
|
import { NativeWorldStateService } from '@aztec/world-state';
|
|
10
10
|
|
|
11
11
|
import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
|
|
12
|
-
import {
|
|
12
|
+
import { getContractFunctionAbi, getFunctionSelector } from '../avm/fixtures/index.js';
|
|
13
13
|
import { SimpleContractDataSource } from '../avm/fixtures/simple_contract_data_source.js';
|
|
14
14
|
import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
|
|
15
15
|
import { type PublicTxResult, PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js';
|
|
16
|
-
import { createTxForPublicCalls } from './
|
|
16
|
+
import { createTxForPublicCalls } from './utils.js';
|
|
17
17
|
|
|
18
18
|
const TIMESTAMP = new Fr(99833);
|
|
19
19
|
const DEFAULT_GAS_FEES = new GasFees(2, 3);
|
|
@@ -54,68 +54,13 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
54
54
|
/* need some unique first nullifier for note-nonce computations */
|
|
55
55
|
firstNullifier = new Fr(420000 + this.txCount++),
|
|
56
56
|
): Promise<Tx> {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (!contractArtifact) {
|
|
63
|
-
throw new Error(`Contract artifact not found for address: ${address}`);
|
|
64
|
-
}
|
|
65
|
-
const req = await executionRequestForCall(
|
|
66
|
-
contractArtifact,
|
|
67
|
-
sender,
|
|
68
|
-
address,
|
|
69
|
-
setupCalls[i].fnName,
|
|
70
|
-
setupCalls[i].args,
|
|
71
|
-
setupCalls[i].isStaticCall,
|
|
72
|
-
);
|
|
73
|
-
setupExecutionRequests.push(req);
|
|
74
|
-
}
|
|
75
|
-
const appExecutionRequests: PublicExecutionRequest[] = [];
|
|
76
|
-
for (let i = 0; i < appCalls.length; i++) {
|
|
77
|
-
const address = appCalls[i].address;
|
|
78
|
-
const contractArtifact =
|
|
79
|
-
appCalls[i].contractArtifact || (await this.contractDataSource.getContractArtifact(address));
|
|
80
|
-
if (!contractArtifact) {
|
|
81
|
-
throw new Error(`Contract artifact not found for address: ${address}`);
|
|
82
|
-
}
|
|
83
|
-
const req = await executionRequestForCall(
|
|
84
|
-
contractArtifact,
|
|
85
|
-
sender,
|
|
86
|
-
address,
|
|
87
|
-
appCalls[i].fnName,
|
|
88
|
-
appCalls[i].args,
|
|
89
|
-
appCalls[i].isStaticCall,
|
|
90
|
-
);
|
|
91
|
-
appExecutionRequests.push(req);
|
|
92
|
-
}
|
|
57
|
+
const setupCallRequests = await asyncMap(setupCalls, call => this.#createPubicCallRequestForCall(call, sender));
|
|
58
|
+
const appCallRequests = await asyncMap(appCalls, call => this.#createPubicCallRequestForCall(call, sender));
|
|
59
|
+
const teardownCallRequest = teardownCall
|
|
60
|
+
? await this.#createPubicCallRequestForCall(teardownCall, sender)
|
|
61
|
+
: undefined;
|
|
93
62
|
|
|
94
|
-
|
|
95
|
-
if (teardownCall) {
|
|
96
|
-
const address = teardownCall.address;
|
|
97
|
-
const contractArtifact =
|
|
98
|
-
teardownCall.contractArtifact || (await this.contractDataSource.getContractArtifact(address));
|
|
99
|
-
if (!contractArtifact) {
|
|
100
|
-
throw new Error(`Contract artifact not found for address: ${address}`);
|
|
101
|
-
}
|
|
102
|
-
teardownExecutionRequest = await executionRequestForCall(
|
|
103
|
-
contractArtifact,
|
|
104
|
-
sender,
|
|
105
|
-
address,
|
|
106
|
-
teardownCall.fnName,
|
|
107
|
-
teardownCall.args,
|
|
108
|
-
teardownCall.isStaticCall,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return await createTxForPublicCalls(
|
|
113
|
-
firstNullifier,
|
|
114
|
-
setupExecutionRequests,
|
|
115
|
-
appExecutionRequests,
|
|
116
|
-
teardownExecutionRequest,
|
|
117
|
-
feePayer,
|
|
118
|
-
);
|
|
63
|
+
return createTxForPublicCalls(firstNullifier, setupCallRequests, appCallRequests, teardownCallRequest, feePayer);
|
|
119
64
|
}
|
|
120
65
|
|
|
121
66
|
public async simulateTx(
|
|
@@ -143,28 +88,26 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
143
88
|
|
|
144
89
|
return avmResult;
|
|
145
90
|
}
|
|
146
|
-
}
|
|
147
91
|
|
|
148
|
-
async
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
address,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return new PublicExecutionRequest(callContext, calldata);
|
|
92
|
+
async #createPubicCallRequestForCall(
|
|
93
|
+
call: TestEnqueuedCall,
|
|
94
|
+
sender: AztecAddress,
|
|
95
|
+
): Promise<PublicCallRequestWithCalldata> {
|
|
96
|
+
const address = call.address;
|
|
97
|
+
const contractArtifact = call.contractArtifact || (await this.contractDataSource.getContractArtifact(address));
|
|
98
|
+
if (!contractArtifact) {
|
|
99
|
+
throw new Error(`Contract artifact not found for address: ${address}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const fnSelector = await getFunctionSelector(call.fnName, contractArtifact);
|
|
103
|
+
const fnAbi = getContractFunctionAbi(call.fnName, contractArtifact)!;
|
|
104
|
+
const encodedArgs = encodeArguments(fnAbi, call.args);
|
|
105
|
+
const calldata = [fnSelector.toField(), ...encodedArgs];
|
|
106
|
+
const isStaticCall = call.isStaticCall ?? false;
|
|
107
|
+
const request = await PublicCallRequest.fromCalldata(sender, address, isStaticCall, calldata);
|
|
108
|
+
|
|
109
|
+
return new PublicCallRequestWithCalldata(request, calldata);
|
|
110
|
+
}
|
|
168
111
|
}
|
|
169
112
|
|
|
170
113
|
export function defaultGlobals() {
|
|
@@ -24,28 +24,33 @@ import {
|
|
|
24
24
|
countAccumulatedItems,
|
|
25
25
|
} from '@aztec/stdlib/kernel';
|
|
26
26
|
import { ContractClassLog, PrivateLog } from '@aztec/stdlib/logs';
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
27
|
+
import { ClientIvcProof } from '@aztec/stdlib/proofs';
|
|
28
|
+
import {
|
|
29
|
+
BlockHeader,
|
|
30
|
+
HashedValues,
|
|
31
|
+
PublicCallRequestWithCalldata,
|
|
32
|
+
Tx,
|
|
33
|
+
TxConstantData,
|
|
34
|
+
TxContext,
|
|
35
|
+
} from '@aztec/stdlib/tx';
|
|
29
36
|
|
|
30
37
|
import { strict as assert } from 'assert';
|
|
31
38
|
|
|
32
39
|
/**
|
|
33
40
|
* Craft a carrier transaction for some public calls for simulation by PublicTxSimulator.
|
|
34
41
|
*/
|
|
35
|
-
export
|
|
42
|
+
export function createTxForPublicCalls(
|
|
36
43
|
firstNullifier: Fr,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
setupCallRequests: PublicCallRequestWithCalldata[],
|
|
45
|
+
appCallRequests: PublicCallRequestWithCalldata[],
|
|
46
|
+
teardownCallRequest?: PublicCallRequestWithCalldata,
|
|
40
47
|
feePayer = AztecAddress.zero(),
|
|
41
48
|
gasUsedByPrivate: Gas = Gas.empty(),
|
|
42
|
-
):
|
|
49
|
+
): Tx {
|
|
43
50
|
assert(
|
|
44
|
-
|
|
51
|
+
setupCallRequests.length > 0 || appCallRequests.length > 0 || teardownCallRequest !== undefined,
|
|
45
52
|
"Can't create public tx with no enqueued calls",
|
|
46
53
|
);
|
|
47
|
-
const setupCallRequests = await Promise.all(setupExecutionRequests.map(er => er.toCallRequest()));
|
|
48
|
-
const appCallRequests = await Promise.all(appExecutionRequests.map(er => er.toCallRequest()));
|
|
49
54
|
// use max limits
|
|
50
55
|
const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_TX_PUBLIC_PORTION);
|
|
51
56
|
|
|
@@ -55,17 +60,18 @@ export async function createTxForPublicCalls(
|
|
|
55
60
|
|
|
56
61
|
// We reverse order because the simulator expects it to be like a "stack" of calls to pop from
|
|
57
62
|
for (let i = setupCallRequests.length - 1; i >= 0; i--) {
|
|
58
|
-
forPublic.nonRevertibleAccumulatedData.publicCallRequests[i] =
|
|
63
|
+
forPublic.nonRevertibleAccumulatedData.publicCallRequests[setupCallRequests.length - i - 1] =
|
|
64
|
+
setupCallRequests[i].request;
|
|
59
65
|
}
|
|
60
66
|
for (let i = appCallRequests.length - 1; i >= 0; i--) {
|
|
61
|
-
forPublic.revertibleAccumulatedData.publicCallRequests[i] = appCallRequests[i];
|
|
67
|
+
forPublic.revertibleAccumulatedData.publicCallRequests[appCallRequests.length - i - 1] = appCallRequests[i].request;
|
|
62
68
|
}
|
|
63
|
-
if (
|
|
64
|
-
forPublic.publicTeardownCallRequest =
|
|
69
|
+
if (teardownCallRequest) {
|
|
70
|
+
forPublic.publicTeardownCallRequest = teardownCallRequest.request;
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
const maxFeesPerGas = feePayer.isZero() ? GasFees.empty() : new GasFees(10, 10);
|
|
68
|
-
const teardownGasLimits =
|
|
74
|
+
const teardownGasLimits = teardownCallRequest ? gasLimits : Gas.empty();
|
|
69
75
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, maxFeesPerGas, GasFees.empty());
|
|
70
76
|
const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
|
|
71
77
|
const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
|
|
@@ -77,18 +83,14 @@ export async function createTxForPublicCalls(
|
|
|
77
83
|
feePayer,
|
|
78
84
|
forPublic,
|
|
79
85
|
);
|
|
80
|
-
const tx = Tx.newWithTxData(txData, teardownExecutionRequest);
|
|
81
86
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
for (let i = setupExecutionRequests.length - 1; i >= 0; i--) {
|
|
88
|
-
tx.enqueuedPublicFunctionCalls.push(setupExecutionRequests[i]);
|
|
89
|
-
}
|
|
87
|
+
const calldata = [
|
|
88
|
+
...setupCallRequests,
|
|
89
|
+
...appCallRequests,
|
|
90
|
+
...(teardownCallRequest ? [teardownCallRequest] : []),
|
|
91
|
+
].map(r => new HashedValues(r.calldata, r.request.calldataHash));
|
|
90
92
|
|
|
91
|
-
return
|
|
93
|
+
return new Tx(txData, ClientIvcProof.empty(), [], calldata);
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
export function createTxForPrivateOnly(feePayer = AztecAddress.zero(), gasUsedByPrivate: Gas = new Gas(10, 10)): Tx {
|
|
@@ -110,7 +112,7 @@ export function createTxForPrivateOnly(feePayer = AztecAddress.zero(), gasUsedBy
|
|
|
110
112
|
/*forPublic=*/ undefined,
|
|
111
113
|
forRollup,
|
|
112
114
|
);
|
|
113
|
-
return Tx.
|
|
115
|
+
return new Tx(txData, ClientIvcProof.empty(), [], []);
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
export async function addNewContractClassToTx(
|
package/src/public/index.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export * from '../common/db_interfaces.js';
|
|
2
2
|
export * from './public_tx_simulator/public_tx_simulator.js';
|
|
3
|
-
export { type EnqueuedPublicCallExecutionResult, type PublicFunctionCallResult } from './execution.js';
|
|
4
3
|
export * from './public_db_sources.js';
|
|
5
4
|
export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
|
|
6
5
|
export { SideEffectTrace } from './side_effect_trace.js';
|
|
7
|
-
export { getExecutionRequestsByPhase } from './utils.js';
|
|
8
6
|
export { PublicTxSimulationTester } from './fixtures/index.js';
|
|
9
7
|
export * from './avm/index.js';
|
|
8
|
+
export { getCallRequestsWithCalldataByPhase } from './utils.js';
|
|
@@ -271,7 +271,7 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
public async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
274
|
-
return await this.dataSource.
|
|
274
|
+
return await this.dataSource.getDebugFunctionName(address, selector);
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
|
|
@@ -431,13 +431,13 @@ export class PublicTreesDB extends ForwardMerkleTree implements PublicStateDBInt
|
|
|
431
431
|
return leafValue;
|
|
432
432
|
}
|
|
433
433
|
|
|
434
|
-
public async
|
|
434
|
+
public async getNoteHash(leafIndex: bigint): Promise<Fr | undefined> {
|
|
435
435
|
const timer = new Timer();
|
|
436
436
|
const leafValue = await this.db.getLeafValue(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
437
|
-
this.logger.debug(`[DB] Fetched
|
|
437
|
+
this.logger.debug(`[DB] Fetched note hash leaf value`, {
|
|
438
438
|
eventName: 'public-db-access',
|
|
439
439
|
duration: timer.ms(),
|
|
440
|
-
operation: 'get-
|
|
440
|
+
operation: 'get-note-hash',
|
|
441
441
|
} satisfies PublicDBAccessStats);
|
|
442
442
|
return leafValue;
|
|
443
443
|
}
|
|
@@ -321,7 +321,7 @@ export class PublicProcessor implements Traceable {
|
|
|
321
321
|
this.log.verbose(
|
|
322
322
|
!tx.hasPublicCalls()
|
|
323
323
|
? `Processed tx ${processedTx.hash} with no public calls in ${time}ms`
|
|
324
|
-
: `Processed tx ${processedTx.hash} with ${tx.
|
|
324
|
+
: `Processed tx ${processedTx.hash} with ${tx.numberOfPublicCalls()} public calls in ${time}ms`,
|
|
325
325
|
{
|
|
326
326
|
txHash: processedTx.hash,
|
|
327
327
|
txFee: processedTx.txEffect.transactionFee.toBigInt(),
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
27
27
|
import {
|
|
28
28
|
type GlobalVariables,
|
|
29
|
-
|
|
29
|
+
PublicCallRequestWithCalldata,
|
|
30
30
|
type StateReference,
|
|
31
31
|
TreeSnapshots,
|
|
32
32
|
type Tx,
|
|
@@ -42,7 +42,7 @@ import { AvmPersistableStateManager } from '../avm/index.js';
|
|
|
42
42
|
import { HintingPublicContractsDB } from '../hinting_db_sources.js';
|
|
43
43
|
import type { PublicTreesDB } from '../public_db_sources.js';
|
|
44
44
|
import { SideEffectArrayLengths, SideEffectTrace } from '../side_effect_trace.js';
|
|
45
|
-
import {
|
|
45
|
+
import { getCallRequestsWithCalldataByPhase } from '../utils.js';
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* The transaction-level context for public execution.
|
|
@@ -70,12 +70,9 @@ export class PublicTxContext {
|
|
|
70
70
|
private readonly gasSettings: GasSettings,
|
|
71
71
|
private readonly gasUsedByPrivate: Gas,
|
|
72
72
|
private readonly gasAllocatedToPublic: Gas,
|
|
73
|
-
private readonly setupCallRequests:
|
|
74
|
-
private readonly appLogicCallRequests:
|
|
75
|
-
private readonly teardownCallRequests:
|
|
76
|
-
private readonly setupExecutionRequests: PublicExecutionRequest[],
|
|
77
|
-
private readonly appLogicExecutionRequests: PublicExecutionRequest[],
|
|
78
|
-
private readonly teardownExecutionRequests: PublicExecutionRequest[],
|
|
73
|
+
private readonly setupCallRequests: PublicCallRequestWithCalldata[],
|
|
74
|
+
private readonly appLogicCallRequests: PublicCallRequestWithCalldata[],
|
|
75
|
+
private readonly teardownCallRequests: PublicCallRequestWithCalldata[],
|
|
79
76
|
public readonly nonRevertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
|
|
80
77
|
public readonly revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
|
|
81
78
|
public readonly feePayer: AztecAddress,
|
|
@@ -135,12 +132,9 @@ export class PublicTxContext {
|
|
|
135
132
|
gasSettings,
|
|
136
133
|
gasUsedByPrivate,
|
|
137
134
|
gasAllocatedToPublic,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
getExecutionRequestsByPhase(tx, TxExecutionPhase.SETUP),
|
|
142
|
-
getExecutionRequestsByPhase(tx, TxExecutionPhase.APP_LOGIC),
|
|
143
|
-
getExecutionRequestsByPhase(tx, TxExecutionPhase.TEARDOWN),
|
|
135
|
+
getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.SETUP),
|
|
136
|
+
getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.APP_LOGIC),
|
|
137
|
+
getCallRequestsWithCalldataByPhase(tx, TxExecutionPhase.TEARDOWN),
|
|
144
138
|
tx.data.forPublic!.nonRevertibleAccumulatedData,
|
|
145
139
|
tx.data.forPublic!.revertibleAccumulatedData,
|
|
146
140
|
tx.data.feePayer,
|
|
@@ -218,7 +212,7 @@ export class PublicTxContext {
|
|
|
218
212
|
/**
|
|
219
213
|
* Get the call requests for the specified phase (including args hashes).
|
|
220
214
|
*/
|
|
221
|
-
getCallRequestsForPhase(phase: TxExecutionPhase):
|
|
215
|
+
getCallRequestsForPhase(phase: TxExecutionPhase): PublicCallRequestWithCalldata[] {
|
|
222
216
|
switch (phase) {
|
|
223
217
|
case TxExecutionPhase.SETUP:
|
|
224
218
|
return this.setupCallRequests;
|
|
@@ -229,20 +223,6 @@ export class PublicTxContext {
|
|
|
229
223
|
}
|
|
230
224
|
}
|
|
231
225
|
|
|
232
|
-
/**
|
|
233
|
-
* Get the call requests for the specified phase (including actual args).
|
|
234
|
-
*/
|
|
235
|
-
getExecutionRequestsForPhase(phase: TxExecutionPhase): PublicExecutionRequest[] {
|
|
236
|
-
switch (phase) {
|
|
237
|
-
case TxExecutionPhase.SETUP:
|
|
238
|
-
return this.setupExecutionRequests;
|
|
239
|
-
case TxExecutionPhase.APP_LOGIC:
|
|
240
|
-
return this.appLogicExecutionRequests;
|
|
241
|
-
case TxExecutionPhase.TEARDOWN:
|
|
242
|
-
return this.teardownExecutionRequests;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
226
|
/**
|
|
247
227
|
* How much gas is left as of the specified phase?
|
|
248
228
|
*/
|
|
@@ -353,10 +333,10 @@ export class PublicTxContext {
|
|
|
353
333
|
/*startGasUsed=*/ this.gasUsedByPrivate,
|
|
354
334
|
this.gasSettings,
|
|
355
335
|
this.feePayer,
|
|
356
|
-
this.setupCallRequests,
|
|
357
|
-
this.appLogicCallRequests,
|
|
336
|
+
this.setupCallRequests.map(r => r.request),
|
|
337
|
+
this.appLogicCallRequests.map(r => r.request),
|
|
358
338
|
/*teardownCallRequest=*/ this.teardownCallRequests.length
|
|
359
|
-
? this.teardownCallRequests[0]
|
|
339
|
+
? this.teardownCallRequests[0].request
|
|
360
340
|
: PublicCallRequest.empty(),
|
|
361
341
|
endTreeSnapshots,
|
|
362
342
|
/*endGasUsed=*/ this.getTotalGasUsed(),
|
|
@@ -13,13 +13,12 @@ import {
|
|
|
13
13
|
} from '@aztec/stdlib/avm';
|
|
14
14
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
15
15
|
import type { Gas, GasUsed } from '@aztec/stdlib/gas';
|
|
16
|
-
import type { PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
17
16
|
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
18
17
|
import type { AvmSimulationStats } from '@aztec/stdlib/stats';
|
|
19
18
|
import {
|
|
20
19
|
type GlobalVariables,
|
|
21
20
|
NestedProcessReturnValues,
|
|
22
|
-
|
|
21
|
+
PublicCallRequestWithCalldata,
|
|
23
22
|
Tx,
|
|
24
23
|
TxExecutionPhase,
|
|
25
24
|
} from '@aztec/stdlib/tx';
|
|
@@ -83,7 +82,7 @@ export class PublicTxSimulator {
|
|
|
83
82
|
const startTime = process.hrtime.bigint();
|
|
84
83
|
|
|
85
84
|
const txHash = await tx.getTxHash();
|
|
86
|
-
this.log.debug(`Simulating ${tx.
|
|
85
|
+
this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, { txHash });
|
|
87
86
|
|
|
88
87
|
const context = await PublicTxContext.create(
|
|
89
88
|
this.treesDB,
|
|
@@ -232,13 +231,11 @@ export class PublicTxSimulator {
|
|
|
232
231
|
*/
|
|
233
232
|
private async simulatePhase(phase: TxExecutionPhase, context: PublicTxContext): Promise<ProcessedPhase> {
|
|
234
233
|
const callRequests = context.getCallRequestsForPhase(phase);
|
|
235
|
-
const executionRequests = context.getExecutionRequestsForPhase(phase);
|
|
236
234
|
|
|
237
235
|
this.log.debug(`Processing phase ${TxExecutionPhase[phase]} for tx ${context.txHash}`, {
|
|
238
236
|
txHash: context.txHash.toString(),
|
|
239
237
|
phase: TxExecutionPhase[phase],
|
|
240
238
|
callRequests: callRequests.length,
|
|
241
|
-
executionRequests: executionRequests.length,
|
|
242
239
|
});
|
|
243
240
|
|
|
244
241
|
const returnValues: NestedProcessReturnValues[] = [];
|
|
@@ -251,9 +248,8 @@ export class PublicTxSimulator {
|
|
|
251
248
|
}
|
|
252
249
|
|
|
253
250
|
const callRequest = callRequests[i];
|
|
254
|
-
const executionRequest = executionRequests[i];
|
|
255
251
|
|
|
256
|
-
const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest
|
|
252
|
+
const enqueuedCallResult = await this.simulateEnqueuedCall(phase, context, callRequest);
|
|
257
253
|
|
|
258
254
|
returnValues.push(new NestedProcessReturnValues(enqueuedCallResult.output));
|
|
259
255
|
|
|
@@ -276,44 +272,42 @@ export class PublicTxSimulator {
|
|
|
276
272
|
* Simulate an enqueued public call.
|
|
277
273
|
* @param phase - The current phase of public execution
|
|
278
274
|
* @param context - WILL BE MUTATED. The context of the currently executing public transaction portion
|
|
279
|
-
* @param callRequest - The
|
|
280
|
-
* @param executionRequest - The execution request (includes args)
|
|
275
|
+
* @param callRequest - The public function call request, including the calldata.
|
|
281
276
|
* @returns The result of execution.
|
|
282
277
|
*/
|
|
283
|
-
@trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context,
|
|
278
|
+
@trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context, callRequest) => ({
|
|
284
279
|
[Attributes.TX_HASH]: context.txHash.toString(),
|
|
285
|
-
[Attributes.TARGET_ADDRESS]:
|
|
286
|
-
[Attributes.SENDER_ADDRESS]:
|
|
280
|
+
[Attributes.TARGET_ADDRESS]: callRequest.request.contractAddress.toString(),
|
|
281
|
+
[Attributes.SENDER_ADDRESS]: callRequest.request.msgSender.toString(),
|
|
287
282
|
[Attributes.SIMULATOR_PHASE]: TxExecutionPhase[phase].toString(),
|
|
288
283
|
}))
|
|
289
284
|
private async simulateEnqueuedCall(
|
|
290
285
|
phase: TxExecutionPhase,
|
|
291
286
|
context: PublicTxContext,
|
|
292
|
-
callRequest:
|
|
293
|
-
executionRequest: PublicExecutionRequest,
|
|
287
|
+
callRequest: PublicCallRequestWithCalldata,
|
|
294
288
|
): Promise<AvmFinalizedCallResult> {
|
|
295
289
|
const stateManager = context.state.getActiveStateManager();
|
|
296
|
-
const
|
|
297
|
-
const fnName = await getPublicFunctionDebugName(this.contractsDB,
|
|
290
|
+
const contractAddress = callRequest.request.contractAddress;
|
|
291
|
+
const fnName = await getPublicFunctionDebugName(this.contractsDB, contractAddress, callRequest.calldata);
|
|
298
292
|
|
|
299
293
|
const allocatedGas = context.getGasLeftAtPhase(phase);
|
|
300
294
|
|
|
301
295
|
// The reason we need enqueued hints at all (and cannot just use the public inputs) is
|
|
302
296
|
// because they don't have the actual calldata, just the hash of it.
|
|
303
297
|
// If/when we pass the whole TX to C++, we can remove this class of hints.
|
|
304
|
-
stateManager.traceEnqueuedCall(callRequest);
|
|
298
|
+
stateManager.traceEnqueuedCall(callRequest.request);
|
|
305
299
|
context.hints.enqueuedCalls.push(
|
|
306
300
|
new AvmEnqueuedCallHint(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
301
|
+
callRequest.request.msgSender,
|
|
302
|
+
contractAddress,
|
|
303
|
+
callRequest.calldata,
|
|
304
|
+
callRequest.request.isStaticCall,
|
|
311
305
|
),
|
|
312
306
|
);
|
|
313
307
|
|
|
314
308
|
const result = await this.simulateEnqueuedCallInternal(
|
|
315
309
|
context.state.getActiveStateManager(),
|
|
316
|
-
|
|
310
|
+
callRequest,
|
|
317
311
|
allocatedGas,
|
|
318
312
|
/*transactionFee=*/ context.getTransactionFee(phase),
|
|
319
313
|
fnName,
|
|
@@ -326,7 +320,7 @@ export class PublicTxSimulator {
|
|
|
326
320
|
);
|
|
327
321
|
|
|
328
322
|
if (result.reverted) {
|
|
329
|
-
const culprit = `${
|
|
323
|
+
const culprit = `${contractAddress}:${callRequest.functionSelector}`;
|
|
330
324
|
context.revert(phase, result.revertReason, culprit); // throws if in setup (non-revertible) phase
|
|
331
325
|
}
|
|
332
326
|
|
|
@@ -342,26 +336,26 @@ export class PublicTxSimulator {
|
|
|
342
336
|
*
|
|
343
337
|
* @param stateManager - The state manager for AvmSimulation
|
|
344
338
|
* @param context - The context of the currently executing public transaction portion
|
|
345
|
-
* @param
|
|
339
|
+
* @param callRequest - The public function call request, including the calldata.
|
|
346
340
|
* @param allocatedGas - The gas allocated to the enqueued call
|
|
347
341
|
* @param fnName - The name of the function
|
|
348
342
|
* @returns The result of execution.
|
|
349
343
|
*/
|
|
350
344
|
@trackSpan(
|
|
351
345
|
'PublicTxSimulator.simulateEnqueuedCallInternal',
|
|
352
|
-
(_stateManager,
|
|
346
|
+
(_stateManager, _callRequest, _allocatedGas, _transactionFee, fnName) => ({
|
|
353
347
|
[Attributes.APP_CIRCUIT_NAME]: fnName,
|
|
354
348
|
}),
|
|
355
349
|
)
|
|
356
350
|
private async simulateEnqueuedCallInternal(
|
|
357
351
|
stateManager: AvmPersistableStateManager,
|
|
358
|
-
|
|
352
|
+
{ request, calldata }: PublicCallRequestWithCalldata,
|
|
359
353
|
allocatedGas: Gas,
|
|
360
354
|
transactionFee: Fr,
|
|
361
355
|
fnName: string,
|
|
362
356
|
): Promise<AvmFinalizedCallResult> {
|
|
363
|
-
const address =
|
|
364
|
-
const sender =
|
|
357
|
+
const address = request.contractAddress;
|
|
358
|
+
const sender = request.msgSender;
|
|
365
359
|
|
|
366
360
|
this.log.debug(
|
|
367
361
|
`Executing enqueued public call to external function ${fnName}@${address} with ${allocatedGas.l2Gas} allocated L2 gas.`,
|
|
@@ -374,8 +368,8 @@ export class PublicTxSimulator {
|
|
|
374
368
|
sender,
|
|
375
369
|
transactionFee,
|
|
376
370
|
this.globalVariables,
|
|
377
|
-
|
|
378
|
-
|
|
371
|
+
request.isStaticCall,
|
|
372
|
+
calldata,
|
|
379
373
|
allocatedGas,
|
|
380
374
|
);
|
|
381
375
|
const avmCallResult = await simulator.execute();
|
package/src/public/utils.ts
CHANGED
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type PublicExecutionRequest, type Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
|
|
1
|
+
import { PublicCallRequestWithCalldata, type Tx, TxExecutionPhase } from '@aztec/stdlib/tx';
|
|
3
2
|
|
|
4
|
-
export function
|
|
3
|
+
export function getCallRequestsWithCalldataByPhase(tx: Tx, phase: TxExecutionPhase): PublicCallRequestWithCalldata[] {
|
|
5
4
|
switch (phase) {
|
|
6
5
|
case TxExecutionPhase.SETUP:
|
|
7
|
-
return tx.
|
|
6
|
+
return tx.getNonRevertiblePublicCallRequestsWithCalldata();
|
|
8
7
|
case TxExecutionPhase.APP_LOGIC:
|
|
9
|
-
return tx.
|
|
8
|
+
return tx.getRevertiblePublicCallRequestsWithCalldata();
|
|
10
9
|
case TxExecutionPhase.TEARDOWN: {
|
|
11
|
-
const request = tx.
|
|
12
|
-
return request ? [request] : [];
|
|
13
|
-
}
|
|
14
|
-
default:
|
|
15
|
-
throw new Error(`Unknown phase: ${phase}`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function getCallRequestsByPhase(tx: Tx, phase: TxExecutionPhase): PublicCallRequest[] {
|
|
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
|
-
const request = tx.data.getTeardownPublicCallRequest();
|
|
10
|
+
const request = tx.getTeardownPublicCallRequestWithCalldata();
|
|
27
11
|
return request ? [request] : [];
|
|
28
12
|
}
|
|
29
13
|
default:
|
package/src/testing.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SimulationProviderRecorderWrapper } from './private/providers/circuit_recording/simulation_provider_recorder_wrapper.js';
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
export declare function markBytecodeAsAvm(bytecode: Buffer): Buffer;
|
|
4
|
-
export declare function isAvmBytecode(bytecode: Buffer): boolean;
|
|
5
|
-
//# sourceMappingURL=bytecode_utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bytecode_utils.d.ts","sourceRoot":"","sources":["../../../src/public/avm/bytecode_utils.ts"],"names":[],"mappings":";;AASA,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGvD"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Opcode } from './serialization/instruction_serialization.js';
|
|
2
|
-
const AVM_MAGIC_SUFFIX = Buffer.from([
|
|
3
|
-
Opcode.MOV_16,
|
|
4
|
-
0x00,
|
|
5
|
-
...Buffer.from('18ca', 'hex'),
|
|
6
|
-
...Buffer.from('18ca', 'hex')
|
|
7
|
-
]);
|
|
8
|
-
export function markBytecodeAsAvm(bytecode) {
|
|
9
|
-
return Buffer.concat([
|
|
10
|
-
bytecode,
|
|
11
|
-
AVM_MAGIC_SUFFIX
|
|
12
|
-
]);
|
|
13
|
-
}
|
|
14
|
-
export function isAvmBytecode(bytecode) {
|
|
15
|
-
const magicSize = AVM_MAGIC_SUFFIX.length;
|
|
16
|
-
return bytecode.subarray(-magicSize).equals(AVM_MAGIC_SUFFIX);
|
|
17
|
-
}
|