@aztec-labs/simulator 6.0.0-nightly.20260829
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/README.md +57 -0
- package/dest/client.d.ts +6 -0
- package/dest/client.d.ts.map +1 -0
- package/dest/client.js +3 -0
- package/dest/common/errors.d.ts +51 -0
- package/dest/common/errors.d.ts.map +1 -0
- package/dest/common/errors.js +154 -0
- package/dest/common/index.d.ts +3 -0
- package/dest/common/index.d.ts.map +1 -0
- package/dest/common/index.js +2 -0
- package/dest/common/stats/index.d.ts +2 -0
- package/dest/common/stats/index.d.ts.map +1 -0
- package/dest/common/stats/index.js +1 -0
- package/dest/common/stats/stats.d.ts +4 -0
- package/dest/common/stats/stats.d.ts.map +1 -0
- package/dest/common/stats/stats.js +10 -0
- package/dest/private/acvm/acvm.d.ts +43 -0
- package/dest/private/acvm/acvm.d.ts.map +1 -0
- package/dest/private/acvm/acvm.js +65 -0
- package/dest/private/acvm/acvm_types.d.ts +10 -0
- package/dest/private/acvm/acvm_types.d.ts.map +1 -0
- package/dest/private/acvm/acvm_types.js +3 -0
- package/dest/private/acvm/deserialize.d.ts +35 -0
- package/dest/private/acvm/deserialize.d.ts.map +1 -0
- package/dest/private/acvm/deserialize.js +50 -0
- package/dest/private/acvm/index.d.ts +5 -0
- package/dest/private/acvm/index.d.ts.map +1 -0
- package/dest/private/acvm/index.js +4 -0
- package/dest/private/acvm/serialize.d.ts +41 -0
- package/dest/private/acvm/serialize.d.ts.map +1 -0
- package/dest/private/acvm/serialize.js +99 -0
- package/dest/private/acvm_native.d.ts +41 -0
- package/dest/private/acvm_native.d.ts.map +1 -0
- package/dest/private/acvm_native.js +147 -0
- package/dest/private/acvm_wasm.d.ts +16 -0
- package/dest/private/acvm_wasm.d.ts.map +1 -0
- package/dest/private/acvm_wasm.js +67 -0
- package/dest/private/acvm_wasm_with_blobs.d.ts +20 -0
- package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -0
- package/dest/private/acvm_wasm_with_blobs.js +35 -0
- package/dest/private/circuit_simulator.d.ts +35 -0
- package/dest/private/circuit_simulator.d.ts.map +1 -0
- package/dest/private/circuit_simulator.js +43 -0
- package/dest/private/factory.d.ts +12 -0
- package/dest/private/factory.d.ts.map +1 -0
- package/dest/private/factory.js +30 -0
- package/dest/public/avm/testing/account_proof_fetcher.d.ts +2 -0
- package/dest/public/avm/testing/account_proof_fetcher.d.ts.map +1 -0
- package/dest/public/avm/testing/account_proof_fetcher.js +152 -0
- package/dest/public/avm/testing/base_avm_simulation_tester.d.ts +39 -0
- package/dest/public/avm/testing/base_avm_simulation_tester.d.ts.map +1 -0
- package/dest/public/avm/testing/base_avm_simulation_tester.js +121 -0
- package/dest/public/avm/testing/utils.d.ts +32 -0
- package/dest/public/avm/testing/utils.d.ts.map +1 -0
- package/dest/public/avm/testing/utils.js +66 -0
- package/dest/public/avm_simulator.d.ts +28 -0
- package/dest/public/avm_simulator.d.ts.map +1 -0
- package/dest/public/avm_simulator.js +4 -0
- package/dest/public/avm_simulator_pool.d.ts +84 -0
- package/dest/public/avm_simulator_pool.d.ts.map +1 -0
- package/dest/public/avm_simulator_pool.js +311 -0
- package/dest/public/cdb_ipc_server.d.ts +40 -0
- package/dest/public/cdb_ipc_server.d.ts.map +1 -0
- package/dest/public/cdb_ipc_server.js +153 -0
- package/dest/public/contracts_db_checkpoint.d.ts +16 -0
- package/dest/public/contracts_db_checkpoint.d.ts.map +1 -0
- package/dest/public/contracts_db_checkpoint.js +30 -0
- package/dest/public/db_interfaces.d.ts +68 -0
- package/dest/public/db_interfaces.d.ts.map +1 -0
- package/dest/public/db_interfaces.js +3 -0
- package/dest/public/executor_metrics.d.ts +21 -0
- package/dest/public/executor_metrics.d.ts.map +1 -0
- package/dest/public/executor_metrics.js +64 -0
- package/dest/public/executor_metrics_interface.d.ts +10 -0
- package/dest/public/executor_metrics_interface.d.ts.map +1 -0
- package/dest/public/executor_metrics_interface.js +1 -0
- package/dest/public/fixtures/amm_test.d.ts +10 -0
- package/dest/public/fixtures/amm_test.d.ts.map +1 -0
- package/dest/public/fixtures/amm_test.js +213 -0
- package/dest/public/fixtures/bulk_test.d.ts +6 -0
- package/dest/public/fixtures/bulk_test.d.ts.map +1 -0
- package/dest/public/fixtures/bulk_test.js +289 -0
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +34 -0
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -0
- package/dest/public/fixtures/custom_bytecode_tester.js +53 -0
- package/dest/public/fixtures/index.d.ts +10 -0
- package/dest/public/fixtures/index.d.ts.map +1 -0
- package/dest/public/fixtures/index.js +9 -0
- package/dest/public/fixtures/public_processor_test_env.d.ts +30 -0
- package/dest/public/fixtures/public_processor_test_env.d.ts.map +1 -0
- package/dest/public/fixtures/public_processor_test_env.js +73 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +77 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -0
- package/dest/public/fixtures/public_tx_simulation_tester.js +176 -0
- package/dest/public/fixtures/simple_contract_data_source.d.ts +36 -0
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -0
- package/dest/public/fixtures/simple_contract_data_source.js +95 -0
- package/dest/public/fixtures/token_test.d.ts +12 -0
- package/dest/public/fixtures/token_test.d.ts.map +1 -0
- package/dest/public/fixtures/token_test.js +96 -0
- package/dest/public/fixtures/utils.d.ts +26 -0
- package/dest/public/fixtures/utils.d.ts.map +1 -0
- package/dest/public/fixtures/utils.js +170 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +65 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +181 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts +2 -0
- package/dest/public/fuzzing/avm_simulator_bin.d.ts.map +1 -0
- package/dest/public/fuzzing/avm_simulator_bin.js +108 -0
- package/dest/public/index.d.ts +10 -0
- package/dest/public/index.d.ts.map +1 -0
- package/dest/public/index.js +6 -0
- package/dest/public/public_db_sources.d.ts +83 -0
- package/dest/public/public_db_sources.d.ts.map +1 -0
- package/dest/public/public_db_sources.js +297 -0
- package/dest/public/public_errors.d.ts +12 -0
- package/dest/public/public_errors.d.ts.map +1 -0
- package/dest/public/public_errors.js +13 -0
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +52 -0
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -0
- package/dest/public/public_processor/guarded_merkle_tree.js +116 -0
- package/dest/public/public_processor/public_processor.d.ts +71 -0
- package/dest/public/public_processor/public_processor.d.ts.map +1 -0
- package/dest/public/public_processor/public_processor.js +858 -0
- package/dest/public/public_processor/public_processor_metrics.d.ts +30 -0
- package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -0
- package/dest/public/public_processor/public_processor_metrics.js +116 -0
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts +17 -0
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/dumping_public_tx_simulator.js +39 -0
- package/dest/public/public_tx_simulator/factories.d.ts +14 -0
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/factories.js +28 -0
- package/dest/public/public_tx_simulator/index.d.ts +6 -0
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/index.js +3 -0
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +53 -0
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_simulator.js +127 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts +24 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_base.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_base.js +31 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts +32 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/public_tx_simulator_interface.js +1 -0
- package/dest/public/side_effect_errors.d.ts +44 -0
- package/dest/public/side_effect_errors.d.ts.map +1 -0
- package/dest/public/side_effect_errors.js +75 -0
- package/dest/public/test_executor_metrics.d.ts +56 -0
- package/dest/public/test_executor_metrics.d.ts.map +1 -0
- package/dest/public/test_executor_metrics.js +305 -0
- package/dest/public/unique_class_ids.d.ts +37 -0
- package/dest/public/unique_class_ids.d.ts.map +1 -0
- package/dest/public/unique_class_ids.js +61 -0
- package/dest/public/utils.d.ts +3 -0
- package/dest/public/utils.d.ts.map +1 -0
- package/dest/public/utils.js +18 -0
- package/dest/server.d.ts +7 -0
- package/dest/server.d.ts.map +1 -0
- package/dest/server.js +5 -0
- package/package.json +109 -0
- package/src/client.ts +5 -0
- package/src/common/errors.ts +219 -0
- package/src/common/index.ts +2 -0
- package/src/common/stats/index.ts +1 -0
- package/src/common/stats/stats.ts +20 -0
- package/src/private/acvm/acvm.ts +114 -0
- package/src/private/acvm/acvm_types.ts +11 -0
- package/src/private/acvm/deserialize.ts +58 -0
- package/src/private/acvm/index.ts +4 -0
- package/src/private/acvm/serialize.ts +123 -0
- package/src/private/acvm_native.ts +200 -0
- package/src/private/acvm_wasm.ts +80 -0
- package/src/private/acvm_wasm_with_blobs.ts +55 -0
- package/src/private/circuit_simulator.ts +91 -0
- package/src/private/factory.ts +40 -0
- package/src/public/avm/testing/account_proof.json +553 -0
- package/src/public/avm/testing/account_proof_fetcher.ts +166 -0
- package/src/public/avm/testing/base_avm_simulation_tester.ts +162 -0
- package/src/public/avm/testing/utils.ts +114 -0
- package/src/public/avm_simulator.ts +29 -0
- package/src/public/avm_simulator_pool.ts +355 -0
- package/src/public/cdb_ipc_server.ts +198 -0
- package/src/public/contracts_db_checkpoint.ts +41 -0
- package/src/public/db_interfaces.ts +76 -0
- package/src/public/executor_metrics.ts +102 -0
- package/src/public/executor_metrics_interface.ts +20 -0
- package/src/public/fixtures/amm_test.ts +331 -0
- package/src/public/fixtures/bulk_test.ts +194 -0
- package/src/public/fixtures/custom_bytecode_tester.ts +83 -0
- package/src/public/fixtures/index.ts +13 -0
- package/src/public/fixtures/public_processor_test_env.ts +88 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +315 -0
- package/src/public/fixtures/simple_contract_data_source.ts +122 -0
- package/src/public/fixtures/token_test.ts +148 -0
- package/src/public/fixtures/utils.ts +269 -0
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +302 -0
- package/src/public/fuzzing/avm_simulator_bin.ts +156 -0
- package/src/public/index.ts +16 -0
- package/src/public/public_db_sources.ts +405 -0
- package/src/public/public_errors.ts +14 -0
- package/src/public/public_processor/guarded_merkle_tree.ts +161 -0
- package/src/public/public_processor/public_processor.ts +657 -0
- package/src/public/public_processor/public_processor_metrics.ts +138 -0
- package/src/public/public_tx_simulator/dumping_public_tx_simulator.ts +66 -0
- package/src/public/public_tx_simulator/factories.ts +61 -0
- package/src/public/public_tx_simulator/index.ts +8 -0
- package/src/public/public_tx_simulator/public_tx_simulator.ts +190 -0
- package/src/public/public_tx_simulator/public_tx_simulator_base.ts +37 -0
- package/src/public/public_tx_simulator/public_tx_simulator_interface.ts +33 -0
- package/src/public/side_effect_errors.ts +96 -0
- package/src/public/test_executor_metrics.ts +399 -0
- package/src/public/unique_class_ids.ts +79 -0
- package/src/public/utils.ts +16 -0
- package/src/server.ts +6 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
2
|
+
/**
|
|
3
|
+
* Adapts the buffer to the field size.
|
|
4
|
+
* @param originalBuf - The buffer to adapt.
|
|
5
|
+
* @returns The adapted buffer.
|
|
6
|
+
*/ function adaptBufferSize(originalBuf) {
|
|
7
|
+
const buffer = Buffer.alloc(Fr.SIZE_IN_BYTES);
|
|
8
|
+
if (originalBuf.length > buffer.length) {
|
|
9
|
+
throw new Error('Buffer does not fit in field');
|
|
10
|
+
}
|
|
11
|
+
originalBuf.copy(buffer, buffer.length - originalBuf.length);
|
|
12
|
+
return buffer;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Converts a value to an ACVM field.
|
|
16
|
+
* @param value - The value to convert.
|
|
17
|
+
* @returns The ACVM field.
|
|
18
|
+
*/ export function toACVMField(value) {
|
|
19
|
+
let buffer;
|
|
20
|
+
if (Buffer.isBuffer(value)) {
|
|
21
|
+
buffer = value;
|
|
22
|
+
} else if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'bigint') {
|
|
23
|
+
buffer = new Fr(value).toBuffer();
|
|
24
|
+
} else if (typeof value === 'string') {
|
|
25
|
+
buffer = Fr.fromHexString(value).toBuffer();
|
|
26
|
+
} else {
|
|
27
|
+
buffer = value.toBuffer();
|
|
28
|
+
}
|
|
29
|
+
return `0x${adaptBufferSize(buffer).toString('hex')}`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Converts a single value or an array of single values into the equivalent ACVM field representation.
|
|
33
|
+
*/ export function toACVMFieldSingleOrArray(value) {
|
|
34
|
+
return Array.isArray(value) ? value.map(toACVMField) : toACVMField(value);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Inserts a list of ACVM fields to a witness.
|
|
38
|
+
* @param witnessStartIndex - The index where to start inserting the fields.
|
|
39
|
+
* @param fields - The fields to insert.
|
|
40
|
+
* @returns The witness.
|
|
41
|
+
*/ export function toACVMWitness(witnessStartIndex, fields) {
|
|
42
|
+
return fields.reduce((witness, field, index)=>{
|
|
43
|
+
witness.set(index + witnessStartIndex, toACVMField(field));
|
|
44
|
+
return witness;
|
|
45
|
+
}, new Map());
|
|
46
|
+
}
|
|
47
|
+
export function bufferToU8Array(buffer) {
|
|
48
|
+
return Array.from(buffer).map((byte)=>toACVMField(BigInt(byte)));
|
|
49
|
+
}
|
|
50
|
+
export function bufferToBoundedVec(buffer, maxLen) {
|
|
51
|
+
const u8Array = bufferToU8Array(buffer);
|
|
52
|
+
return arrayToBoundedVec(u8Array, maxLen);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Converts a ForeignCallArray into a tuple which represents a nr BoundedVec.
|
|
56
|
+
* If the input array is shorter than the maxLen, it pads the result with zeros,
|
|
57
|
+
* so that nr can correctly coerce this result into a BoundedVec.
|
|
58
|
+
* @param bVecStorage - The array underlying the BoundedVec.
|
|
59
|
+
* @param maxLen - the max length of the BoundedVec.
|
|
60
|
+
* @returns a tuple representing a BoundedVec.
|
|
61
|
+
*/ export function arrayToBoundedVec(bVecStorage, maxLen) {
|
|
62
|
+
if (bVecStorage.length > maxLen) {
|
|
63
|
+
throw new Error(`Array of length ${bVecStorage.length} larger than maxLen ${maxLen}`);
|
|
64
|
+
}
|
|
65
|
+
const lengthDiff = maxLen - bVecStorage.length;
|
|
66
|
+
const zeroPaddingArray = Array(lengthDiff).fill(toACVMField(BigInt(0)));
|
|
67
|
+
const storage = bVecStorage.concat(zeroPaddingArray);
|
|
68
|
+
const len = toACVMField(BigInt(bVecStorage.length));
|
|
69
|
+
return [
|
|
70
|
+
storage,
|
|
71
|
+
len
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Converts an array of arrays representing Noir BoundedVec of nested arrays into its Noir serialized form.
|
|
76
|
+
* @param bVecStorage - The array underlying the BoundedVec.
|
|
77
|
+
* @param maxLen - The max length of the BoundedVec (max num of the nested arrays in the BoundedVec).
|
|
78
|
+
* @param nestedArrayLength - The length of the nested arrays (each nested array has to have the same length).
|
|
79
|
+
* @returns Serialized BoundedVec following Noir intrinsic serialization.
|
|
80
|
+
*/ export function arrayOfArraysToBoundedVecOfArrays(bVecStorage, maxLen, nestedArrayLength) {
|
|
81
|
+
if (bVecStorage.length > maxLen) {
|
|
82
|
+
throw new Error(`Array of length ${bVecStorage.length} larger than maxLen ${maxLen}`);
|
|
83
|
+
}
|
|
84
|
+
// Check that all nested arrays have length nestedArrayLength
|
|
85
|
+
if (!bVecStorage.every((nestedArray)=>nestedArray.length === nestedArrayLength)) {
|
|
86
|
+
throw new Error(`Nested array length passed in from Noir does not correspond to the length obtained in TS: ${nestedArrayLength} !== ${bVecStorage[0].length}`);
|
|
87
|
+
}
|
|
88
|
+
// Flatten the array of arrays
|
|
89
|
+
const flattenedStorage = bVecStorage.flat();
|
|
90
|
+
// Calculate and add padding
|
|
91
|
+
const numFieldsToPad = maxLen * nestedArrayLength - flattenedStorage.length;
|
|
92
|
+
const flattenedStorageWithPadding = flattenedStorage.concat(Array(numFieldsToPad).fill(toACVMField(BigInt(0))));
|
|
93
|
+
// Return flattened array with padding and length
|
|
94
|
+
const len = toACVMField(BigInt(bVecStorage.length));
|
|
95
|
+
return [
|
|
96
|
+
flattenedStorageWithPadding,
|
|
97
|
+
len
|
|
98
|
+
];
|
|
99
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ForeignCallHandler, WitnessMap } from '@aztec/noir-acvm_js';
|
|
2
|
+
import { type Logger, type LoggerBindings } from '@aztec-labs/foundation/log';
|
|
3
|
+
import type { FunctionArtifactWithContractName } from '@aztec-labs/stdlib/abi';
|
|
4
|
+
import type { NoirCompiledCircuitWithName } from '@aztec-labs/stdlib/noir';
|
|
5
|
+
import type { ACIRCallback, ACIRExecutionResult } from './acvm/acvm.js';
|
|
6
|
+
import type { ACVMWitness } from './acvm/acvm_types.js';
|
|
7
|
+
import type { CircuitSimulator } from './circuit_simulator.js';
|
|
8
|
+
export declare enum ACVM_RESULT {
|
|
9
|
+
SUCCESS = 0,
|
|
10
|
+
FAILURE = 1
|
|
11
|
+
}
|
|
12
|
+
export type ACVMSuccess = {
|
|
13
|
+
status: ACVM_RESULT.SUCCESS;
|
|
14
|
+
duration: number;
|
|
15
|
+
witness: Map<number, string>;
|
|
16
|
+
};
|
|
17
|
+
export type ACVMFailure = {
|
|
18
|
+
status: ACVM_RESULT.FAILURE;
|
|
19
|
+
reason: string;
|
|
20
|
+
};
|
|
21
|
+
export type ACVMResult = ACVMSuccess | ACVMFailure;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param inputWitness - The circuit's input witness
|
|
25
|
+
* @param bytecode - The circuit bytecode
|
|
26
|
+
* @param workingDirectory - A directory to use for temporary files by the ACVM
|
|
27
|
+
* @param pathToAcvm - The path to the ACVM binary
|
|
28
|
+
* @param outputFilename - If specified, the output will be stored as a file, encoded using Bincode
|
|
29
|
+
* @returns The completed partial witness outputted from the circuit
|
|
30
|
+
*/
|
|
31
|
+
export declare function executeNativeCircuit(inputWitness: WitnessMap, bytecode: Buffer, workingDirectory: string, pathToAcvm: string, outputFilename?: string, loggerOrBindings?: Logger | LoggerBindings): Promise<ACVMResult>;
|
|
32
|
+
export declare class NativeACVMSimulator implements CircuitSimulator {
|
|
33
|
+
private workingDirectory;
|
|
34
|
+
private pathToAcvm;
|
|
35
|
+
private witnessFilename?;
|
|
36
|
+
private logger;
|
|
37
|
+
constructor(workingDirectory: string, pathToAcvm: string, witnessFilename?: string | undefined, loggerOrBindings?: Logger | LoggerBindings);
|
|
38
|
+
executeProtocolCircuit(input: ACVMWitness, artifact: NoirCompiledCircuitWithName, callback: ForeignCallHandler | undefined): Promise<ACVMSuccess>;
|
|
39
|
+
executeUserCircuit(_input: ACVMWitness, _artifact: FunctionArtifactWithContractName, _callback: ACIRCallback): Promise<ACIRExecutionResult>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWN2bV9uYXRpdmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wcml2YXRlL2Fjdm1fbmF0aXZlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLFVBQVUsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRzFFLE9BQU8sRUFB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CAC1B,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,2BAA2B,EACrC,QAAQ,EAAE,kBAAkB,GAAG,SAAS,GACvC,OAAO,CAAC,WAAW,CAAC,CA4BtB;IAED,kBAAkB,CAChB,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,gCAAgC,EAC3C,SAAS,EAAE,YAAY,GACtB,OAAO,CAAC,mBAAmB,CAAC,CAE9B;CACF"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { runInDirectory } from '@aztec-labs/foundation/fs';
|
|
2
|
+
import { resolveLogger } from '@aztec-labs/foundation/log';
|
|
3
|
+
import { Timer } from '@aztec-labs/foundation/timer';
|
|
4
|
+
import * as proc from 'child_process';
|
|
5
|
+
import { promises as fs } from 'fs';
|
|
6
|
+
export var ACVM_RESULT = /*#__PURE__*/ function(ACVM_RESULT) {
|
|
7
|
+
ACVM_RESULT[ACVM_RESULT["SUCCESS"] = 0] = "SUCCESS";
|
|
8
|
+
ACVM_RESULT[ACVM_RESULT["FAILURE"] = 1] = "FAILURE";
|
|
9
|
+
return ACVM_RESULT;
|
|
10
|
+
}({});
|
|
11
|
+
/**
|
|
12
|
+
* Parses a TOML format witness map string into a Map structure
|
|
13
|
+
* @param outputString - The witness map in TOML format
|
|
14
|
+
* @returns The parsed witness map
|
|
15
|
+
*/ function parseIntoWitnessMap(outputString) {
|
|
16
|
+
const lines = outputString.split('\n');
|
|
17
|
+
return new Map(lines.filter((line)=>line.length).map((line)=>{
|
|
18
|
+
const pair = line.replaceAll(' ', '').split('=');
|
|
19
|
+
return [
|
|
20
|
+
Number(pair[0]),
|
|
21
|
+
pair[1].replaceAll('"', '')
|
|
22
|
+
];
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param inputWitness - The circuit's input witness
|
|
28
|
+
* @param bytecode - The circuit bytecode
|
|
29
|
+
* @param workingDirectory - A directory to use for temporary files by the ACVM
|
|
30
|
+
* @param pathToAcvm - The path to the ACVM binary
|
|
31
|
+
* @param outputFilename - If specified, the output will be stored as a file, encoded using Bincode
|
|
32
|
+
* @returns The completed partial witness outputted from the circuit
|
|
33
|
+
*/ export async function executeNativeCircuit(inputWitness, bytecode, workingDirectory, pathToAcvm, outputFilename, loggerOrBindings) {
|
|
34
|
+
const logger = resolveLogger('simulator:acvm-native', loggerOrBindings);
|
|
35
|
+
const bytecodeFilename = 'bytecode';
|
|
36
|
+
const witnessFilename = 'input_witness.toml';
|
|
37
|
+
// convert the witness map to TOML format
|
|
38
|
+
let witnessMap = '';
|
|
39
|
+
inputWitness.forEach((value, key)=>{
|
|
40
|
+
witnessMap = witnessMap.concat(`${key} = '${value}'\n`);
|
|
41
|
+
});
|
|
42
|
+
try {
|
|
43
|
+
// Check that the directory exists
|
|
44
|
+
await fs.access(workingDirectory);
|
|
45
|
+
} catch {
|
|
46
|
+
return {
|
|
47
|
+
status: 1,
|
|
48
|
+
reason: `Working directory ${workingDirectory} does not exist`
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
// Write the bytecode and input witness to the working directory
|
|
53
|
+
await fs.writeFile(`${workingDirectory}/${bytecodeFilename}`, bytecode);
|
|
54
|
+
await fs.writeFile(`${workingDirectory}/${witnessFilename}`, witnessMap);
|
|
55
|
+
// Execute the ACVM using the given args
|
|
56
|
+
const args = [
|
|
57
|
+
`execute`,
|
|
58
|
+
`--working-directory`,
|
|
59
|
+
`${workingDirectory}`,
|
|
60
|
+
`--bytecode`,
|
|
61
|
+
`${bytecodeFilename}`,
|
|
62
|
+
`--input-witness`,
|
|
63
|
+
`${witnessFilename}`,
|
|
64
|
+
'--print',
|
|
65
|
+
'--output-witness',
|
|
66
|
+
'output-witness'
|
|
67
|
+
];
|
|
68
|
+
logger.debug(`Calling ACVM with ${args.join(' ')}`);
|
|
69
|
+
const processPromise = new Promise((resolve, reject)=>{
|
|
70
|
+
const outChunks = [];
|
|
71
|
+
const errChunks = [];
|
|
72
|
+
let outLen = 0;
|
|
73
|
+
let errLen = 0;
|
|
74
|
+
const acvm = proc.spawn(pathToAcvm, args);
|
|
75
|
+
acvm.stdout.on('data', (data)=>{
|
|
76
|
+
outChunks.push(data);
|
|
77
|
+
outLen += data.length;
|
|
78
|
+
});
|
|
79
|
+
acvm.stderr.on('data', (data)=>{
|
|
80
|
+
errChunks.push(data);
|
|
81
|
+
errLen += data.length;
|
|
82
|
+
});
|
|
83
|
+
acvm.on('close', (code)=>{
|
|
84
|
+
if (code === 0) {
|
|
85
|
+
resolve(Buffer.concat(outChunks, outLen).toString('utf-8'));
|
|
86
|
+
} else {
|
|
87
|
+
const stderr = Buffer.concat(errChunks, errLen);
|
|
88
|
+
logger.error(`From ACVM: ${stderr.toString('utf-8')}`);
|
|
89
|
+
reject(stderr.toString('utf-8'));
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
const timer = new Timer();
|
|
94
|
+
const output = await processPromise;
|
|
95
|
+
const duration = timer.ms();
|
|
96
|
+
if (outputFilename) {
|
|
97
|
+
const outputWitnessFileName = `${workingDirectory}/output-witness.gz`;
|
|
98
|
+
await fs.copyFile(outputWitnessFileName, outputFilename);
|
|
99
|
+
}
|
|
100
|
+
// TODO: We shouldn't be parsing the witness from stdout, it's not very performant, and we end up with two ways of fetching the witness.
|
|
101
|
+
// We probably should implement the WitnessStack type, run the ACVM with msgpack serialization mode (env variable), and ungzip and parse the witness from
|
|
102
|
+
// the outputted gz witness file.
|
|
103
|
+
const witness = parseIntoWitnessMap(output);
|
|
104
|
+
return {
|
|
105
|
+
status: 0,
|
|
106
|
+
witness,
|
|
107
|
+
duration
|
|
108
|
+
};
|
|
109
|
+
} catch (error) {
|
|
110
|
+
return {
|
|
111
|
+
status: 1,
|
|
112
|
+
reason: `${error}`
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export class NativeACVMSimulator {
|
|
117
|
+
workingDirectory;
|
|
118
|
+
pathToAcvm;
|
|
119
|
+
witnessFilename;
|
|
120
|
+
logger;
|
|
121
|
+
constructor(workingDirectory, pathToAcvm, witnessFilename, loggerOrBindings){
|
|
122
|
+
this.workingDirectory = workingDirectory;
|
|
123
|
+
this.pathToAcvm = pathToAcvm;
|
|
124
|
+
this.witnessFilename = witnessFilename;
|
|
125
|
+
this.logger = resolveLogger('simulator:acvm-native', loggerOrBindings);
|
|
126
|
+
}
|
|
127
|
+
async executeProtocolCircuit(input, artifact, callback) {
|
|
128
|
+
// Execute the circuit on those initial witness values
|
|
129
|
+
if (callback) {
|
|
130
|
+
throw new Error('Native ACVM simulator does not support foreign calls. Ignoring callback.');
|
|
131
|
+
}
|
|
132
|
+
const operation = async (directory)=>{
|
|
133
|
+
// Decode the bytecode from base64 since the acvm does not know about base64 encoding
|
|
134
|
+
const decodedBytecode = Buffer.from(artifact.bytecode, 'base64');
|
|
135
|
+
// Execute the circuit
|
|
136
|
+
const result = await executeNativeCircuit(input, decodedBytecode, directory, this.pathToAcvm, this.witnessFilename, this.logger);
|
|
137
|
+
if (result.status == 1) {
|
|
138
|
+
throw new Error(`Failed to generate witness: ${result.reason}`);
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
};
|
|
142
|
+
return await runInDirectory(this.workingDirectory, operation, false, this.logger);
|
|
143
|
+
}
|
|
144
|
+
executeUserCircuit(_input, _artifact, _callback) {
|
|
145
|
+
throw new Error('Not implemented');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ForeignCallHandler } from '@aztec/noir-acvm_js';
|
|
2
|
+
import { type Logger, type LoggerBindings } from '@aztec-labs/foundation/log';
|
|
3
|
+
import type { FunctionArtifactWithContractName } from '@aztec-labs/stdlib/abi';
|
|
4
|
+
import type { NoirCompiledCircuitWithName } from '@aztec-labs/stdlib/noir';
|
|
5
|
+
import { type ACIRCallback, type ACIRExecutionResult } from './acvm/acvm.js';
|
|
6
|
+
import type { ACVMWitness } from './acvm/acvm_types.js';
|
|
7
|
+
import type { ACVMSuccess } from './acvm_native.js';
|
|
8
|
+
import { type CircuitSimulator } from './circuit_simulator.js';
|
|
9
|
+
export declare class WASMSimulator implements CircuitSimulator {
|
|
10
|
+
protected log: Logger;
|
|
11
|
+
constructor(loggerOrBindings?: Logger | LoggerBindings);
|
|
12
|
+
init(): Promise<void>;
|
|
13
|
+
executeProtocolCircuit(input: ACVMWitness, artifact: NoirCompiledCircuitWithName, callback: ForeignCallHandler): Promise<ACVMSuccess>;
|
|
14
|
+
executeUserCircuit(input: ACVMWitness, artifact: FunctionArtifactWithContractName, callback: ACIRCallback): Promise<ACIRExecutionResult>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWN2bV93YXNtLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHJpdmF0ZS9hY3ZtX3dhc20udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBaUIsRUFBdUIsS0FBSyxrQkFBa0IsRUFBa0IsTUFBTSxxQkFBcUIsQ0FBQztBQUc3RyxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQUUsS0FBSyxjQUFjLEVBQWlCLE1BQU0sNEJBQTRCLENBQUM7QUFFN0YsT0FBTyxLQUFLLEVBQUUsZ0NBQWdDLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUMvRSxPQUFPLEtBQUssRUFBRSwyQkFBMkIsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBRTNFLE9BQU8sRUFBRSxLQUFLLFlBQVksRUFBRSxLQUFLLG1CQUFtQixFQUFRLE1BQU0sZ0JBQWdCLENBQUM7QUFDbkYsT0FBTyxLQUFLLEVBQUUsV0FBVyxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFDeEQsT0FBTyxLQUFLLEVBQUUsV0FBVyxFQU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xD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,KAAK,gBAAgB,EAAmB,MAAM,wBAAwB,CAAC;AAIhF,qBAAa,aAAc,YAAW,gBAAgB;IACpD,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC;IAEtB,YAAY,gBAAgB,CAAC,EAAE,MAAM,GAAG,cAAc,EAErD;IAEK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAS1B;IAEK,sBAAsB,CAC1B,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,2BAA2B,EACrC,QAAQ,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,CAAC,CAgCtB;IAEK,kBAAkB,CACtB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,gCAAgC,EAC1C,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,mBAAmB,CAAC,CAG9B;CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import initACVM, { executeCircuit } from '@aztec/noir-acvm_js';
|
|
2
|
+
import initAbi from '@aztec/noir-noirc_abi';
|
|
3
|
+
import { resolveLogger } from '@aztec-labs/foundation/log';
|
|
4
|
+
import { Timer } from '@aztec-labs/foundation/timer';
|
|
5
|
+
import { acvm } from './acvm/acvm.js';
|
|
6
|
+
import { enrichNoirError } from './circuit_simulator.js';
|
|
7
|
+
let wasmInitPromise;
|
|
8
|
+
export class WASMSimulator {
|
|
9
|
+
log;
|
|
10
|
+
constructor(loggerOrBindings){
|
|
11
|
+
this.log = resolveLogger('wasm-simulator', loggerOrBindings);
|
|
12
|
+
}
|
|
13
|
+
async init() {
|
|
14
|
+
// If these are available, then we are in the
|
|
15
|
+
// web environment. For the node environment, this
|
|
16
|
+
// is a no-op.
|
|
17
|
+
if (typeof initAbi === 'function') {
|
|
18
|
+
/** @ts-expect-error The node bundle doesn't include these default imports, so TS complains */ wasmInitPromise ??= Promise.all([
|
|
19
|
+
initAbi(),
|
|
20
|
+
initACVM()
|
|
21
|
+
]);
|
|
22
|
+
await wasmInitPromise;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async executeProtocolCircuit(input, artifact, callback) {
|
|
26
|
+
this.log.debug('init', {
|
|
27
|
+
hash: artifact.hash
|
|
28
|
+
});
|
|
29
|
+
await this.init();
|
|
30
|
+
// Decode the bytecode from base64 since the acvm does not know about base64 encoding
|
|
31
|
+
const decodedBytecode = Buffer.from(artifact.bytecode, 'base64');
|
|
32
|
+
//
|
|
33
|
+
// Execute the circuit
|
|
34
|
+
try {
|
|
35
|
+
const timer = new Timer();
|
|
36
|
+
const result = await executeCircuit(decodedBytecode, input, callback);
|
|
37
|
+
this.log.debug('execution successful', {
|
|
38
|
+
hash: artifact.hash
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
witness: result,
|
|
42
|
+
duration: timer.ms()
|
|
43
|
+
};
|
|
44
|
+
} catch (err) {
|
|
45
|
+
// Typescript types caught errors as unknown or any, so we need to narrow its type to check if it has raw
|
|
46
|
+
// assertion payload.
|
|
47
|
+
if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {
|
|
48
|
+
const parsed = enrichNoirError(artifact, err);
|
|
49
|
+
this.log.debug('execution failed', {
|
|
50
|
+
hash: artifact.hash,
|
|
51
|
+
error: parsed,
|
|
52
|
+
message: parsed.message
|
|
53
|
+
});
|
|
54
|
+
throw parsed;
|
|
55
|
+
}
|
|
56
|
+
this.log.debug('execution failed', {
|
|
57
|
+
hash: artifact.hash,
|
|
58
|
+
error: err
|
|
59
|
+
});
|
|
60
|
+
throw new Error(`Circuit execution failed: ${err}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async executeUserCircuit(input, artifact, callback) {
|
|
64
|
+
await this.init();
|
|
65
|
+
return acvm(artifact.bytecode, input, callback, this.log.createChild('acvm'));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ForeignCallHandler } from '@aztec/noir-acvm_js';
|
|
2
|
+
import type { WitnessMap } from '@aztec/noir-types';
|
|
3
|
+
import type { FunctionArtifactWithContractName } from '@aztec-labs/stdlib/abi';
|
|
4
|
+
import type { NoirCompiledCircuitWithName } from '@aztec-labs/stdlib/noir';
|
|
5
|
+
import type { ACIRCallback, ACIRExecutionResult } from './acvm/acvm.js';
|
|
6
|
+
import type { ACVMWitness } from './acvm/acvm_types.js';
|
|
7
|
+
import type { ACVMSuccess } from './acvm_native.js';
|
|
8
|
+
import { type CircuitSimulator } from './circuit_simulator.js';
|
|
9
|
+
/**
|
|
10
|
+
* A circuit simulator that uses the WASM simulator with the ability to handle blobs via the foreign call handler.
|
|
11
|
+
* This class is temporary while brillig cannot handle the blob math, and it is kept separate
|
|
12
|
+
* because the zkg commitment library used in the blob code is not browser compatible.
|
|
13
|
+
*
|
|
14
|
+
* It is only used in the context of server-side code executing simulated protocol circuits.
|
|
15
|
+
*/
|
|
16
|
+
export declare class WASMSimulatorWithBlobs implements CircuitSimulator {
|
|
17
|
+
executeProtocolCircuit(input: WitnessMap, artifact: NoirCompiledCircuitWithName, callback: ForeignCallHandler): Promise<ACVMSuccess>;
|
|
18
|
+
executeUserCircuit(_input: ACVMWitness, _artifact: FunctionArtifactWithContractName, _callback: ACIRCallback): Promise<ACIRExecutionResult>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWN2bV93YXNtX3dpdGhfYmxvYnMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wcml2YXRlL2Fjdm1fd2FzbV93aXRoX2Jsb2JzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBdUIsS0FBSyxrQkFBa0IsRUFBa0IsTUFBTSxxQkFBcUIsQ0FBQztBQUNuRyxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTU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gC,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,KAAK,gBAAgB,EAAmB,MAAM,wBAAwB,CAAC;AAEhF;;;;;;GAMG;AACH,qBAAa,sBAAuB,YAAW,gBAAgB;IACvD,sBAAsB,CAC1B,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,2BAA2B,EACrC,QAAQ,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,CAAC,CAqBtB;IAED,kBAAkB,CAChB,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,gCAAgC,EAC3C,SAAS,EAAE,YAAY,GACtB,OAAO,CAAC,mBAAmB,CAAC,CAE9B;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { executeCircuit } from '@aztec/noir-acvm_js';
|
|
2
|
+
import { Timer } from '@aztec-labs/foundation/timer';
|
|
3
|
+
import { enrichNoirError } from './circuit_simulator.js';
|
|
4
|
+
/**
|
|
5
|
+
* A circuit simulator that uses the WASM simulator with the ability to handle blobs via the foreign call handler.
|
|
6
|
+
* This class is temporary while brillig cannot handle the blob math, and it is kept separate
|
|
7
|
+
* because the zkg commitment library used in the blob code is not browser compatible.
|
|
8
|
+
*
|
|
9
|
+
* It is only used in the context of server-side code executing simulated protocol circuits.
|
|
10
|
+
*/ export class WASMSimulatorWithBlobs {
|
|
11
|
+
async executeProtocolCircuit(input, artifact, callback) {
|
|
12
|
+
// Decode the bytecode from base64 since the acvm does not know about base64 encoding
|
|
13
|
+
const decodedBytecode = Buffer.from(artifact.bytecode, 'base64');
|
|
14
|
+
//
|
|
15
|
+
// Execute the circuit
|
|
16
|
+
try {
|
|
17
|
+
const timer = new Timer();
|
|
18
|
+
const _witnessMap = await executeCircuit(decodedBytecode, input, callback);
|
|
19
|
+
return {
|
|
20
|
+
witness: _witnessMap,
|
|
21
|
+
duration: timer.ms()
|
|
22
|
+
};
|
|
23
|
+
} catch (err) {
|
|
24
|
+
// Typescript types caught errors as unknown or any, so we need to narrow its type to check if it has raw
|
|
25
|
+
// assertion payload.
|
|
26
|
+
if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {
|
|
27
|
+
throw enrichNoirError(artifact, err);
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`Circuit execution failed: ${err}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
executeUserCircuit(_input, _artifact, _callback) {
|
|
33
|
+
throw new Error('Not implemented');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ExecutionError, ForeignCallHandler } from '@aztec/noir-acvm_js';
|
|
2
|
+
import type { FunctionArtifactWithContractName } from '@aztec-labs/stdlib/abi';
|
|
3
|
+
import type { NoirCompiledCircuit, NoirCompiledCircuitWithName } from '@aztec-labs/stdlib/noir';
|
|
4
|
+
import { type ACIRCallback, type ACIRExecutionResult } from './acvm/acvm.js';
|
|
5
|
+
import type { ACVMWitness } from './acvm/acvm_types.js';
|
|
6
|
+
import type { ACVMSuccess } from './acvm_native.js';
|
|
7
|
+
/**
|
|
8
|
+
* Low level simulation interface
|
|
9
|
+
*/
|
|
10
|
+
export interface CircuitSimulator {
|
|
11
|
+
/**
|
|
12
|
+
* Execute a protocol circuit/generate a witness
|
|
13
|
+
* @param input - The initial witness map defining all of the inputs to `circuit`.
|
|
14
|
+
* @param artifact - ACIR circuit bytecode and its metadata.
|
|
15
|
+
* @param callback - A callback to process any foreign calls from the circuit. Can be undefined as for native
|
|
16
|
+
* ACVM simulator we don't process foreign calls.
|
|
17
|
+
* @returns The solved witness calculated by executing the circuit on the provided inputs.
|
|
18
|
+
*/
|
|
19
|
+
executeProtocolCircuit(input: ACVMWitness, artifact: NoirCompiledCircuitWithName, callback: ForeignCallHandler | undefined): Promise<ACVMSuccess>;
|
|
20
|
+
/**
|
|
21
|
+
* Execute a user circuit (smart contract function)/generate a witness
|
|
22
|
+
* @param input - The initial witness map defining all of the inputs to `circuit`.
|
|
23
|
+
* @param artifact - Contract function ACIR circuit bytecode and its metadata.
|
|
24
|
+
* @param callback - A callback to process any foreign calls from the circuit.
|
|
25
|
+
* @returns The solved witness calculated by executing the circuit on the provided inputs, as well as the return
|
|
26
|
+
* witness indices as specified by the circuit.
|
|
27
|
+
*/
|
|
28
|
+
executeUserCircuit(input: ACVMWitness, artifact: FunctionArtifactWithContractName, callback: ACIRCallback): Promise<ACIRExecutionResult>;
|
|
29
|
+
}
|
|
30
|
+
export type DecodedError = ExecutionError & {
|
|
31
|
+
decodedAssertionPayload?: any;
|
|
32
|
+
noirCallStack?: string[];
|
|
33
|
+
};
|
|
34
|
+
export declare function enrichNoirError(artifact: NoirCompiledCircuit, originalError: ExecutionError): DecodedError;
|
|
35
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2lyY3VpdF9zaW11bGF0b3IuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wcml2YXRlL2NpcmN1aXRfc2ltdWxhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBSTlFLE9BQU8sS0FBSyxFQUFFLGdDQUFnQyxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFDL0UsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsMkJBQTJCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUVoRyxPQUFPLEVBQUUsS0F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gC,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAEhG,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAoB,MAAM,gBAAgB,CAAC;AAC/F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;OAOG;IACH,sBAAsB,CACpB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,2BAA2B,EACrC,QAAQ,EAAE,kBAAkB,GAAG,SAAS,GACvC,OAAO,CAAC,WAAW,CAAC,CAAC;IAExB;;;;;;;OAOG;IACH,kBAAkB,CAChB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,gCAAgC,EAC1C,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACjC;AAED,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG;IAAE,uBAAuB,CAAC,EAAE,GAAG,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAIxG,wBAAgB,eAAe,CAAC,QAAQ,EAAE,mBAAmB,EAAE,aAAa,EAAE,cAAc,GAAG,YAAY,CA0C1G"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { abiDecodeError } from '@aztec/noir-noirc_abi';
|
|
2
|
+
import { parseDebugSymbols } from '@aztec-labs/stdlib/abi';
|
|
3
|
+
import { extractCallStack } from './acvm/acvm.js';
|
|
4
|
+
// Payload parsing taken from noir/noir-repo/tooling/noir_js/src/witness_generation.ts.
|
|
5
|
+
// TODO: import this in isolation without having to import noir_js in its entirety.
|
|
6
|
+
export function enrichNoirError(artifact, originalError) {
|
|
7
|
+
const enrichedError = originalError;
|
|
8
|
+
if (originalError.rawAssertionPayload) {
|
|
9
|
+
try {
|
|
10
|
+
// Decode the payload
|
|
11
|
+
const decodedPayload = abiDecodeError(artifact.abi, originalError.rawAssertionPayload);
|
|
12
|
+
if (typeof decodedPayload === 'string') {
|
|
13
|
+
// If it's a string, just add it to the error message
|
|
14
|
+
enrichedError.message = `Circuit execution failed: ${decodedPayload}`;
|
|
15
|
+
} else {
|
|
16
|
+
// If not, attach the payload to the original error
|
|
17
|
+
enrichedError.decodedAssertionPayload = decodedPayload;
|
|
18
|
+
}
|
|
19
|
+
} catch {
|
|
20
|
+
// Ignore errors decoding the payload
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
// Decode the callstack
|
|
25
|
+
const callStack = extractCallStack(originalError, {
|
|
26
|
+
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/5813)
|
|
27
|
+
// We only support handling debug info for the circuit entry point.
|
|
28
|
+
// So for now we simply index into the first debug info.
|
|
29
|
+
debugSymbols: parseDebugSymbols(artifact.debug_symbols)[0],
|
|
30
|
+
files: artifact.file_map
|
|
31
|
+
});
|
|
32
|
+
enrichedError.noirCallStack = callStack?.map((errorLocation)=>{
|
|
33
|
+
if (typeof errorLocation === 'string') {
|
|
34
|
+
return `at opcode ${errorLocation}`;
|
|
35
|
+
} else {
|
|
36
|
+
return `at ${errorLocation.locationText} (${errorLocation.filePath}:${errorLocation.line}:${errorLocation.column})`;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
} catch {
|
|
40
|
+
// Ignore errors resolving the callstack
|
|
41
|
+
}
|
|
42
|
+
return enrichedError;
|
|
43
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Logger, type LoggerBindings } from '@aztec-labs/foundation/log';
|
|
2
|
+
import type { CircuitSimulator } from './circuit_simulator.js';
|
|
3
|
+
export type SimulatorConfig = {
|
|
4
|
+
acvmBinaryPath?: string;
|
|
5
|
+
acvmWorkingDirectory?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function getSimulatorConfigFromEnv(): {
|
|
8
|
+
acvmWorkingDirectory: string | undefined;
|
|
9
|
+
acvmBinaryPath: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
export declare function createSimulator(config: SimulatorConfig, loggerOrBindings?: Logger | LoggerBindings): Promise<CircuitSimulator>;
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3ByaXZhdGUvZmFjdG9yeS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQUUsS0FBSyxjQUFjLEVBQWlCLE1BQU0sNEJBQTRCLENBQUM7QUFLN0YsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUUvRCxNQUFNLE1BQU0sZUFBZSxHQUFHO0lBQzVCLGNBQWMsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUN4QixvQkFBb0IsQ0FBQyxFQUFFLE1BQU0sQ0FBQztDQUMvQixDQUFDO0FBRUYsd0JBQWdCLHlCQUF5Qjs7O0VBTXhDO0FBRUQsd0JBQXNCLGVBQWUsQ0FDbkMsTUFBTSxFQUFFLGVBQWUsRUFDdkIsZ0JBQWdCLENBQUMsRUFBRSxNQUFNLEdBQUcsY0FBYyxHQUN6QyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FnQjNCIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/private/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,cAAc,EAAiB,MAAM,4BAA4B,CAAC;AAK7F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,MAAM,MAAM,eAAe,GAAG;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,wBAAgB,yBAAyB;;;EAMxC;AAED,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,gBAAgB,CAAC,EAAE,MAAM,GAAG,cAAc,GACzC,OAAO,CAAC,gBAAgB,CAAC,CAgB3B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { resolveLogger } from '@aztec-labs/foundation/log';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import { NativeACVMSimulator } from './acvm_native.js';
|
|
4
|
+
import { WASMSimulator } from './acvm_wasm.js';
|
|
5
|
+
export function getSimulatorConfigFromEnv() {
|
|
6
|
+
const { ACVM_BINARY_PATH, ACVM_WORKING_DIRECTORY } = process.env;
|
|
7
|
+
return {
|
|
8
|
+
acvmWorkingDirectory: ACVM_WORKING_DIRECTORY ? ACVM_WORKING_DIRECTORY : undefined,
|
|
9
|
+
acvmBinaryPath: ACVM_BINARY_PATH ? ACVM_BINARY_PATH : undefined
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export async function createSimulator(config, loggerOrBindings) {
|
|
13
|
+
const logger = resolveLogger('simulator', loggerOrBindings);
|
|
14
|
+
if (config.acvmBinaryPath && config.acvmWorkingDirectory) {
|
|
15
|
+
try {
|
|
16
|
+
await fs.access(config.acvmBinaryPath, fs.constants.R_OK);
|
|
17
|
+
await fs.mkdir(config.acvmWorkingDirectory, {
|
|
18
|
+
recursive: true
|
|
19
|
+
});
|
|
20
|
+
logger.info(`Using native ACVM at ${config.acvmBinaryPath} and working directory ${config.acvmWorkingDirectory}`);
|
|
21
|
+
const acvmLogger = logger.createChild('acvm-native');
|
|
22
|
+
return new NativeACVMSimulator(config.acvmWorkingDirectory, config.acvmBinaryPath, undefined, acvmLogger);
|
|
23
|
+
} catch {
|
|
24
|
+
logger.warn(`Failed to access ACVM at ${config.acvmBinaryPath}, falling back to WASM`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
logger.info('Using WASM ACVM simulation');
|
|
28
|
+
const wasmLogger = logger.createChild('wasm');
|
|
29
|
+
return new WASMSimulator(wasmLogger);
|
|
30
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjb3VudF9wcm9vZl9mZXRjaGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvcHVibGljL2F2bS90ZXN0aW5nL2FjY291bnRfcHJvb2ZfZmV0Y2hlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account_proof_fetcher.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/testing/account_proof_fetcher.ts"],"names":[],"mappings":""}
|