@aztec/simulator 0.41.0 → 0.43.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 +2 -2
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +3 -3
- package/dest/acvm/oracle/oracle.d.ts +7 -4
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +32 -12
- package/dest/acvm/oracle/typed_oracle.d.ts +6 -3
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +15 -6
- package/dest/acvm/serialize.js +2 -2
- package/dest/avm/avm_gas.d.ts +1 -5
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +69 -73
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +2 -4
- package/dest/avm/avm_simulator.d.ts +5 -0
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +8 -1
- package/dest/avm/fixtures/index.d.ts +6 -0
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +18 -1
- package/dest/avm/index.d.ts +2 -0
- package/dest/avm/index.d.ts.map +1 -0
- package/dest/avm/index.js +2 -0
- package/dest/avm/journal/host_storage.d.ts +1 -1
- package/dest/avm/journal/host_storage.d.ts.map +1 -1
- package/dest/avm/journal/journal.d.ts +5 -3
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +23 -14
- package/dest/avm/journal/trace.d.ts +3 -1
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace.js +8 -1
- package/dest/avm/journal/trace_types.d.ts +5 -0
- package/dest/avm/journal/trace_types.d.ts.map +1 -1
- package/dest/avm/journal/trace_types.js +1 -5
- package/dest/avm/opcodes/accrued_substate.d.ts +2 -2
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +36 -21
- package/dest/avm/opcodes/arithmetic.d.ts +1 -7
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +12 -20
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +11 -8
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +7 -5
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +20 -24
- package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/avm/opcodes/control_flow.js +4 -2
- package/dest/avm/opcodes/conversion.js +2 -2
- package/dest/avm/opcodes/ec_add.d.ts +19 -0
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -0
- package/dest/avm/opcodes/ec_add.js +78 -0
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +11 -5
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +10 -2
- package/dest/avm/opcodes/instruction.d.ts +1 -1
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +6 -4
- package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction_impl.js +4 -2
- package/dest/avm/opcodes/memory.d.ts +1 -5
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +14 -18
- package/dest/avm/opcodes/multi_scalar_mul.d.ts +16 -0
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -0
- package/dest/avm/opcodes/multi_scalar_mul.js +95 -0
- package/dest/avm/opcodes/storage.d.ts +1 -6
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +11 -14
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +6 -2
- package/dest/avm/serialization/instruction_serialization.d.ts +3 -1
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +4 -2
- package/dest/client/client_execution_context.d.ts +24 -20
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +52 -55
- package/dest/client/db_oracle.d.ts +7 -1
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/execution_note_cache.d.ts +0 -17
- package/dest/client/execution_note_cache.d.ts.map +1 -1
- package/dest/client/execution_note_cache.js +1 -24
- package/dest/client/execution_result.d.ts +8 -4
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +16 -6
- package/dest/client/private_execution.d.ts +2 -3
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +20 -9
- package/dest/client/simulator.d.ts +2 -17
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +24 -33
- package/dest/client/unconstrained_execution.d.ts +2 -3
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +5 -7
- package/dest/client/view_data_oracle.d.ts +2 -0
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +7 -1
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +4 -2
- package/dest/mocks/fixtures.d.ts +14 -10
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +22 -16
- package/dest/{simulator → providers}/acvm_native.d.ts.map +1 -1
- package/dest/{simulator → providers}/acvm_native.js +13 -14
- package/dest/providers/acvm_wasm.d.ts.map +1 -0
- package/dest/providers/acvm_wasm.js +15 -0
- package/dest/providers/index.d.ts.map +1 -0
- package/dest/{simulator → providers}/index.js +1 -1
- package/dest/{simulator → providers}/simulation_provider.d.ts.map +1 -1
- package/dest/{simulator → providers}/simulation_provider.js +1 -1
- package/dest/public/abstract_phase_manager.d.ts +53 -53
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +146 -153
- package/dest/public/app_logic_phase_manager.d.ts +8 -9
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/public/app_logic_phase_manager.js +15 -15
- package/dest/public/{db.d.ts → db_interfaces.d.ts} +4 -3
- package/dest/public/db_interfaces.d.ts.map +1 -0
- package/dest/public/db_interfaces.js +2 -0
- package/dest/public/execution.d.ts +16 -23
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -51
- package/dest/public/executor.d.ts +4 -31
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +40 -283
- package/dest/public/fee_payment.d.ts +11 -0
- package/dest/public/fee_payment.d.ts.map +1 -0
- package/dest/public/fee_payment.js +24 -0
- package/dest/public/hints_builder.d.ts +2 -1
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +6 -2
- package/dest/public/index.d.ts +8 -6
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +9 -7
- package/dest/public/phase_manager_factory.d.ts +4 -4
- package/dest/public/phase_manager_factory.d.ts.map +1 -1
- package/dest/public/phase_manager_factory.js +5 -5
- package/dest/public/{public_executor.d.ts → public_db_sources.d.ts} +6 -3
- package/dest/public/public_db_sources.d.ts.map +1 -0
- package/dest/public/public_db_sources.js +244 -0
- package/dest/public/public_kernel.js +14 -14
- package/dest/public/public_processor.d.ts +6 -4
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +48 -30
- package/dest/public/setup_phase_manager.d.ts +8 -10
- package/dest/public/setup_phase_manager.d.ts.map +1 -1
- package/dest/public/setup_phase_manager.js +12 -21
- package/dest/public/tail_phase_manager.d.ts +7 -13
- package/dest/public/tail_phase_manager.d.ts.map +1 -1
- package/dest/public/tail_phase_manager.js +17 -37
- package/dest/public/teardown_phase_manager.d.ts +8 -10
- package/dest/public/teardown_phase_manager.d.ts.map +1 -1
- package/dest/public/teardown_phase_manager.js +16 -22
- package/dest/public/transitional_adaptors.d.ts +2 -2
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +14 -6
- package/package.json +12 -9
- package/src/acvm/acvm.ts +0 -3
- package/src/acvm/oracle/oracle.ts +68 -16
- package/src/acvm/oracle/typed_oracle.ts +31 -6
- package/src/acvm/serialize.ts +1 -1
- package/src/avm/avm_gas.ts +68 -73
- package/src/avm/avm_memory_types.ts +1 -3
- package/src/avm/avm_simulator.ts +9 -0
- package/src/avm/fixtures/index.ts +24 -0
- package/src/avm/index.ts +1 -0
- package/src/avm/journal/host_storage.ts +1 -1
- package/src/avm/journal/journal.ts +32 -22
- package/src/avm/journal/trace.ts +9 -0
- package/src/avm/journal/trace_types.ts +4 -0
- package/src/avm/opcodes/accrued_substate.ts +53 -20
- package/src/avm/opcodes/arithmetic.ts +18 -22
- package/src/avm/opcodes/bitwise.ts +13 -8
- package/src/avm/opcodes/comparators.ts +9 -4
- package/src/avm/opcodes/contract.ts +22 -26
- package/src/avm/opcodes/control_flow.ts +3 -1
- package/src/avm/opcodes/conversion.ts +1 -1
- package/src/avm/opcodes/ec_add.ts +92 -0
- package/src/avm/opcodes/external_calls.ts +11 -3
- package/src/avm/opcodes/hashing.ts +11 -1
- package/src/avm/opcodes/instruction.ts +5 -3
- package/src/avm/opcodes/instruction_impl.ts +4 -1
- package/src/avm/opcodes/memory.ts +19 -19
- package/src/avm/opcodes/multi_scalar_mul.ts +114 -0
- package/src/avm/opcodes/storage.ts +10 -17
- package/src/avm/serialization/bytecode_serialization.ts +5 -1
- package/src/avm/serialization/instruction_serialization.ts +2 -0
- package/src/client/client_execution_context.ts +76 -60
- package/src/client/db_oracle.ts +8 -1
- package/src/client/execution_note_cache.ts +0 -28
- package/src/client/execution_result.ts +21 -7
- package/src/client/private_execution.ts +36 -21
- package/src/client/simulator.ts +25 -35
- package/src/client/unconstrained_execution.ts +9 -12
- package/src/client/view_data_oracle.ts +8 -0
- package/src/index.ts +3 -1
- package/src/mocks/fixtures.ts +30 -32
- package/src/{simulator → providers}/acvm_native.ts +21 -19
- package/src/{simulator → providers}/acvm_wasm.ts +2 -16
- package/src/public/abstract_phase_manager.ts +209 -258
- package/src/public/app_logic_phase_manager.ts +24 -40
- package/src/public/{db.ts → db_interfaces.ts} +4 -2
- package/src/public/execution.ts +15 -77
- package/src/public/executor.ts +61 -399
- package/src/public/fee_payment.ts +26 -0
- package/src/public/hints_builder.ts +6 -0
- package/src/public/index.ts +8 -12
- package/src/public/phase_manager_factory.ts +7 -7
- package/src/public/{public_executor.ts → public_db_sources.ts} +65 -9
- package/src/public/public_kernel.ts +24 -24
- package/src/public/public_processor.ts +81 -40
- package/src/public/setup_phase_manager.ts +21 -46
- package/src/public/tail_phase_manager.ts +19 -67
- package/src/public/teardown_phase_manager.ts +23 -42
- package/src/public/transitional_adaptors.ts +41 -5
- package/dest/public/db.d.ts.map +0 -1
- package/dest/public/db.js +0 -2
- package/dest/public/public_execution_context.d.ts +0 -121
- package/dest/public/public_execution_context.d.ts.map +0 -1
- package/dest/public/public_execution_context.js +0 -214
- package/dest/public/public_executor.d.ts.map +0 -1
- package/dest/public/public_executor.js +0 -197
- package/dest/public/state_actions.d.ts +0 -39
- package/dest/public/state_actions.d.ts.map +0 -1
- package/dest/public/state_actions.js +0 -80
- package/dest/public/utils.d.ts +0 -8
- package/dest/public/utils.d.ts.map +0 -1
- package/dest/public/utils.js +0 -31
- package/dest/simulator/acvm_wasm.d.ts.map +0 -1
- package/dest/simulator/acvm_wasm.js +0 -22
- package/dest/simulator/index.d.ts.map +0 -1
- package/src/public/public_execution_context.ts +0 -289
- package/src/public/state_actions.ts +0 -102
- package/src/public/utils.ts +0 -33
- /package/dest/{simulator → providers}/acvm_native.d.ts +0 -0
- /package/dest/{simulator → providers}/acvm_wasm.d.ts +0 -0
- /package/dest/{simulator → providers}/index.d.ts +0 -0
- /package/dest/{simulator → providers}/simulation_provider.d.ts +0 -0
- /package/src/{simulator → providers}/index.ts +0 -0
- /package/src/{simulator → providers}/simulation_provider.ts +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EncryptedFunctionL2Logs,
|
|
3
3
|
type EncryptedL2Log,
|
|
4
|
+
type EncryptedL2NoteLog,
|
|
5
|
+
EncryptedNoteFunctionL2Logs,
|
|
4
6
|
type Note,
|
|
5
7
|
UnencryptedFunctionL2Logs,
|
|
6
8
|
type UnencryptedL2Log,
|
|
@@ -22,7 +24,7 @@ export interface NoteAndSlot {
|
|
|
22
24
|
noteTypeId: Fr;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
export class CountedLog<TLog extends UnencryptedL2Log | EncryptedL2Log> implements IsEmpty {
|
|
27
|
+
export class CountedLog<TLog extends UnencryptedL2Log | EncryptedL2NoteLog | EncryptedL2Log> implements IsEmpty {
|
|
26
28
|
constructor(public log: TLog, public counter: number) {}
|
|
27
29
|
|
|
28
30
|
isEmpty(): boolean {
|
|
@@ -30,6 +32,11 @@ export class CountedLog<TLog extends UnencryptedL2Log | EncryptedL2Log> implemen
|
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
export class CountedNoteLog extends CountedLog<EncryptedL2NoteLog> {
|
|
36
|
+
constructor(log: EncryptedL2NoteLog, counter: number, public noteHashCounter: number) {
|
|
37
|
+
super(log, counter);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
33
40
|
/**
|
|
34
41
|
* The result of executing a private function.
|
|
35
42
|
*/
|
|
@@ -62,7 +69,7 @@ export interface ExecutionResult {
|
|
|
62
69
|
* Encrypted note logs emitted during execution of this function call.
|
|
63
70
|
* Note: These are preimages to `noteEncryptedLogsHashes`.
|
|
64
71
|
*/
|
|
65
|
-
noteEncryptedLogs:
|
|
72
|
+
noteEncryptedLogs: CountedNoteLog[];
|
|
66
73
|
/**
|
|
67
74
|
* Encrypted logs emitted during execution of this function call.
|
|
68
75
|
* Note: These are preimages to `encryptedLogsHashes`.
|
|
@@ -92,8 +99,14 @@ export function collectNullifiedNoteHashCounters(execResult: ExecutionResult, ac
|
|
|
92
99
|
* @param execResult - The topmost execution result.
|
|
93
100
|
* @returns All encrypted logs.
|
|
94
101
|
*/
|
|
95
|
-
function collectNoteEncryptedLogs(
|
|
96
|
-
|
|
102
|
+
function collectNoteEncryptedLogs(
|
|
103
|
+
execResult: ExecutionResult,
|
|
104
|
+
nullifiedNoteHashCounters: Map<number, number>,
|
|
105
|
+
): CountedLog<EncryptedL2NoteLog>[] {
|
|
106
|
+
return [
|
|
107
|
+
execResult.noteEncryptedLogs.filter(noteLog => !nullifiedNoteHashCounters.has(noteLog.noteHashCounter)),
|
|
108
|
+
...execResult.nestedExecutions.flatMap(res => collectNoteEncryptedLogs(res, nullifiedNoteHashCounters)),
|
|
109
|
+
].flat();
|
|
97
110
|
}
|
|
98
111
|
|
|
99
112
|
/**
|
|
@@ -101,10 +114,11 @@ function collectNoteEncryptedLogs(execResult: ExecutionResult): CountedLog<Encry
|
|
|
101
114
|
* @param execResult - The topmost execution result.
|
|
102
115
|
* @returns All encrypted logs.
|
|
103
116
|
*/
|
|
104
|
-
export function collectSortedNoteEncryptedLogs(execResult: ExecutionResult):
|
|
105
|
-
const
|
|
117
|
+
export function collectSortedNoteEncryptedLogs(execResult: ExecutionResult): EncryptedNoteFunctionL2Logs {
|
|
118
|
+
const nullifiedNoteHashCounters = collectNullifiedNoteHashCounters(execResult);
|
|
119
|
+
const allLogs = collectNoteEncryptedLogs(execResult, nullifiedNoteHashCounters);
|
|
106
120
|
const sortedLogs = sortByCounter(allLogs);
|
|
107
|
-
return new
|
|
121
|
+
return new EncryptedNoteFunctionL2Logs(sortedLogs.map(l => l.log));
|
|
108
122
|
}
|
|
109
123
|
/**
|
|
110
124
|
* Collect all encrypted logs across all nested executions.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
1
|
+
import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats';
|
|
2
|
+
import { Fr, FunctionData, PrivateCallStackItem, PrivateCircuitPublicInputs } from '@aztec/circuits.js';
|
|
3
|
+
import type { FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
|
|
3
4
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
5
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
5
7
|
|
|
6
8
|
import { witnessMapToFields } from '../acvm/deserialize.js';
|
|
7
9
|
import { Oracle, acvm, extractCallStack } from '../acvm/index.js';
|
|
8
10
|
import { ExecutionError } from '../common/errors.js';
|
|
9
11
|
import { type ClientExecutionContext } from './client_execution_context.js';
|
|
10
12
|
import { type ExecutionResult } from './execution_result.js';
|
|
11
|
-
import { AcirSimulator } from './simulator.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Execute a private function and return the execution result.
|
|
@@ -17,37 +18,51 @@ export async function executePrivateFunction(
|
|
|
17
18
|
context: ClientExecutionContext,
|
|
18
19
|
artifact: FunctionArtifact,
|
|
19
20
|
contractAddress: AztecAddress,
|
|
20
|
-
|
|
21
|
+
functionSelector: FunctionSelector,
|
|
21
22
|
log = createDebugLogger('aztec:simulator:secret_execution'),
|
|
22
23
|
): Promise<ExecutionResult> {
|
|
23
|
-
const
|
|
24
|
-
log.verbose(`Executing external function ${contractAddress}:${functionSelector}(${
|
|
24
|
+
const functionName = await context.getDebugFunctionName();
|
|
25
|
+
log.verbose(`Executing external function ${contractAddress}:${functionSelector}(${functionName})`);
|
|
25
26
|
const acir = artifact.bytecode;
|
|
26
27
|
const initialWitness = context.getInitialWitness(artifact);
|
|
27
28
|
const acvmCallback = new Oracle(context);
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
);
|
|
29
|
+
const timer = new Timer();
|
|
30
|
+
const acirExecutionResult = await acvm(acir, initialWitness, acvmCallback).catch((err: Error) => {
|
|
31
|
+
throw new ExecutionError(
|
|
32
|
+
err.message,
|
|
33
|
+
{
|
|
34
|
+
contractAddress,
|
|
35
|
+
functionSelector,
|
|
36
|
+
},
|
|
37
|
+
extractCallStack(err, artifact.debug),
|
|
38
|
+
{ cause: err },
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
const duration = timer.ms();
|
|
41
42
|
const partialWitness = acirExecutionResult.partialWitness;
|
|
42
43
|
const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness);
|
|
43
44
|
const publicInputs = PrivateCircuitPublicInputs.fromFields(returnWitness);
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
// TODO (alexg) estimate this size
|
|
47
|
+
const initialWitnessSize = witnessMapToFields(initialWitness).length * Fr.SIZE_IN_BYTES;
|
|
48
|
+
log.debug(`Ran external function ${contractAddress.toString()}:${functionSelector}`, {
|
|
49
|
+
circuitName: 'app-circuit',
|
|
50
|
+
duration,
|
|
51
|
+
eventName: 'circuit-witness-generation',
|
|
52
|
+
inputSize: initialWitnessSize,
|
|
53
|
+
outputSize: publicInputs.toBuffer().length,
|
|
54
|
+
appCircuitName: functionName,
|
|
55
|
+
} satisfies CircuitWitnessGenerationStats);
|
|
56
|
+
|
|
46
57
|
const noteEncryptedLogs = context.getNoteEncryptedLogs();
|
|
47
58
|
const encryptedLogs = context.getEncryptedLogs();
|
|
48
59
|
const unencryptedLogs = context.getUnencryptedLogs();
|
|
49
60
|
|
|
50
|
-
const callStackItem = new PrivateCallStackItem(
|
|
61
|
+
const callStackItem = new PrivateCallStackItem(
|
|
62
|
+
contractAddress,
|
|
63
|
+
new FunctionData(functionSelector, true),
|
|
64
|
+
publicInputs,
|
|
65
|
+
);
|
|
51
66
|
|
|
52
67
|
const rawReturnValues = await context.unpackReturns(publicInputs.returnsHash);
|
|
53
68
|
|
package/src/client/simulator.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AztecNode, type FunctionCall, type Note, type TxExecutionRequest } from '@aztec/circuit-types';
|
|
2
|
-
import { CallContext
|
|
2
|
+
import { CallContext } from '@aztec/circuits.js';
|
|
3
3
|
import {
|
|
4
4
|
type ArrayType,
|
|
5
5
|
type FunctionArtifact,
|
|
@@ -11,8 +11,6 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
|
11
11
|
import { Fr } from '@aztec/foundation/fields';
|
|
12
12
|
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
13
13
|
|
|
14
|
-
import { type WasmBlackBoxFunctionSolver, createBlackBoxSolver } from '@noir-lang/acvm_js';
|
|
15
|
-
|
|
16
14
|
import { createSimulationError } from '../common/errors.js';
|
|
17
15
|
import { PackedValuesCache } from '../common/packed_values_cache.js';
|
|
18
16
|
import { ClientExecutionContext } from './client_execution_context.js';
|
|
@@ -27,33 +25,12 @@ import { ViewDataOracle } from './view_data_oracle.js';
|
|
|
27
25
|
* The ACIR simulator.
|
|
28
26
|
*/
|
|
29
27
|
export class AcirSimulator {
|
|
30
|
-
private static solver: Promise<WasmBlackBoxFunctionSolver>; // ACVM's backend
|
|
31
28
|
private log: DebugLogger;
|
|
32
29
|
|
|
33
30
|
constructor(private db: DBOracle, private node: AztecNode) {
|
|
34
31
|
this.log = createDebugLogger('aztec:simulator');
|
|
35
32
|
}
|
|
36
33
|
|
|
37
|
-
/**
|
|
38
|
-
* Gets or initializes the ACVM WasmBlackBoxFunctionSolver.
|
|
39
|
-
*
|
|
40
|
-
* @remarks
|
|
41
|
-
*
|
|
42
|
-
* Occurs only once across all instances of AcirSimulator.
|
|
43
|
-
* Speeds up execution by only performing setup tasks (like pedersen
|
|
44
|
-
* generator initialization) one time.
|
|
45
|
-
* TODO(https://github.com/AztecProtocol/aztec-packages/issues/1627):
|
|
46
|
-
* determine whether this requires a lock
|
|
47
|
-
*
|
|
48
|
-
* @returns ACVM WasmBlackBoxFunctionSolver
|
|
49
|
-
*/
|
|
50
|
-
public static getSolver(): Promise<WasmBlackBoxFunctionSolver> {
|
|
51
|
-
if (!this.solver) {
|
|
52
|
-
this.solver = createBlackBoxSolver();
|
|
53
|
-
}
|
|
54
|
-
return this.solver;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
34
|
/**
|
|
58
35
|
* Runs a private function.
|
|
59
36
|
* @param request - The transaction request.
|
|
@@ -110,7 +87,7 @@ export class AcirSimulator {
|
|
|
110
87
|
context,
|
|
111
88
|
entryPointArtifact,
|
|
112
89
|
contractAddress,
|
|
113
|
-
request.
|
|
90
|
+
request.functionSelector,
|
|
114
91
|
);
|
|
115
92
|
return executionResult;
|
|
116
93
|
} catch (err) {
|
|
@@ -141,7 +118,7 @@ export class AcirSimulator {
|
|
|
141
118
|
context,
|
|
142
119
|
entryPointArtifact,
|
|
143
120
|
contractAddress,
|
|
144
|
-
request.
|
|
121
|
+
request.selector,
|
|
145
122
|
request.args,
|
|
146
123
|
);
|
|
147
124
|
} catch (err) {
|
|
@@ -155,29 +132,31 @@ export class AcirSimulator {
|
|
|
155
132
|
* @param nonce - The nonce of the note hash.
|
|
156
133
|
* @param storageSlot - The storage slot.
|
|
157
134
|
* @param noteTypeId - The note type identifier.
|
|
135
|
+
* @param computeNullifier - A flag indicating whether to compute the nullifier or just return 0.
|
|
158
136
|
* @param note - The note.
|
|
159
137
|
* @returns The nullifier.
|
|
160
138
|
*/
|
|
161
|
-
public async
|
|
139
|
+
public async computeNoteHashAndOptionallyANullifier(
|
|
162
140
|
contractAddress: AztecAddress,
|
|
163
141
|
nonce: Fr,
|
|
164
142
|
storageSlot: Fr,
|
|
165
143
|
noteTypeId: Fr,
|
|
144
|
+
computeNullifier: boolean,
|
|
166
145
|
note: Note,
|
|
167
146
|
) {
|
|
168
147
|
const artifact: FunctionArtifact | undefined = await this.db.getFunctionArtifactByName(
|
|
169
148
|
contractAddress,
|
|
170
|
-
'
|
|
149
|
+
'compute_note_hash_and_optionally_a_nullifier',
|
|
171
150
|
);
|
|
172
151
|
if (!artifact) {
|
|
173
152
|
throw new Error(
|
|
174
|
-
`Mandatory implementation of "
|
|
153
|
+
`Mandatory implementation of "compute_note_hash_and_optionally_a_nullifier" missing in noir contract ${contractAddress.toString()}.`,
|
|
175
154
|
);
|
|
176
155
|
}
|
|
177
156
|
|
|
178
|
-
if (artifact.parameters.length !=
|
|
157
|
+
if (artifact.parameters.length != 6) {
|
|
179
158
|
throw new Error(
|
|
180
|
-
`Expected
|
|
159
|
+
`Expected 6 parameters in mandatory implementation of "compute_note_hash_and_optionally_a_nullifier", but found ${
|
|
181
160
|
artifact.parameters.length
|
|
182
161
|
} in noir contract ${contractAddress.toString()}.`,
|
|
183
162
|
);
|
|
@@ -186,17 +165,27 @@ export class AcirSimulator {
|
|
|
186
165
|
const maxNoteFields = (artifact.parameters[artifact.parameters.length - 1].type as ArrayType).length;
|
|
187
166
|
if (maxNoteFields < note.items.length) {
|
|
188
167
|
throw new Error(
|
|
189
|
-
`The note being processed has ${note.items.length} fields, while "
|
|
168
|
+
`The note being processed has ${note.items.length} fields, while "compute_note_hash_and_optionally_a_nullifier" can only handle a maximum of ${maxNoteFields} fields. Please reduce the number of fields in your note.`,
|
|
190
169
|
);
|
|
191
170
|
}
|
|
192
171
|
|
|
193
172
|
const extendedNoteItems = note.items.concat(Array(maxNoteFields - note.items.length).fill(Fr.ZERO));
|
|
194
173
|
|
|
195
174
|
const execRequest: FunctionCall = {
|
|
175
|
+
name: artifact.name,
|
|
196
176
|
to: contractAddress,
|
|
197
|
-
|
|
177
|
+
selector: FunctionSelector.empty(),
|
|
178
|
+
type: FunctionType.UNCONSTRAINED,
|
|
198
179
|
isStatic: artifact.isStatic,
|
|
199
|
-
args: encodeArguments(artifact, [
|
|
180
|
+
args: encodeArguments(artifact, [
|
|
181
|
+
contractAddress,
|
|
182
|
+
nonce,
|
|
183
|
+
storageSlot,
|
|
184
|
+
noteTypeId,
|
|
185
|
+
computeNullifier,
|
|
186
|
+
extendedNoteItems,
|
|
187
|
+
]),
|
|
188
|
+
returnTypes: artifact.returnTypes,
|
|
200
189
|
};
|
|
201
190
|
|
|
202
191
|
const [innerNoteHash, uniqueNoteHash, siloedNoteHash, innerNullifier] = (await this.runUnconstrained(
|
|
@@ -222,11 +211,12 @@ export class AcirSimulator {
|
|
|
222
211
|
* @returns The note hash.
|
|
223
212
|
*/
|
|
224
213
|
public async computeInnerNoteHash(contractAddress: AztecAddress, storageSlot: Fr, noteTypeId: Fr, note: Note) {
|
|
225
|
-
const { innerNoteHash } = await this.
|
|
214
|
+
const { innerNoteHash } = await this.computeNoteHashAndOptionallyANullifier(
|
|
226
215
|
contractAddress,
|
|
227
216
|
Fr.ZERO,
|
|
228
217
|
storageSlot,
|
|
229
218
|
noteTypeId,
|
|
219
|
+
false,
|
|
230
220
|
note,
|
|
231
221
|
);
|
|
232
222
|
return innerNoteHash;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type DecodedReturn,
|
|
3
|
+
type FunctionArtifact,
|
|
4
|
+
type FunctionSelector,
|
|
5
|
+
decodeReturnValues,
|
|
6
|
+
} from '@aztec/foundation/abi';
|
|
3
7
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
8
|
import { type Fr } from '@aztec/foundation/fields';
|
|
5
9
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
@@ -7,7 +11,6 @@ import { createDebugLogger } from '@aztec/foundation/log';
|
|
|
7
11
|
import { witnessMapToFields } from '../acvm/deserialize.js';
|
|
8
12
|
import { Oracle, acvm, extractCallStack, toACVMWitness } from '../acvm/index.js';
|
|
9
13
|
import { ExecutionError } from '../common/errors.js';
|
|
10
|
-
import { AcirSimulator } from './simulator.js';
|
|
11
14
|
import { type ViewDataOracle } from './view_data_oracle.js';
|
|
12
15
|
|
|
13
16
|
// docs:start:execute_unconstrained_function
|
|
@@ -18,21 +21,15 @@ export async function executeUnconstrainedFunction(
|
|
|
18
21
|
oracle: ViewDataOracle,
|
|
19
22
|
artifact: FunctionArtifact,
|
|
20
23
|
contractAddress: AztecAddress,
|
|
21
|
-
|
|
24
|
+
functionSelector: FunctionSelector,
|
|
22
25
|
args: Fr[],
|
|
23
26
|
log = createDebugLogger('aztec:simulator:unconstrained_execution'),
|
|
24
27
|
): Promise<DecodedReturn> {
|
|
25
|
-
const functionSelector = functionData.selector;
|
|
26
28
|
log.verbose(`Executing unconstrained function ${contractAddress}:${functionSelector}(${artifact.name})`);
|
|
27
29
|
|
|
28
30
|
const acir = artifact.bytecode;
|
|
29
31
|
const initialWitness = toACVMWitness(0, args);
|
|
30
|
-
const acirExecutionResult = await acvm(
|
|
31
|
-
await AcirSimulator.getSolver(),
|
|
32
|
-
acir,
|
|
33
|
-
initialWitness,
|
|
34
|
-
new Oracle(oracle),
|
|
35
|
-
).catch((err: Error) => {
|
|
32
|
+
const acirExecutionResult = await acvm(acir, initialWitness, new Oracle(oracle)).catch((err: Error) => {
|
|
36
33
|
throw new ExecutionError(
|
|
37
34
|
err.message,
|
|
38
35
|
{
|
|
@@ -45,6 +42,6 @@ export async function executeUnconstrainedFunction(
|
|
|
45
42
|
});
|
|
46
43
|
|
|
47
44
|
const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness);
|
|
48
|
-
return decodeReturnValues(artifact, returnWitness);
|
|
45
|
+
return decodeReturnValues(artifact.returnTypes, returnWitness);
|
|
49
46
|
}
|
|
50
47
|
// docs:end:execute_unconstrained_function
|
|
@@ -34,6 +34,14 @@ export class ViewDataOracle extends TypedOracle {
|
|
|
34
34
|
super();
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
public override getBlockNumber(): Promise<number> {
|
|
38
|
+
return this.aztecNode.getBlockNumber();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public override getContractAddress(): Promise<AztecAddress> {
|
|
42
|
+
return Promise.resolve(this.contractAddress);
|
|
43
|
+
}
|
|
44
|
+
|
|
37
45
|
/**
|
|
38
46
|
* Retrieve keys associated with a specific master public key and app address.
|
|
39
47
|
* @param pkMHash - The master public key hash.
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from './acvm/index.js';
|
|
2
|
+
export * from './avm/index.js';
|
|
2
3
|
export * from './client/index.js';
|
|
3
4
|
export * from './common/index.js';
|
|
4
5
|
export * from './public/index.js';
|
|
5
|
-
export * from './
|
|
6
|
+
export * from './providers/index.js';
|
|
6
7
|
export * from './mocks/index.js';
|
|
7
8
|
export * from './stats/index.js';
|
|
9
|
+
export * from './utils.js';
|
package/src/mocks/fixtures.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { type FunctionCall, type SimulationError, UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
3
|
ARGS_LENGTH,
|
|
4
|
+
AvmExecutionHints,
|
|
4
5
|
type AztecAddress,
|
|
5
6
|
CallContext,
|
|
6
|
-
|
|
7
|
+
type ContractStorageRead,
|
|
7
8
|
type ContractStorageUpdateRequest,
|
|
8
9
|
Fr,
|
|
9
|
-
FunctionData,
|
|
10
10
|
Gas,
|
|
11
|
-
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
12
|
-
type PrivateKernelTailCircuitPublicInputs,
|
|
13
11
|
type PublicCallRequest,
|
|
14
12
|
} from '@aztec/circuits.js';
|
|
15
13
|
import { makeAztecAddress, makeSelector } from '@aztec/circuits.js/testing';
|
|
14
|
+
import { FunctionType } from '@aztec/foundation/abi';
|
|
16
15
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
17
16
|
|
|
18
17
|
import { type PublicExecution, type PublicExecutionResult } from '../public/execution.js';
|
|
@@ -21,6 +20,7 @@ export class PublicExecutionResultBuilder {
|
|
|
21
20
|
private _execution: PublicExecution;
|
|
22
21
|
private _nestedExecutions: PublicExecutionResult[] = [];
|
|
23
22
|
private _contractStorageUpdateRequests: ContractStorageUpdateRequest[] = [];
|
|
23
|
+
private _contractStorageReads: ContractStorageRead[] = [];
|
|
24
24
|
private _returnValues: Fr[] = [];
|
|
25
25
|
private _reverted = false;
|
|
26
26
|
private _revertReason: SimulationError | undefined = undefined;
|
|
@@ -34,17 +34,25 @@ export class PublicExecutionResultBuilder {
|
|
|
34
34
|
returnValues = [new Fr(1n)],
|
|
35
35
|
nestedExecutions = [],
|
|
36
36
|
contractStorageUpdateRequests = [],
|
|
37
|
+
contractStorageReads = [],
|
|
38
|
+
revertReason = undefined,
|
|
37
39
|
}: {
|
|
38
40
|
request: PublicCallRequest;
|
|
39
41
|
returnValues?: Fr[];
|
|
40
42
|
nestedExecutions?: PublicExecutionResult[];
|
|
41
43
|
contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
|
|
44
|
+
contractStorageReads?: ContractStorageRead[];
|
|
45
|
+
revertReason?: SimulationError;
|
|
42
46
|
}): PublicExecutionResultBuilder {
|
|
43
47
|
const builder = new PublicExecutionResultBuilder(request);
|
|
44
48
|
|
|
45
49
|
builder.withNestedExecutions(...nestedExecutions);
|
|
46
50
|
builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
|
|
51
|
+
builder.withContractStorageRead(...contractStorageReads);
|
|
47
52
|
builder.withReturnValues(...returnValues);
|
|
53
|
+
if (revertReason) {
|
|
54
|
+
builder.withReverted(revertReason);
|
|
55
|
+
}
|
|
48
56
|
|
|
49
57
|
return builder;
|
|
50
58
|
}
|
|
@@ -55,6 +63,7 @@ export class PublicExecutionResultBuilder {
|
|
|
55
63
|
returnValues = [new Fr(1n)],
|
|
56
64
|
nestedExecutions = [],
|
|
57
65
|
contractStorageUpdateRequests = [],
|
|
66
|
+
contractStorageReads = [],
|
|
58
67
|
revertReason,
|
|
59
68
|
}: {
|
|
60
69
|
from: AztecAddress;
|
|
@@ -62,17 +71,19 @@ export class PublicExecutionResultBuilder {
|
|
|
62
71
|
returnValues?: Fr[];
|
|
63
72
|
nestedExecutions?: PublicExecutionResult[];
|
|
64
73
|
contractStorageUpdateRequests?: ContractStorageUpdateRequest[];
|
|
74
|
+
contractStorageReads?: ContractStorageRead[];
|
|
65
75
|
revertReason?: SimulationError;
|
|
66
76
|
}) {
|
|
67
77
|
const builder = new PublicExecutionResultBuilder({
|
|
68
|
-
callContext: new CallContext(from, tx.to, tx.
|
|
78
|
+
callContext: new CallContext(from, tx.to, tx.selector, false, false, 0),
|
|
69
79
|
contractAddress: tx.to,
|
|
70
|
-
|
|
80
|
+
functionSelector: tx.selector,
|
|
71
81
|
args: tx.args,
|
|
72
82
|
});
|
|
73
83
|
|
|
74
84
|
builder.withNestedExecutions(...nestedExecutions);
|
|
75
85
|
builder.withContractStorageUpdateRequest(...contractStorageUpdateRequests);
|
|
86
|
+
builder.withContractStorageRead(...contractStorageReads);
|
|
76
87
|
builder.withReturnValues(...returnValues);
|
|
77
88
|
if (revertReason) {
|
|
78
89
|
builder.withReverted(revertReason);
|
|
@@ -91,6 +102,11 @@ export class PublicExecutionResultBuilder {
|
|
|
91
102
|
return this;
|
|
92
103
|
}
|
|
93
104
|
|
|
105
|
+
withContractStorageRead(...reads: ContractStorageRead[]): PublicExecutionResultBuilder {
|
|
106
|
+
this._contractStorageReads.push(...reads);
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
|
|
94
110
|
withReturnValues(...values: Fr[]): PublicExecutionResultBuilder {
|
|
95
111
|
this._returnValues.push(...values);
|
|
96
112
|
return this;
|
|
@@ -106,8 +122,10 @@ export class PublicExecutionResultBuilder {
|
|
|
106
122
|
return {
|
|
107
123
|
execution: this._execution,
|
|
108
124
|
nestedExecutions: this._nestedExecutions,
|
|
125
|
+
noteHashReadRequests: [],
|
|
109
126
|
nullifierReadRequests: [],
|
|
110
127
|
nullifierNonExistentReadRequests: [],
|
|
128
|
+
l1ToL2MsgReadRequests: [],
|
|
111
129
|
contractStorageUpdateRequests: this._contractStorageUpdateRequests,
|
|
112
130
|
returnValues: padArrayEnd(this._returnValues, Fr.ZERO, 4), // TODO(#5450) Need to use the proper return values here
|
|
113
131
|
newNoteHashes: [],
|
|
@@ -124,39 +142,19 @@ export class PublicExecutionResultBuilder {
|
|
|
124
142
|
startGasLeft: Gas.test(),
|
|
125
143
|
endGasLeft: Gas.test(),
|
|
126
144
|
transactionFee: Fr.ZERO,
|
|
145
|
+
calldata: [],
|
|
146
|
+
avmHints: AvmExecutionHints.empty(),
|
|
127
147
|
...overrides,
|
|
128
148
|
};
|
|
129
149
|
}
|
|
130
150
|
}
|
|
131
151
|
|
|
132
152
|
export const makeFunctionCall = (
|
|
153
|
+
name = 'function',
|
|
133
154
|
to = makeAztecAddress(30),
|
|
134
155
|
selector = makeSelector(5),
|
|
156
|
+
type = FunctionType.PUBLIC,
|
|
135
157
|
args = new Array(ARGS_LENGTH).fill(Fr.ZERO),
|
|
136
158
|
isStatic = false,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
export function addKernelPublicCallStack(
|
|
140
|
-
kernelOutput: PrivateKernelTailCircuitPublicInputs,
|
|
141
|
-
calls: {
|
|
142
|
-
setupCalls: PublicCallRequest[];
|
|
143
|
-
appLogicCalls: PublicCallRequest[];
|
|
144
|
-
teardownCall: PublicCallRequest;
|
|
145
|
-
},
|
|
146
|
-
) {
|
|
147
|
-
// the first two calls are non-revertible
|
|
148
|
-
// the first is for setup, the second is for teardown
|
|
149
|
-
kernelOutput.forPublic!.endNonRevertibleData.publicCallStack = padArrayEnd(
|
|
150
|
-
// this is a stack, so the first item is the last call
|
|
151
|
-
// and callRequests is in the order of the calls
|
|
152
|
-
[calls.teardownCall.toCallRequest(), ...calls.setupCalls.map(c => c.toCallRequest())],
|
|
153
|
-
CallRequest.empty(),
|
|
154
|
-
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
kernelOutput.forPublic!.end.publicCallStack = padArrayEnd(
|
|
158
|
-
calls.appLogicCalls.map(c => c.toCallRequest()),
|
|
159
|
-
CallRequest.empty(),
|
|
160
|
-
MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX,
|
|
161
|
-
);
|
|
162
|
-
}
|
|
159
|
+
returnTypes = [],
|
|
160
|
+
) => ({ name, to, selector, type, args, isStatic, returnTypes });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { runInDirectory } from '@aztec/foundation/fs';
|
|
2
2
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
4
|
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
@@ -137,23 +137,25 @@ export class NativeACVMSimulator implements SimulationProvider {
|
|
|
137
137
|
async simulateCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
|
|
138
138
|
// Execute the circuit on those initial witness values
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
140
|
+
const operation = async (directory: string) => {
|
|
141
|
+
// Decode the bytecode from base64 since the acvm does not know about base64 encoding
|
|
142
|
+
const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
143
|
+
// Execute the circuit
|
|
144
|
+
const result = await executeNativeCircuit(
|
|
145
|
+
input,
|
|
146
|
+
decodedBytecode,
|
|
147
|
+
directory,
|
|
148
|
+
this.pathToAcvm,
|
|
149
|
+
this.witnessFilename,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
if (result.status == ACVM_RESULT.FAILURE) {
|
|
153
|
+
throw new Error(`Failed to generate witness: ${result.reason}`);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return result.witness;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return await runInDirectory(this.workingDirectory, operation);
|
|
158
160
|
}
|
|
159
161
|
}
|
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types';
|
|
2
2
|
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
type WasmBlackBoxFunctionSolver,
|
|
6
|
-
createBlackBoxSolver,
|
|
7
|
-
executeCircuitWithBlackBoxSolver,
|
|
8
|
-
} from '@noir-lang/acvm_js';
|
|
4
|
+
import { executeCircuit } from '@noir-lang/acvm_js';
|
|
9
5
|
import { type WitnessMap } from '@noir-lang/types';
|
|
10
6
|
|
|
11
7
|
import { type SimulationProvider } from './simulation_provider.js';
|
|
12
8
|
|
|
13
|
-
let solver: Promise<WasmBlackBoxFunctionSolver>;
|
|
14
|
-
|
|
15
|
-
const getSolver = (): Promise<WasmBlackBoxFunctionSolver> => {
|
|
16
|
-
if (!solver) {
|
|
17
|
-
solver = createBlackBoxSolver();
|
|
18
|
-
}
|
|
19
|
-
return solver;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
9
|
export class WASMSimulator implements SimulationProvider {
|
|
23
10
|
async simulateCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap> {
|
|
24
11
|
// Execute the circuit on those initial witness values
|
|
@@ -27,8 +14,7 @@ export class WASMSimulator implements SimulationProvider {
|
|
|
27
14
|
const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
28
15
|
//
|
|
29
16
|
// Execute the circuit
|
|
30
|
-
const _witnessMap = await
|
|
31
|
-
await getSolver(),
|
|
17
|
+
const _witnessMap = await executeCircuit(
|
|
32
18
|
decodedBytecode,
|
|
33
19
|
input,
|
|
34
20
|
foreignCallHandler, // handle calls to debug_log
|