@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
|
@@ -1,174 +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 { FunctionSelector, getAllFunctionAbis } from '@aztec/stdlib/abi';
|
|
7
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
-
import { computeInitializationHash } from '@aztec/stdlib/contract';
|
|
9
|
-
import { isNoirCallStackUnresolved } from '@aztec/stdlib/errors';
|
|
10
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
11
|
-
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
12
|
-
import { deriveKeys } from '@aztec/stdlib/keys';
|
|
13
|
-
import { makeContractClassPublic, makeContractInstanceFromClassId } from '@aztec/stdlib/testing';
|
|
14
|
-
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
15
|
-
import { strict as assert } from 'assert';
|
|
16
|
-
import { mock } from 'jest-mock-extended';
|
|
17
|
-
import merge from 'lodash.merge';
|
|
18
|
-
import { resolveAssertionMessageFromRevertData, traverseCauseChain } from '../../../common/index.js';
|
|
19
|
-
import { PublicPersistableStateManager } from '../../state_manager/state_manager.js';
|
|
20
|
-
import { AvmContext } from '../avm_context.js';
|
|
21
|
-
import { AvmExecutionEnvironment } from '../avm_execution_environment.js';
|
|
22
|
-
import { AvmMachineState } from '../avm_machine_state.js';
|
|
23
|
-
import { Field, Uint8, Uint32, Uint64 } from '../avm_memory_types.js';
|
|
24
|
-
import { AvmSimulator } from '../avm_simulator.js';
|
|
25
|
-
export const PUBLIC_DISPATCH_FN_NAME = 'public_dispatch';
|
|
26
|
-
export const DEFAULT_BLOCK_NUMBER = 42;
|
|
27
|
-
/**
|
|
28
|
-
* Create a new AVM context with default values.
|
|
29
|
-
*/ export function initContext(overrides) {
|
|
30
|
-
const ctx = new AvmContext(overrides?.persistableState || initPersistableStateManager(), overrides?.env || initExecutionEnvironment(), overrides?.machineState || initMachineState());
|
|
31
|
-
ctx.provideSimulator = AvmSimulator.build;
|
|
32
|
-
return ctx;
|
|
33
|
-
}
|
|
34
|
-
/** Creates an empty state manager with mocked host storage. */ export function initPersistableStateManager(overrides) {
|
|
35
|
-
const treesDB = overrides?.treesDB || mock();
|
|
36
|
-
return new PublicPersistableStateManager(treesDB, overrides?.contractsDB || mock(), overrides?.trace || mock(), overrides?.firstNullifier || new Fr(27), overrides?.blockNumber || DEFAULT_BLOCK_NUMBER, overrides?.doMerkleOperations || false, overrides?.publicStorage, overrides?.nullifiers);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Create an empty instance of the Execution Environment where all values are zero, unless overridden in the overrides object
|
|
40
|
-
*/ export function initExecutionEnvironment(overrides) {
|
|
41
|
-
return new AvmExecutionEnvironment(overrides?.address ?? AztecAddress.zero(), overrides?.sender ?? AztecAddress.zero(), overrides?.contractCallDepth ?? Fr.zero(), overrides?.transactionFee ?? Fr.zero(), overrides?.globals ?? GlobalVariables.empty(), overrides?.isStaticCall ?? false, overrides?.calldata ?? []);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Create an empty instance of the Execution Environment where all values are zero, unless overridden in the overrides object
|
|
45
|
-
*/ export function initGlobalVariables(overrides) {
|
|
46
|
-
return new GlobalVariables(overrides?.chainId ?? Fr.zero(), overrides?.version ?? Fr.zero(), overrides?.blockNumber ?? Fr.zero(), overrides?.slotNumber ?? Fr.zero(), overrides?.timestamp ?? Fr.zero(), overrides?.coinbase ?? EthAddress.ZERO, overrides?.feeRecipient ?? AztecAddress.zero(), overrides?.gasFees ?? GasFees.empty());
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Create an empty instance of the Machine State where all values are set to a large enough amount, unless overridden in the overrides object
|
|
50
|
-
*/ export function initMachineState(overrides) {
|
|
51
|
-
return AvmMachineState.fromState({
|
|
52
|
-
l2GasLeft: overrides?.l2GasLeft ?? MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
|
|
53
|
-
daGasLeft: overrides?.daGasLeft ?? 1e8
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Create a new object with all the same properties as the original, except for the ones in the overrides object.
|
|
58
|
-
*/ export function allSameExcept(original, overrides) {
|
|
59
|
-
return merge({}, original, overrides);
|
|
60
|
-
}
|
|
61
|
-
export function randomMemoryBytes(length) {
|
|
62
|
-
return [
|
|
63
|
-
...Array(length)
|
|
64
|
-
].map((_)=>new Uint8(Math.floor(Math.random() * 255)));
|
|
65
|
-
}
|
|
66
|
-
export function randomMemoryUint32s(length) {
|
|
67
|
-
return [
|
|
68
|
-
...Array(length)
|
|
69
|
-
].map((_)=>new Uint32(Math.floor(Math.random() * 255)));
|
|
70
|
-
}
|
|
71
|
-
export function randomMemoryUint64s(length) {
|
|
72
|
-
return [
|
|
73
|
-
...Array(length)
|
|
74
|
-
].map((_)=>new Uint64(Math.floor(Math.random() * 255)));
|
|
75
|
-
}
|
|
76
|
-
export function randomMemoryFields(length) {
|
|
77
|
-
return [
|
|
78
|
-
...Array(length)
|
|
79
|
-
].map((_)=>new Field(Fr.random()));
|
|
80
|
-
}
|
|
81
|
-
export function getFunctionSelector(functionName, contractArtifact) {
|
|
82
|
-
const fnArtifact = getAllFunctionAbis(contractArtifact).find((f)=>f.name === functionName);
|
|
83
|
-
assert(!!fnArtifact, `Function ${functionName} not found in ${contractArtifact.name}`);
|
|
84
|
-
const params = fnArtifact.parameters;
|
|
85
|
-
return FunctionSelector.fromNameAndParameters(fnArtifact.name, params);
|
|
86
|
-
}
|
|
87
|
-
export function getContractFunctionArtifact(functionName, contractArtifact) {
|
|
88
|
-
return contractArtifact.functions.find((f)=>f.name === functionName);
|
|
89
|
-
}
|
|
90
|
-
export function getContractFunctionAbi(functionName, contractArtifact) {
|
|
91
|
-
return contractArtifact.functions.find((f)=>f.name === functionName) ?? contractArtifact.nonDispatchPublicFunctions.find((f)=>f.name === functionName);
|
|
92
|
-
}
|
|
93
|
-
export function resolveContractAssertionMessage(functionName, revertReason, output, contractArtifact) {
|
|
94
|
-
traverseCauseChain(revertReason, (cause)=>{
|
|
95
|
-
revertReason = cause;
|
|
96
|
-
});
|
|
97
|
-
const functionArtifact = getAllFunctionAbis(contractArtifact).find((f)=>f.name === functionName);
|
|
98
|
-
if (!functionArtifact || !revertReason.noirCallStack || !isNoirCallStackUnresolved(revertReason.noirCallStack)) {
|
|
99
|
-
return undefined;
|
|
100
|
-
}
|
|
101
|
-
return resolveAssertionMessageFromRevertData(output, functionArtifact);
|
|
102
|
-
}
|
|
103
|
-
export function getAvmTestContractFunctionSelector(functionName) {
|
|
104
|
-
return getFunctionSelector(functionName, AvmTestContract.artifactForPublic);
|
|
105
|
-
}
|
|
106
|
-
export function getAvmGadgetsTestContractFunctionSelector(functionName) {
|
|
107
|
-
const artifact = getAllFunctionAbis(AvmGadgetsTestContract.artifactForPublic).find((f)=>f.name === functionName);
|
|
108
|
-
assert(!!artifact, `Function ${functionName} not found in AvmGadgetsTestContractArtifact`);
|
|
109
|
-
const params = artifact.parameters;
|
|
110
|
-
return FunctionSelector.fromNameAndParameters(artifact.name, params);
|
|
111
|
-
}
|
|
112
|
-
export function getAvmTestContractArtifact(functionName) {
|
|
113
|
-
const artifact = getContractFunctionArtifact(functionName, AvmTestContract.artifactForPublic);
|
|
114
|
-
assert(!!artifact?.bytecode, `No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`);
|
|
115
|
-
return artifact;
|
|
116
|
-
}
|
|
117
|
-
export function getAvmGadgetsTestContractArtifact(functionName) {
|
|
118
|
-
const artifact = AvmGadgetsTestContract.artifactForPublic.functions.find((f)=>f.name === functionName);
|
|
119
|
-
assert(!!artifact?.bytecode, `No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`);
|
|
120
|
-
return artifact;
|
|
121
|
-
}
|
|
122
|
-
export function getAvmTestContractBytecode(functionName) {
|
|
123
|
-
const artifact = getAvmTestContractArtifact(functionName);
|
|
124
|
-
return artifact.bytecode;
|
|
125
|
-
}
|
|
126
|
-
export function getAvmGadgetsTestContractBytecode(functionName) {
|
|
127
|
-
const artifact = getAvmGadgetsTestContractArtifact(functionName);
|
|
128
|
-
return artifact.bytecode;
|
|
129
|
-
}
|
|
130
|
-
export function resolveAvmTestContractAssertionMessage(functionName, revertReason, output) {
|
|
131
|
-
return resolveContractAssertionMessage(functionName, revertReason, output, AvmTestContract.artifactForPublic);
|
|
132
|
-
}
|
|
133
|
-
export function resolveAvmGadgetsTestContractAssertionMessage(functionName, revertReason, output) {
|
|
134
|
-
traverseCauseChain(revertReason, (cause)=>{
|
|
135
|
-
revertReason = cause;
|
|
136
|
-
});
|
|
137
|
-
const functionArtifact = AvmGadgetsTestContract.artifactForPublic.functions.find((f)=>f.name === functionName);
|
|
138
|
-
if (!functionArtifact || !revertReason.noirCallStack || !isNoirCallStackUnresolved(revertReason.noirCallStack)) {
|
|
139
|
-
return undefined;
|
|
140
|
-
}
|
|
141
|
-
return resolveAssertionMessageFromRevertData(output, functionArtifact);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Create a contract class and instance given constructor args, artifact, etc.
|
|
145
|
-
* NOTE: This is useful for testing real-ish contract class registration and instance deployment TXs (via logs)
|
|
146
|
-
* @param constructorArgs - The constructor arguments for the contract.
|
|
147
|
-
* @param deployer - The deployer of the contract.
|
|
148
|
-
* @param contractArtifact - The contract artifact for the contract.
|
|
149
|
-
* @param seed - The seed for the contract.
|
|
150
|
-
* @param originalContractClassId - The original contract class ID (if upgraded)
|
|
151
|
-
* @returns The contract class, instance, and contract address nullifier.
|
|
152
|
-
*/ export async function createContractClassAndInstance(constructorArgs, deployer, contractArtifact, seed = 0, originalContractClassId) {
|
|
153
|
-
const bytecode = getContractFunctionArtifact(PUBLIC_DISPATCH_FN_NAME, contractArtifact).bytecode;
|
|
154
|
-
const contractClass = await makeContractClassPublic(seed, bytecode);
|
|
155
|
-
const constructorAbi = getContractFunctionAbi('constructor', contractArtifact);
|
|
156
|
-
const { publicKeys } = await deriveKeys(Fr.random());
|
|
157
|
-
const initializationHash = await computeInitializationHash(constructorAbi, constructorArgs);
|
|
158
|
-
const contractInstance = originalContractClassId === undefined ? await makeContractInstanceFromClassId(contractClass.id, seed, {
|
|
159
|
-
deployer,
|
|
160
|
-
initializationHash,
|
|
161
|
-
publicKeys
|
|
162
|
-
}) : await makeContractInstanceFromClassId(originalContractClassId, seed, {
|
|
163
|
-
deployer,
|
|
164
|
-
initializationHash,
|
|
165
|
-
currentClassId: contractClass.id,
|
|
166
|
-
publicKeys
|
|
167
|
-
});
|
|
168
|
-
const contractAddressNullifier = await siloNullifier(AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS), contractInstance.address.toField());
|
|
169
|
-
return {
|
|
170
|
-
contractClass,
|
|
171
|
-
contractInstance,
|
|
172
|
-
contractAddressNullifier
|
|
173
|
-
};
|
|
174
|
-
}
|
|
1
|
+
export * from './initializers.js';
|
|
2
|
+
export * from './utils.js';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
3
|
+
import type { PublicContractsDB, PublicTreesDB } from '../../public_db_sources.js';
|
|
4
|
+
import type { PublicSideEffectTraceInterface } from '../../side_effect_trace_interface.js';
|
|
5
|
+
import { NullifierManager } from '../../state_manager/nullifiers.js';
|
|
6
|
+
import { PublicStorage } from '../../state_manager/public_storage.js';
|
|
7
|
+
import { PublicPersistableStateManager } from '../../state_manager/state_manager.js';
|
|
8
|
+
import { AvmContext } from '../avm_context.js';
|
|
9
|
+
import { AvmExecutionEnvironment } from '../avm_execution_environment.js';
|
|
10
|
+
import { AvmMachineState } from '../avm_machine_state.js';
|
|
11
|
+
/**
|
|
12
|
+
* Create a new AVM context with default values.
|
|
13
|
+
*/
|
|
14
|
+
export declare function initContext(overrides?: {
|
|
15
|
+
persistableState?: PublicPersistableStateManager;
|
|
16
|
+
env?: AvmExecutionEnvironment;
|
|
17
|
+
machineState?: AvmMachineState;
|
|
18
|
+
}): AvmContext;
|
|
19
|
+
/** Creates an empty state manager with mocked host storage. */
|
|
20
|
+
export declare function initPersistableStateManager(overrides?: {
|
|
21
|
+
treesDB?: PublicTreesDB;
|
|
22
|
+
contractsDB?: PublicContractsDB;
|
|
23
|
+
trace?: PublicSideEffectTraceInterface;
|
|
24
|
+
publicStorage?: PublicStorage;
|
|
25
|
+
nullifiers?: NullifierManager;
|
|
26
|
+
doMerkleOperations?: boolean;
|
|
27
|
+
firstNullifier?: Fr;
|
|
28
|
+
blockNumber?: number;
|
|
29
|
+
}): PublicPersistableStateManager;
|
|
30
|
+
/**
|
|
31
|
+
* Create an empty instance of the Execution Environment where all values are zero, unless overridden in the overrides object
|
|
32
|
+
*/
|
|
33
|
+
export declare function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnvironment>): AvmExecutionEnvironment;
|
|
34
|
+
/**
|
|
35
|
+
* Create an empty instance of the Execution Environment where all values are zero, unless overridden in the overrides object
|
|
36
|
+
*/
|
|
37
|
+
export declare function initGlobalVariables(overrides?: Partial<GlobalVariables>): GlobalVariables;
|
|
38
|
+
/**
|
|
39
|
+
* Create an empty instance of the Machine State where all values are set to a large enough amount, unless overridden in the overrides object
|
|
40
|
+
*/
|
|
41
|
+
export declare function initMachineState(overrides?: Partial<AvmMachineState>): AvmMachineState;
|
|
42
|
+
//# sourceMappingURL=initializers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializers.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/fixtures/initializers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAInD,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACnF,OAAO,KAAK,EAAE,8B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AAe,CAKtF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MAX_L2_GAS_PER_TX_PUBLIC_PORTION } from '@aztec/constants';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
6
|
+
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
7
|
+
import { mock } from 'jest-mock-extended';
|
|
8
|
+
import { PublicPersistableStateManager } from '../../state_manager/state_manager.js';
|
|
9
|
+
import { AvmContext } from '../avm_context.js';
|
|
10
|
+
import { AvmExecutionEnvironment } from '../avm_execution_environment.js';
|
|
11
|
+
import { AvmMachineState } from '../avm_machine_state.js';
|
|
12
|
+
import { AvmSimulator } from '../avm_simulator.js';
|
|
13
|
+
import { DEFAULT_BLOCK_NUMBER } from './utils.js';
|
|
14
|
+
/**
|
|
15
|
+
* Create a new AVM context with default values.
|
|
16
|
+
*/ export function initContext(overrides) {
|
|
17
|
+
const ctx = new AvmContext(overrides?.persistableState || initPersistableStateManager(), overrides?.env || initExecutionEnvironment(), overrides?.machineState || initMachineState());
|
|
18
|
+
ctx.provideSimulator = AvmSimulator.build;
|
|
19
|
+
return ctx;
|
|
20
|
+
}
|
|
21
|
+
/** Creates an empty state manager with mocked host storage. */ export function initPersistableStateManager(overrides) {
|
|
22
|
+
const treesDB = overrides?.treesDB || mock();
|
|
23
|
+
return new PublicPersistableStateManager(treesDB, overrides?.contractsDB || mock(), overrides?.trace || mock(), overrides?.firstNullifier || new Fr(27), overrides?.blockNumber || DEFAULT_BLOCK_NUMBER, overrides?.doMerkleOperations || false, overrides?.publicStorage, overrides?.nullifiers);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create an empty instance of the Execution Environment where all values are zero, unless overridden in the overrides object
|
|
27
|
+
*/ export function initExecutionEnvironment(overrides) {
|
|
28
|
+
return new AvmExecutionEnvironment(overrides?.address ?? AztecAddress.zero(), overrides?.sender ?? AztecAddress.zero(), overrides?.contractCallDepth ?? Fr.zero(), overrides?.transactionFee ?? Fr.zero(), overrides?.globals ?? GlobalVariables.empty(), overrides?.isStaticCall ?? false, overrides?.calldata ?? []);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create an empty instance of the Execution Environment where all values are zero, unless overridden in the overrides object
|
|
32
|
+
*/ export function initGlobalVariables(overrides) {
|
|
33
|
+
return new GlobalVariables(overrides?.chainId ?? Fr.zero(), overrides?.version ?? Fr.zero(), overrides?.blockNumber ?? Fr.zero(), overrides?.slotNumber ?? Fr.zero(), overrides?.timestamp ?? Fr.zero(), overrides?.coinbase ?? EthAddress.ZERO, overrides?.feeRecipient ?? AztecAddress.zero(), overrides?.gasFees ?? GasFees.empty());
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create an empty instance of the Machine State where all values are set to a large enough amount, unless overridden in the overrides object
|
|
37
|
+
*/ export function initMachineState(overrides) {
|
|
38
|
+
return AvmMachineState.fromState({
|
|
39
|
+
l2GasLeft: overrides?.l2GasLeft ?? MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
|
|
40
|
+
daGasLeft: overrides?.daGasLeft ?? 1e8
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { type ContractArtifact, type FunctionAbi, type FunctionArtifact, FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
import { type ContractClassPublic, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
7
|
+
import { Field, Uint8, Uint32, Uint64 } from '../avm_memory_types.js';
|
|
8
|
+
import type { AvmRevertReason } from '../errors.js';
|
|
9
|
+
export declare const PUBLIC_DISPATCH_FN_NAME = "public_dispatch";
|
|
10
|
+
export declare const DEFAULT_BLOCK_NUMBER = 42;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new object with all the same properties as the original, except for the ones in the overrides object.
|
|
13
|
+
*/
|
|
14
|
+
export declare function allSameExcept(original: any, overrides: any): any;
|
|
15
|
+
export declare function randomMemoryBytes(length: number): Uint8[];
|
|
16
|
+
export declare function randomMemoryUint32s(length: number): Uint32[];
|
|
17
|
+
export declare function randomMemoryUint64s(length: number): Uint64[];
|
|
18
|
+
export declare function randomMemoryFields(length: number): Field[];
|
|
19
|
+
export declare function getFunctionSelector(functionName: string, contractArtifact: ContractArtifact): Promise<FunctionSelector>;
|
|
20
|
+
export declare function getContractFunctionArtifact(functionName: string, contractArtifact: ContractArtifact): FunctionArtifact | undefined;
|
|
21
|
+
export declare function getContractFunctionAbi(functionName: string, contractArtifact: ContractArtifact): FunctionAbi | undefined;
|
|
22
|
+
export declare function resolveContractAssertionMessage(functionName: string, revertReason: AvmRevertReason, output: Fr[], contractArtifact: ContractArtifact): string | undefined;
|
|
23
|
+
export declare function getAvmTestContractFunctionSelector(functionName: string): Promise<FunctionSelector>;
|
|
24
|
+
export declare function getAvmGadgetsTestContractFunctionSelector(functionName: string): Promise<FunctionSelector>;
|
|
25
|
+
export declare function getAvmTestContractArtifact(functionName: string): FunctionArtifact;
|
|
26
|
+
export declare function getAvmGadgetsTestContractArtifact(functionName: string): FunctionArtifact;
|
|
27
|
+
export declare function getAvmTestContractBytecode(functionName: string): Buffer;
|
|
28
|
+
export declare function getAvmGadgetsTestContractBytecode(functionName: string): Buffer;
|
|
29
|
+
export declare function resolveAvmTestContractAssertionMessage(functionName: string, revertReason: AvmRevertReason, output: Fr[]): string | undefined;
|
|
30
|
+
export declare function resolveAvmGadgetsTestContractAssertionMessage(functionName: string, revertReason: AvmRevertReason, output: Fr[]): string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Create a contract class and instance given constructor args, artifact, etc.
|
|
33
|
+
* NOTE: This is useful for testing real-ish contract class registration and instance deployment TXs (via logs)
|
|
34
|
+
* @param constructorArgs - The constructor arguments for the contract.
|
|
35
|
+
* @param deployer - The deployer of the contract.
|
|
36
|
+
* @param contractArtifact - The contract artifact for the contract.
|
|
37
|
+
* @param seed - The seed for the contract.
|
|
38
|
+
* @param originalContractClassId - The original contract class ID (if upgraded)
|
|
39
|
+
* @returns The contract class, instance, and contract address nullifier.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createContractClassAndInstance(constructorArgs: any[], deployer: AztecAddress, contractArtifact: ContractArtifact, seed?: number, originalContractClassId?: Fr): Promise<{
|
|
42
|
+
contractClass: ContractClassPublic;
|
|
43
|
+
contractInstance: ContractInstanceWithAddress;
|
|
44
|
+
contractAddressNullifier: Fr;
|
|
45
|
+
}>;
|
|
46
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/fixtures/utils.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAG9C,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,gBAAgB,EAEjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAEjC,MAAM,wBAAwB,CAAC;AAUhC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,eAAO,MAAM,uBAAuB,oBAAoB,CAAC;AACzD,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC;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CAGvE;AAED,wBAAgB,iCAAiC,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAG9E;AAED,wBAAgB,sCAAsC,CACpD,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,eAAe,EAC7B,MAAM,EAAE,EAAE,EAAE,GACX,MAAM,GAAG,SAAS,CAEpB;AAED,wBAAgB,6CAA6C,CAC3D,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,eAAe,EAC7B,MAAM,EAAE,EAAE,EAAE,GACX,MAAM,GAAG,SAAS,CAWpB;AAED;;;;;;;;;GASG;AACH,wBAAsB,8BAA8B,CAClD,eAAe,EAAE,GAAG,EAAE,EACtB,QAAQ,EAAE,YAAY,EACtB,gBAAgB,EAAE,gBAAgB,EAClC,IAAI,SAAI,EACR,uBAAuB,CAAC,EAAE,EAAE,GAC3B,OAAO,CAAC;IACT,aAAa,EAAE,mBAAmB,CAAC;IACnC,gBAAgB,EAAE,2BAA2B,CAAC;IAC9C,wBAAwB,EAAE,EAAE,CAAC;CAC9B,CAAC,CA4BD"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { DEPLOYER_CONTRACT_ADDRESS } from '@aztec/constants';
|
|
2
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
+
import { AvmGadgetsTestContract } from '@aztec/noir-contracts.js/AvmGadgetsTest';
|
|
4
|
+
import { AvmTestContract } from '@aztec/noir-contracts.js/AvmTest';
|
|
5
|
+
import { FunctionSelector, getAllFunctionAbis } from '@aztec/stdlib/abi';
|
|
6
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
+
import { computeInitializationHash } from '@aztec/stdlib/contract';
|
|
8
|
+
import { isNoirCallStackUnresolved } from '@aztec/stdlib/errors';
|
|
9
|
+
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
10
|
+
import { deriveKeys } from '@aztec/stdlib/keys';
|
|
11
|
+
import { makeContractClassPublic, makeContractInstanceFromClassId } from '@aztec/stdlib/testing';
|
|
12
|
+
import { strict as assert } from 'assert';
|
|
13
|
+
import merge from 'lodash.merge';
|
|
14
|
+
import { resolveAssertionMessageFromRevertData, traverseCauseChain } from '../../../common/index.js';
|
|
15
|
+
import { Field, Uint8, Uint32, Uint64 } from '../avm_memory_types.js';
|
|
16
|
+
export const PUBLIC_DISPATCH_FN_NAME = 'public_dispatch';
|
|
17
|
+
export const DEFAULT_BLOCK_NUMBER = 42;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new object with all the same properties as the original, except for the ones in the overrides object.
|
|
20
|
+
*/ export function allSameExcept(original, overrides) {
|
|
21
|
+
return merge({}, original, overrides);
|
|
22
|
+
}
|
|
23
|
+
export function randomMemoryBytes(length) {
|
|
24
|
+
return [
|
|
25
|
+
...Array(length)
|
|
26
|
+
].map((_)=>new Uint8(Math.floor(Math.random() * 255)));
|
|
27
|
+
}
|
|
28
|
+
export function randomMemoryUint32s(length) {
|
|
29
|
+
return [
|
|
30
|
+
...Array(length)
|
|
31
|
+
].map((_)=>new Uint32(Math.floor(Math.random() * 255)));
|
|
32
|
+
}
|
|
33
|
+
export function randomMemoryUint64s(length) {
|
|
34
|
+
return [
|
|
35
|
+
...Array(length)
|
|
36
|
+
].map((_)=>new Uint64(Math.floor(Math.random() * 255)));
|
|
37
|
+
}
|
|
38
|
+
export function randomMemoryFields(length) {
|
|
39
|
+
return [
|
|
40
|
+
...Array(length)
|
|
41
|
+
].map((_)=>new Field(Fr.random()));
|
|
42
|
+
}
|
|
43
|
+
export function getFunctionSelector(functionName, contractArtifact) {
|
|
44
|
+
const fnArtifact = getAllFunctionAbis(contractArtifact).find((f)=>f.name === functionName);
|
|
45
|
+
assert(!!fnArtifact, `Function ${functionName} not found in ${contractArtifact.name}`);
|
|
46
|
+
const params = fnArtifact.parameters;
|
|
47
|
+
return FunctionSelector.fromNameAndParameters(fnArtifact.name, params);
|
|
48
|
+
}
|
|
49
|
+
export function getContractFunctionArtifact(functionName, contractArtifact) {
|
|
50
|
+
return contractArtifact.functions.find((f)=>f.name === functionName);
|
|
51
|
+
}
|
|
52
|
+
export function getContractFunctionAbi(functionName, contractArtifact) {
|
|
53
|
+
return contractArtifact.functions.find((f)=>f.name === functionName) ?? contractArtifact.nonDispatchPublicFunctions.find((f)=>f.name === functionName);
|
|
54
|
+
}
|
|
55
|
+
export function resolveContractAssertionMessage(functionName, revertReason, output, contractArtifact) {
|
|
56
|
+
traverseCauseChain(revertReason, (cause)=>{
|
|
57
|
+
revertReason = cause;
|
|
58
|
+
});
|
|
59
|
+
const functionArtifact = getAllFunctionAbis(contractArtifact).find((f)=>f.name === functionName);
|
|
60
|
+
if (!functionArtifact || !revertReason.noirCallStack || !isNoirCallStackUnresolved(revertReason.noirCallStack)) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
return resolveAssertionMessageFromRevertData(output, functionArtifact);
|
|
64
|
+
}
|
|
65
|
+
export function getAvmTestContractFunctionSelector(functionName) {
|
|
66
|
+
return getFunctionSelector(functionName, AvmTestContract.artifactForPublic);
|
|
67
|
+
}
|
|
68
|
+
export function getAvmGadgetsTestContractFunctionSelector(functionName) {
|
|
69
|
+
const artifact = getAllFunctionAbis(AvmGadgetsTestContract.artifactForPublic).find((f)=>f.name === functionName);
|
|
70
|
+
assert(!!artifact, `Function ${functionName} not found in AvmGadgetsTestContractArtifact`);
|
|
71
|
+
const params = artifact.parameters;
|
|
72
|
+
return FunctionSelector.fromNameAndParameters(artifact.name, params);
|
|
73
|
+
}
|
|
74
|
+
export function getAvmTestContractArtifact(functionName) {
|
|
75
|
+
const artifact = getContractFunctionArtifact(functionName, AvmTestContract.artifactForPublic);
|
|
76
|
+
assert(!!artifact?.bytecode, `No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`);
|
|
77
|
+
return artifact;
|
|
78
|
+
}
|
|
79
|
+
export function getAvmGadgetsTestContractArtifact(functionName) {
|
|
80
|
+
const artifact = AvmGadgetsTestContract.artifactForPublic.functions.find((f)=>f.name === functionName);
|
|
81
|
+
assert(!!artifact?.bytecode, `No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`);
|
|
82
|
+
return artifact;
|
|
83
|
+
}
|
|
84
|
+
export function getAvmTestContractBytecode(functionName) {
|
|
85
|
+
const artifact = getAvmTestContractArtifact(functionName);
|
|
86
|
+
return artifact.bytecode;
|
|
87
|
+
}
|
|
88
|
+
export function getAvmGadgetsTestContractBytecode(functionName) {
|
|
89
|
+
const artifact = getAvmGadgetsTestContractArtifact(functionName);
|
|
90
|
+
return artifact.bytecode;
|
|
91
|
+
}
|
|
92
|
+
export function resolveAvmTestContractAssertionMessage(functionName, revertReason, output) {
|
|
93
|
+
return resolveContractAssertionMessage(functionName, revertReason, output, AvmTestContract.artifactForPublic);
|
|
94
|
+
}
|
|
95
|
+
export function resolveAvmGadgetsTestContractAssertionMessage(functionName, revertReason, output) {
|
|
96
|
+
traverseCauseChain(revertReason, (cause)=>{
|
|
97
|
+
revertReason = cause;
|
|
98
|
+
});
|
|
99
|
+
const functionArtifact = AvmGadgetsTestContract.artifactForPublic.functions.find((f)=>f.name === functionName);
|
|
100
|
+
if (!functionArtifact || !revertReason.noirCallStack || !isNoirCallStackUnresolved(revertReason.noirCallStack)) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
return resolveAssertionMessageFromRevertData(output, functionArtifact);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Create a contract class and instance given constructor args, artifact, etc.
|
|
107
|
+
* NOTE: This is useful for testing real-ish contract class registration and instance deployment TXs (via logs)
|
|
108
|
+
* @param constructorArgs - The constructor arguments for the contract.
|
|
109
|
+
* @param deployer - The deployer of the contract.
|
|
110
|
+
* @param contractArtifact - The contract artifact for the contract.
|
|
111
|
+
* @param seed - The seed for the contract.
|
|
112
|
+
* @param originalContractClassId - The original contract class ID (if upgraded)
|
|
113
|
+
* @returns The contract class, instance, and contract address nullifier.
|
|
114
|
+
*/ export async function createContractClassAndInstance(constructorArgs, deployer, contractArtifact, seed = 0, originalContractClassId) {
|
|
115
|
+
const bytecode = getContractFunctionArtifact(PUBLIC_DISPATCH_FN_NAME, contractArtifact).bytecode;
|
|
116
|
+
const contractClass = await makeContractClassPublic(seed, bytecode);
|
|
117
|
+
const constructorAbi = getContractFunctionAbi('constructor', contractArtifact);
|
|
118
|
+
const { publicKeys } = await deriveKeys(Fr.random());
|
|
119
|
+
const initializationHash = await computeInitializationHash(constructorAbi, constructorArgs);
|
|
120
|
+
const contractInstance = originalContractClassId === undefined ? await makeContractInstanceFromClassId(contractClass.id, seed, {
|
|
121
|
+
deployer,
|
|
122
|
+
initializationHash,
|
|
123
|
+
publicKeys
|
|
124
|
+
}) : await makeContractInstanceFromClassId(originalContractClassId, seed, {
|
|
125
|
+
deployer,
|
|
126
|
+
initializationHash,
|
|
127
|
+
currentClassId: contractClass.id,
|
|
128
|
+
publicKeys
|
|
129
|
+
});
|
|
130
|
+
const contractAddressNullifier = await siloNullifier(AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS), contractInstance.address.toField());
|
|
131
|
+
return {
|
|
132
|
+
contractClass,
|
|
133
|
+
contractInstance,
|
|
134
|
+
contractAddressNullifier
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/public/avm/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/public/avm/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
package/dest/public/avm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accrued_substate.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/opcodes/accrued_substate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,MAAM,E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SAAQ,WAAW;IAMpC,OAAO,CAAC,QAAQ;IAAU,OAAO,CAAC,eAAe;IAAU,OAAO,CAAC,aAAa;IAL5F,MAAM,CAAC,IAAI,EAAE,MAAM,CAAmB;IACtC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAwB;IAEtD,MAAM,CAAC,QAAQ,CAAC,UAAU,gBAAkF;gBAExF,QAAQ,EAAE,MAAM,EAAU,eAAe,EAAE,MAAM,EAAU,aAAa,EAAE,MAAM;IAIvF,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBzD"}
|
|
@@ -175,7 +175,7 @@ export class L1ToL2MessageExists extends Instruction {
|
|
|
175
175
|
memory.checkTags(TypeTag.FIELD, msgHashOffset, msgLeafIndexOffset);
|
|
176
176
|
const msgHash = memory.get(msgHashOffset).toFr();
|
|
177
177
|
const msgLeafIndex = memory.get(msgLeafIndexOffset).toFr();
|
|
178
|
-
const exists = await context.persistableState.checkL1ToL2MessageExists(
|
|
178
|
+
const exists = await context.persistableState.checkL1ToL2MessageExists(msgHash, msgLeafIndex);
|
|
179
179
|
memory.set(existsOffset, exists ? new Uint1(1) : new Uint1(0));
|
|
180
180
|
}
|
|
181
181
|
}
|
|
@@ -3,12 +3,13 @@ import { Opcode, OperandType } from '../serialization/instruction_serialization.
|
|
|
3
3
|
import { Instruction } from './instruction.js';
|
|
4
4
|
declare abstract class ExternalCall extends Instruction {
|
|
5
5
|
private indirect;
|
|
6
|
-
private
|
|
6
|
+
private l2GasOffset;
|
|
7
|
+
private daGasOffset;
|
|
7
8
|
private addrOffset;
|
|
8
9
|
private argsOffset;
|
|
9
10
|
private argsSizeOffset;
|
|
10
11
|
static readonly wireFormat: OperandType[];
|
|
11
|
-
constructor(indirect: number,
|
|
12
|
+
constructor(indirect: number, l2GasOffset: number, daGasOffset: number, addrOffset: number, argsOffset: number, argsSizeOffset: number);
|
|
12
13
|
execute(context: AvmContext): Promise<void>;
|
|
13
14
|
abstract get type(): 'CALL' | 'STATICCALL';
|
|
14
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external_calls.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/opcodes/external_calls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAEpF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,uBAAe,YAAa,SAAQ,WAAW;
|
|
1
|
+
{"version":3,"file":"external_calls.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/opcodes/external_calls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAEpF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,uBAAe,YAAa,SAAQ,WAAW;IAa3C,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,cAAc;IAhBxB,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,WAAW,EAAE,CAQvC;gBAGQ,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM;IAKnB,OAAO,CAAC,OAAO,EAAE,UAAU;IA0ExC,aAA6B,IAAI,IAAI,MAAM,GAAG,YAAY,CAAC;CAC5D;AAED,qBAAa,IAAK,SAAQ,YAAY;IACpC,MAAM,CAAC,IAAI,SAAmB;IAC9B,MAAM,CAAC,QAAQ,CAAC,MAAM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;IAEjD,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,CAKxC;IACF,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,WAAW,EAAE,CAKzC;gBAEkB,QAAQ,EAAE,MAAM,EAAU,YAAY,EAAE,MAAM,EAAU,aAAa,EAAE,MAAM;IAIpF,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBxC,SAAS,IAAI,OAAO;CAGrC"}
|
|
@@ -4,33 +4,38 @@ import { Addressing } from './addressing_mode.js';
|
|
|
4
4
|
import { Instruction } from './instruction.js';
|
|
5
5
|
class ExternalCall extends Instruction {
|
|
6
6
|
indirect;
|
|
7
|
-
|
|
7
|
+
l2GasOffset;
|
|
8
|
+
daGasOffset;
|
|
8
9
|
addrOffset;
|
|
9
10
|
argsOffset;
|
|
10
11
|
argsSizeOffset;
|
|
11
12
|
// Informs (de)serialization. See Instruction.deserialize.
|
|
12
13
|
static wireFormat = [
|
|
13
14
|
OperandType.UINT8,
|
|
14
|
-
OperandType.
|
|
15
|
+
OperandType.UINT16,
|
|
16
|
+
OperandType.UINT16,
|
|
15
17
|
OperandType.UINT16,
|
|
16
18
|
OperandType.UINT16,
|
|
17
19
|
OperandType.UINT16,
|
|
18
20
|
OperandType.UINT16
|
|
19
21
|
];
|
|
20
|
-
constructor(indirect,
|
|
21
|
-
super(), this.indirect = indirect, this.
|
|
22
|
+
constructor(indirect, l2GasOffset, daGasOffset, addrOffset, argsOffset, argsSizeOffset){
|
|
23
|
+
super(), this.indirect = indirect, this.l2GasOffset = l2GasOffset, this.daGasOffset = daGasOffset, this.addrOffset = addrOffset, this.argsOffset = argsOffset, this.argsSizeOffset = argsSizeOffset;
|
|
22
24
|
}
|
|
23
25
|
async execute(context) {
|
|
24
26
|
const memory = context.machineState.memory;
|
|
25
27
|
const operands = [
|
|
26
|
-
this.
|
|
28
|
+
this.l2GasOffset,
|
|
29
|
+
this.daGasOffset,
|
|
27
30
|
this.addrOffset,
|
|
28
31
|
this.argsOffset,
|
|
29
32
|
this.argsSizeOffset
|
|
30
33
|
];
|
|
31
34
|
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
32
|
-
const [
|
|
33
|
-
|
|
35
|
+
const [l2GasOffset, daGasOffset, addrOffset, argsOffset, argsSizeOffset] = addressing.resolve(operands, memory);
|
|
36
|
+
// TODO: Should be U32
|
|
37
|
+
memory.checkTags(TypeTag.FIELD, l2GasOffset);
|
|
38
|
+
memory.checkTags(TypeTag.FIELD, daGasOffset);
|
|
34
39
|
memory.checkTag(TypeTag.FIELD, addrOffset);
|
|
35
40
|
memory.checkTag(TypeTag.UINT32, argsSizeOffset);
|
|
36
41
|
const calldataSize = memory.get(argsSizeOffset).toNumber();
|
|
@@ -45,8 +50,8 @@ class ExternalCall extends Instruction {
|
|
|
45
50
|
// Gas allocation is capped by the amount of gas left in the current context.
|
|
46
51
|
// We have to do some dancing here because the gas allocation is a field,
|
|
47
52
|
// but in the machine state we track gas as a number.
|
|
48
|
-
const allocatedL2Gas = Number(BigIntMin(memory.get(
|
|
49
|
-
const allocatedDaGas = Number(BigIntMin(memory.get(
|
|
53
|
+
const allocatedL2Gas = Number(BigIntMin(memory.get(l2GasOffset).toBigInt(), BigInt(context.machineState.l2GasLeft)));
|
|
54
|
+
const allocatedDaGas = Number(BigIntMin(memory.get(daGasOffset).toBigInt(), BigInt(context.machineState.daGasLeft)));
|
|
50
55
|
const allocatedGas = {
|
|
51
56
|
l2Gas: allocatedL2Gas,
|
|
52
57
|
daGas: allocatedDaGas
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { Bufferable } from '@aztec/foundation/serialize';
|
|
3
4
|
import type { AvmContext } from '../avm_context.js';
|
|
4
5
|
import { type Gas } from '../avm_gas.js';
|
|
5
6
|
import type { BufferCursor } from '../serialization/buffer_cursor.js';
|
|
6
|
-
import type { Serializable } from '../serialization/bytecode_serialization.js';
|
|
7
7
|
import { Opcode, type OperandType } from '../serialization/instruction_serialization.js';
|
|
8
8
|
type InstructionConstructor = {
|
|
9
9
|
new (...args: any[]): Instruction;
|
|
@@ -29,18 +29,18 @@ export declare abstract class Instruction {
|
|
|
29
29
|
* @returns Thee string representation.
|
|
30
30
|
*/
|
|
31
31
|
toString(): string;
|
|
32
|
-
static
|
|
32
|
+
static fromBuffer(this: InstructionConstructor & {
|
|
33
33
|
wireFormat: OperandType[];
|
|
34
34
|
as: any;
|
|
35
35
|
}, buf: BufferCursor | Buffer): Instruction;
|
|
36
|
-
|
|
36
|
+
toBuffer(): Buffer;
|
|
37
37
|
/**
|
|
38
38
|
* Returns a new instruction instance that can be serialized with the given opcode and wire format.
|
|
39
39
|
* @param opcode The opcode of the instruction.
|
|
40
40
|
* @param wireFormat The wire format of the instruction.
|
|
41
41
|
* @returns The new instruction instance.
|
|
42
42
|
*/
|
|
43
|
-
as(opcode: Opcode, wireFormat: OperandType[]): Instruction &
|
|
43
|
+
as(opcode: Opcode, wireFormat: OperandType[]): Instruction & Bufferable;
|
|
44
44
|
/**
|
|
45
45
|
* Returns a new instruction class that can be deserialized with the given opcode and wire format.
|
|
46
46
|
* @param opcode The opcode of the instruction.
|
|
@@ -48,7 +48,7 @@ export declare abstract class Instruction {
|
|
|
48
48
|
* @returns The new instruction class.
|
|
49
49
|
*/
|
|
50
50
|
static as(this: InstructionConstructor, wireFormat: OperandType[]): InstructionConstructor & {
|
|
51
|
-
|
|
51
|
+
fromBuffer: (buf: BufferCursor | Buffer) => Instruction;
|
|
52
52
|
};
|
|
53
53
|
/**
|
|
54
54
|
* Computes gas cost for the instruction based on its base cost and memory operations.
|