@aztec/simulator 0.85.0 → 0.86.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/private/providers/acvm_native.d.ts +1 -1
- package/dest/private/providers/acvm_native.d.ts.map +1 -1
- package/dest/private/providers/acvm_native.js +4 -3
- package/dest/private/providers/acvm_wasm.d.ts +2 -1
- package/dest/private/providers/acvm_wasm.d.ts.map +1 -1
- package/dest/private/providers/acvm_wasm.js +6 -1
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts +2 -1
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +1 -1
- package/dest/private/providers/acvm_wasm_with_blobs.js +6 -1
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts +2 -1
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts.map +1 -1
- package/dest/private/providers/simulation_provider.d.ts +2 -1
- package/dest/private/providers/simulation_provider.d.ts.map +1 -1
- package/dest/public/avm/avm_context.d.ts +2 -2
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.d.ts +2 -1
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +2 -1
- package/dest/public/avm/avm_simulator_interface.d.ts +11 -0
- package/dest/public/avm/avm_simulator_interface.d.ts.map +1 -0
- package/dest/public/avm/avm_simulator_interface.js +3 -0
- package/dest/public/avm/errors.d.ts +1 -16
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/errors.js +0 -37
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/index.d.ts +2 -85
- package/dest/public/avm/fixtures/index.d.ts.map +1 -1
- package/dest/public/avm/fixtures/index.js +2 -174
- package/dest/public/avm/fixtures/initializers.d.ts +42 -0
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -0
- package/dest/public/avm/fixtures/initializers.js +42 -0
- package/dest/public/avm/fixtures/utils.d.ts +46 -0
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -0
- package/dest/public/avm/fixtures/utils.js +136 -0
- package/dest/public/avm/index.d.ts +0 -1
- package/dest/public/avm/index.d.ts.map +1 -1
- package/dest/public/avm/index.js +0 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts +3 -2
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +14 -9
- package/dest/public/avm/opcodes/instruction.d.ts +5 -5
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction.js +6 -6
- package/dest/public/avm/revert_reason.d.ts +18 -0
- package/dest/public/avm/revert_reason.d.ts.map +1 -0
- package/dest/public/avm/revert_reason.js +38 -0
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +2 -4
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.js +70 -69
- package/dest/{common → public}/debug_fn_name.d.ts +1 -1
- package/dest/{common → public}/debug_fn_name.d.ts.map +1 -1
- package/dest/public/fixtures/index.d.ts +1 -0
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +1 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +3 -4
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -0
- package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.js +1 -1
- package/dest/public/hinting_db_sources.d.ts +15 -5
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +65 -27
- package/dest/public/index.d.ts +2 -6
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +2 -6
- package/dest/public/public_db_sources.d.ts +19 -52
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +96 -107
- package/dest/public/public_processor/public_processor.d.ts +6 -6
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +24 -26
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +3 -2
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +2 -2
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +3 -4
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +11 -21
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +5 -4
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +21 -10
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +3 -2
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +2 -2
- package/dest/public/side_effect_trace.d.ts +1 -3
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +3 -2
- package/dest/public/state_manager/state_manager.d.ts +6 -4
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +20 -41
- package/package.json +14 -16
- package/src/private/providers/acvm_native.ts +5 -4
- package/src/private/providers/acvm_wasm.ts +5 -2
- package/src/private/providers/acvm_wasm_with_blobs.ts +5 -3
- package/src/private/providers/circuit_recording/simulation_provider_recorder_wrapper.ts +3 -2
- package/src/private/providers/simulation_provider.ts +2 -1
- package/src/public/avm/avm_context.ts +2 -2
- package/src/public/avm/avm_simulator.ts +4 -8
- package/src/public/avm/avm_simulator_interface.ts +8 -0
- package/src/public/avm/errors.ts +1 -53
- package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/index.ts +2 -308
- package/src/public/avm/fixtures/initializers.ts +101 -0
- package/src/public/avm/fixtures/utils.ts +213 -0
- package/src/public/avm/index.ts +0 -1
- package/src/public/avm/opcodes/accrued_substate.ts +1 -5
- package/src/public/avm/opcodes/external_calls.ts +17 -11
- package/src/public/avm/opcodes/instruction.ts +9 -8
- package/src/public/avm/revert_reason.ts +55 -0
- package/src/public/avm/serialization/bytecode_serialization.ts +72 -74
- package/src/{common → public}/debug_fn_name.ts +1 -1
- package/src/public/fixtures/index.ts +1 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +3 -5
- package/src/public/{avm/fixtures → fixtures}/simple_contract_data_source.ts +1 -1
- package/src/public/hinting_db_sources.ts +104 -39
- package/src/public/index.ts +2 -6
- package/src/public/public_db_sources.ts +111 -164
- package/src/public/public_processor/public_processor.ts +27 -29
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +4 -3
- package/src/public/public_tx_simulator/public_tx_context.ts +10 -47
- package/src/public/public_tx_simulator/public_tx_simulator.ts +25 -10
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +4 -3
- package/src/public/side_effect_trace.ts +2 -4
- package/src/public/state_manager/state_manager.ts +24 -50
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +0 -1
- /package/dest/{common → public}/debug_fn_name.js +0 -0
- /package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/simulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.86.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": "./dest/server.js",
|
|
@@ -19,8 +19,6 @@
|
|
|
19
19
|
"build": "yarn clean && tsc -b",
|
|
20
20
|
"build:dev": "tsc -b --watch",
|
|
21
21
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
22
|
-
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
|
|
23
|
-
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
|
|
24
22
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
25
23
|
},
|
|
26
24
|
"inherits": [
|
|
@@ -60,24 +58,24 @@
|
|
|
60
58
|
]
|
|
61
59
|
},
|
|
62
60
|
"dependencies": {
|
|
63
|
-
"@aztec/constants": "0.
|
|
64
|
-
"@aztec/foundation": "0.
|
|
65
|
-
"@aztec/noir-acvm_js": "0.
|
|
66
|
-
"@aztec/noir-noirc_abi": "0.
|
|
67
|
-
"@aztec/noir-protocol-circuits-types": "0.
|
|
68
|
-
"@aztec/noir-types": "0.
|
|
69
|
-
"@aztec/protocol-contracts": "0.
|
|
70
|
-
"@aztec/stdlib": "0.
|
|
71
|
-
"@aztec/telemetry-client": "0.
|
|
72
|
-
"@aztec/world-state": "0.
|
|
61
|
+
"@aztec/constants": "0.86.0",
|
|
62
|
+
"@aztec/foundation": "0.86.0",
|
|
63
|
+
"@aztec/noir-acvm_js": "0.86.0",
|
|
64
|
+
"@aztec/noir-noirc_abi": "0.86.0",
|
|
65
|
+
"@aztec/noir-protocol-circuits-types": "0.86.0",
|
|
66
|
+
"@aztec/noir-types": "0.86.0",
|
|
67
|
+
"@aztec/protocol-contracts": "0.86.0",
|
|
68
|
+
"@aztec/stdlib": "0.86.0",
|
|
69
|
+
"@aztec/telemetry-client": "0.86.0",
|
|
70
|
+
"@aztec/world-state": "0.86.0",
|
|
73
71
|
"lodash.clonedeep": "^4.5.0",
|
|
74
72
|
"lodash.merge": "^4.6.2",
|
|
75
73
|
"tslib": "^2.4.0"
|
|
76
74
|
},
|
|
77
75
|
"devDependencies": {
|
|
78
|
-
"@aztec/kv-store": "0.
|
|
79
|
-
"@aztec/merkle-tree": "0.
|
|
80
|
-
"@aztec/noir-contracts.js": "0.
|
|
76
|
+
"@aztec/kv-store": "0.86.0",
|
|
77
|
+
"@aztec/merkle-tree": "0.86.0",
|
|
78
|
+
"@aztec/noir-contracts.js": "0.86.0",
|
|
81
79
|
"@jest/globals": "^29.5.0",
|
|
82
80
|
"@types/jest": "^29.5.0",
|
|
83
81
|
"@types/lodash.clonedeep": "^4.5.7",
|
|
@@ -123,14 +123,15 @@ export async function executeNativeCircuit(
|
|
|
123
123
|
});
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
-
const
|
|
126
|
+
const timer = new Timer();
|
|
127
127
|
const output = await processPromise;
|
|
128
|
+
const duration = timer.ms();
|
|
128
129
|
if (outputFilename) {
|
|
129
130
|
const outputWitnessFileName = `${workingDirectory}/output-witness.gz`;
|
|
130
131
|
await fs.copyFile(outputWitnessFileName, outputFilename);
|
|
131
132
|
}
|
|
132
133
|
const witness = parseIntoWitnessMap(output);
|
|
133
|
-
return { status: ACVM_RESULT.SUCCESS, witness, duration
|
|
134
|
+
return { status: ACVM_RESULT.SUCCESS, witness, duration };
|
|
134
135
|
} catch (error) {
|
|
135
136
|
return { status: ACVM_RESULT.FAILURE, reason: `${error}` };
|
|
136
137
|
}
|
|
@@ -143,7 +144,7 @@ export class NativeACVMSimulator implements SimulationProvider {
|
|
|
143
144
|
input: ACVMWitness,
|
|
144
145
|
artifact: NoirCompiledCircuitWithName,
|
|
145
146
|
callback: ForeignCallHandler | undefined,
|
|
146
|
-
): Promise<
|
|
147
|
+
): Promise<ACVMSuccess> {
|
|
147
148
|
// Execute the circuit on those initial witness values
|
|
148
149
|
|
|
149
150
|
if (callback) {
|
|
@@ -166,7 +167,7 @@ export class NativeACVMSimulator implements SimulationProvider {
|
|
|
166
167
|
throw new Error(`Failed to generate witness: ${result.reason}`);
|
|
167
168
|
}
|
|
168
169
|
|
|
169
|
-
return result
|
|
170
|
+
return result;
|
|
170
171
|
};
|
|
171
172
|
|
|
172
173
|
return await runInDirectory(this.workingDirectory, operation, false, logger);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
2
3
|
import initACVM, { type ExecutionError, type ForeignCallHandler, executeCircuit } from '@aztec/noir-acvm_js';
|
|
3
4
|
import initAbi from '@aztec/noir-noirc_abi';
|
|
4
5
|
import type { FunctionArtifactWithContractName } from '@aztec/stdlib/abi';
|
|
@@ -6,6 +7,7 @@ import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
|
|
|
6
7
|
|
|
7
8
|
import { type ACIRCallback, type ACIRExecutionResult, acvm } from '../acvm/acvm.js';
|
|
8
9
|
import type { ACVMWitness } from '../acvm/acvm_types.js';
|
|
10
|
+
import type { ACVMSuccess } from './acvm_native.js';
|
|
9
11
|
import { type SimulationProvider, enrichNoirError } from './simulation_provider.js';
|
|
10
12
|
|
|
11
13
|
export class WASMSimulator implements SimulationProvider {
|
|
@@ -25,7 +27,7 @@ export class WASMSimulator implements SimulationProvider {
|
|
|
25
27
|
input: ACVMWitness,
|
|
26
28
|
artifact: NoirCompiledCircuitWithName,
|
|
27
29
|
callback: ForeignCallHandler,
|
|
28
|
-
): Promise<
|
|
30
|
+
): Promise<ACVMSuccess> {
|
|
29
31
|
this.log.debug('init', { hash: artifact.hash });
|
|
30
32
|
await this.init();
|
|
31
33
|
|
|
@@ -34,13 +36,14 @@ export class WASMSimulator implements SimulationProvider {
|
|
|
34
36
|
//
|
|
35
37
|
// Execute the circuit
|
|
36
38
|
try {
|
|
39
|
+
const timer = new Timer();
|
|
37
40
|
const result = await executeCircuit(
|
|
38
41
|
decodedBytecode,
|
|
39
42
|
input,
|
|
40
43
|
callback, // handle calls to debug_log
|
|
41
44
|
);
|
|
42
45
|
this.log.debug('execution successful', { hash: artifact.hash });
|
|
43
|
-
return result;
|
|
46
|
+
return { witness: result, duration: timer.ms() } as ACVMSuccess;
|
|
44
47
|
} catch (err) {
|
|
45
48
|
// Typescript types caught errors as unknown or any, so we need to narrow its type to check if it has raw
|
|
46
49
|
// assertion payload.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
1
2
|
import { type ExecutionError, type ForeignCallHandler, executeCircuit } from '@aztec/noir-acvm_js';
|
|
2
3
|
import type { WitnessMap } from '@aztec/noir-types';
|
|
3
4
|
import type { FunctionArtifactWithContractName } from '@aztec/stdlib/abi';
|
|
@@ -5,6 +6,7 @@ import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
|
|
|
5
6
|
|
|
6
7
|
import type { ACIRCallback, ACIRExecutionResult } from '../acvm/acvm.js';
|
|
7
8
|
import type { ACVMWitness } from '../acvm/acvm_types.js';
|
|
9
|
+
import type { ACVMSuccess } from './acvm_native.js';
|
|
8
10
|
import { type SimulationProvider, enrichNoirError } from './simulation_provider.js';
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -19,19 +21,19 @@ export class WASMSimulatorWithBlobs implements SimulationProvider {
|
|
|
19
21
|
input: WitnessMap,
|
|
20
22
|
artifact: NoirCompiledCircuitWithName,
|
|
21
23
|
callback: ForeignCallHandler,
|
|
22
|
-
): Promise<
|
|
24
|
+
): Promise<ACVMSuccess> {
|
|
23
25
|
// Decode the bytecode from base64 since the acvm does not know about base64 encoding
|
|
24
26
|
const decodedBytecode = Buffer.from(artifact.bytecode, 'base64');
|
|
25
27
|
//
|
|
26
28
|
// Execute the circuit
|
|
27
29
|
try {
|
|
30
|
+
const timer = new Timer();
|
|
28
31
|
const _witnessMap = await executeCircuit(
|
|
29
32
|
decodedBytecode,
|
|
30
33
|
input,
|
|
31
34
|
callback, // handle calls to debug_log and evaluate_blobs mock
|
|
32
35
|
);
|
|
33
|
-
|
|
34
|
-
return _witnessMap;
|
|
36
|
+
return { witness: _witnessMap, duration: timer.ms() } as ACVMSuccess;
|
|
35
37
|
} catch (err) {
|
|
36
38
|
// Typescript types caught errors as unknown or any, so we need to narrow its type to check if it has raw
|
|
37
39
|
// assertion payload.
|
|
@@ -4,6 +4,7 @@ import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
|
|
|
4
4
|
|
|
5
5
|
import type { ACIRCallback, ACIRExecutionResult } from '../../acvm/acvm.js';
|
|
6
6
|
import type { ACVMWitness } from '../../acvm/acvm_types.js';
|
|
7
|
+
import type { ACVMSuccess } from '../acvm_native.js';
|
|
7
8
|
import type { SimulationProvider } from '../simulation_provider.js';
|
|
8
9
|
import { CircuitRecorder } from './circuit_recorder.js';
|
|
9
10
|
|
|
@@ -18,10 +19,10 @@ export class SimulationProviderRecorderWrapper implements SimulationProvider {
|
|
|
18
19
|
input: ACVMWitness,
|
|
19
20
|
artifact: NoirCompiledCircuitWithName,
|
|
20
21
|
callback: ForeignCallHandler | undefined,
|
|
21
|
-
): Promise<
|
|
22
|
+
): Promise<ACVMSuccess> {
|
|
22
23
|
const bytecode = Buffer.from(artifact.bytecode, 'base64');
|
|
23
24
|
|
|
24
|
-
return this.#simulate<ForeignCallHandler | undefined,
|
|
25
|
+
return this.#simulate<ForeignCallHandler | undefined, ACVMSuccess>(
|
|
25
26
|
wrappedCallback => this.simulator.executeProtocolCircuit(input, artifact, wrappedCallback),
|
|
26
27
|
input,
|
|
27
28
|
bytecode,
|
|
@@ -6,6 +6,7 @@ import type { NoirCompiledCircuit, NoirCompiledCircuitWithName } from '@aztec/st
|
|
|
6
6
|
|
|
7
7
|
import { type ACIRCallback, type ACIRExecutionResult, extractCallStack } from '../acvm/acvm.js';
|
|
8
8
|
import type { ACVMWitness } from '../acvm/acvm_types.js';
|
|
9
|
+
import type { ACVMSuccess } from './acvm_native.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Low level simulation interface
|
|
@@ -23,7 +24,7 @@ export interface SimulationProvider {
|
|
|
23
24
|
input: ACVMWitness,
|
|
24
25
|
artifact: NoirCompiledCircuitWithName,
|
|
25
26
|
callback: ForeignCallHandler | undefined,
|
|
26
|
-
): Promise<
|
|
27
|
+
): Promise<ACVMSuccess>;
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Execute a user circuit (smart contract function)/generate a witness
|
|
@@ -5,7 +5,7 @@ import type { PublicPersistableStateManager } from '../state_manager/state_manag
|
|
|
5
5
|
import type { AvmExecutionEnvironment } from './avm_execution_environment.js';
|
|
6
6
|
import { type Gas, gasToGasLeft } from './avm_gas.js';
|
|
7
7
|
import { AvmMachineState } from './avm_machine_state.js';
|
|
8
|
-
import type {
|
|
8
|
+
import type { AvmSimulatorInterface } from './avm_simulator_interface.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* An execution context includes the information necessary to initiate AVM
|
|
@@ -27,7 +27,7 @@ export class AvmContext {
|
|
|
27
27
|
|
|
28
28
|
// This is needed to break a dependency cycle created by the CALL opcode,
|
|
29
29
|
// which needs to create a new simulator but cannot depend directly on AvmSimulator.
|
|
30
|
-
public provideSimulator?: (
|
|
30
|
+
public provideSimulator?: (context: AvmContext) => Promise<AvmSimulatorInterface>;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Prepare a new AVM context that will be ready for an external/nested call
|
|
@@ -13,14 +13,10 @@ import { AvmContractCallResult } from './avm_contract_call_result.js';
|
|
|
13
13
|
import { AvmExecutionEnvironment } from './avm_execution_environment.js';
|
|
14
14
|
import type { Gas } from './avm_gas.js';
|
|
15
15
|
import { AvmMachineState } from './avm_machine_state.js';
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
AvmRevertReason,
|
|
19
|
-
InvalidProgramCounterError,
|
|
20
|
-
revertReasonFromExceptionalHalt,
|
|
21
|
-
revertReasonFromExplicitRevert,
|
|
22
|
-
} from './errors.js';
|
|
16
|
+
import type { AvmSimulatorInterface } from './avm_simulator_interface.js';
|
|
17
|
+
import { AvmExecutionError, AvmRevertReason, InvalidProgramCounterError } from './errors.js';
|
|
23
18
|
import type { Instruction } from './opcodes/instruction.js';
|
|
19
|
+
import { revertReasonFromExceptionalHalt, revertReasonFromExplicitRevert } from './revert_reason.js';
|
|
24
20
|
import {
|
|
25
21
|
INSTRUCTION_SET,
|
|
26
22
|
type InstructionSet,
|
|
@@ -32,7 +28,7 @@ type OpcodeTally = {
|
|
|
32
28
|
gas: Gas;
|
|
33
29
|
};
|
|
34
30
|
|
|
35
|
-
export class AvmSimulator {
|
|
31
|
+
export class AvmSimulator implements AvmSimulatorInterface {
|
|
36
32
|
private log: Logger;
|
|
37
33
|
private bytecode: Buffer | undefined;
|
|
38
34
|
private opcodeTallies: Map<string, OpcodeTally> = new Map();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for AvmSimulator to break the circular dependency between avm_context.ts and avm_simulator.ts
|
|
3
|
+
*/
|
|
4
|
+
export interface AvmSimulatorInterface {
|
|
5
|
+
execute(): Promise<any>; // Using any here to avoid importing AvmContractCallResult
|
|
6
|
+
executeBytecode(bytecode: Buffer): Promise<any>;
|
|
7
|
+
getBytecode(): Buffer | undefined;
|
|
8
|
+
}
|
package/src/public/avm/errors.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Point } from '@aztec/foundation/fields';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import type { FailingFunction, NoirCallStack } from '@aztec/stdlib/errors';
|
|
4
4
|
|
|
5
5
|
import { ExecutionError } from '../../common/errors.js';
|
|
6
|
-
import type { AvmContext } from './avm_context.js';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Avm-specific errors should derive from this
|
|
@@ -179,54 +178,3 @@ export class AvmRevertReason extends ExecutionError {
|
|
|
179
178
|
super(message, failingFunction, noirCallStack, options);
|
|
180
179
|
}
|
|
181
180
|
}
|
|
182
|
-
|
|
183
|
-
async function createRevertReason(message: string, revertData: Fr[], context: AvmContext): Promise<AvmRevertReason> {
|
|
184
|
-
// We drop the returnPc information.
|
|
185
|
-
const internalCallStack = context.machineState.internalCallStack.map(entry => entry.callPc);
|
|
186
|
-
|
|
187
|
-
// If we are reverting due to the same error that we have been tracking, we use the nested error as the cause.
|
|
188
|
-
let nestedError = undefined;
|
|
189
|
-
const revertDataEquals = (a: Fr[], b: Fr[]) => a.length === b.length && a.every((v, i) => v.equals(b[i]));
|
|
190
|
-
if (
|
|
191
|
-
context.machineState.collectedRevertInfo &&
|
|
192
|
-
revertDataEquals(context.machineState.collectedRevertInfo.revertDataRepresentative, revertData)
|
|
193
|
-
) {
|
|
194
|
-
nestedError = context.machineState.collectedRevertInfo.recursiveRevertReason;
|
|
195
|
-
message = context.machineState.collectedRevertInfo.recursiveRevertReason.message;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const fnName = await context.persistableState.getPublicFunctionDebugName(context.environment);
|
|
199
|
-
|
|
200
|
-
return new AvmRevertReason(
|
|
201
|
-
message,
|
|
202
|
-
/*failingFunction=*/ {
|
|
203
|
-
contractAddress: context.environment.address,
|
|
204
|
-
functionName: fnName,
|
|
205
|
-
},
|
|
206
|
-
/*noirCallStack=*/ [...internalCallStack, context.machineState.pc].map(pc => `0.${pc}`),
|
|
207
|
-
/*options=*/ { cause: nestedError },
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Create a "revert reason" error for an exceptional halt.
|
|
213
|
-
*
|
|
214
|
-
* @param haltingError - the lower-level error causing the exceptional halt
|
|
215
|
-
* @param context - the context of the AVM execution used to extract the failingFunction and noirCallStack
|
|
216
|
-
*/
|
|
217
|
-
export async function revertReasonFromExceptionalHalt(
|
|
218
|
-
haltingError: AvmExecutionError,
|
|
219
|
-
context: AvmContext,
|
|
220
|
-
): Promise<AvmRevertReason> {
|
|
221
|
-
return await createRevertReason(haltingError.message, [], context);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Create a "revert reason" error for an explicit revert (a root cause).
|
|
226
|
-
*
|
|
227
|
-
* @param revertData - output data of the explicit REVERT instruction
|
|
228
|
-
* @param context - the context of the AVM execution used to extract the failingFunction and noirCallStack
|
|
229
|
-
*/
|
|
230
|
-
export async function revertReasonFromExplicitRevert(revertData: Fr[], context: AvmContext): Promise<AvmRevertReason> {
|
|
231
|
-
return await createRevertReason('Assertion failed: ', revertData, context);
|
|
232
|
-
}
|
|
@@ -16,11 +16,11 @@ import {
|
|
|
16
16
|
initExecutionEnvironment,
|
|
17
17
|
resolveContractAssertionMessage,
|
|
18
18
|
} from '../../avm/fixtures/index.js';
|
|
19
|
+
import { SimpleContractDataSource } from '../../fixtures/simple_contract_data_source.js';
|
|
19
20
|
import { PublicContractsDB, PublicTreesDB } from '../../public_db_sources.js';
|
|
20
21
|
import { PublicPersistableStateManager } from '../../state_manager/state_manager.js';
|
|
21
22
|
import { AvmSimulator } from '../avm_simulator.js';
|
|
22
23
|
import { BaseAvmSimulationTester } from './base_avm_simulation_tester.js';
|
|
23
|
-
import { SimpleContractDataSource } from './simple_contract_data_source.js';
|
|
24
24
|
|
|
25
25
|
const TIMESTAMP = new Fr(99833);
|
|
26
26
|
const DEFAULT_GAS_FEES = new GasFees(2, 3);
|
|
@@ -11,8 +11,8 @@ import { computePublicDataTreeLeafSlot, siloNullifier } from '@aztec/stdlib/hash
|
|
|
11
11
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
12
12
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
13
13
|
|
|
14
|
+
import type { SimpleContractDataSource } from '../../fixtures/simple_contract_data_source.js';
|
|
14
15
|
import { createContractClassAndInstance } from './index.js';
|
|
15
|
-
import type { SimpleContractDataSource } from './simple_contract_data_source.js';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* An abstract test class that enables tests of real apps in the AVM without requiring e2e tests.
|
|
@@ -1,308 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
-
import { AvmGadgetsTestContract } from '@aztec/noir-contracts.js/AvmGadgetsTest';
|
|
5
|
-
import { AvmTestContract } from '@aztec/noir-contracts.js/AvmTest';
|
|
6
|
-
import {
|
|
7
|
-
type ContractArtifact,
|
|
8
|
-
type FunctionAbi,
|
|
9
|
-
type FunctionArtifact,
|
|
10
|
-
FunctionSelector,
|
|
11
|
-
getAllFunctionAbis,
|
|
12
|
-
} from '@aztec/stdlib/abi';
|
|
13
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
14
|
-
import {
|
|
15
|
-
type ContractClassPublic,
|
|
16
|
-
type ContractInstanceWithAddress,
|
|
17
|
-
computeInitializationHash,
|
|
18
|
-
} from '@aztec/stdlib/contract';
|
|
19
|
-
import { isNoirCallStackUnresolved } from '@aztec/stdlib/errors';
|
|
20
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
21
|
-
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
22
|
-
import { deriveKeys } from '@aztec/stdlib/keys';
|
|
23
|
-
import { makeContractClassPublic, makeContractInstanceFromClassId } from '@aztec/stdlib/testing';
|
|
24
|
-
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
25
|
-
|
|
26
|
-
import { strict as assert } from 'assert';
|
|
27
|
-
import { mock } from 'jest-mock-extended';
|
|
28
|
-
import merge from 'lodash.merge';
|
|
29
|
-
|
|
30
|
-
import { resolveAssertionMessageFromRevertData, traverseCauseChain } from '../../../common/index.js';
|
|
31
|
-
import type { PublicContractsDB, PublicTreesDB } from '../../public_db_sources.js';
|
|
32
|
-
import type { PublicSideEffectTraceInterface } from '../../side_effect_trace_interface.js';
|
|
33
|
-
import { NullifierManager } from '../../state_manager/nullifiers.js';
|
|
34
|
-
import { PublicStorage } from '../../state_manager/public_storage.js';
|
|
35
|
-
import { PublicPersistableStateManager } from '../../state_manager/state_manager.js';
|
|
36
|
-
import { AvmContext } from '../avm_context.js';
|
|
37
|
-
import { AvmExecutionEnvironment } from '../avm_execution_environment.js';
|
|
38
|
-
import { AvmMachineState } from '../avm_machine_state.js';
|
|
39
|
-
import { Field, Uint8, Uint32, Uint64 } from '../avm_memory_types.js';
|
|
40
|
-
import { AvmSimulator } from '../avm_simulator.js';
|
|
41
|
-
import type { AvmRevertReason } from '../errors.js';
|
|
42
|
-
|
|
43
|
-
export const PUBLIC_DISPATCH_FN_NAME = 'public_dispatch';
|
|
44
|
-
export const DEFAULT_BLOCK_NUMBER = 42;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Create a new AVM context with default values.
|
|
48
|
-
*/
|
|
49
|
-
export function initContext(overrides?: {
|
|
50
|
-
persistableState?: PublicPersistableStateManager;
|
|
51
|
-
env?: AvmExecutionEnvironment;
|
|
52
|
-
machineState?: AvmMachineState;
|
|
53
|
-
}): AvmContext {
|
|
54
|
-
const ctx = new AvmContext(
|
|
55
|
-
overrides?.persistableState || initPersistableStateManager(),
|
|
56
|
-
overrides?.env || initExecutionEnvironment(),
|
|
57
|
-
overrides?.machineState || initMachineState(),
|
|
58
|
-
);
|
|
59
|
-
ctx.provideSimulator = AvmSimulator.build;
|
|
60
|
-
return ctx;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Creates an empty state manager with mocked host storage. */
|
|
64
|
-
export function initPersistableStateManager(overrides?: {
|
|
65
|
-
treesDB?: PublicTreesDB;
|
|
66
|
-
contractsDB?: PublicContractsDB;
|
|
67
|
-
trace?: PublicSideEffectTraceInterface;
|
|
68
|
-
publicStorage?: PublicStorage;
|
|
69
|
-
nullifiers?: NullifierManager;
|
|
70
|
-
doMerkleOperations?: boolean;
|
|
71
|
-
firstNullifier?: Fr;
|
|
72
|
-
blockNumber?: number;
|
|
73
|
-
}): PublicPersistableStateManager {
|
|
74
|
-
const treesDB = overrides?.treesDB || mock<PublicTreesDB>();
|
|
75
|
-
return new PublicPersistableStateManager(
|
|
76
|
-
treesDB,
|
|
77
|
-
overrides?.contractsDB || mock<PublicContractsDB>(),
|
|
78
|
-
overrides?.trace || mock<PublicSideEffectTraceInterface>(),
|
|
79
|
-
overrides?.firstNullifier || new Fr(27),
|
|
80
|
-
overrides?.blockNumber || DEFAULT_BLOCK_NUMBER,
|
|
81
|
-
overrides?.doMerkleOperations || false,
|
|
82
|
-
overrides?.publicStorage,
|
|
83
|
-
overrides?.nullifiers,
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Create an empty instance of the Execution Environment where all values are zero, unless overridden in the overrides object
|
|
89
|
-
*/
|
|
90
|
-
export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnvironment>): AvmExecutionEnvironment {
|
|
91
|
-
return new AvmExecutionEnvironment(
|
|
92
|
-
overrides?.address ?? AztecAddress.zero(),
|
|
93
|
-
overrides?.sender ?? AztecAddress.zero(),
|
|
94
|
-
overrides?.contractCallDepth ?? Fr.zero(),
|
|
95
|
-
overrides?.transactionFee ?? Fr.zero(),
|
|
96
|
-
overrides?.globals ?? GlobalVariables.empty(),
|
|
97
|
-
overrides?.isStaticCall ?? false,
|
|
98
|
-
overrides?.calldata ?? [],
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Create an empty instance of the Execution Environment where all values are zero, unless overridden in the overrides object
|
|
104
|
-
*/
|
|
105
|
-
export function initGlobalVariables(overrides?: Partial<GlobalVariables>): GlobalVariables {
|
|
106
|
-
return new GlobalVariables(
|
|
107
|
-
overrides?.chainId ?? Fr.zero(),
|
|
108
|
-
overrides?.version ?? Fr.zero(),
|
|
109
|
-
overrides?.blockNumber ?? Fr.zero(),
|
|
110
|
-
overrides?.slotNumber ?? Fr.zero(),
|
|
111
|
-
overrides?.timestamp ?? Fr.zero(),
|
|
112
|
-
overrides?.coinbase ?? EthAddress.ZERO,
|
|
113
|
-
overrides?.feeRecipient ?? AztecAddress.zero(),
|
|
114
|
-
overrides?.gasFees ?? GasFees.empty(),
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Create an empty instance of the Machine State where all values are set to a large enough amount, unless overridden in the overrides object
|
|
120
|
-
*/
|
|
121
|
-
export function initMachineState(overrides?: Partial<AvmMachineState>): AvmMachineState {
|
|
122
|
-
return AvmMachineState.fromState({
|
|
123
|
-
l2GasLeft: overrides?.l2GasLeft ?? MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
|
|
124
|
-
daGasLeft: overrides?.daGasLeft ?? 1e8,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Create a new object with all the same properties as the original, except for the ones in the overrides object.
|
|
130
|
-
*/
|
|
131
|
-
export function allSameExcept(original: any, overrides: any): any {
|
|
132
|
-
return merge({}, original, overrides);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export function randomMemoryBytes(length: number): Uint8[] {
|
|
136
|
-
return [...Array(length)].map(_ => new Uint8(Math.floor(Math.random() * 255)));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function randomMemoryUint32s(length: number): Uint32[] {
|
|
140
|
-
return [...Array(length)].map(_ => new Uint32(Math.floor(Math.random() * 255)));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export function randomMemoryUint64s(length: number): Uint64[] {
|
|
144
|
-
return [...Array(length)].map(_ => new Uint64(Math.floor(Math.random() * 255)));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function randomMemoryFields(length: number): Field[] {
|
|
148
|
-
return [...Array(length)].map(_ => new Field(Fr.random()));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function getFunctionSelector(
|
|
152
|
-
functionName: string,
|
|
153
|
-
contractArtifact: ContractArtifact,
|
|
154
|
-
): Promise<FunctionSelector> {
|
|
155
|
-
const fnArtifact = getAllFunctionAbis(contractArtifact).find(f => f.name === functionName)!;
|
|
156
|
-
assert(!!fnArtifact, `Function ${functionName} not found in ${contractArtifact.name}`);
|
|
157
|
-
const params = fnArtifact.parameters;
|
|
158
|
-
return FunctionSelector.fromNameAndParameters(fnArtifact.name, params);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function getContractFunctionArtifact(
|
|
162
|
-
functionName: string,
|
|
163
|
-
contractArtifact: ContractArtifact,
|
|
164
|
-
): FunctionArtifact | undefined {
|
|
165
|
-
return contractArtifact.functions.find(f => f.name === functionName);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export function getContractFunctionAbi(
|
|
169
|
-
functionName: string,
|
|
170
|
-
contractArtifact: ContractArtifact,
|
|
171
|
-
): FunctionAbi | undefined {
|
|
172
|
-
return (
|
|
173
|
-
contractArtifact.functions.find(f => f.name === functionName) ??
|
|
174
|
-
contractArtifact.nonDispatchPublicFunctions.find(f => f.name === functionName)
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export function resolveContractAssertionMessage(
|
|
179
|
-
functionName: string,
|
|
180
|
-
revertReason: AvmRevertReason,
|
|
181
|
-
output: Fr[],
|
|
182
|
-
contractArtifact: ContractArtifact,
|
|
183
|
-
): string | undefined {
|
|
184
|
-
traverseCauseChain(revertReason, cause => {
|
|
185
|
-
revertReason = cause as AvmRevertReason;
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
const functionArtifact = getAllFunctionAbis(contractArtifact).find(f => f.name === functionName);
|
|
189
|
-
if (!functionArtifact || !revertReason.noirCallStack || !isNoirCallStackUnresolved(revertReason.noirCallStack)) {
|
|
190
|
-
return undefined;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return resolveAssertionMessageFromRevertData(output, functionArtifact);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export function getAvmTestContractFunctionSelector(functionName: string): Promise<FunctionSelector> {
|
|
197
|
-
return getFunctionSelector(functionName, AvmTestContract.artifactForPublic);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export function getAvmGadgetsTestContractFunctionSelector(functionName: string): Promise<FunctionSelector> {
|
|
201
|
-
const artifact = getAllFunctionAbis(AvmGadgetsTestContract.artifactForPublic).find(f => f.name === functionName)!;
|
|
202
|
-
assert(!!artifact, `Function ${functionName} not found in AvmGadgetsTestContractArtifact`);
|
|
203
|
-
const params = artifact.parameters;
|
|
204
|
-
return FunctionSelector.fromNameAndParameters(artifact.name, params);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export function getAvmTestContractArtifact(functionName: string): FunctionArtifact {
|
|
208
|
-
const artifact = getContractFunctionArtifact(functionName, AvmTestContract.artifactForPublic) as FunctionArtifact;
|
|
209
|
-
assert(
|
|
210
|
-
!!artifact?.bytecode,
|
|
211
|
-
`No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`,
|
|
212
|
-
);
|
|
213
|
-
return artifact;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export function getAvmGadgetsTestContractArtifact(functionName: string): FunctionArtifact {
|
|
217
|
-
const artifact = AvmGadgetsTestContract.artifactForPublic.functions.find(f => f.name === functionName)!;
|
|
218
|
-
assert(
|
|
219
|
-
!!artifact?.bytecode,
|
|
220
|
-
`No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`,
|
|
221
|
-
);
|
|
222
|
-
return artifact;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export function getAvmTestContractBytecode(functionName: string): Buffer {
|
|
226
|
-
const artifact = getAvmTestContractArtifact(functionName);
|
|
227
|
-
return artifact.bytecode;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export function getAvmGadgetsTestContractBytecode(functionName: string): Buffer {
|
|
231
|
-
const artifact = getAvmGadgetsTestContractArtifact(functionName);
|
|
232
|
-
return artifact.bytecode;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export function resolveAvmTestContractAssertionMessage(
|
|
236
|
-
functionName: string,
|
|
237
|
-
revertReason: AvmRevertReason,
|
|
238
|
-
output: Fr[],
|
|
239
|
-
): string | undefined {
|
|
240
|
-
return resolveContractAssertionMessage(functionName, revertReason, output, AvmTestContract.artifactForPublic);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export function resolveAvmGadgetsTestContractAssertionMessage(
|
|
244
|
-
functionName: string,
|
|
245
|
-
revertReason: AvmRevertReason,
|
|
246
|
-
output: Fr[],
|
|
247
|
-
): string | undefined {
|
|
248
|
-
traverseCauseChain(revertReason, cause => {
|
|
249
|
-
revertReason = cause as AvmRevertReason;
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
const functionArtifact = AvmGadgetsTestContract.artifactForPublic.functions.find(f => f.name === functionName);
|
|
253
|
-
if (!functionArtifact || !revertReason.noirCallStack || !isNoirCallStackUnresolved(revertReason.noirCallStack)) {
|
|
254
|
-
return undefined;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return resolveAssertionMessageFromRevertData(output, functionArtifact);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Create a contract class and instance given constructor args, artifact, etc.
|
|
262
|
-
* NOTE: This is useful for testing real-ish contract class registration and instance deployment TXs (via logs)
|
|
263
|
-
* @param constructorArgs - The constructor arguments for the contract.
|
|
264
|
-
* @param deployer - The deployer of the contract.
|
|
265
|
-
* @param contractArtifact - The contract artifact for the contract.
|
|
266
|
-
* @param seed - The seed for the contract.
|
|
267
|
-
* @param originalContractClassId - The original contract class ID (if upgraded)
|
|
268
|
-
* @returns The contract class, instance, and contract address nullifier.
|
|
269
|
-
*/
|
|
270
|
-
export async function createContractClassAndInstance(
|
|
271
|
-
constructorArgs: any[],
|
|
272
|
-
deployer: AztecAddress,
|
|
273
|
-
contractArtifact: ContractArtifact,
|
|
274
|
-
seed = 0,
|
|
275
|
-
originalContractClassId?: Fr, // if previously upgraded
|
|
276
|
-
): Promise<{
|
|
277
|
-
contractClass: ContractClassPublic;
|
|
278
|
-
contractInstance: ContractInstanceWithAddress;
|
|
279
|
-
contractAddressNullifier: Fr;
|
|
280
|
-
}> {
|
|
281
|
-
const bytecode = (getContractFunctionArtifact(PUBLIC_DISPATCH_FN_NAME, contractArtifact) as FunctionArtifact)!
|
|
282
|
-
.bytecode;
|
|
283
|
-
const contractClass = await makeContractClassPublic(seed, bytecode);
|
|
284
|
-
|
|
285
|
-
const constructorAbi = getContractFunctionAbi('constructor', contractArtifact);
|
|
286
|
-
const { publicKeys } = await deriveKeys(Fr.random());
|
|
287
|
-
const initializationHash = await computeInitializationHash(constructorAbi, constructorArgs);
|
|
288
|
-
const contractInstance =
|
|
289
|
-
originalContractClassId === undefined
|
|
290
|
-
? await makeContractInstanceFromClassId(contractClass.id, seed, {
|
|
291
|
-
deployer,
|
|
292
|
-
initializationHash,
|
|
293
|
-
publicKeys,
|
|
294
|
-
})
|
|
295
|
-
: await makeContractInstanceFromClassId(originalContractClassId, seed, {
|
|
296
|
-
deployer,
|
|
297
|
-
initializationHash,
|
|
298
|
-
currentClassId: contractClass.id,
|
|
299
|
-
publicKeys,
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
const contractAddressNullifier = await siloNullifier(
|
|
303
|
-
AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS),
|
|
304
|
-
contractInstance.address.toField(),
|
|
305
|
-
);
|
|
306
|
-
|
|
307
|
-
return { contractClass, contractInstance, contractAddressNullifier };
|
|
308
|
-
}
|
|
1
|
+
export * from './initializers.js';
|
|
2
|
+
export * from './utils.js';
|