@aztec/simulator 0.80.0 → 0.82.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/common/db_interfaces.d.ts +30 -17
- package/dest/common/db_interfaces.d.ts.map +1 -1
- package/dest/common/db_interfaces.js +1 -1
- package/dest/common/debug_fn_name.d.ts +2 -2
- package/dest/common/debug_fn_name.d.ts.map +1 -1
- 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 +19 -18
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/deserialize.js +31 -23
- package/dest/private/acvm/oracle/oracle.d.ts +36 -34
- package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.js +134 -79
- package/dest/private/acvm/oracle/typed_oracle.d.ts +3 -2
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/typed_oracle.js +5 -2
- package/dest/private/acvm/serialize.d.ts +11 -0
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +27 -0
- package/dest/private/execution_data_provider.d.ts +15 -13
- package/dest/private/execution_data_provider.d.ts.map +1 -1
- 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 -5
- package/dest/private/private_execution_oracle.d.ts.map +1 -1
- package/dest/private/private_execution_oracle.js +1 -1
- 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 +2 -2
- 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 +5 -3
- package/dest/private/unconstrained_execution_oracle.d.ts.map +1 -1
- package/dest/private/unconstrained_execution_oracle.js +9 -5
- 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.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +5 -5
- package/dest/public/avm/fixtures/index.d.ts +4 -4
- package/dest/public/avm/fixtures/index.d.ts.map +1 -1
- package/dest/public/avm/fixtures/index.js +9 -6
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +1 -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 +0 -3
- package/dest/public/avm/journal/journal.d.ts +16 -70
- package/dest/public/avm/journal/journal.d.ts.map +1 -1
- package/dest/public/avm/journal/journal.js +88 -210
- package/dest/public/avm/journal/nullifiers.d.ts +2 -2
- package/dest/public/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/public/avm/journal/public_storage.d.ts +2 -2
- package/dest/public/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/public/avm/test_utils.d.ts +10 -13
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/avm/test_utils.js +8 -13
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +3 -3
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +10 -9
- package/dest/public/hinting_db_sources.d.ts +19 -0
- package/dest/public/hinting_db_sources.d.ts.map +1 -0
- package/dest/public/hinting_db_sources.js +36 -0
- package/dest/public/public_db_sources.d.ts +46 -22
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +82 -27
- package/dest/public/public_processor/public_processor.d.ts +5 -5
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +21 -20
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +9 -14
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +15 -19
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +9 -6
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +28 -14
- package/dest/public/side_effect_trace.d.ts +6 -22
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +11 -70
- package/dest/public/side_effect_trace_interface.d.ts +5 -19
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- 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 +32 -18
- package/src/common/debug_fn_name.ts +2 -2
- package/src/common/message_load_oracle_inputs.ts +8 -0
- package/src/private/acvm/acvm.ts +8 -24
- package/src/private/acvm/deserialize.ts +35 -29
- package/src/private/acvm/oracle/oracle.ts +171 -129
- package/src/private/acvm/oracle/typed_oracle.ts +7 -3
- package/src/private/acvm/serialize.ts +28 -0
- package/src/private/execution_data_provider.ts +19 -14
- package/src/private/private_execution.ts +11 -7
- package/src/private/private_execution_oracle.ts +5 -1
- 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 +5 -3
- package/src/private/unconstrained_execution.ts +8 -4
- package/src/private/unconstrained_execution_oracle.ts +15 -9
- package/src/public/avm/avm_simulator.ts +0 -2
- package/src/public/avm/fixtures/avm_simulation_tester.ts +8 -5
- package/src/public/avm/fixtures/index.ts +16 -10
- package/src/public/avm/fixtures/simple_contract_data_source.ts +1 -10
- package/src/public/avm/journal/journal.ts +119 -353
- package/src/public/avm/journal/nullifiers.ts +2 -2
- package/src/public/avm/journal/public_storage.ts +2 -2
- package/src/public/avm/test_utils.ts +20 -29
- package/src/public/fixtures/public_tx_simulation_tester.ts +9 -12
- package/src/public/hinting_db_sources.ts +71 -0
- package/src/public/public_db_sources.ts +134 -32
- package/src/public/public_processor/public_processor.ts +22 -21
- package/src/public/public_tx_simulator/public_tx_context.ts +30 -38
- package/src/public/public_tx_simulator/public_tx_simulator.ts +47 -17
- package/src/public/side_effect_trace.ts +8 -172
- package/src/public/side_effect_trace_interface.ts +4 -55
- 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/src/public/avm/bytecode_utils.ts +0 -17
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ForeignCallHandler } from '@aztec/noir-protocol-circuits-types/types';
|
|
2
|
+
import type { FunctionArtifactWithContractName } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
|
|
4
|
+
|
|
5
|
+
import type { ACIRCallback, ACIRExecutionResult } from '../../acvm/acvm.js';
|
|
6
|
+
import type { ACVMWitness } from '../../acvm/acvm_types.js';
|
|
7
|
+
import type { SimulationProvider } from '../simulation_provider.js';
|
|
8
|
+
import { CircuitRecorder } from './circuit_recorder.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Takes a simulation provider and wraps it in a circuit recorder. See CircuitRecorder for more details on how circuit
|
|
12
|
+
* recording works.
|
|
13
|
+
*/
|
|
14
|
+
export class SimulationProviderRecorderWrapper implements SimulationProvider {
|
|
15
|
+
constructor(private simulator: SimulationProvider) {}
|
|
16
|
+
|
|
17
|
+
executeProtocolCircuit(
|
|
18
|
+
input: ACVMWitness,
|
|
19
|
+
artifact: NoirCompiledCircuitWithName,
|
|
20
|
+
callback: ForeignCallHandler | undefined,
|
|
21
|
+
): Promise<ACVMWitness> {
|
|
22
|
+
const bytecode = Buffer.from(artifact.bytecode, 'base64');
|
|
23
|
+
|
|
24
|
+
return this.#simulate<ForeignCallHandler | undefined, ACVMWitness>(
|
|
25
|
+
wrappedCallback => this.simulator.executeProtocolCircuit(input, artifact, wrappedCallback),
|
|
26
|
+
input,
|
|
27
|
+
bytecode,
|
|
28
|
+
artifact.name,
|
|
29
|
+
'main',
|
|
30
|
+
callback,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
executeUserCircuit(
|
|
35
|
+
input: ACVMWitness,
|
|
36
|
+
artifact: FunctionArtifactWithContractName,
|
|
37
|
+
callback: ACIRCallback,
|
|
38
|
+
): Promise<ACIRExecutionResult> {
|
|
39
|
+
return this.#simulate<ACIRCallback, ACIRExecutionResult>(
|
|
40
|
+
wrappedCallback => this.simulator.executeUserCircuit(input, artifact, wrappedCallback),
|
|
41
|
+
input,
|
|
42
|
+
artifact.bytecode,
|
|
43
|
+
artifact.contractName,
|
|
44
|
+
artifact.name,
|
|
45
|
+
callback,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async #simulate<C extends ACIRCallback | ForeignCallHandler | undefined, T>(
|
|
50
|
+
simulateFn: (wrappedCallback: C) => Promise<T>,
|
|
51
|
+
input: ACVMWitness,
|
|
52
|
+
bytecode: Buffer,
|
|
53
|
+
contractName: string,
|
|
54
|
+
functionName: string,
|
|
55
|
+
callback: C,
|
|
56
|
+
): Promise<T> {
|
|
57
|
+
const recordDir = process.env.CIRCUIT_RECORD_DIR;
|
|
58
|
+
if (!recordDir) {
|
|
59
|
+
// Recording is not enabled so we just execute the circuit
|
|
60
|
+
return simulateFn(callback);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Start recording circuit execution
|
|
64
|
+
const recorder = await CircuitRecorder.start(recordDir, input, bytecode, contractName, functionName);
|
|
65
|
+
|
|
66
|
+
// If callback was provided, we wrap it in a circuit recorder callback wrapper
|
|
67
|
+
const wrappedCallback = recorder.wrapCallback(callback);
|
|
68
|
+
let result: T;
|
|
69
|
+
try {
|
|
70
|
+
result = await simulateFn(wrappedCallback as C);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
// If an error occurs, we finalize the recording file with the error
|
|
73
|
+
await recorder.finishWithError(error);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Witness generation is complete so we finish the circuit recorder
|
|
78
|
+
await recorder.finish();
|
|
79
|
+
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ExecutionError } from '@aztec/noir-acvm_js';
|
|
1
|
+
import type { ExecutionError, ForeignCallHandler } from '@aztec/noir-acvm_js';
|
|
2
2
|
import { abiDecodeError } from '@aztec/noir-noirc_abi';
|
|
3
|
-
import type { WitnessMap } from '@aztec/noir-types';
|
|
4
3
|
import { parseDebugSymbols } from '@aztec/stdlib/abi';
|
|
5
|
-
import type {
|
|
4
|
+
import type { FunctionArtifactWithContractName } from '@aztec/stdlib/abi';
|
|
5
|
+
import type { NoirCompiledCircuit, NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
|
|
6
6
|
|
|
7
7
|
import { type ACIRCallback, type ACIRExecutionResult, extractCallStack } from '../acvm/acvm.js';
|
|
8
8
|
import type { ACVMWitness } from '../acvm/acvm_types.js';
|
|
@@ -11,8 +11,33 @@ import type { ACVMWitness } from '../acvm/acvm_types.js';
|
|
|
11
11
|
* Low level simulation interface
|
|
12
12
|
*/
|
|
13
13
|
export interface SimulationProvider {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Execute a protocol circuit/generate a witness
|
|
16
|
+
* @param input - The initial witness map defining all of the inputs to `circuit`.
|
|
17
|
+
* @param artifact - ACIR circuit bytecode and its metadata.
|
|
18
|
+
* @param callback - A callback to process any foreign calls from the circuit. Can be undefined as for native
|
|
19
|
+
* ACVM simulator we don't process foreign calls.
|
|
20
|
+
* @returns The solved witness calculated by executing the circuit on the provided inputs.
|
|
21
|
+
*/
|
|
22
|
+
executeProtocolCircuit(
|
|
23
|
+
input: ACVMWitness,
|
|
24
|
+
artifact: NoirCompiledCircuitWithName,
|
|
25
|
+
callback: ForeignCallHandler | undefined,
|
|
26
|
+
): Promise<ACVMWitness>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Execute a user circuit (smart contract function)/generate a witness
|
|
30
|
+
* @param input - The initial witness map defining all of the inputs to `circuit`.
|
|
31
|
+
* @param artifact - Contract function ACIR circuit bytecode and its metadata.
|
|
32
|
+
* @param callback - A callback to process any foreign calls from the circuit.
|
|
33
|
+
* @returns The solved witness calculated by executing the circuit on the provided inputs, as well as the return
|
|
34
|
+
* witness indices as specified by the circuit.
|
|
35
|
+
*/
|
|
36
|
+
executeUserCircuit(
|
|
37
|
+
input: ACVMWitness,
|
|
38
|
+
artifact: FunctionArtifactWithContractName,
|
|
39
|
+
callback: ACIRCallback,
|
|
40
|
+
): Promise<ACIRExecutionResult>;
|
|
16
41
|
}
|
|
17
42
|
|
|
18
43
|
export type DecodedError = ExecutionError & { decodedAssertionPayload?: any; noirCallStack?: string[] };
|
package/src/private/simulator.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import type { FunctionCall } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AbiDecoded, FunctionCall } from '@aztec/stdlib/abi';
|
|
4
4
|
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
5
|
+
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
5
6
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
7
|
import { CallContext, PrivateExecutionResult, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
7
8
|
|
|
@@ -113,8 +114,9 @@ export class AcirSimulator {
|
|
|
113
114
|
request: FunctionCall,
|
|
114
115
|
contractAddress: AztecAddress,
|
|
115
116
|
selector: FunctionSelector,
|
|
117
|
+
authwits: AuthWitness[],
|
|
116
118
|
scopes?: AztecAddress[],
|
|
117
|
-
) {
|
|
119
|
+
): Promise<AbiDecoded> {
|
|
118
120
|
await verifyCurrentClassId(contractAddress, this.executionDataProvider);
|
|
119
121
|
const entryPointArtifact = await this.executionDataProvider.getFunctionArtifact(contractAddress, selector);
|
|
120
122
|
|
|
@@ -124,7 +126,7 @@ export class AcirSimulator {
|
|
|
124
126
|
|
|
125
127
|
const context = new UnconstrainedExecutionOracle(
|
|
126
128
|
contractAddress,
|
|
127
|
-
|
|
129
|
+
authwits,
|
|
128
130
|
[],
|
|
129
131
|
this.executionDataProvider,
|
|
130
132
|
undefined,
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type AbiDecoded,
|
|
5
|
+
type FunctionArtifactWithContractName,
|
|
6
|
+
type FunctionSelector,
|
|
7
|
+
decodeFromAbi,
|
|
8
|
+
} from '@aztec/stdlib/abi';
|
|
4
9
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
10
|
|
|
6
11
|
import { ExecutionError, resolveAssertionMessageFromError } from '../common/errors.js';
|
|
@@ -16,7 +21,7 @@ import type { UnconstrainedExecutionOracle } from './unconstrained_execution_ora
|
|
|
16
21
|
export async function executeUnconstrainedFunction(
|
|
17
22
|
simulatorProvider: SimulationProvider,
|
|
18
23
|
oracle: UnconstrainedExecutionOracle,
|
|
19
|
-
artifact:
|
|
24
|
+
artifact: FunctionArtifactWithContractName,
|
|
20
25
|
contractAddress: AztecAddress,
|
|
21
26
|
functionSelector: FunctionSelector,
|
|
22
27
|
args: Fr[],
|
|
@@ -27,10 +32,9 @@ export async function executeUnconstrainedFunction(
|
|
|
27
32
|
selector: functionSelector,
|
|
28
33
|
});
|
|
29
34
|
|
|
30
|
-
const acir = artifact.bytecode;
|
|
31
35
|
const initialWitness = toACVMWitness(0, args);
|
|
32
36
|
const acirExecutionResult = await simulatorProvider
|
|
33
|
-
.executeUserCircuit(
|
|
37
|
+
.executeUserCircuit(initialWitness, artifact, new Oracle(oracle))
|
|
34
38
|
.catch((err: Error) => {
|
|
35
39
|
err.message = resolveAssertionMessageFromError(err, artifact);
|
|
36
40
|
throw new ExecutionError(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Aes128 } from '@aztec/foundation/crypto';
|
|
2
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { Fr, Point } from '@aztec/foundation/fields';
|
|
3
3
|
import { applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
5
5
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -23,7 +23,7 @@ export class UnconstrainedExecutionOracle extends TypedOracle {
|
|
|
23
23
|
protected readonly contractAddress: AztecAddress,
|
|
24
24
|
/** List of transient auth witnesses to be used during this simulation */
|
|
25
25
|
protected readonly authWitnesses: AuthWitness[],
|
|
26
|
-
protected readonly capsules: Capsule[],
|
|
26
|
+
protected readonly capsules: Capsule[], // TODO(#12425): Rename to transientCapsules
|
|
27
27
|
protected readonly executionDataProvider: ExecutionDataProvider,
|
|
28
28
|
protected log = createLogger('simulator:client_view_context'),
|
|
29
29
|
protected readonly scopes?: AztecAddress[],
|
|
@@ -103,11 +103,11 @@ export class UnconstrainedExecutionOracle extends TypedOracle {
|
|
|
103
103
|
* @param leafSlot - The slot of the public data tree to get the witness for.
|
|
104
104
|
* @returns - The witness
|
|
105
105
|
*/
|
|
106
|
-
public override async
|
|
106
|
+
public override async getPublicDataWitness(
|
|
107
107
|
blockNumber: number,
|
|
108
108
|
leafSlot: Fr,
|
|
109
109
|
): Promise<PublicDataWitness | undefined> {
|
|
110
|
-
return await this.executionDataProvider.
|
|
110
|
+
return await this.executionDataProvider.getPublicDataWitness(blockNumber, leafSlot);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**
|
|
@@ -149,10 +149,7 @@ export class UnconstrainedExecutionOracle extends TypedOracle {
|
|
|
149
149
|
* @returns Authentication witness for the requested message hash.
|
|
150
150
|
*/
|
|
151
151
|
public override getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
|
|
152
|
-
return Promise.resolve(
|
|
153
|
-
this.authWitnesses.find(w => w.requestHash.equals(messageHash))?.witness ??
|
|
154
|
-
this.executionDataProvider.getAuthWitness(messageHash),
|
|
155
|
-
);
|
|
152
|
+
return Promise.resolve(this.authWitnesses.find(w => w.requestHash.equals(messageHash))?.witness);
|
|
156
153
|
}
|
|
157
154
|
|
|
158
155
|
/**
|
|
@@ -288,7 +285,11 @@ export class UnconstrainedExecutionOracle extends TypedOracle {
|
|
|
288
285
|
);
|
|
289
286
|
|
|
290
287
|
for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) {
|
|
291
|
-
await this.executionDataProvider.processTaggedLogs(
|
|
288
|
+
await this.executionDataProvider.processTaggedLogs(
|
|
289
|
+
this.contractAddress,
|
|
290
|
+
taggedLogs,
|
|
291
|
+
AztecAddress.fromString(recipient),
|
|
292
|
+
);
|
|
292
293
|
}
|
|
293
294
|
|
|
294
295
|
await this.executionDataProvider.removeNullifiedNotes(this.contractAddress);
|
|
@@ -339,6 +340,7 @@ export class UnconstrainedExecutionOracle extends TypedOracle {
|
|
|
339
340
|
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
|
|
340
341
|
}
|
|
341
342
|
return (
|
|
343
|
+
// TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
|
|
342
344
|
this.capsules.find(c => c.contractAddress.equals(contractAddress) && c.storageSlot.equals(slot))?.data ??
|
|
343
345
|
(await this.executionDataProvider.loadCapsule(this.contractAddress, slot))
|
|
344
346
|
);
|
|
@@ -370,4 +372,8 @@ export class UnconstrainedExecutionOracle extends TypedOracle {
|
|
|
370
372
|
const aes128 = new Aes128();
|
|
371
373
|
return aes128.decryptBufferCBC(ciphertext, iv, symKey);
|
|
372
374
|
}
|
|
375
|
+
|
|
376
|
+
public override getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
|
|
377
|
+
return this.executionDataProvider.getSharedSecret(address, ephPk);
|
|
378
|
+
}
|
|
373
379
|
}
|
|
@@ -12,7 +12,6 @@ import { AvmContractCallResult } from './avm_contract_call_result.js';
|
|
|
12
12
|
import { AvmExecutionEnvironment } from './avm_execution_environment.js';
|
|
13
13
|
import type { Gas } from './avm_gas.js';
|
|
14
14
|
import { AvmMachineState } from './avm_machine_state.js';
|
|
15
|
-
import { isAvmBytecode } from './bytecode_utils.js';
|
|
16
15
|
import {
|
|
17
16
|
AvmExecutionError,
|
|
18
17
|
AvmRevertReason,
|
|
@@ -139,7 +138,6 @@ export class AvmSimulator {
|
|
|
139
138
|
*/
|
|
140
139
|
public async executeBytecode(bytecode: Buffer): Promise<AvmContractCallResult> {
|
|
141
140
|
const startTotalTime = performance.now();
|
|
142
|
-
assert(isAvmBytecode(bytecode), "AVM simulator can't execute non-AVM bytecode");
|
|
143
141
|
assert(bytecode.length > 0, "AVM simulator can't execute empty bytecode");
|
|
144
142
|
|
|
145
143
|
this.bytecode = bytecode;
|
|
@@ -16,7 +16,8 @@ import {
|
|
|
16
16
|
resolveContractAssertionMessage,
|
|
17
17
|
} from '../../avm/fixtures/index.js';
|
|
18
18
|
import { AvmPersistableStateManager } from '../../avm/journal/journal.js';
|
|
19
|
-
import {
|
|
19
|
+
import { DEFAULT_BLOCK_NUMBER } from '../../fixtures/public_tx_simulation_tester.js';
|
|
20
|
+
import { PublicContractsDB, PublicTreesDB } from '../../public_db_sources.js';
|
|
20
21
|
import { AvmSimulator } from '../avm_simulator.js';
|
|
21
22
|
import { BaseAvmSimulationTester } from './base_avm_simulation_tester.js';
|
|
22
23
|
import { SimpleContractDataSource } from './simple_contract_data_source.js';
|
|
@@ -41,16 +42,18 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
|
|
|
41
42
|
static async create(): Promise<AvmSimulationTester> {
|
|
42
43
|
const contractDataSource = new SimpleContractDataSource();
|
|
43
44
|
const merkleTrees = await (await NativeWorldStateService.tmp()).fork();
|
|
44
|
-
const
|
|
45
|
+
const treesDB = new PublicTreesDB(merkleTrees);
|
|
46
|
+
const contractsDB = new PublicContractsDB(contractDataSource);
|
|
45
47
|
const trace = new SideEffectTrace();
|
|
46
48
|
const firstNullifier = new Fr(420000);
|
|
47
|
-
|
|
48
|
-
// failures on 2nd call to simulateCall with merkle ops on
|
|
49
|
+
|
|
49
50
|
const stateManager = AvmPersistableStateManager.create(
|
|
50
|
-
|
|
51
|
+
treesDB,
|
|
52
|
+
contractsDB,
|
|
51
53
|
trace,
|
|
52
54
|
/*doMerkleOperations=*/ false,
|
|
53
55
|
firstNullifier,
|
|
56
|
+
DEFAULT_BLOCK_NUMBER,
|
|
54
57
|
);
|
|
55
58
|
return new AvmSimulationTester(contractDataSource, merkleTrees, stateManager);
|
|
56
59
|
}
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import { isNoirCallStackUnresolved } from '@aztec/stdlib/errors';
|
|
24
24
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
25
25
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
26
|
-
import
|
|
26
|
+
import { deriveKeys } from '@aztec/stdlib/keys';
|
|
27
27
|
import { makeContractClassPublic, makeContractInstanceFromClassId } from '@aztec/stdlib/testing';
|
|
28
28
|
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
29
29
|
|
|
@@ -32,7 +32,8 @@ import { mock } from 'jest-mock-extended';
|
|
|
32
32
|
import merge from 'lodash.merge';
|
|
33
33
|
|
|
34
34
|
import { resolveAssertionMessageFromRevertData, traverseCauseChain } from '../../../common/index.js';
|
|
35
|
-
import
|
|
35
|
+
import { DEFAULT_BLOCK_NUMBER } from '../../fixtures/public_tx_simulation_tester.js';
|
|
36
|
+
import type { PublicContractsDB, PublicTreesDB } from '../../public_db_sources.js';
|
|
36
37
|
import type { PublicSideEffectTraceInterface } from '../../side_effect_trace_interface.js';
|
|
37
38
|
import { AvmContext } from '../avm_context.js';
|
|
38
39
|
import { AvmExecutionEnvironment } from '../avm_execution_environment.js';
|
|
@@ -65,23 +66,25 @@ export function initContext(overrides?: {
|
|
|
65
66
|
|
|
66
67
|
/** Creates an empty state manager with mocked host storage. */
|
|
67
68
|
export function initPersistableStateManager(overrides?: {
|
|
68
|
-
|
|
69
|
+
treesDB?: PublicTreesDB;
|
|
70
|
+
contractsDB?: PublicContractsDB;
|
|
69
71
|
trace?: PublicSideEffectTraceInterface;
|
|
70
72
|
publicStorage?: PublicStorage;
|
|
71
73
|
nullifiers?: NullifierManager;
|
|
72
74
|
doMerkleOperations?: boolean;
|
|
73
|
-
db?: MerkleTreeWriteOperations;
|
|
74
75
|
firstNullifier?: Fr;
|
|
76
|
+
blockNumber?: number;
|
|
75
77
|
}): AvmPersistableStateManager {
|
|
76
|
-
const
|
|
78
|
+
const treesDB = overrides?.treesDB || mock<PublicTreesDB>();
|
|
77
79
|
return new AvmPersistableStateManager(
|
|
78
|
-
|
|
80
|
+
treesDB,
|
|
81
|
+
overrides?.contractsDB || mock<PublicContractsDB>(),
|
|
79
82
|
overrides?.trace || mock<PublicSideEffectTraceInterface>(),
|
|
80
|
-
overrides?.publicStorage || new PublicStorage(worldStateDB),
|
|
81
|
-
overrides?.nullifiers || new NullifierManager(worldStateDB),
|
|
82
|
-
overrides?.doMerkleOperations || false,
|
|
83
|
-
overrides?.db || mock<MerkleTreeWriteOperations>(),
|
|
84
83
|
overrides?.firstNullifier || new Fr(27),
|
|
84
|
+
overrides?.blockNumber || DEFAULT_BLOCK_NUMBER,
|
|
85
|
+
overrides?.doMerkleOperations || false,
|
|
86
|
+
overrides?.publicStorage,
|
|
87
|
+
overrides?.nullifiers,
|
|
85
88
|
);
|
|
86
89
|
}
|
|
87
90
|
|
|
@@ -282,17 +285,20 @@ export async function createContractClassAndInstance(
|
|
|
282
285
|
);
|
|
283
286
|
|
|
284
287
|
const constructorAbi = getContractFunctionArtifact('constructor', contractArtifact);
|
|
288
|
+
const { publicKeys } = await deriveKeys(Fr.random());
|
|
285
289
|
const initializationHash = await computeInitializationHash(constructorAbi, constructorArgs);
|
|
286
290
|
const contractInstance =
|
|
287
291
|
originalContractClassId === undefined
|
|
288
292
|
? await makeContractInstanceFromClassId(contractClass.id, seed, {
|
|
289
293
|
deployer,
|
|
290
294
|
initializationHash,
|
|
295
|
+
publicKeys,
|
|
291
296
|
})
|
|
292
297
|
: await makeContractInstanceFromClassId(originalContractClassId, seed, {
|
|
293
298
|
deployer,
|
|
294
299
|
initializationHash,
|
|
295
300
|
currentClassId: contractClass.id,
|
|
301
|
+
publicKeys,
|
|
296
302
|
});
|
|
297
303
|
|
|
298
304
|
const contractAddressNullifier = await siloNullifier(
|
|
@@ -2,12 +2,7 @@ import type { Fr } from '@aztec/foundation/fields';
|
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import type {
|
|
6
|
-
ContractClassPublic,
|
|
7
|
-
ContractDataSource,
|
|
8
|
-
ContractInstanceWithAddress,
|
|
9
|
-
PublicFunction,
|
|
10
|
-
} from '@aztec/stdlib/contract';
|
|
5
|
+
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
11
6
|
|
|
12
7
|
import { PUBLIC_DISPATCH_FN_NAME } from './index.js';
|
|
13
8
|
|
|
@@ -50,10 +45,6 @@ export class SimpleContractDataSource implements ContractDataSource {
|
|
|
50
45
|
|
|
51
46
|
/////////////////////////////////////////////////////////////
|
|
52
47
|
// ContractDataSource function implementations
|
|
53
|
-
getPublicFunction(_address: AztecAddress, _selector: FunctionSelector): Promise<PublicFunction> {
|
|
54
|
-
throw new Error('Method not implemented.');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
48
|
getBlockNumber(): Promise<number> {
|
|
58
49
|
throw new Error('Method not implemented.');
|
|
59
50
|
}
|