@aztec/simulator 0.43.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/acvm/oracle/oracle.d.ts +3 -1
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +12 -6
- package/dest/acvm/oracle/typed_oracle.d.ts +6 -4
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +8 -2
- package/dest/avm/avm_context.d.ts +1 -1
- package/dest/avm/avm_context.d.ts.map +1 -1
- package/dest/avm/avm_context.js +3 -3
- package/dest/avm/{avm_message_call_result.d.ts → avm_contract_call_result.d.ts} +2 -2
- package/dest/avm/avm_contract_call_result.d.ts.map +1 -0
- package/dest/avm/avm_contract_call_result.js +18 -0
- package/dest/avm/avm_execution_environment.d.ts +8 -10
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +15 -19
- package/dest/avm/avm_gas.js +2 -2
- package/dest/avm/avm_simulator.d.ts +4 -4
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +7 -8
- package/dest/avm/bytecode_utils.d.ts +5 -0
- package/dest/avm/bytecode_utils.d.ts.map +1 -0
- package/dest/avm/bytecode_utils.js +29 -0
- package/dest/avm/errors.js +2 -2
- package/dest/avm/fixtures/index.d.ts +10 -6
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +10 -17
- package/dest/avm/journal/journal.d.ts +56 -65
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +80 -117
- package/dest/avm/journal/nullifiers.d.ts +21 -8
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +26 -8
- package/dest/avm/journal/public_storage.d.ts +5 -1
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +11 -2
- package/dest/avm/opcodes/accrued_substate.d.ts +1 -2
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +8 -17
- package/dest/avm/opcodes/environment_getters.d.ts +13 -8
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +20 -13
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +11 -27
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +5 -5
- package/dest/avm/serialization/instruction_serialization.d.ts +9 -9
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +10 -10
- package/dest/avm/test_utils.d.ts +14 -0
- package/dest/avm/test_utils.d.ts.map +1 -0
- package/dest/avm/test_utils.js +36 -0
- package/dest/client/client_execution_context.d.ts +6 -4
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +8 -6
- package/dest/client/execution_note_cache.d.ts.map +1 -1
- package/dest/client/execution_note_cache.js +1 -1
- package/dest/client/execution_result.d.ts +2 -1
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +1 -1
- package/dest/client/index.d.ts +2 -0
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +3 -1
- package/dest/client/simulator.d.ts +3 -3
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +1 -1
- package/dest/client/view_data_oracle.d.ts +5 -1
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +12 -4
- package/dest/mocks/fixtures.d.ts +3 -3
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +6 -5
- package/dest/public/abstract_phase_manager.d.ts +1 -0
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +17 -14
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/public/app_logic_phase_manager.js +2 -1
- package/dest/public/execution.d.ts +33 -30
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +2 -2
- package/dest/public/executor.d.ts +12 -7
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +42 -33
- package/dest/public/hints_builder.d.ts +1 -1
- package/dest/public/index.d.ts +1 -1
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_kernel.d.ts +1 -1
- package/dest/public/public_kernel.d.ts.map +1 -1
- package/dest/public/public_kernel.js +2 -2
- package/dest/public/public_processor.d.ts +5 -2
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +142 -123
- package/dest/public/side_effect_trace.d.ts +87 -0
- package/dest/public/side_effect_trace.d.ts.map +1 -0
- package/dest/public/side_effect_trace.js +236 -0
- package/dest/public/side_effect_trace_interface.d.ts +36 -0
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -0
- package/dest/public/side_effect_trace_interface.js +2 -0
- package/dest/public/teardown_phase_manager.d.ts.map +1 -1
- package/dest/public/teardown_phase_manager.js +2 -1
- package/dest/rollup/rollup.d.ts +1 -1
- package/dest/rollup/rollup.d.ts.map +1 -1
- package/dest/rollup/rollup.js +2 -2
- package/package.json +18 -9
- package/src/acvm/oracle/oracle.ts +23 -5
- package/src/acvm/oracle/typed_oracle.ts +23 -4
- package/src/avm/avm_context.ts +2 -2
- package/src/avm/{avm_message_call_result.ts → avm_contract_call_result.ts} +1 -1
- package/src/avm/avm_execution_environment.ts +16 -26
- package/src/avm/avm_gas.ts +1 -1
- package/src/avm/avm_simulator.ts +10 -13
- package/src/avm/bytecode_utils.ts +32 -0
- package/src/avm/errors.ts +1 -1
- package/src/avm/fixtures/index.ts +21 -23
- package/src/avm/journal/journal.ts +118 -224
- package/src/avm/journal/nullifiers.ts +30 -13
- package/src/avm/journal/public_storage.ts +12 -2
- package/src/avm/opcodes/accrued_substate.ts +12 -21
- package/src/avm/opcodes/environment_getters.ts +23 -14
- package/src/avm/opcodes/external_calls.ts +13 -36
- package/src/avm/serialization/bytecode_serialization.ts +4 -3
- package/src/avm/serialization/instruction_serialization.ts +3 -3
- package/src/avm/test_utils.ts +53 -0
- package/src/client/client_execution_context.ts +22 -7
- package/src/client/execution_note_cache.ts +0 -1
- package/src/client/execution_result.ts +2 -1
- package/src/client/index.ts +2 -0
- package/src/client/simulator.ts +8 -2
- package/src/client/view_data_oracle.ts +20 -3
- package/src/mocks/fixtures.ts +7 -6
- package/src/public/abstract_phase_manager.ts +32 -21
- package/src/public/app_logic_phase_manager.ts +1 -0
- package/src/public/execution.ts +45 -31
- package/src/public/executor.ts +71 -49
- package/src/public/index.ts +1 -1
- package/src/public/public_kernel.ts +2 -1
- package/src/public/public_processor.ts +11 -2
- package/src/public/side_effect_trace.ts +341 -0
- package/src/public/side_effect_trace_interface.ts +41 -0
- package/src/public/teardown_phase_manager.ts +1 -0
- package/src/rollup/rollup.ts +3 -1
- package/dest/avm/avm_message_call_result.d.ts.map +0 -1
- package/dest/avm/avm_message_call_result.js +0 -18
- package/dest/avm/journal/trace.d.ts +0 -33
- package/dest/avm/journal/trace.d.ts.map +0 -1
- package/dest/avm/journal/trace.js +0 -152
- package/dest/avm/journal/trace_types.d.ts +0 -55
- package/dest/avm/journal/trace_types.d.ts.map +0 -1
- package/dest/avm/journal/trace_types.js +0 -2
- package/dest/public/transitional_adaptors.d.ts +0 -21
- package/dest/public/transitional_adaptors.d.ts.map +0 -1
- package/dest/public/transitional_adaptors.js +0 -90
- package/src/avm/journal/trace.ts +0 -181
- package/src/avm/journal/trace_types.ts +0 -91
- package/src/public/transitional_adaptors.ts +0 -168
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { FunctionSelector, type
|
|
1
|
+
import { FunctionSelector, type GlobalVariables, type Header } from '@aztec/circuits.js';
|
|
2
2
|
import { computeVarArgsHash } from '@aztec/circuits.js/hash';
|
|
3
3
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
|
|
6
6
|
export class AvmContextInputs {
|
|
7
|
-
static readonly SIZE =
|
|
7
|
+
static readonly SIZE = 2;
|
|
8
8
|
|
|
9
|
-
constructor(private
|
|
9
|
+
constructor(private argsHash: Fr, private isStaticCall: boolean) {}
|
|
10
10
|
|
|
11
11
|
public toFields(): Fr[] {
|
|
12
|
-
return [this.
|
|
12
|
+
return [this.argsHash, new Fr(this.isStaticCall)];
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -17,36 +17,24 @@ export class AvmContextInputs {
|
|
|
17
17
|
* Contains variables that remain constant during AVM execution
|
|
18
18
|
* These variables are provided by the public kernel circuit
|
|
19
19
|
*/
|
|
20
|
-
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/3992): gas not implemented
|
|
21
20
|
export class AvmExecutionEnvironment {
|
|
22
21
|
constructor(
|
|
23
22
|
public readonly address: AztecAddress,
|
|
24
23
|
public readonly storageAddress: AztecAddress,
|
|
25
24
|
public readonly sender: AztecAddress,
|
|
26
|
-
public readonly
|
|
27
|
-
public readonly feePerDaGas: Fr,
|
|
25
|
+
public readonly functionSelector: FunctionSelector, // may be temporary (#7224)
|
|
28
26
|
public readonly contractCallDepth: Fr,
|
|
27
|
+
public readonly transactionFee: Fr,
|
|
29
28
|
public readonly header: Header,
|
|
30
29
|
public readonly globals: GlobalVariables,
|
|
31
30
|
public readonly isStaticCall: boolean,
|
|
32
31
|
public readonly isDelegateCall: boolean,
|
|
33
32
|
public readonly calldata: Fr[],
|
|
34
|
-
public readonly gasSettings: GasSettings,
|
|
35
|
-
public readonly transactionFee: Fr,
|
|
36
|
-
|
|
37
|
-
// Function selector is temporary since eventually public contract bytecode will be one blob
|
|
38
|
-
// containing all functions, and function selector will become an application-level mechanism
|
|
39
|
-
// (e.g. first few bytes of calldata + compiler-generated jump table)
|
|
40
|
-
public readonly temporaryFunctionSelector: FunctionSelector,
|
|
41
33
|
) {
|
|
42
34
|
// We encode some extra inputs (AvmContextInputs) in calldata.
|
|
43
35
|
// This will have to go once we move away from one proof per call.
|
|
44
|
-
const inputs = new AvmContextInputs(
|
|
45
|
-
|
|
46
|
-
computeVarArgsHash(calldata),
|
|
47
|
-
isStaticCall,
|
|
48
|
-
);
|
|
49
|
-
this.calldata = [...inputs.toFields(), ...calldata];
|
|
36
|
+
const inputs = new AvmContextInputs(computeVarArgsHash(calldata), isStaticCall).toFields();
|
|
37
|
+
this.calldata = [...inputs, ...calldata];
|
|
50
38
|
}
|
|
51
39
|
|
|
52
40
|
private deriveEnvironmentForNestedCallInternal(
|
|
@@ -60,17 +48,14 @@ export class AvmExecutionEnvironment {
|
|
|
60
48
|
/*address=*/ targetAddress,
|
|
61
49
|
/*storageAddress=*/ targetAddress,
|
|
62
50
|
/*sender=*/ this.address,
|
|
63
|
-
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
51
|
+
functionSelector,
|
|
52
|
+
this.contractCallDepth.add(Fr.ONE),
|
|
53
|
+
this.transactionFee,
|
|
66
54
|
this.header,
|
|
67
55
|
this.globals,
|
|
68
56
|
isStaticCall,
|
|
69
57
|
isDelegateCall,
|
|
70
58
|
calldata,
|
|
71
|
-
this.gasSettings,
|
|
72
|
-
this.transactionFee,
|
|
73
|
-
functionSelector,
|
|
74
59
|
);
|
|
75
60
|
}
|
|
76
61
|
|
|
@@ -109,4 +94,9 @@ export class AvmExecutionEnvironment {
|
|
|
109
94
|
): AvmExecutionEnvironment {
|
|
110
95
|
throw new Error('Delegate calls not supported!');
|
|
111
96
|
}
|
|
97
|
+
|
|
98
|
+
public getCalldataWithoutPrefix(): Fr[] {
|
|
99
|
+
// clip off the first few entries
|
|
100
|
+
return this.calldata.slice(AvmContextInputs.SIZE);
|
|
101
|
+
}
|
|
112
102
|
}
|
package/src/avm/avm_gas.ts
CHANGED
|
@@ -76,7 +76,7 @@ const BaseGasCosts: Record<Opcode, Gas> = {
|
|
|
76
76
|
[Opcode.FEEPERL2GAS]: DefaultBaseGasCost,
|
|
77
77
|
[Opcode.FEEPERDAGAS]: DefaultBaseGasCost,
|
|
78
78
|
[Opcode.TRANSACTIONFEE]: DefaultBaseGasCost,
|
|
79
|
-
[Opcode.
|
|
79
|
+
[Opcode.FUNCTIONSELECTOR]: DefaultBaseGasCost,
|
|
80
80
|
[Opcode.CHAINID]: DefaultBaseGasCost,
|
|
81
81
|
[Opcode.VERSION]: DefaultBaseGasCost,
|
|
82
82
|
[Opcode.BLOCKNUMBER]: DefaultBaseGasCost,
|
package/src/avm/avm_simulator.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
|
2
2
|
|
|
3
3
|
import { strict as assert } from 'assert';
|
|
4
4
|
|
|
5
|
-
import { decompressBytecodeIfCompressed, isAvmBytecode } from '../public/transitional_adaptors.js';
|
|
6
5
|
import type { AvmContext } from './avm_context.js';
|
|
7
|
-
import {
|
|
6
|
+
import { AvmContractCallResult } from './avm_contract_call_result.js';
|
|
7
|
+
import { decompressBytecodeIfCompressed, isAvmBytecode } from './bytecode_utils.js';
|
|
8
8
|
import {
|
|
9
9
|
AvmExecutionError,
|
|
10
10
|
InvalidProgramCounterError,
|
|
@@ -20,19 +20,16 @@ export class AvmSimulator {
|
|
|
20
20
|
private bytecode: Buffer | undefined;
|
|
21
21
|
|
|
22
22
|
constructor(private context: AvmContext) {
|
|
23
|
-
this.log = createDebugLogger(
|
|
24
|
-
`aztec:avm_simulator:core(f:${context.environment.temporaryFunctionSelector.toString()})`,
|
|
25
|
-
);
|
|
23
|
+
this.log = createDebugLogger(`aztec:avm_simulator:core(f:${context.environment.functionSelector.toString()})`);
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
/**
|
|
29
27
|
* Fetch the bytecode and execute it in the current context.
|
|
30
28
|
*/
|
|
31
|
-
public async execute(): Promise<
|
|
32
|
-
const
|
|
33
|
-
const bytecode = await this.context.persistableState.hostStorage.contractsDb.getBytecode(
|
|
29
|
+
public async execute(): Promise<AvmContractCallResult> {
|
|
30
|
+
const bytecode = await this.context.persistableState.getBytecode(
|
|
34
31
|
this.context.environment.address,
|
|
35
|
-
|
|
32
|
+
this.context.environment.functionSelector,
|
|
36
33
|
);
|
|
37
34
|
|
|
38
35
|
// This assumes that we will not be able to send messages to accounts without code
|
|
@@ -55,7 +52,7 @@ export class AvmSimulator {
|
|
|
55
52
|
* Executes the provided bytecode in the current context.
|
|
56
53
|
* This method is useful for testing and debugging.
|
|
57
54
|
*/
|
|
58
|
-
public async executeBytecode(bytecode: Buffer): Promise<
|
|
55
|
+
public async executeBytecode(bytecode: Buffer): Promise<AvmContractCallResult> {
|
|
59
56
|
const decompressedBytecode = await decompressBytecodeIfCompressed(bytecode);
|
|
60
57
|
assert(isAvmBytecode(decompressedBytecode), "AVM simulator can't execute non-AVM bytecode");
|
|
61
58
|
|
|
@@ -67,7 +64,7 @@ export class AvmSimulator {
|
|
|
67
64
|
* Executes the provided instructions in the current context.
|
|
68
65
|
* This method is useful for testing and debugging.
|
|
69
66
|
*/
|
|
70
|
-
public async executeInstructions(instructions: Instruction[]): Promise<
|
|
67
|
+
public async executeInstructions(instructions: Instruction[]): Promise<AvmContractCallResult> {
|
|
71
68
|
assert(instructions.length > 0);
|
|
72
69
|
const { machineState } = this.context;
|
|
73
70
|
try {
|
|
@@ -96,7 +93,7 @@ export class AvmSimulator {
|
|
|
96
93
|
const output = machineState.getOutput();
|
|
97
94
|
const reverted = machineState.getReverted();
|
|
98
95
|
const revertReason = reverted ? revertReasonFromExplicitRevert(output, this.context) : undefined;
|
|
99
|
-
const results = new
|
|
96
|
+
const results = new AvmContractCallResult(reverted, output, revertReason);
|
|
100
97
|
this.log.debug(`Context execution results: ${results.toString()}`);
|
|
101
98
|
// Return results for processing by calling context
|
|
102
99
|
return results;
|
|
@@ -109,7 +106,7 @@ export class AvmSimulator {
|
|
|
109
106
|
|
|
110
107
|
const revertReason = revertReasonFromExceptionalHalt(err, this.context);
|
|
111
108
|
// Note: "exceptional halts" cannot return data, hence []
|
|
112
|
-
const results = new
|
|
109
|
+
const results = new AvmContractCallResult(/*reverted=*/ true, /*output=*/ [], revertReason);
|
|
113
110
|
this.log.debug(`Context execution results: ${results.toString()}`);
|
|
114
111
|
// Return results for processing by calling context
|
|
115
112
|
return results;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { promisify } from 'util';
|
|
2
|
+
import { gunzip } from 'zlib';
|
|
3
|
+
|
|
4
|
+
import { Mov } from '../avm/opcodes/memory.js';
|
|
5
|
+
|
|
6
|
+
const AVM_MAGIC_SUFFIX = Buffer.from([
|
|
7
|
+
Mov.opcode, // opcode
|
|
8
|
+
0x00, // indirect
|
|
9
|
+
...Buffer.from('000018ca', 'hex'), // srcOffset
|
|
10
|
+
...Buffer.from('000018ca', 'hex'), // dstOffset
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
export function markBytecodeAsAvm(bytecode: Buffer): Buffer {
|
|
14
|
+
return Buffer.concat([bytecode, AVM_MAGIC_SUFFIX]);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// This is just a helper function for the AVM simulator
|
|
18
|
+
export async function decompressBytecodeIfCompressed(bytecode: Buffer): Promise<Buffer> {
|
|
19
|
+
try {
|
|
20
|
+
return await promisify(gunzip)(bytecode);
|
|
21
|
+
} catch {
|
|
22
|
+
// If the bytecode is not compressed, the gunzip call will throw an error
|
|
23
|
+
// In this case, we assume the bytecode is not compressed and continue.
|
|
24
|
+
return Promise.resolve(bytecode);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function isAvmBytecode(bytecode: Buffer): Promise<boolean> {
|
|
29
|
+
const decompressedBytecode = await decompressBytecodeIfCompressed(bytecode);
|
|
30
|
+
const magicSize = AVM_MAGIC_SUFFIX.length;
|
|
31
|
+
return decompressedBytecode.subarray(-magicSize).equals(AVM_MAGIC_SUFFIX);
|
|
32
|
+
}
|
package/src/avm/errors.ts
CHANGED
|
@@ -113,7 +113,7 @@ function createRevertReason(message: string, context: AvmContext, nestedError?:
|
|
|
113
113
|
message,
|
|
114
114
|
/*failingFunction=*/ {
|
|
115
115
|
contractAddress: context.environment.address,
|
|
116
|
-
functionSelector: context.environment.
|
|
116
|
+
functionSelector: context.environment.functionSelector,
|
|
117
117
|
},
|
|
118
118
|
/*noirCallStack=*/ [...context.machineState.internalCallStack, context.machineState.pc].map(pc => `0.${pc}`),
|
|
119
119
|
/*options=*/ { cause: nestedError },
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { GasFees,
|
|
1
|
+
import { GasFees, GlobalVariables, Header } from '@aztec/circuits.js';
|
|
2
2
|
import { FunctionSelector } from '@aztec/foundation/abi';
|
|
3
3
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
6
6
|
import { AvmTestContractArtifact } from '@aztec/noir-contracts.js';
|
|
7
|
-
import { SerializableContractInstance } from '@aztec/types/contracts';
|
|
8
7
|
|
|
9
8
|
import { strict as assert } from 'assert';
|
|
10
9
|
import { mock } from 'jest-mock-extended';
|
|
11
10
|
import merge from 'lodash.merge';
|
|
12
11
|
|
|
13
12
|
import { type CommitmentsDB, type PublicContractsDB, type PublicStateDB } from '../../index.js';
|
|
13
|
+
import { type PublicSideEffectTraceInterface } from '../../public/side_effect_trace_interface.js';
|
|
14
14
|
import { AvmContext } from '../avm_context.js';
|
|
15
15
|
import { AvmContextInputs, AvmExecutionEnvironment } from '../avm_execution_environment.js';
|
|
16
16
|
import { AvmMachineState } from '../avm_machine_state.js';
|
|
17
17
|
import { Field, Uint8 } from '../avm_memory_types.js';
|
|
18
18
|
import { HostStorage } from '../journal/host_storage.js';
|
|
19
19
|
import { AvmPersistableStateManager } from '../journal/journal.js';
|
|
20
|
-
import {
|
|
20
|
+
import { NullifierManager } from '../journal/nullifiers.js';
|
|
21
|
+
import { PublicStorage } from '../journal/public_storage.js';
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* Create a new AVM context with default values.
|
|
@@ -28,7 +29,7 @@ export function initContext(overrides?: {
|
|
|
28
29
|
machineState?: AvmMachineState;
|
|
29
30
|
}): AvmContext {
|
|
30
31
|
return new AvmContext(
|
|
31
|
-
overrides?.persistableState ||
|
|
32
|
+
overrides?.persistableState || initPersistableStateManager(),
|
|
32
33
|
overrides?.env || initExecutionEnvironment(),
|
|
33
34
|
overrides?.machineState || initMachineState(),
|
|
34
35
|
);
|
|
@@ -47,9 +48,20 @@ export function initHostStorage(overrides?: {
|
|
|
47
48
|
);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
/** Creates an empty state manager with mocked storage. */
|
|
51
|
-
export function
|
|
52
|
-
|
|
51
|
+
/** Creates an empty state manager with mocked host storage. */
|
|
52
|
+
export function initPersistableStateManager(overrides?: {
|
|
53
|
+
hostStorage?: HostStorage;
|
|
54
|
+
trace?: PublicSideEffectTraceInterface;
|
|
55
|
+
publicStorage?: PublicStorage;
|
|
56
|
+
nullifiers?: NullifierManager;
|
|
57
|
+
}): AvmPersistableStateManager {
|
|
58
|
+
const hostStorage = overrides?.hostStorage || initHostStorage();
|
|
59
|
+
return new AvmPersistableStateManager(
|
|
60
|
+
hostStorage,
|
|
61
|
+
overrides?.trace || mock<PublicSideEffectTraceInterface>(),
|
|
62
|
+
overrides?.publicStorage || new PublicStorage(hostStorage.publicStateDb),
|
|
63
|
+
overrides?.nullifiers || new NullifierManager(hostStorage.commitmentsDb),
|
|
64
|
+
);
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
/**
|
|
@@ -60,17 +72,14 @@ export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnviron
|
|
|
60
72
|
overrides?.address ?? AztecAddress.zero(),
|
|
61
73
|
overrides?.storageAddress ?? AztecAddress.zero(),
|
|
62
74
|
overrides?.sender ?? AztecAddress.zero(),
|
|
63
|
-
overrides?.
|
|
64
|
-
overrides?.feePerDaGas ?? Fr.zero(),
|
|
75
|
+
overrides?.functionSelector ?? FunctionSelector.empty(),
|
|
65
76
|
overrides?.contractCallDepth ?? Fr.zero(),
|
|
77
|
+
overrides?.transactionFee ?? Fr.zero(),
|
|
66
78
|
overrides?.header ?? Header.empty(),
|
|
67
79
|
overrides?.globals ?? GlobalVariables.empty(),
|
|
68
80
|
overrides?.isStaticCall ?? false,
|
|
69
81
|
overrides?.isDelegateCall ?? false,
|
|
70
82
|
overrides?.calldata ?? [],
|
|
71
|
-
overrides?.gasSettings ?? GasSettings.empty(),
|
|
72
|
-
overrides?.transactionFee ?? Fr.ZERO,
|
|
73
|
-
overrides?.temporaryFunctionSelector ?? FunctionSelector.empty(),
|
|
74
83
|
);
|
|
75
84
|
}
|
|
76
85
|
|
|
@@ -138,14 +147,3 @@ export function getAvmTestContractBytecode(functionName: string): Buffer {
|
|
|
138
147
|
);
|
|
139
148
|
return artifact.bytecode;
|
|
140
149
|
}
|
|
141
|
-
|
|
142
|
-
export function randomTracedContractInstance(): TracedContractInstance {
|
|
143
|
-
const instance = SerializableContractInstance.random();
|
|
144
|
-
const address = AztecAddress.random();
|
|
145
|
-
return { exists: true, ...instance, address };
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function emptyTracedContractInstance(withAddress?: AztecAddress): TracedContractInstance {
|
|
149
|
-
const instance = SerializableContractInstance.empty().withAddress(withAddress ?? AztecAddress.zero());
|
|
150
|
-
return { exists: false, ...instance };
|
|
151
|
-
}
|