@aztec/simulator 0.34.0 → 0.35.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 +4 -1
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +5 -5
- package/dest/acvm/deserialize.d.ts +3 -5
- package/dest/acvm/deserialize.d.ts.map +1 -1
- package/dest/acvm/deserialize.js +6 -9
- package/dest/acvm/oracle/oracle.d.ts +2 -0
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +12 -4
- package/dest/acvm/oracle/typed_oracle.d.ts +2 -0
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +7 -1
- package/dest/avm/avm_execution_environment.d.ts +4 -2
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +7 -5
- package/dest/avm/avm_gas.js +2 -2
- package/dest/avm/avm_machine_state.d.ts +2 -0
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +24 -6
- package/dest/avm/avm_memory_types.js +2 -2
- package/dest/avm/avm_simulator.js +2 -2
- package/dest/avm/fixtures/index.d.ts +3 -0
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +11 -4
- package/dest/avm/journal/journal.d.ts +1 -0
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +12 -1
- package/dest/avm/opcodes/accrued_substate.d.ts +2 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +13 -5
- package/dest/avm/opcodes/context_getters.js +2 -2
- package/dest/avm/opcodes/external_calls.d.ts +2 -2
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +7 -6
- package/dest/avm/opcodes/hashing.d.ts +8 -8
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +35 -43
- package/dest/avm/serialization/instruction_serialization.d.ts +1 -1
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +2 -2
- package/dest/client/client_execution_context.d.ts +13 -3
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +23 -8
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +8 -6
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +6 -5
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +5 -4
- package/dest/common/index.d.ts +1 -1
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +2 -2
- package/dest/common/packed_values_cache.d.ts +28 -0
- package/dest/common/packed_values_cache.d.ts.map +1 -0
- package/dest/common/packed_values_cache.js +50 -0
- package/dest/index.d.ts +1 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/mocks/fixtures.d.ts +42 -0
- package/dest/mocks/fixtures.d.ts.map +1 -0
- package/dest/mocks/fixtures.js +84 -0
- package/dest/mocks/index.d.ts +2 -0
- package/dest/mocks/index.d.ts.map +1 -0
- package/dest/mocks/index.js +2 -0
- package/dest/public/abstract_phase_manager.d.ts +82 -0
- package/dest/public/abstract_phase_manager.d.ts.map +1 -0
- package/dest/public/abstract_phase_manager.js +320 -0
- package/dest/public/app_logic_phase_manager.d.ts +29 -0
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -0
- package/dest/public/app_logic_phase_manager.js +50 -0
- package/dest/public/execution.d.ts +3 -0
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -1
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +17 -13
- package/dest/public/hints_builder.d.ts +23 -0
- package/dest/public/hints_builder.d.ts.map +1 -0
- package/dest/public/hints_builder.js +62 -0
- package/dest/public/index.d.ts +5 -0
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +6 -1
- package/dest/public/phase_manager_factory.d.ts +18 -0
- package/dest/public/phase_manager_factory.d.ts.map +1 -0
- package/dest/public/phase_manager_factory.js +56 -0
- package/dest/public/public_execution_context.d.ts +15 -5
- package/dest/public/public_execution_context.d.ts.map +1 -1
- package/dest/public/public_execution_context.js +28 -12
- package/dest/public/public_executor.d.ts +79 -0
- package/dest/public/public_executor.d.ts.map +1 -0
- package/dest/public/public_executor.js +198 -0
- package/dest/public/public_kernel.d.ts +37 -0
- package/dest/public/public_kernel.d.ts.map +1 -0
- package/dest/public/public_kernel.js +97 -0
- package/dest/public/public_kernel_circuit_simulator.d.ts +31 -0
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +1 -0
- package/dest/public/public_kernel_circuit_simulator.js +2 -0
- package/dest/public/public_processor.d.ts +53 -0
- package/dest/public/public_processor.d.ts.map +1 -0
- package/dest/public/public_processor.js +144 -0
- package/dest/public/setup_phase_manager.d.ts +30 -0
- package/dest/public/setup_phase_manager.d.ts.map +1 -0
- package/dest/public/setup_phase_manager.js +46 -0
- package/dest/public/tail_phase_manager.d.ts +30 -0
- package/dest/public/tail_phase_manager.d.ts.map +1 -0
- package/dest/public/tail_phase_manager.js +60 -0
- package/dest/public/teardown_phase_manager.d.ts +30 -0
- package/dest/public/teardown_phase_manager.d.ts.map +1 -0
- package/dest/public/teardown_phase_manager.js +46 -0
- package/dest/public/transitional_adaptors.d.ts +2 -1
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +11 -10
- package/dest/public/utils.d.ts +8 -0
- package/dest/public/utils.d.ts.map +1 -0
- package/dest/public/utils.js +29 -0
- package/dest/simulator/acvm_native.d.ts +19 -3
- package/dest/simulator/acvm_native.d.ts.map +1 -1
- package/dest/simulator/acvm_native.js +75 -48
- package/dest/simulator/acvm_wasm.d.ts.map +1 -1
- package/dest/simulator/acvm_wasm.js +3 -4
- package/package.json +8 -5
- package/src/acvm/acvm.ts +8 -5
- package/src/acvm/deserialize.ts +5 -9
- package/src/acvm/oracle/oracle.ts +13 -3
- package/src/acvm/oracle/typed_oracle.ts +8 -0
- package/src/avm/avm_execution_environment.ts +9 -1
- package/src/avm/avm_gas.ts +1 -1
- package/src/avm/avm_machine_state.ts +26 -5
- package/src/avm/avm_memory_types.ts +1 -1
- package/src/avm/avm_simulator.ts +1 -1
- package/src/avm/fixtures/index.ts +13 -1
- package/src/avm/journal/journal.ts +13 -0
- package/src/avm/opcodes/accrued_substate.ts +16 -4
- package/src/avm/opcodes/context_getters.ts +1 -1
- package/src/avm/opcodes/external_calls.ts +8 -5
- package/src/avm/opcodes/hashing.ts +38 -54
- package/src/avm/serialization/instruction_serialization.ts +1 -1
- package/src/client/client_execution_context.ts +25 -6
- package/src/client/private_execution.ts +7 -6
- package/src/client/simulator.ts +7 -3
- package/src/client/unconstrained_execution.ts +4 -3
- package/src/common/index.ts +1 -1
- package/src/common/packed_values_cache.ts +55 -0
- package/src/index.ts +1 -0
- package/src/mocks/fixtures.ts +169 -0
- package/src/mocks/index.ts +1 -0
- package/src/public/abstract_phase_manager.ts +571 -0
- package/src/public/app_logic_phase_manager.ts +76 -0
- package/src/public/execution.ts +4 -0
- package/src/public/executor.ts +18 -13
- package/src/public/hints_builder.ts +119 -0
- package/src/public/index.ts +5 -0
- package/src/public/phase_manager_factory.ts +126 -0
- package/src/public/public_execution_context.ts +29 -18
- package/src/public/public_executor.ts +267 -0
- package/src/public/public_kernel.ts +139 -0
- package/src/public/public_kernel_circuit_simulator.ts +36 -0
- package/src/public/public_processor.ts +212 -0
- package/src/public/setup_phase_manager.ts +66 -0
- package/src/public/tail_phase_manager.ts +120 -0
- package/src/public/teardown_phase_manager.ts +66 -0
- package/src/public/transitional_adaptors.ts +14 -5
- package/src/public/utils.ts +31 -0
- package/src/simulator/acvm_native.ts +94 -47
- package/src/simulator/acvm_wasm.ts +7 -3
- package/dest/common/packed_args_cache.d.ts +0 -28
- package/dest/common/packed_args_cache.d.ts.map +0 -1
- package/dest/common/packed_args_cache.js +0 -50
- package/src/common/packed_args_cache.ts +0 -55
|
@@ -2,19 +2,35 @@
|
|
|
2
2
|
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
3
3
|
import { type WitnessMap } from '@noir-lang/types';
|
|
4
4
|
import { type SimulationProvider } from './simulation_provider.js';
|
|
5
|
+
export declare enum ACVM_RESULT {
|
|
6
|
+
SUCCESS = 0,
|
|
7
|
+
FAILURE = 1
|
|
8
|
+
}
|
|
9
|
+
export type ACVMSuccess = {
|
|
10
|
+
status: ACVM_RESULT.SUCCESS;
|
|
11
|
+
duration: number;
|
|
12
|
+
witness: Map<number, string>;
|
|
13
|
+
};
|
|
14
|
+
export type ACVMFailure = {
|
|
15
|
+
status: ACVM_RESULT.FAILURE;
|
|
16
|
+
reason: string;
|
|
17
|
+
};
|
|
18
|
+
export type ACVMResult = ACVMSuccess | ACVMFailure;
|
|
5
19
|
/**
|
|
6
20
|
*
|
|
7
21
|
* @param inputWitness - The circuit's input witness
|
|
8
22
|
* @param bytecode - The circuit bytecode
|
|
9
23
|
* @param workingDirectory - A directory to use for temporary files by the ACVM
|
|
10
|
-
* @param pathToAcvm - The path to the
|
|
24
|
+
* @param pathToAcvm - The path to the ACVM binary
|
|
25
|
+
* @param outputFilename - If specified, the output will be stored as a file, encoded using Bincode
|
|
11
26
|
* @returns The completed partial witness outputted from the circuit
|
|
12
27
|
*/
|
|
13
|
-
export declare function executeNativeCircuit(inputWitness: WitnessMap, bytecode: Buffer, workingDirectory: string, pathToAcvm: string): Promise<
|
|
28
|
+
export declare function executeNativeCircuit(inputWitness: WitnessMap, bytecode: Buffer, workingDirectory: string, pathToAcvm: string, outputFilename?: string): Promise<ACVMResult>;
|
|
14
29
|
export declare class NativeACVMSimulator implements SimulationProvider {
|
|
15
30
|
private workingDirectory;
|
|
16
31
|
private pathToAcvm;
|
|
17
|
-
|
|
32
|
+
private witnessFilename?;
|
|
33
|
+
constructor(workingDirectory: string, pathToAcvm: string, witnessFilename?: string | undefined);
|
|
18
34
|
simulateCircuit(input: WitnessMap, compiledCircuit: NoirCompiledCircuit): Promise<WitnessMap>;
|
|
19
35
|
}
|
|
20
36
|
//# sourceMappingURL=acvm_native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acvm_native.d.ts","sourceRoot":"","sources":["../../src/simulator/acvm_native.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"acvm_native.d.ts","sourceRoot":"","sources":["../../src/simulator/acvm_native.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAInE,oBAAY,WAAW;IACrB,OAAO,IAAA;IACP,OAAO,IAAA;CACR;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC;AAmBnD;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,YAAY,EAAE,UAAU,EACxB,QAAQ,EAAE,MAAM,EAChB,gBAAgB,EAAE,MAAM,EACxB,UAAU,EAAE,MAAM,EAClB,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,UAAU,CAAC,CAqErB;AAED,qBAAa,mBAAoB,YAAW,kBAAkB;IAChD,OAAO,CAAC,gBAAgB;IAAU,OAAO,CAAC,UAAU;IAAU,OAAO,CAAC,eAAe,CAAC;gBAA9E,gBAAgB,EAAE,MAAM,EAAU,UAAU,EAAE,MAAM,EAAU,eAAe,CAAC,oBAAQ;IACpG,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;CAsBpG"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { randomBytes } from '@aztec/foundation/crypto';
|
|
2
|
+
import { createDebugLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
2
4
|
import * as proc from 'child_process';
|
|
3
5
|
import fs from 'fs/promises';
|
|
6
|
+
const logger = createDebugLogger('aztec:acvm-native');
|
|
7
|
+
export var ACVM_RESULT;
|
|
8
|
+
(function (ACVM_RESULT) {
|
|
9
|
+
ACVM_RESULT[ACVM_RESULT["SUCCESS"] = 0] = "SUCCESS";
|
|
10
|
+
ACVM_RESULT[ACVM_RESULT["FAILURE"] = 1] = "FAILURE";
|
|
11
|
+
})(ACVM_RESULT || (ACVM_RESULT = {}));
|
|
4
12
|
/**
|
|
5
13
|
* Parses a TOML format witness map string into a Map structure
|
|
6
14
|
* @param outputString - The witness map in TOML format
|
|
@@ -20,10 +28,11 @@ function parseIntoWitnessMap(outputString) {
|
|
|
20
28
|
* @param inputWitness - The circuit's input witness
|
|
21
29
|
* @param bytecode - The circuit bytecode
|
|
22
30
|
* @param workingDirectory - A directory to use for temporary files by the ACVM
|
|
23
|
-
* @param pathToAcvm - The path to the
|
|
31
|
+
* @param pathToAcvm - The path to the ACVM binary
|
|
32
|
+
* @param outputFilename - If specified, the output will be stored as a file, encoded using Bincode
|
|
24
33
|
* @returns The completed partial witness outputted from the circuit
|
|
25
34
|
*/
|
|
26
|
-
export async function executeNativeCircuit(inputWitness, bytecode, workingDirectory, pathToAcvm) {
|
|
35
|
+
export async function executeNativeCircuit(inputWitness, bytecode, workingDirectory, pathToAcvm, outputFilename) {
|
|
27
36
|
const bytecodeFilename = 'bytecode';
|
|
28
37
|
const witnessFilename = 'input_witness.toml';
|
|
29
38
|
// convert the witness map to TOML format
|
|
@@ -31,66 +40,84 @@ export async function executeNativeCircuit(inputWitness, bytecode, workingDirect
|
|
|
31
40
|
inputWitness.forEach((value, key) => {
|
|
32
41
|
witnessMap = witnessMap.concat(`${key} = '${value}'\n`);
|
|
33
42
|
});
|
|
34
|
-
// In case the directory is still around from some time previously, remove it
|
|
35
|
-
await fs.rm(workingDirectory, { recursive: true, force: true });
|
|
36
|
-
// Create the new working directory
|
|
37
|
-
await fs.mkdir(workingDirectory, { recursive: true });
|
|
38
|
-
// Write the bytecode and input witness to the working directory
|
|
39
|
-
await fs.writeFile(`${workingDirectory}/${bytecodeFilename}`, bytecode);
|
|
40
|
-
await fs.writeFile(`${workingDirectory}/${witnessFilename}`, witnessMap);
|
|
41
|
-
// Execute the ACVM using the given args
|
|
42
|
-
const args = [
|
|
43
|
-
`execute`,
|
|
44
|
-
`--working-directory`,
|
|
45
|
-
`${workingDirectory}`,
|
|
46
|
-
`--bytecode`,
|
|
47
|
-
`${bytecodeFilename}`,
|
|
48
|
-
`--input-witness`,
|
|
49
|
-
`${witnessFilename}`,
|
|
50
|
-
`--print`,
|
|
51
|
-
];
|
|
52
|
-
const processPromise = new Promise((resolve, reject) => {
|
|
53
|
-
let outputWitness = Buffer.alloc(0);
|
|
54
|
-
let errorBuffer = Buffer.alloc(0);
|
|
55
|
-
const acvm = proc.spawn(pathToAcvm, args);
|
|
56
|
-
acvm.stdout.on('data', data => {
|
|
57
|
-
outputWitness = Buffer.concat([outputWitness, data]);
|
|
58
|
-
});
|
|
59
|
-
acvm.stderr.on('data', data => {
|
|
60
|
-
errorBuffer = Buffer.concat([errorBuffer, data]);
|
|
61
|
-
});
|
|
62
|
-
acvm.on('close', code => {
|
|
63
|
-
if (code === 0) {
|
|
64
|
-
resolve(outputWitness.toString('utf-8'));
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
reject(errorBuffer.toString('utf-8'));
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
43
|
try {
|
|
44
|
+
// Check that the directory exists
|
|
45
|
+
await fs.access(workingDirectory);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return { status: ACVM_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
// Write the bytecode and input witness to the working directory
|
|
52
|
+
await fs.writeFile(`${workingDirectory}/${bytecodeFilename}`, bytecode);
|
|
53
|
+
await fs.writeFile(`${workingDirectory}/${witnessFilename}`, witnessMap);
|
|
54
|
+
// Execute the ACVM using the given args
|
|
55
|
+
const args = [
|
|
56
|
+
`execute`,
|
|
57
|
+
`--working-directory`,
|
|
58
|
+
`${workingDirectory}`,
|
|
59
|
+
`--bytecode`,
|
|
60
|
+
`${bytecodeFilename}`,
|
|
61
|
+
`--input-witness`,
|
|
62
|
+
`${witnessFilename}`,
|
|
63
|
+
'--print',
|
|
64
|
+
'--output-witness',
|
|
65
|
+
'output-witness',
|
|
66
|
+
];
|
|
67
|
+
logger.debug(`Calling ACVM with ${args.join(' ')}`);
|
|
68
|
+
const processPromise = new Promise((resolve, reject) => {
|
|
69
|
+
let outputWitness = Buffer.alloc(0);
|
|
70
|
+
let errorBuffer = Buffer.alloc(0);
|
|
71
|
+
const acvm = proc.spawn(pathToAcvm, args);
|
|
72
|
+
acvm.stdout.on('data', data => {
|
|
73
|
+
outputWitness = Buffer.concat([outputWitness, data]);
|
|
74
|
+
});
|
|
75
|
+
acvm.stderr.on('data', data => {
|
|
76
|
+
errorBuffer = Buffer.concat([errorBuffer, data]);
|
|
77
|
+
});
|
|
78
|
+
acvm.on('close', code => {
|
|
79
|
+
if (code === 0) {
|
|
80
|
+
resolve(outputWitness.toString('utf-8'));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
logger.error(`From ACVM: ${errorBuffer.toString('utf-8')}`);
|
|
84
|
+
reject(errorBuffer.toString('utf-8'));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
const duration = new Timer();
|
|
72
89
|
const output = await processPromise;
|
|
73
|
-
|
|
90
|
+
if (outputFilename) {
|
|
91
|
+
const outputWitnessFileName = `${workingDirectory}/output-witness.gz`;
|
|
92
|
+
await fs.copyFile(outputWitnessFileName, outputFilename);
|
|
93
|
+
}
|
|
94
|
+
const witness = parseIntoWitnessMap(output);
|
|
95
|
+
return { status: ACVM_RESULT.SUCCESS, witness, duration: duration.ms() };
|
|
74
96
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
await fs.rm(workingDirectory, { recursive: true, force: true });
|
|
97
|
+
catch (error) {
|
|
98
|
+
return { status: ACVM_RESULT.FAILURE, reason: `${error}` };
|
|
78
99
|
}
|
|
79
100
|
}
|
|
80
101
|
export class NativeACVMSimulator {
|
|
81
|
-
constructor(workingDirectory, pathToAcvm) {
|
|
102
|
+
constructor(workingDirectory, pathToAcvm, witnessFilename) {
|
|
82
103
|
this.workingDirectory = workingDirectory;
|
|
83
104
|
this.pathToAcvm = pathToAcvm;
|
|
105
|
+
this.witnessFilename = witnessFilename;
|
|
84
106
|
}
|
|
85
107
|
async simulateCircuit(input, compiledCircuit) {
|
|
86
108
|
// Execute the circuit on those initial witness values
|
|
87
109
|
// Decode the bytecode from base64 since the acvm does not know about base64 encoding
|
|
88
110
|
const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
89
111
|
// Provide a unique working directory so we don't get clashes with parallel executions
|
|
90
|
-
const directory = `${this.workingDirectory}/${randomBytes(
|
|
112
|
+
const directory = `${this.workingDirectory}/${randomBytes(8).toString('hex')}`;
|
|
113
|
+
await fs.mkdir(directory, { recursive: true });
|
|
91
114
|
// Execute the circuit
|
|
92
|
-
const
|
|
93
|
-
|
|
115
|
+
const result = await executeNativeCircuit(input, decodedBytecode, directory, this.pathToAcvm, this.witnessFilename);
|
|
116
|
+
await fs.rm(directory, { force: true, recursive: true });
|
|
117
|
+
if (result.status == ACVM_RESULT.FAILURE) {
|
|
118
|
+
throw new Error(`Failed to generate witness: ${result.reason}`);
|
|
119
|
+
}
|
|
120
|
+
return result.witness;
|
|
94
121
|
}
|
|
95
122
|
}
|
|
96
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
123
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWN2bV9uYXRpdmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2ltdWxhdG9yL2Fjdm1fbmF0aXZlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUN2RCxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUMxRCxPQUFPLEVBQUUsS0FBSyxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFJaEQsT0FBTyxLQUFLLElBQUksTUFBTSxlQUFlLENBQUM7QUFDdEMsT0FBTyxFQUFFLE1BQU0sYUFBYSxDQUFDO0FBSTdCLE1BQU0sTUFBTSxHQUFHLGlCQUFpQixDQUFDLG1CQUFtQixDQUFDLENBQUM7QUFFdEQsTUFBTSxDQUFOLElBQVksV0FHWDtBQUhELFdBQVksV0FBVztJQUNyQixtREFBTyxDQUFBO0lBQ1AsbURBQU8sQ0FBQTtBQUNULENBQUMsRUFIVyxXQUFXLEtBQVgsV0FBVyxRQUd0QjtBQWVEOzs7O0dBSUc7QUFDSCxTQUFTLG1CQUFtQixDQUFDLFlBQW9CO0lBQy9DLE1BQU0sS0FBSyxHQUFHLFlBQVksQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDdkM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O1FBRXhFLHNGQUFzRjtRQUN0RixNQUFNLFNBQVMsR0FBRyxHQUFHLElBQUksQ0FBQyxnQkFBZ0IsSUFBSSxXQUFXLENBQUMsQ0FBQyxDQUFDLENBQUMsUUFBUSxDQUFDLEtBQUssQ0FBQyxFQUFFLENBQUM7UUFFL0UsTUFBTSxFQUFFLENBQUMsS0FBSyxDQUFDLFNBQVMsRUFBRSxFQUFFLFNBQVMsRUFBRSxJQUFJLEVBQUUsQ0FBQyxDQUFDO1FBRS9DLHNCQUFzQjtRQUN0QixNQUFNLE1BQU0sR0FBRyxNQUFNLG9CQUFvQixDQUFDLEtBQUssRUFBRSxlQUFlLEVBQUUsU0FBUyxFQUFFLElBQUksQ0FBQyxVQUFVLEVBQUUsSUFBSSxDQUFDLGVBQWUsQ0FBQyxDQUFDO1FBRXBILE1BQU0sRUFBRSxDQUFDLEVBQUUsQ0FBQyxTQUFTLEVBQUUsRUFBRSxLQUFLLEVBQUUsSUFBSSxFQUFFLFNBQVMsRUFBRSxJQUFJLEVBQUUsQ0FBQyxDQUFDO1FBRXpELElBQUksTUFBTSxDQUFDLE1BQU0sSUFBSSxXQUFXLENBQUMsT0FBTyxFQUFFLENBQUM7WUFDekMsTUFBTSxJQUFJLEtBQUssQ0FBQywrQkFBK0IsTUFBTSxDQUFDLE1BQU0sRUFBRSxDQUFDLENBQUM7UUFDbEUsQ0FBQztRQUVELE9BQU8sTUFBTSxDQUFDLE9BQU8sQ0FBQztJQUN4QixDQUFDO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acvm_wasm.d.ts","sourceRoot":"","sources":["../../src/simulator/acvm_wasm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"acvm_wasm.d.ts","sourceRoot":"","sources":["../../src/simulator/acvm_wasm.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAO7D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAWnE,qBAAa,aAAc,YAAW,kBAAkB;IAChD,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;CAgBpG"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { foreignCallHandler } from '@aztec/noir-protocol-circuits-types';
|
|
1
2
|
import { createBlackBoxSolver, executeCircuitWithBlackBoxSolver, } from '@noir-lang/acvm_js';
|
|
2
3
|
let solver;
|
|
3
4
|
const getSolver = () => {
|
|
@@ -14,10 +15,8 @@ export class WASMSimulator {
|
|
|
14
15
|
const decodedBytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
15
16
|
//
|
|
16
17
|
// Execute the circuit
|
|
17
|
-
const _witnessMap = await executeCircuitWithBlackBoxSolver(await getSolver(), decodedBytecode, input,
|
|
18
|
-
throw Error('unexpected oracle during execution');
|
|
19
|
-
});
|
|
18
|
+
const _witnessMap = await executeCircuitWithBlackBoxSolver(await getSolver(), decodedBytecode, input, foreignCallHandler);
|
|
20
19
|
return _witnessMap;
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
22
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWN2bV93YXNtLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3NpbXVsYXRvci9hY3ZtX3dhc20udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGtCQUFrQixFQUFFLE1BQU0scUNBQXFDLENBQUM7QUFHekUsT0FBTyxFQUVMLG9CQUFvQixFQUNwQixnQ0FBZ0MsR0FDakMsTUFBTSxvQkFBb0IsQ0FBQztBQUs1QixJQUFJLE1BQTJDLENBQUM7QUFFaEQsTUFBTSxTQUFTLEdBQUcsR0FBd0MsRUFBRTtJQUMxRCxJQUFJLENBQUMsTUFBTSxFQUFFLENBQUM7UUFDWixNQUFNLEdBQUcsb0JBQW9CLEVBQUUsQ0FBQztJQUNsQyxDQUFDO0lBQ0QsT0FBTyxNQUFNLENBQUM7QUFDaEIsQ0FBQyxDQUFDO0FBRUYsTUFBTSxPQUFPLGFBQWE7SUFDeEIsS0FBSyxDQUFDLGVBQWUsQ0FBQyxLQUFpQixFQUFFLGVBQW9DO1FBQzNFLHNEQUFzRDtRQUN0RCxFQUFFO1FBQ0YscUZBQXFGO1FBQ3JGLE1BQU0sZUFBZSxHQUFHLE1BQU0sQ0FBQyxJQUFJLENBQUMsZUFBZSxDQUFDLFFBQVEsRUFBRSxRQUFRLENBQUMsQ0FBQztRQUN4RSxFQUFFO1FBQ0Ysc0JBQXNCO1FBQ3RCLE1BQU0sV0FBVyxHQUFHLE1BQU0sZ0NBQWdDLENBQ3hELE1BQU0sU0FBUyxFQUFFLEVBQ2pCLGVBQWUsRUFDZixLQUFLLEVBQ0wsa0JBQWtCLENBQ25CLENBQUM7UUFFRixPQUFPLFdBQVcsQ0FBQztJQUNyQixDQUFDO0NBQ0YifQ==
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/simulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dest/index.js",
|
|
6
6
|
"typedocOptions": {
|
|
@@ -37,10 +37,13 @@
|
|
|
37
37
|
]
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@aztec/circuit-types": "0.
|
|
41
|
-
"@aztec/circuits.js": "0.
|
|
42
|
-
"@aztec/foundation": "0.
|
|
43
|
-
"@aztec/types": "0.
|
|
40
|
+
"@aztec/circuit-types": "0.35.0",
|
|
41
|
+
"@aztec/circuits.js": "0.35.0",
|
|
42
|
+
"@aztec/foundation": "0.35.0",
|
|
43
|
+
"@aztec/noir-protocol-circuits-types": "0.35.0",
|
|
44
|
+
"@aztec/protocol-contracts": "0.35.0",
|
|
45
|
+
"@aztec/types": "0.35.0",
|
|
46
|
+
"@aztec/world-state": "0.35.0",
|
|
44
47
|
"@noir-lang/acvm_js": "portal:../../noir/packages/acvm_js",
|
|
45
48
|
"@noir-lang/types": "portal:../../noir/packages/types",
|
|
46
49
|
"levelup": "^5.1.1",
|
package/src/acvm/acvm.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type ForeignCallInput,
|
|
8
8
|
type ForeignCallOutput,
|
|
9
9
|
type WasmBlackBoxFunctionSolver,
|
|
10
|
-
|
|
10
|
+
executeCircuitWithReturnWitness,
|
|
11
11
|
} from '@noir-lang/acvm_js';
|
|
12
12
|
|
|
13
13
|
import { traverseCauseChain } from '../common/errors.js';
|
|
@@ -27,9 +27,12 @@ type ACIRCallback = Record<
|
|
|
27
27
|
*/
|
|
28
28
|
export interface ACIRExecutionResult {
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* An execution result contains two witnesses.
|
|
31
|
+
* 1. The partial witness of the execution.
|
|
32
|
+
* 2. The return witness which contains the given public return values within the full witness.
|
|
31
33
|
*/
|
|
32
34
|
partialWitness: ACVMWitness;
|
|
35
|
+
returnWitness: ACVMWitness;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
/**
|
|
@@ -89,13 +92,13 @@ export async function acvm(
|
|
|
89
92
|
): Promise<ACIRExecutionResult> {
|
|
90
93
|
const logger = createDebugLogger('aztec:simulator:acvm');
|
|
91
94
|
|
|
92
|
-
const
|
|
95
|
+
const solvedAndReturnWitness = await executeCircuitWithReturnWitness(
|
|
93
96
|
solver,
|
|
94
97
|
acir,
|
|
95
98
|
initialWitness,
|
|
96
99
|
async (name: string, args: ForeignCallInput[]) => {
|
|
97
100
|
try {
|
|
98
|
-
logger.
|
|
101
|
+
logger.debug(`Oracle callback ${name}`);
|
|
99
102
|
const oracleFunction = callback[name as ORACLE_NAMES];
|
|
100
103
|
if (!oracleFunction) {
|
|
101
104
|
throw new Error(`Oracle callback ${name} not found`);
|
|
@@ -127,7 +130,7 @@ export async function acvm(
|
|
|
127
130
|
throw err;
|
|
128
131
|
});
|
|
129
132
|
|
|
130
|
-
return { partialWitness };
|
|
133
|
+
return { partialWitness: solvedAndReturnWitness.solvedWitness, returnWitness: solvedAndReturnWitness.returnWitness };
|
|
131
134
|
}
|
|
132
135
|
|
|
133
136
|
/**
|
package/src/acvm/deserialize.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
|
|
3
|
-
import { getReturnWitness } from '@noir-lang/acvm_js';
|
|
4
|
-
|
|
5
3
|
import { type ACVMField, type ACVMWitness } from './acvm_types.js';
|
|
6
4
|
|
|
7
5
|
/**
|
|
@@ -32,13 +30,11 @@ export function frToBoolean(fr: Fr): boolean {
|
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @param
|
|
37
|
-
* @param partialWitness - The witness to extract from.
|
|
33
|
+
* Transforms a witness map to its field elements.
|
|
34
|
+
* @param witness - The witness to extract from.
|
|
38
35
|
* @returns The return values.
|
|
39
36
|
*/
|
|
40
|
-
export function
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
return sortedKeys.map(key => returnWitness.get(key)!).map(fromACVMField);
|
|
37
|
+
export function witnessMapToFields(witness: ACVMWitness): Fr[] {
|
|
38
|
+
const sortedKeys = [...witness.keys()].sort((a, b) => a - b);
|
|
39
|
+
return sortedKeys.map(key => witness.get(key)!).map(fromACVMField);
|
|
44
40
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { MerkleTreeId, UnencryptedL2Log } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
2
|
+
import { acvmFieldMessageToString, oracleDebugCallToFormattedStr } from '@aztec/circuits.js';
|
|
3
3
|
import { EventSelector, FunctionSelector } from '@aztec/foundation/abi';
|
|
4
4
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
5
|
-
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
6
5
|
import { Fr, Point } from '@aztec/foundation/fields';
|
|
7
6
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
8
7
|
|
|
@@ -27,6 +26,17 @@ export class Oracle {
|
|
|
27
26
|
return toACVMField(packed);
|
|
28
27
|
}
|
|
29
28
|
|
|
29
|
+
// Since the argument is a slice, noir automatically adds a length field to oracle call.
|
|
30
|
+
async packReturns(_length: ACVMField[], values: ACVMField[]): Promise<ACVMField> {
|
|
31
|
+
const packed = await this.typedOracle.packReturns(values.map(fromACVMField));
|
|
32
|
+
return toACVMField(packed);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async unpackReturns([returnsHash]: ACVMField[]): Promise<ACVMField[]> {
|
|
36
|
+
const unpacked = await this.typedOracle.unpackReturns(fromACVMField(returnsHash));
|
|
37
|
+
return unpacked.map(toACVMField);
|
|
38
|
+
}
|
|
39
|
+
|
|
30
40
|
async getNullifierKeyPair([accountAddress]: ACVMField[]): Promise<ACVMField[]> {
|
|
31
41
|
const { publicKey, secretKey } = await this.typedOracle.getNullifierKeyPair(fromACVMField(accountAddress));
|
|
32
42
|
return [
|
|
@@ -348,7 +358,7 @@ export class Oracle {
|
|
|
348
358
|
frToBoolean(fromACVMField(isStaticCall)),
|
|
349
359
|
frToBoolean(fromACVMField(isDelegateCall)),
|
|
350
360
|
);
|
|
351
|
-
return
|
|
361
|
+
return returnValues.map(toACVMField);
|
|
352
362
|
}
|
|
353
363
|
|
|
354
364
|
async enqueuePublicFunctionCall(
|
|
@@ -89,6 +89,14 @@ export abstract class TypedOracle {
|
|
|
89
89
|
throw new OracleMethodNotAvailableError('packArguments');
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
packReturns(_returns: Fr[]): Promise<Fr> {
|
|
93
|
+
throw new OracleMethodNotAvailableError('packReturns');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
unpackReturns(_returnsHash: Fr): Promise<Fr[]> {
|
|
97
|
+
throw new OracleMethodNotAvailableError('unpackReturns');
|
|
98
|
+
}
|
|
99
|
+
|
|
92
100
|
getNullifierKeyPair(_accountAddress: AztecAddress): Promise<KeyPair> {
|
|
93
101
|
throw new OracleMethodNotAvailableError('getNullifierKeyPair');
|
|
94
102
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FunctionSelector, type GlobalVariables, type Header } from '@aztec/circuits.js';
|
|
1
|
+
import { FunctionSelector, type GasSettings, type GlobalVariables, type Header } from '@aztec/circuits.js';
|
|
2
2
|
import { computeVarArgsHash } from '@aztec/circuits.js/hash';
|
|
3
3
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
4
|
import { type EthAddress } from '@aztec/foundation/eth-address';
|
|
@@ -35,6 +35,8 @@ export class AvmExecutionEnvironment {
|
|
|
35
35
|
public readonly isStaticCall: boolean,
|
|
36
36
|
public readonly isDelegateCall: boolean,
|
|
37
37
|
public readonly calldata: Fr[],
|
|
38
|
+
public readonly gasSettings: GasSettings,
|
|
39
|
+
public readonly transactionFee: Fr,
|
|
38
40
|
|
|
39
41
|
// Function selector is temporary since eventually public contract bytecode will be one blob
|
|
40
42
|
// containing all functions, and function selector will become an application-level mechanism
|
|
@@ -67,6 +69,8 @@ export class AvmExecutionEnvironment {
|
|
|
67
69
|
this.isStaticCall,
|
|
68
70
|
this.isDelegateCall,
|
|
69
71
|
calldata,
|
|
72
|
+
this.gasSettings,
|
|
73
|
+
this.transactionFee,
|
|
70
74
|
temporaryFunctionSelector,
|
|
71
75
|
);
|
|
72
76
|
}
|
|
@@ -91,6 +95,8 @@ export class AvmExecutionEnvironment {
|
|
|
91
95
|
/*isStaticCall=*/ true,
|
|
92
96
|
this.isDelegateCall,
|
|
93
97
|
calldata,
|
|
98
|
+
this.gasSettings,
|
|
99
|
+
this.transactionFee,
|
|
94
100
|
temporaryFunctionSelector,
|
|
95
101
|
);
|
|
96
102
|
}
|
|
@@ -115,6 +121,8 @@ export class AvmExecutionEnvironment {
|
|
|
115
121
|
this.isStaticCall,
|
|
116
122
|
/*isDelegateCall=*/ true,
|
|
117
123
|
calldata,
|
|
124
|
+
this.gasSettings,
|
|
125
|
+
this.transactionFee,
|
|
118
126
|
temporaryFunctionSelector,
|
|
119
127
|
);
|
|
120
128
|
}
|
package/src/avm/avm_gas.ts
CHANGED
|
@@ -127,7 +127,7 @@ export const GasCosts: Record<Opcode, Gas | typeof DynamicGasCost> = {
|
|
|
127
127
|
[Opcode.REVERT]: TemporaryDefaultGasCost,
|
|
128
128
|
// Gadgets
|
|
129
129
|
[Opcode.KECCAK]: TemporaryDefaultGasCost,
|
|
130
|
-
[Opcode.
|
|
130
|
+
[Opcode.POSEIDON2]: TemporaryDefaultGasCost,
|
|
131
131
|
[Opcode.SHA256]: TemporaryDefaultGasCost, // temp - may be removed, but alot of contracts rely on i: TemporaryDefaultGasCost,
|
|
132
132
|
[Opcode.PEDERSEN]: TemporaryDefaultGasCost, // temp - may be removed, but alot of contracts rely on i: TemporaryDefaultGasCost,t
|
|
133
133
|
};
|
|
@@ -44,10 +44,20 @@ export class AvmMachineState {
|
|
|
44
44
|
/** Output data must NOT be modified once it is set */
|
|
45
45
|
private output: Fr[] = [];
|
|
46
46
|
|
|
47
|
-
constructor(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
constructor(gasLeft: Gas);
|
|
48
|
+
constructor(l1GasLeft: number, l2GasLeft: number, daGasLeft: number);
|
|
49
|
+
constructor(gasLeftOrL1GasLeft: Gas | number, l2GasLeft?: number, daGasLeft?: number) {
|
|
50
|
+
if (typeof gasLeftOrL1GasLeft === 'object') {
|
|
51
|
+
({ l1Gas: this.l1GasLeft, l2Gas: this.l2GasLeft, daGas: this.daGasLeft } = gasLeftOrL1GasLeft);
|
|
52
|
+
} else {
|
|
53
|
+
this.l1GasLeft = gasLeftOrL1GasLeft;
|
|
54
|
+
this.l2GasLeft = l2GasLeft!;
|
|
55
|
+
this.daGasLeft = daGasLeft!;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public get gasLeft(): Gas {
|
|
60
|
+
return { l1Gas: this.l1GasLeft, l2Gas: this.l2GasLeft, daGas: this.daGasLeft };
|
|
51
61
|
}
|
|
52
62
|
|
|
53
63
|
public static fromState(state: InitialAvmMachineState): AvmMachineState {
|
|
@@ -128,6 +138,17 @@ export class AvmMachineState {
|
|
|
128
138
|
if (!this.halted) {
|
|
129
139
|
throw new Error('Execution results are not ready! Execution is ongoing.');
|
|
130
140
|
}
|
|
131
|
-
|
|
141
|
+
let revertReason = undefined;
|
|
142
|
+
if (this.reverted && this.output.length > 0) {
|
|
143
|
+
try {
|
|
144
|
+
// Try to interpret the output as a text string.
|
|
145
|
+
revertReason = new Error(
|
|
146
|
+
'Reverted with output: ' + String.fromCharCode(...this.output.map(fr => fr.toNumber())),
|
|
147
|
+
);
|
|
148
|
+
} catch (e) {
|
|
149
|
+
revertReason = new Error('Reverted with non-string output');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return new AvmContractCallResults(this.reverted, this.output, revertReason);
|
|
132
153
|
}
|
|
133
154
|
}
|
|
@@ -240,7 +240,7 @@ export class TaggedMemory implements TaggedMemoryInterface {
|
|
|
240
240
|
const word = this._mem[offset];
|
|
241
241
|
TaggedMemory.log.debug(`get(${offset}) = ${word}`);
|
|
242
242
|
if (word === undefined) {
|
|
243
|
-
TaggedMemory.log.
|
|
243
|
+
TaggedMemory.log.debug(`WARNING: Memory at offset ${offset} is undefined!`);
|
|
244
244
|
}
|
|
245
245
|
return word as T;
|
|
246
246
|
}
|
package/src/avm/avm_simulator.ts
CHANGED
|
@@ -62,7 +62,7 @@ export class AvmSimulator {
|
|
|
62
62
|
);
|
|
63
63
|
|
|
64
64
|
const gasLeft = `l1=${machineState.l1GasLeft} l2=${machineState.l2GasLeft} da=${machineState.daGasLeft}`;
|
|
65
|
-
this.log.debug(`@${machineState.pc}
|
|
65
|
+
this.log.debug(`@${machineState.pc} ${instruction.toString()} (${gasLeft})`);
|
|
66
66
|
// Execute the instruction.
|
|
67
67
|
// Normal returns and reverts will return normally here.
|
|
68
68
|
// "Exceptional halts" will throw.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SiblingPath } from '@aztec/circuit-types';
|
|
2
|
-
import { GlobalVariables, Header, L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/circuits.js';
|
|
2
|
+
import { GasFees, GasSettings, GlobalVariables, Header, L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/circuits.js';
|
|
3
3
|
import { FunctionSelector } from '@aztec/foundation/abi';
|
|
4
4
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
5
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import { AvmContext } from '../avm_context.js';
|
|
18
18
|
import { AvmContextInputs, AvmExecutionEnvironment } from '../avm_execution_environment.js';
|
|
19
19
|
import { AvmMachineState } from '../avm_machine_state.js';
|
|
20
|
+
import { Field, Uint8 } from '../avm_memory_types.js';
|
|
20
21
|
import { HostStorage } from '../journal/host_storage.js';
|
|
21
22
|
import { AvmPersistableStateManager } from '../journal/journal.js';
|
|
22
23
|
|
|
@@ -72,6 +73,8 @@ export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnviron
|
|
|
72
73
|
overrides?.isStaticCall ?? false,
|
|
73
74
|
overrides?.isDelegateCall ?? false,
|
|
74
75
|
overrides?.calldata ?? [],
|
|
76
|
+
overrides?.gasSettings ?? GasSettings.empty(),
|
|
77
|
+
overrides?.transactionFee ?? Fr.ZERO,
|
|
75
78
|
overrides?.temporaryFunctionSelector ?? FunctionSelector.empty(),
|
|
76
79
|
);
|
|
77
80
|
}
|
|
@@ -87,6 +90,7 @@ export function initGlobalVariables(overrides?: Partial<GlobalVariables>): Globa
|
|
|
87
90
|
overrides?.timestamp ?? Fr.zero(),
|
|
88
91
|
overrides?.coinbase ?? EthAddress.ZERO,
|
|
89
92
|
overrides?.feeRecipient ?? AztecAddress.zero(),
|
|
93
|
+
overrides?.gasFees ?? GasFees.empty(),
|
|
90
94
|
);
|
|
91
95
|
}
|
|
92
96
|
|
|
@@ -135,3 +139,11 @@ export function anyAvmContextInputs() {
|
|
|
135
139
|
}
|
|
136
140
|
return tv;
|
|
137
141
|
}
|
|
142
|
+
|
|
143
|
+
export function randomMemoryBytes(length: number): Uint8[] {
|
|
144
|
+
return [...Array(length)].map(_ => new Uint8(Math.floor(Math.random() * 255)));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function randomMemoryFields(length: number): Field[] {
|
|
148
|
+
return [...Array(length)].map(_ => new Field(Fr.random()));
|
|
149
|
+
}
|
|
@@ -2,6 +2,7 @@ import { UnencryptedL2Log } from '@aztec/circuit-types';
|
|
|
2
2
|
import { AztecAddress, EthAddress, L2ToL1Message } from '@aztec/circuits.js';
|
|
3
3
|
import { EventSelector } from '@aztec/foundation/abi';
|
|
4
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
+
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
5
6
|
|
|
6
7
|
import { type HostStorage } from './host_storage.js';
|
|
7
8
|
import { Nullifiers } from './nullifiers.js';
|
|
@@ -47,6 +48,7 @@ export type JournalData = {
|
|
|
47
48
|
* Manages merging of successful/reverted child state into current state.
|
|
48
49
|
*/
|
|
49
50
|
export class AvmPersistableStateManager {
|
|
51
|
+
private readonly log: DebugLogger = createDebugLogger('aztec:avm_simulator:state_manager');
|
|
50
52
|
/** Reference to node storage */
|
|
51
53
|
public readonly hostStorage: HostStorage;
|
|
52
54
|
|
|
@@ -86,6 +88,7 @@ export class AvmPersistableStateManager {
|
|
|
86
88
|
* @param value - the value being written to the slot
|
|
87
89
|
*/
|
|
88
90
|
public writeStorage(storageAddress: Fr, slot: Fr, value: Fr) {
|
|
91
|
+
this.log.debug(`storage(${storageAddress})@${slot} <- ${value}`);
|
|
89
92
|
// Cache storage writes for later reference/reads
|
|
90
93
|
this.publicStorage.write(storageAddress, slot, value);
|
|
91
94
|
// Trace all storage writes (even reverted ones)
|
|
@@ -101,6 +104,7 @@ export class AvmPersistableStateManager {
|
|
|
101
104
|
*/
|
|
102
105
|
public async readStorage(storageAddress: Fr, slot: Fr): Promise<Fr> {
|
|
103
106
|
const [exists, value] = await this.publicStorage.read(storageAddress, slot);
|
|
107
|
+
this.log.debug(`storage(${storageAddress})@${slot} ?? value: ${value}, exists: ${exists}.`);
|
|
104
108
|
// We want to keep track of all performed reads (even reverted ones)
|
|
105
109
|
this.trace.tracePublicStorageRead(storageAddress, slot, value, exists);
|
|
106
110
|
return Promise.resolve(value);
|
|
@@ -118,6 +122,7 @@ export class AvmPersistableStateManager {
|
|
|
118
122
|
public async checkNoteHashExists(storageAddress: Fr, noteHash: Fr, leafIndex: Fr): Promise<boolean> {
|
|
119
123
|
const gotLeafIndex = await this.hostStorage.commitmentsDb.getCommitmentIndex(noteHash);
|
|
120
124
|
const exists = gotLeafIndex === leafIndex.toBigInt();
|
|
125
|
+
this.log.debug(`noteHashes(${storageAddress})@${noteHash} ?? leafIndex: ${leafIndex}, exists: ${exists}.`);
|
|
121
126
|
this.trace.traceNoteHashCheck(storageAddress, noteHash, exists, leafIndex);
|
|
122
127
|
return Promise.resolve(exists);
|
|
123
128
|
}
|
|
@@ -127,6 +132,7 @@ export class AvmPersistableStateManager {
|
|
|
127
132
|
* @param noteHash - the unsiloed note hash to write
|
|
128
133
|
*/
|
|
129
134
|
public writeNoteHash(storageAddress: Fr, noteHash: Fr) {
|
|
135
|
+
this.log.debug(`noteHashes(${storageAddress}) += @${noteHash}.`);
|
|
130
136
|
this.trace.traceNewNoteHash(storageAddress, noteHash);
|
|
131
137
|
}
|
|
132
138
|
|
|
@@ -138,6 +144,9 @@ export class AvmPersistableStateManager {
|
|
|
138
144
|
*/
|
|
139
145
|
public async checkNullifierExists(storageAddress: Fr, nullifier: Fr): Promise<boolean> {
|
|
140
146
|
const [exists, isPending, leafIndex] = await this.nullifiers.checkExists(storageAddress, nullifier);
|
|
147
|
+
this.log.debug(
|
|
148
|
+
`nullifiers(${storageAddress})@${nullifier} ?? leafIndex: ${leafIndex}, pending: ${isPending}, exists: ${exists}.`,
|
|
149
|
+
);
|
|
141
150
|
this.trace.traceNullifierCheck(storageAddress, nullifier, exists, isPending, leafIndex);
|
|
142
151
|
return Promise.resolve(exists);
|
|
143
152
|
}
|
|
@@ -148,6 +157,7 @@ export class AvmPersistableStateManager {
|
|
|
148
157
|
* @param nullifier - the unsiloed nullifier to write
|
|
149
158
|
*/
|
|
150
159
|
public async writeNullifier(storageAddress: Fr, nullifier: Fr) {
|
|
160
|
+
this.log.debug(`nullifiers(${storageAddress}) += ${nullifier}.`);
|
|
151
161
|
// Cache pending nullifiers for later access
|
|
152
162
|
await this.nullifiers.append(storageAddress, nullifier);
|
|
153
163
|
// Trace all nullifier creations (even reverted ones)
|
|
@@ -178,6 +188,7 @@ export class AvmPersistableStateManager {
|
|
|
178
188
|
// error getting message - doesn't exist!
|
|
179
189
|
exists = false;
|
|
180
190
|
}
|
|
191
|
+
this.log.debug(`l1ToL2Messages(${msgHash})@${msgLeafIndex} ?? exists: ${exists}.`);
|
|
181
192
|
this.trace.traceL1ToL2MessageCheck(msgHash, msgLeafIndex, exists);
|
|
182
193
|
return Promise.resolve(exists);
|
|
183
194
|
}
|
|
@@ -188,11 +199,13 @@ export class AvmPersistableStateManager {
|
|
|
188
199
|
* @param content - Message content.
|
|
189
200
|
*/
|
|
190
201
|
public writeL1Message(recipient: EthAddress | Fr, content: Fr) {
|
|
202
|
+
this.log.debug(`L1Messages(${recipient}) += ${content}.`);
|
|
191
203
|
const recipientAddress = recipient instanceof EthAddress ? recipient : EthAddress.fromField(recipient);
|
|
192
204
|
this.newL1Messages.push(new L2ToL1Message(recipientAddress, content));
|
|
193
205
|
}
|
|
194
206
|
|
|
195
207
|
public writeLog(contractAddress: Fr, event: Fr, log: Fr[]) {
|
|
208
|
+
this.log.debug(`UnencryptedL2Log(${contractAddress}) += event ${event} with ${log.length} fields.`);
|
|
196
209
|
this.newLogs.push(
|
|
197
210
|
new UnencryptedL2Log(
|
|
198
211
|
AztecAddress.fromField(contractAddress),
|