@aztec/simulator 0.69.1 → 0.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/acvm/acvm.d.ts +1 -2
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +12 -2
- package/dest/acvm/index.d.ts +1 -1
- package/dest/acvm/index.d.ts.map +1 -1
- package/dest/acvm/index.js +2 -2
- package/dest/acvm/oracle/oracle.d.ts +13 -5
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +46 -21
- package/dest/acvm/oracle/typed_oracle.d.ts +8 -17
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +16 -23
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +7 -1
- package/dest/avm/fixtures/index.d.ts +2 -3
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +4 -4
- package/dest/avm/journal/journal.d.ts +3 -4
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +11 -10
- package/dest/avm/journal/nullifiers.d.ts +1 -1
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.d.ts +1 -1
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/client/client_execution_context.d.ts +29 -18
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +42 -29
- package/dest/client/db_oracle.d.ts +24 -16
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/execution_note_cache.d.ts +27 -4
- package/dest/client/execution_note_cache.d.ts.map +1 -1
- package/dest/client/execution_note_cache.js +62 -12
- package/dest/client/index.d.ts +11 -3
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +11 -4
- package/dest/client/private_execution.d.ts +3 -2
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +9 -7
- package/dest/client/simulator.d.ts +4 -2
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +13 -8
- package/dest/client/unconstrained_execution.d.ts +2 -1
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +6 -4
- package/dest/client/view_data_oracle.d.ts +4 -10
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +17 -19
- package/dest/common/hashed_values_cache.d.ts +28 -0
- package/dest/common/hashed_values_cache.d.ts.map +1 -0
- package/dest/common/{packed_values_cache.js → hashed_values_cache.js} +22 -22
- package/dest/common/index.d.ts +1 -1
- package/dest/common/index.js +1 -1
- package/dest/common/message_load_oracle_inputs.d.ts +15 -0
- package/dest/common/message_load_oracle_inputs.d.ts.map +1 -0
- package/dest/common/message_load_oracle_inputs.js +15 -0
- package/dest/common/simulation_provider.d.ts +19 -0
- package/dest/common/simulation_provider.d.ts.map +1 -0
- package/dest/common/simulation_provider.js +27 -0
- package/dest/common.d.ts +2 -0
- package/dest/common.d.ts.map +1 -0
- package/dest/common.js +2 -0
- package/dest/providers/acvm_native.d.ts +5 -2
- package/dest/providers/acvm_native.d.ts.map +1 -1
- package/dest/providers/acvm_native.js +5 -2
- package/dest/providers/acvm_wasm.d.ts +8 -2
- package/dest/providers/acvm_wasm.d.ts.map +1 -1
- package/dest/providers/acvm_wasm.js +31 -5
- package/dest/providers/acvm_wasm_with_blobs.d.ts +14 -2
- package/dest/providers/acvm_wasm_with_blobs.d.ts.map +1 -1
- package/dest/providers/acvm_wasm_with_blobs.js +25 -5
- package/dest/providers/factory.d.ts +1 -1
- package/dest/providers/factory.d.ts.map +1 -1
- package/dest/providers/factory.js +1 -1
- package/dest/providers/index.d.ts +1 -1
- package/dest/providers/index.d.ts.map +1 -1
- package/dest/providers/index.js +2 -2
- package/dest/public/db_interfaces.d.ts +1 -1
- package/dest/public/db_interfaces.d.ts.map +1 -1
- package/dest/public/fixtures/index.d.ts +3 -3
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +48 -18
- package/dest/public/public_db_sources.d.ts +2 -1
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +2 -2
- package/dest/public/public_processor.js +2 -2
- package/dest/public/public_tx_context.d.ts +3 -7
- package/dest/public/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_context.js +7 -20
- package/dest/public/public_tx_simulator.js +5 -5
- package/{src/index.ts → dest/server.d.ts} +1 -2
- package/dest/server.d.ts.map +1 -0
- package/dest/server.js +6 -0
- package/package.json +11 -12
- package/src/acvm/acvm.ts +20 -3
- package/src/acvm/index.ts +1 -1
- package/src/acvm/oracle/oracle.ts +48 -27
- package/src/acvm/oracle/typed_oracle.ts +20 -24
- package/src/avm/avm_simulator.ts +6 -0
- package/src/avm/fixtures/index.ts +5 -4
- package/src/avm/journal/journal.ts +9 -9
- package/src/avm/journal/nullifiers.ts +1 -1
- package/src/avm/journal/public_storage.ts +1 -1
- package/src/client/client_execution_context.ts +47 -30
- package/src/client/db_oracle.ts +25 -17
- package/src/client/execution_note_cache.ts +67 -14
- package/src/client/index.ts +11 -3
- package/src/client/private_execution.ts +21 -17
- package/src/client/simulator.ts +20 -7
- package/src/client/unconstrained_execution.ts +17 -13
- package/src/client/view_data_oracle.ts +23 -19
- package/src/common/hashed_values_cache.ts +55 -0
- package/src/common/index.ts +1 -1
- package/src/common/message_load_oracle_inputs.ts +15 -0
- package/src/common/simulation_provider.ts +45 -0
- package/src/common.ts +1 -0
- package/src/providers/acvm_native.ts +12 -2
- package/src/providers/acvm_wasm.ts +36 -9
- package/src/providers/acvm_wasm_with_blobs.ts +35 -10
- package/src/providers/factory.ts +1 -1
- package/src/providers/index.ts +1 -1
- package/src/public/db_interfaces.ts +1 -1
- package/src/public/fixtures/index.ts +62 -26
- package/src/public/public_db_sources.ts +3 -6
- package/src/public/public_processor.ts +1 -1
- package/src/public/public_tx_context.ts +6 -19
- package/src/public/public_tx_simulator.ts +4 -4
- package/{dest/index.d.ts → src/server.ts} +0 -3
- package/dest/common/packed_values_cache.d.ts +0 -28
- package/dest/common/packed_values_cache.d.ts.map +0 -1
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -8
- package/dest/providers/simulation_provider.d.ts +0 -9
- package/dest/providers/simulation_provider.d.ts.map +0 -1
- package/dest/providers/simulation_provider.js +0 -2
- package/src/common/packed_values_cache.ts +0 -55
- package/src/providers/simulation_provider.ts +0 -10
|
@@ -1,25 +1,50 @@
|
|
|
1
|
-
import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types';
|
|
1
|
+
import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types/server';
|
|
2
2
|
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
3
3
|
|
|
4
|
-
import { executeCircuit } from '@noir-lang/acvm_js';
|
|
4
|
+
import { type ExecutionError, executeCircuit } from '@noir-lang/acvm_js';
|
|
5
5
|
import { type WitnessMap } from '@noir-lang/types';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type ACIRCallback, type ACIRExecutionResult } from '../acvm/acvm.js';
|
|
8
|
+
import { type ACVMWitness } from '../acvm/acvm_types.js';
|
|
9
|
+
import { type SimulationProvider, parseErrorPayload } from '../common/simulation_provider.js';
|
|
8
10
|
|
|
11
|
+
/**
|
|
12
|
+
* A simulation provider that uses the WASM simulator with the ability to handle blobs via the foreign call handler.
|
|
13
|
+
* This class is temporary while brillig cannot handle the blob math, and it is kept separate
|
|
14
|
+
* because the zkg commitment library used in the blob code is not browser compatible.
|
|
15
|
+
*
|
|
16
|
+
* It is only used in the context of server-side code executing simulated protocol circuits.
|
|
17
|
+
*/
|
|
9
18
|
export class WASMSimulatorWithBlobs implements SimulationProvider {
|
|
10
|
-
async
|
|
19
|
+
async executeProtocolCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
|
|
11
20
|
// Execute the circuit on those initial witness values
|
|
12
21
|
//
|
|
13
22
|
// Decode the bytecode from base64 since the acvm does not know about base64 encoding
|
|
14
23
|
const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
15
24
|
//
|
|
16
25
|
// Execute the circuit
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
try {
|
|
27
|
+
const _witnessMap = await executeCircuit(
|
|
28
|
+
decodedBytecode,
|
|
29
|
+
input,
|
|
30
|
+
foreignCallHandler, // handle calls to debug_log and evaluate_blobs mock
|
|
31
|
+
);
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
return _witnessMap;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
// Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.
|
|
36
|
+
if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {
|
|
37
|
+
throw parseErrorPayload(compiledCircuit.abi, err as ExecutionError);
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Circuit execution failed: ${err}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
executeUserCircuit(
|
|
44
|
+
_acir: Buffer,
|
|
45
|
+
_initialWitness: ACVMWitness,
|
|
46
|
+
_callback: ACIRCallback,
|
|
47
|
+
): Promise<ACIRExecutionResult> {
|
|
48
|
+
throw new Error('Not implemented');
|
|
24
49
|
}
|
|
25
50
|
}
|
package/src/providers/factory.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
2
2
|
|
|
3
3
|
import { promises as fs } from 'fs';
|
|
4
4
|
|
|
5
|
+
import { type SimulationProvider } from '../common/simulation_provider.js';
|
|
5
6
|
import { NativeACVMSimulator } from './acvm_native.js';
|
|
6
7
|
import { WASMSimulator } from './acvm_wasm.js';
|
|
7
|
-
import { type SimulationProvider } from './simulation_provider.js';
|
|
8
8
|
|
|
9
9
|
export type SimulationProviderConfig = {
|
|
10
10
|
acvmBinaryPath?: string;
|
package/src/providers/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
8
8
|
import { type Fr } from '@aztec/foundation/fields';
|
|
9
9
|
|
|
10
|
-
import { type MessageLoadOracleInputs } from '../
|
|
10
|
+
import { type MessageLoadOracleInputs } from '../common/message_load_oracle_inputs.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Database interface for providing access to public state.
|
|
@@ -32,25 +32,26 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
|
32
32
|
import { Fr, Point } from '@aztec/foundation/fields';
|
|
33
33
|
import { openTmpStore } from '@aztec/kv-store/lmdb';
|
|
34
34
|
import { AvmTestContractArtifact } from '@aztec/noir-contracts.js/AvmTest';
|
|
35
|
-
import {
|
|
36
|
-
AvmEphemeralForest,
|
|
37
|
-
AvmSimulator,
|
|
38
|
-
PublicEnqueuedCallSideEffectTrace,
|
|
39
|
-
PublicTxSimulator,
|
|
40
|
-
WorldStateDB,
|
|
41
|
-
} from '@aztec/simulator';
|
|
42
35
|
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
|
|
43
36
|
import { MerkleTrees } from '@aztec/world-state';
|
|
44
37
|
|
|
45
38
|
import { strict as assert } from 'assert';
|
|
46
39
|
|
|
47
40
|
import { initContext, initExecutionEnvironment, initPersistableStateManager } from '../../avm/fixtures/index.js';
|
|
41
|
+
import { AvmEphemeralForest, AvmSimulator } from '../../server.js';
|
|
42
|
+
import { PublicEnqueuedCallSideEffectTrace } from '../enqueued_call_side_effect_trace.js';
|
|
43
|
+
import { WorldStateDB } from '../public_db_sources.js';
|
|
44
|
+
import { PublicTxSimulator } from '../public_tx_simulator.js';
|
|
48
45
|
|
|
49
46
|
const TIMESTAMP = new Fr(99833);
|
|
50
47
|
|
|
51
48
|
export async function simulateAvmTestContractGenerateCircuitInputs(
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
setupFunctionNames: string[],
|
|
50
|
+
setupArgs: Fr[][] = [],
|
|
51
|
+
appFunctionNames: string[],
|
|
52
|
+
appArgs: Fr[][] = [],
|
|
53
|
+
teardownFunctionName?: string,
|
|
54
|
+
teardownArgs: Fr[] = [],
|
|
54
55
|
expectRevert: boolean = false,
|
|
55
56
|
contractDataSource = new MockedAvmTestContractDataSource(),
|
|
56
57
|
assertionErrString?: string,
|
|
@@ -71,17 +72,37 @@ export async function simulateAvmTestContractGenerateCircuitInputs(
|
|
|
71
72
|
);
|
|
72
73
|
|
|
73
74
|
const sender = AztecAddress.random();
|
|
74
|
-
const functionSelector = getAvmTestContractFunctionSelector(functionName);
|
|
75
|
-
args = [functionSelector.toField(), ...args];
|
|
76
75
|
const callContext = new CallContext(
|
|
77
76
|
sender,
|
|
78
77
|
contractDataSource.firstContractInstance.address,
|
|
79
78
|
contractDataSource.fnSelector,
|
|
80
79
|
/*isStaticCall=*/ false,
|
|
81
80
|
);
|
|
82
|
-
const
|
|
81
|
+
const setupExecutionRequests: PublicExecutionRequest[] = [];
|
|
82
|
+
// we reverse order because the simulator expects it to be like a "stack" of calls to pop from
|
|
83
|
+
for (let i = setupFunctionNames.length - 1; i >= 0; i--) {
|
|
84
|
+
const functionSelector = getAvmTestContractFunctionSelector(setupFunctionNames[i]);
|
|
85
|
+
const fnArgs = [functionSelector.toField(), ...setupArgs[i]];
|
|
86
|
+
const executionRequest = new PublicExecutionRequest(callContext, fnArgs);
|
|
87
|
+
setupExecutionRequests.push(executionRequest);
|
|
88
|
+
}
|
|
89
|
+
const appExecutionRequests: PublicExecutionRequest[] = [];
|
|
90
|
+
// we reverse order because the simulator expects it to be like a "stack" of calls to pop from
|
|
91
|
+
for (let i = appFunctionNames.length - 1; i >= 0; i--) {
|
|
92
|
+
const functionSelector = getAvmTestContractFunctionSelector(appFunctionNames[i]);
|
|
93
|
+
const fnArgs = [functionSelector.toField(), ...appArgs[i]];
|
|
94
|
+
const executionRequest = new PublicExecutionRequest(callContext, fnArgs);
|
|
95
|
+
appExecutionRequests.push(executionRequest);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let teardownExecutionRequest: PublicExecutionRequest | undefined = undefined;
|
|
99
|
+
if (teardownFunctionName) {
|
|
100
|
+
const functionSelector = getAvmTestContractFunctionSelector(teardownFunctionName);
|
|
101
|
+
const fnArgs = [functionSelector.toField(), ...teardownArgs];
|
|
102
|
+
teardownExecutionRequest = new PublicExecutionRequest(callContext, fnArgs);
|
|
103
|
+
}
|
|
83
104
|
|
|
84
|
-
const tx: Tx =
|
|
105
|
+
const tx: Tx = createTxForPublicCalls(setupExecutionRequests, appExecutionRequests, teardownExecutionRequest);
|
|
85
106
|
|
|
86
107
|
const avmResult = await simulator.simulate(tx);
|
|
87
108
|
|
|
@@ -141,27 +162,38 @@ export async function simulateAvmTestContractCall(
|
|
|
141
162
|
}
|
|
142
163
|
|
|
143
164
|
/**
|
|
144
|
-
* Craft a carrier transaction for
|
|
165
|
+
* Craft a carrier transaction for some public calls for simulation by PublicTxSimulator.
|
|
145
166
|
*/
|
|
146
|
-
export function
|
|
147
|
-
|
|
167
|
+
export function createTxForPublicCalls(
|
|
168
|
+
setupExecutionRequests: PublicExecutionRequest[],
|
|
169
|
+
appExecutionRequests: PublicExecutionRequest[],
|
|
170
|
+
teardownExecutionRequest?: PublicExecutionRequest,
|
|
148
171
|
gasUsedByPrivate: Gas = Gas.empty(),
|
|
149
|
-
isTeardown: boolean = false,
|
|
150
172
|
): Tx {
|
|
151
|
-
|
|
173
|
+
assert(
|
|
174
|
+
setupExecutionRequests.length > 0 || appExecutionRequests.length > 0 || teardownExecutionRequest !== undefined,
|
|
175
|
+
"Can't create public tx with no enqueued calls",
|
|
176
|
+
);
|
|
177
|
+
const setupCallRequests = setupExecutionRequests.map(er => er.toCallRequest());
|
|
178
|
+
const appCallRequests = appExecutionRequests.map(er => er.toCallRequest());
|
|
152
179
|
// use max limits
|
|
153
180
|
const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_TX_PUBLIC_PORTION);
|
|
154
181
|
|
|
155
182
|
const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
|
|
156
183
|
// TODO(#9269): Remove this fake nullifier method as we move away from 1st nullifier as hash.
|
|
157
184
|
forPublic.nonRevertibleAccumulatedData.nullifiers[0] = Fr.random(); // fake tx nullifier
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
185
|
+
|
|
186
|
+
for (let i = 0; i < setupExecutionRequests.length; i++) {
|
|
187
|
+
forPublic.nonRevertibleAccumulatedData.publicCallRequests[i] = setupCallRequests[i];
|
|
188
|
+
}
|
|
189
|
+
for (let i = 0; i < appCallRequests.length; i++) {
|
|
190
|
+
forPublic.revertibleAccumulatedData.publicCallRequests[i] = appCallRequests[i];
|
|
191
|
+
}
|
|
192
|
+
if (teardownExecutionRequest) {
|
|
193
|
+
forPublic.publicTeardownCallRequest = teardownExecutionRequest.toCallRequest();
|
|
162
194
|
}
|
|
163
195
|
|
|
164
|
-
const teardownGasLimits =
|
|
196
|
+
const teardownGasLimits = teardownExecutionRequest ? gasLimits : Gas.empty();
|
|
165
197
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
166
198
|
const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
|
|
167
199
|
const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
|
|
@@ -173,9 +205,13 @@ export function createTxForPublicCall(
|
|
|
173
205
|
AztecAddress.zero(),
|
|
174
206
|
forPublic,
|
|
175
207
|
);
|
|
176
|
-
const tx =
|
|
177
|
-
|
|
178
|
-
|
|
208
|
+
const tx = Tx.newWithTxData(txData, teardownExecutionRequest);
|
|
209
|
+
|
|
210
|
+
for (let i = 0; i < setupExecutionRequests.length; i++) {
|
|
211
|
+
tx.enqueuedPublicFunctionCalls.push(setupExecutionRequests[i]);
|
|
212
|
+
}
|
|
213
|
+
for (let i = 0; i < appExecutionRequests.length; i++) {
|
|
214
|
+
tx.enqueuedPublicFunctionCalls.push(appExecutionRequests[i]);
|
|
179
215
|
}
|
|
180
216
|
|
|
181
217
|
return tx;
|
|
@@ -24,12 +24,9 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
24
24
|
import { Timer } from '@aztec/foundation/timer';
|
|
25
25
|
import { ContractClassRegisteredEvent } from '@aztec/protocol-contracts/class-registerer';
|
|
26
26
|
import { ContractInstanceDeployedEvent } from '@aztec/protocol-contracts/instance-deployer';
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
type PublicContractsDB,
|
|
31
|
-
type PublicStateDB,
|
|
32
|
-
} from '@aztec/simulator';
|
|
27
|
+
|
|
28
|
+
import { MessageLoadOracleInputs } from '../common/message_load_oracle_inputs.js';
|
|
29
|
+
import { type CommitmentsDB, type PublicContractsDB, type PublicStateDB } from './db_interfaces.js';
|
|
33
30
|
|
|
34
31
|
/**
|
|
35
32
|
* Implements the PublicContractsDB using a ContractDataSource.
|
|
@@ -290,7 +290,7 @@ export class PublicProcessor implements Traceable {
|
|
|
290
290
|
return [result, failed, returns];
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
@trackSpan('PublicProcessor.processTx', tx => ({ [Attributes.TX_HASH]: tx.
|
|
293
|
+
@trackSpan('PublicProcessor.processTx', tx => ({ [Attributes.TX_HASH]: tx.getTxHash().toString() }))
|
|
294
294
|
private async processTx(tx: Tx, deadline?: Date): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
|
|
295
295
|
const [time, [processedTx, returnValues]] = await elapsed(() => this.processTxWithinDeadline(tx, deadline));
|
|
296
296
|
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type SimulationError,
|
|
8
8
|
type Tx,
|
|
9
9
|
TxExecutionPhase,
|
|
10
|
-
TxHash,
|
|
10
|
+
type TxHash,
|
|
11
11
|
} from '@aztec/circuit-types';
|
|
12
12
|
import {
|
|
13
13
|
AvmCircuitInputs,
|
|
@@ -61,6 +61,7 @@ export class PublicTxContext {
|
|
|
61
61
|
public avmProvingRequest: AvmProvingRequest | undefined; // FIXME(dbanks12): remove
|
|
62
62
|
|
|
63
63
|
constructor(
|
|
64
|
+
public readonly txHash: TxHash,
|
|
64
65
|
public readonly state: PhaseStateManager,
|
|
65
66
|
private readonly globalVariables: GlobalVariables,
|
|
66
67
|
private readonly startStateReference: StateReference,
|
|
@@ -103,12 +104,14 @@ export class PublicTxContext {
|
|
|
103
104
|
previousAccumulatedDataArrayLengths,
|
|
104
105
|
);
|
|
105
106
|
|
|
107
|
+
const firstNullifier = nonRevertibleAccumulatedDataFromPrivate.nullifiers[0];
|
|
108
|
+
|
|
106
109
|
// Transaction level state manager that will be forked for revertible phases.
|
|
107
110
|
const txStateManager = await AvmPersistableStateManager.create(
|
|
108
111
|
worldStateDB,
|
|
109
112
|
enqueuedCallTrace,
|
|
110
113
|
doMerkleOperations,
|
|
111
|
-
|
|
114
|
+
firstNullifier,
|
|
112
115
|
);
|
|
113
116
|
|
|
114
117
|
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
@@ -117,6 +120,7 @@ export class PublicTxContext {
|
|
|
117
120
|
const gasAllocatedToPublic = applyMaxToAvailableGas(gasSettings.gasLimits.sub(gasUsedByPrivate));
|
|
118
121
|
|
|
119
122
|
return new PublicTxContext(
|
|
123
|
+
tx.getTxHash(),
|
|
120
124
|
new PhaseStateManager(txStateManager),
|
|
121
125
|
globalVariables,
|
|
122
126
|
await db.getStateReference(),
|
|
@@ -188,14 +192,6 @@ export class PublicTxContext {
|
|
|
188
192
|
return this.revertCode;
|
|
189
193
|
}
|
|
190
194
|
|
|
191
|
-
/**
|
|
192
|
-
* Construct & return transaction hash.
|
|
193
|
-
* @returns The transaction's hash.
|
|
194
|
-
*/
|
|
195
|
-
getTxHash(): TxHash {
|
|
196
|
-
return fetchTxHash(this.nonRevertibleAccumulatedDataFromPrivate);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
195
|
/**
|
|
200
196
|
* Are there any call requests for the speciiied phase?
|
|
201
197
|
*/
|
|
@@ -452,12 +448,3 @@ function applyMaxToAvailableGas(availableGas: Gas) {
|
|
|
452
448
|
/*l2Gas=*/ Math.min(availableGas.l2Gas, MAX_L2_GAS_PER_TX_PUBLIC_PORTION),
|
|
453
449
|
);
|
|
454
450
|
}
|
|
455
|
-
|
|
456
|
-
function fetchTxHash(nonRevertibleAccumulatedData: PrivateToPublicAccumulatedData): TxHash {
|
|
457
|
-
// Private kernel functions are executed client side and for this reason tx hash is already set as first nullifier
|
|
458
|
-
const firstNullifier = nonRevertibleAccumulatedData.nullifiers[0];
|
|
459
|
-
if (!firstNullifier || firstNullifier.isZero()) {
|
|
460
|
-
throw new Error(`Cannot get tx hash since first nullifier is missing`);
|
|
461
|
-
}
|
|
462
|
-
return new TxHash(firstNullifier);
|
|
463
|
-
}
|
|
@@ -219,8 +219,8 @@ export class PublicTxSimulator {
|
|
|
219
219
|
const callRequests = context.getCallRequestsForPhase(phase);
|
|
220
220
|
const executionRequests = context.getExecutionRequestsForPhase(phase);
|
|
221
221
|
|
|
222
|
-
this.log.debug(`Processing phase ${TxExecutionPhase[phase]} for tx ${context.
|
|
223
|
-
txHash: context.
|
|
222
|
+
this.log.debug(`Processing phase ${TxExecutionPhase[phase]} for tx ${context.txHash}`, {
|
|
223
|
+
txHash: context.txHash.toString(),
|
|
224
224
|
phase: TxExecutionPhase[phase],
|
|
225
225
|
callRequests: callRequests.length,
|
|
226
226
|
executionRequests: executionRequests.length,
|
|
@@ -266,7 +266,7 @@ export class PublicTxSimulator {
|
|
|
266
266
|
* @returns The result of execution.
|
|
267
267
|
*/
|
|
268
268
|
@trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context, _callRequest, executionRequest) => ({
|
|
269
|
-
[Attributes.TX_HASH]: context.
|
|
269
|
+
[Attributes.TX_HASH]: context.txHash.toString(),
|
|
270
270
|
[Attributes.TARGET_ADDRESS]: executionRequest.callContext.contractAddress.toString(),
|
|
271
271
|
[Attributes.SENDER_ADDRESS]: executionRequest.callContext.msgSender.toString(),
|
|
272
272
|
[Attributes.SIMULATOR_PHASE]: TxExecutionPhase[phase].toString(),
|
|
@@ -294,7 +294,7 @@ export class PublicTxSimulator {
|
|
|
294
294
|
const gasUsed = allocatedGas.sub(result.gasLeft); // by enqueued call
|
|
295
295
|
context.consumeGas(phase, gasUsed);
|
|
296
296
|
this.log.debug(
|
|
297
|
-
`Simulated enqueued public call consumed ${gasUsed.l2Gas} L2 gas ending with ${result.gasLeft.l2Gas} L2 gas left.`,
|
|
297
|
+
`Simulated enqueued public call (${fnName}) consumed ${gasUsed.l2Gas} L2 gas ending with ${result.gasLeft.l2Gas} L2 gas left.`,
|
|
298
298
|
);
|
|
299
299
|
|
|
300
300
|
stateManager.traceEnqueuedCall(callRequest, executionRequest.args, result.reverted);
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
export * from './acvm/index.js';
|
|
2
1
|
export * from './avm/index.js';
|
|
3
|
-
export * from './client/index.js';
|
|
4
2
|
export * from './common/index.js';
|
|
5
3
|
export * from './public/index.js';
|
|
6
4
|
export * from './providers/index.js';
|
|
7
5
|
export * from './stats/index.js';
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { PackedValues } from '@aztec/circuit-types';
|
|
2
|
-
import { Fr } from '@aztec/circuits.js';
|
|
3
|
-
/**
|
|
4
|
-
* A cache for packed values (arguments, returns) during transaction execution.
|
|
5
|
-
*/
|
|
6
|
-
export declare class PackedValuesCache {
|
|
7
|
-
private cache;
|
|
8
|
-
constructor(initialArguments?: PackedValues[]);
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new packed values cache.
|
|
11
|
-
* @param initialArguments - The initial arguments to add to the cache.
|
|
12
|
-
* @returns The new packed values cache.
|
|
13
|
-
*/
|
|
14
|
-
static create(initialArguments?: PackedValues[]): PackedValuesCache;
|
|
15
|
-
/**
|
|
16
|
-
* Unpacks packed values.
|
|
17
|
-
* @param hash - The hash of the packed values.
|
|
18
|
-
* @returns The unpacked values.
|
|
19
|
-
*/
|
|
20
|
-
unpack(hash: Fr): Fr[];
|
|
21
|
-
/**
|
|
22
|
-
* Packs values.
|
|
23
|
-
* @param values - The values to pack.
|
|
24
|
-
* @returns The hash of the packed values.
|
|
25
|
-
*/
|
|
26
|
-
pack(values: Fr[]): Fr;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=packed_values_cache.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"packed_values_cache.d.ts","sourceRoot":"","sources":["../../src/common/packed_values_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAExC;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,KAAK,CAAoB;gBAErB,gBAAgB,GAAE,YAAY,EAAO;IAOjD;;;;OAIG;WACW,MAAM,CAAC,gBAAgB,GAAE,YAAY,EAAO;IAI1D;;;;OAIG;IACI,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE;IAW7B;;;;OAIG;IACI,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE;CAQzB"}
|
package/dest/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC"}
|
package/dest/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './acvm/index.js';
|
|
2
|
-
export * from './avm/index.js';
|
|
3
|
-
export * from './client/index.js';
|
|
4
|
-
export * from './common/index.js';
|
|
5
|
-
export * from './public/index.js';
|
|
6
|
-
export * from './providers/index.js';
|
|
7
|
-
export * from './stats/index.js';
|
|
8
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxpQkFBaUIsQ0FBQztBQUNoQyxjQUFjLGdCQUFnQixDQUFDO0FBQy9CLGNBQWMsbUJBQW1CLENBQUM7QUFDbEMsY0FBYyxtQkFBbUIsQ0FBQztBQUNsQyxjQUFjLG1CQUFtQixDQUFDO0FBQ2xDLGNBQWMsc0JBQXNCLENBQUM7QUFDckMsY0FBYyxrQkFBa0IsQ0FBQyJ9
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
2
|
-
import { type WitnessMap } from '@noir-lang/types';
|
|
3
|
-
/**
|
|
4
|
-
* Low level simulation interface
|
|
5
|
-
*/
|
|
6
|
-
export interface SimulationProvider {
|
|
7
|
-
simulateCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap>;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=simulation_provider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"simulation_provider.d.ts","sourceRoot":"","sources":["../../src/providers/simulation_provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC/F"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { PackedValues } from '@aztec/circuit-types';
|
|
2
|
-
import { Fr } from '@aztec/circuits.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A cache for packed values (arguments, returns) during transaction execution.
|
|
6
|
-
*/
|
|
7
|
-
export class PackedValuesCache {
|
|
8
|
-
private cache: Map<bigint, Fr[]>;
|
|
9
|
-
|
|
10
|
-
constructor(initialArguments: PackedValues[] = []) {
|
|
11
|
-
this.cache = new Map();
|
|
12
|
-
for (const initialArg of initialArguments) {
|
|
13
|
-
this.cache.set(initialArg.hash.toBigInt(), initialArg.values);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Creates a new packed values cache.
|
|
19
|
-
* @param initialArguments - The initial arguments to add to the cache.
|
|
20
|
-
* @returns The new packed values cache.
|
|
21
|
-
*/
|
|
22
|
-
public static create(initialArguments: PackedValues[] = []) {
|
|
23
|
-
return new PackedValuesCache(initialArguments);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Unpacks packed values.
|
|
28
|
-
* @param hash - The hash of the packed values.
|
|
29
|
-
* @returns The unpacked values.
|
|
30
|
-
*/
|
|
31
|
-
public unpack(hash: Fr): Fr[] {
|
|
32
|
-
if (hash.equals(Fr.ZERO)) {
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
const packedValues = this.cache.get(hash.value);
|
|
36
|
-
if (!packedValues) {
|
|
37
|
-
throw new Error(`Packed values for hash ${hash.toString()} not found in cache`);
|
|
38
|
-
}
|
|
39
|
-
return packedValues;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Packs values.
|
|
44
|
-
* @param values - The values to pack.
|
|
45
|
-
* @returns The hash of the packed values.
|
|
46
|
-
*/
|
|
47
|
-
public pack(values: Fr[]) {
|
|
48
|
-
if (values.length === 0) {
|
|
49
|
-
return Fr.ZERO;
|
|
50
|
-
}
|
|
51
|
-
const packedValues = PackedValues.fromValues(values);
|
|
52
|
-
this.cache.set(packedValues.hash.value, packedValues.values);
|
|
53
|
-
return packedValues.hash;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
2
|
-
|
|
3
|
-
import { type WitnessMap } from '@noir-lang/types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Low level simulation interface
|
|
7
|
-
*/
|
|
8
|
-
export interface SimulationProvider {
|
|
9
|
-
simulateCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap>;
|
|
10
|
-
}
|