@aztec/simulator 0.24.0 → 0.26.1
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/deserialize.d.ts +5 -0
- package/dest/acvm/deserialize.d.ts.map +1 -1
- package/dest/acvm/deserialize.js +8 -1
- package/dest/acvm/oracle/oracle.d.ts +5 -4
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +24 -11
- package/dest/acvm/oracle/typed_oracle.d.ts +7 -9
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +9 -9
- package/dest/avm/avm_context.d.ts +4 -4
- package/dest/avm/avm_context.d.ts.map +1 -1
- package/dest/avm/avm_context.js +6 -6
- package/dest/avm/avm_memory_types.d.ts +11 -2
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +11 -1
- package/dest/avm/avm_simulator.d.ts +6 -4
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +17 -18
- package/dest/avm/fixtures/index.d.ts +17 -5
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +19 -8
- package/dest/avm/journal/host_storage.d.ts.map +1 -1
- package/dest/avm/journal/host_storage.js +1 -1
- package/dest/avm/journal/journal.d.ts +78 -50
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +125 -169
- package/dest/avm/journal/nullifiers.d.ts +85 -0
- package/dest/avm/journal/nullifiers.d.ts.map +1 -0
- package/dest/avm/journal/nullifiers.js +147 -0
- package/dest/avm/journal/public_storage.d.ts +88 -0
- package/dest/avm/journal/public_storage.d.ts.map +1 -0
- package/dest/avm/journal/public_storage.js +135 -0
- package/dest/avm/journal/trace.d.ts +43 -0
- package/dest/avm/journal/trace.d.ts.map +1 -0
- package/dest/avm/journal/trace.js +204 -0
- package/dest/avm/journal/trace_types.d.ts +26 -0
- package/dest/avm/journal/trace_types.d.ts.map +1 -0
- package/dest/avm/journal/trace_types.js +6 -0
- package/dest/avm/opcodes/accrued_substate.d.ts +37 -4
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +109 -12
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +5 -8
- package/dest/avm/opcodes/environment_getters.d.ts +14 -13
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +1 -1
- package/dest/avm/opcodes/external_calls.js +5 -5
- package/dest/avm/opcodes/hashing.d.ts +48 -0
- package/dest/avm/opcodes/hashing.d.ts.map +1 -0
- package/dest/avm/opcodes/hashing.js +127 -0
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +1 -1
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +3 -3
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +12 -8
- package/dest/avm/serialization/instruction_serialization.d.ts +10 -7
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +12 -9
- package/dest/avm/temporary_executor_migration.d.ts.map +1 -1
- package/dest/avm/temporary_executor_migration.js +5 -5
- package/dest/client/client_execution_context.d.ts +9 -5
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +46 -24
- package/dest/client/db_oracle.d.ts +7 -0
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/execution_note_cache.js +1 -1
- package/dest/client/execution_result.d.ts +2 -2
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +4 -4
- package/dest/client/simulator.d.ts +1 -1
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +3 -2
- package/dest/client/view_data_oracle.d.ts +9 -2
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +13 -5
- package/dest/public/db.d.ts +17 -4
- package/dest/public/db.d.ts.map +1 -1
- package/dest/public/execution.d.ts +9 -4
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +17 -4
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +18 -9
- package/dest/public/public_execution_context.d.ts +5 -4
- package/dest/public/public_execution_context.d.ts.map +1 -1
- package/dest/public/public_execution_context.js +23 -12
- package/dest/public/state_actions.js +2 -2
- package/dest/test/utils.js +4 -4
- package/dest/utils.js +2 -3
- package/package.json +6 -5
- package/src/acvm/deserialize.ts +8 -0
- package/src/acvm/oracle/oracle.ts +30 -6
- package/src/acvm/oracle/typed_oracle.ts +13 -5
- package/src/avm/avm_context.ts +5 -5
- package/src/avm/avm_memory_types.ts +18 -3
- package/src/avm/avm_simulator.ts +22 -24
- package/src/avm/fixtures/index.ts +34 -9
- package/src/avm/journal/host_storage.ts +5 -11
- package/src/avm/journal/journal.ts +147 -182
- package/src/avm/journal/nullifiers.ts +170 -0
- package/src/avm/journal/public_storage.ts +149 -0
- package/src/avm/journal/trace.ts +223 -0
- package/src/avm/journal/trace_types.ts +79 -0
- package/src/avm/opcodes/accrued_substate.ts +132 -10
- package/src/avm/opcodes/comparators.ts +4 -7
- package/src/avm/opcodes/environment_getters.ts +15 -13
- package/src/avm/opcodes/external_calls.ts +4 -4
- package/src/avm/opcodes/hashing.ts +170 -0
- package/src/avm/opcodes/memory.ts +1 -0
- package/src/avm/opcodes/storage.ts +5 -2
- package/src/avm/serialization/bytecode_serialization.ts +13 -6
- package/src/avm/serialization/instruction_serialization.ts +6 -3
- package/src/avm/temporary_executor_migration.ts +4 -3
- package/src/client/client_execution_context.ts +53 -23
- package/src/client/db_oracle.ts +8 -0
- package/src/client/execution_note_cache.ts +1 -1
- package/src/client/execution_result.ts +2 -2
- package/src/client/private_execution.ts +5 -4
- package/src/client/simulator.ts +2 -1
- package/src/client/view_data_oracle.ts +14 -4
- package/src/public/db.ts +19 -4
- package/src/public/execution.ts +30 -6
- package/src/public/executor.ts +29 -9
- package/src/public/public_execution_context.ts +36 -12
- package/src/public/state_actions.ts +1 -1
- package/src/test/utils.ts +3 -3
- package/src/utils.ts +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CompleteAddress,
|
|
3
|
-
L1ToL2Message,
|
|
4
3
|
MerkleTreeId,
|
|
5
4
|
Note,
|
|
6
5
|
NoteStatus,
|
|
@@ -21,6 +20,7 @@ import { FunctionSelector } from '@aztec/foundation/abi';
|
|
|
21
20
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
22
21
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
23
22
|
import { Fr } from '@aztec/foundation/fields';
|
|
23
|
+
import { ContractInstance } from '@aztec/types/contracts';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* A pair of public key and secret key.
|
|
@@ -58,8 +58,6 @@ export interface NoteData {
|
|
|
58
58
|
|
|
59
59
|
export class MessageLoadOracleInputs<N extends number> {
|
|
60
60
|
constructor(
|
|
61
|
-
/** The message. */
|
|
62
|
-
public message: L1ToL2Message,
|
|
63
61
|
/** The index of the message commitment in the merkle tree. */
|
|
64
62
|
public index: bigint,
|
|
65
63
|
/** The path in the merkle tree to the message. */
|
|
@@ -67,7 +65,7 @@ export class MessageLoadOracleInputs<N extends number> {
|
|
|
67
65
|
) {}
|
|
68
66
|
|
|
69
67
|
toFields(): Fr[] {
|
|
70
|
-
return [
|
|
68
|
+
return [new Fr(this.index), ...this.siblingPath.toFields()];
|
|
71
69
|
}
|
|
72
70
|
}
|
|
73
71
|
|
|
@@ -93,6 +91,10 @@ export abstract class TypedOracle {
|
|
|
93
91
|
throw new Error('Not available.');
|
|
94
92
|
}
|
|
95
93
|
|
|
94
|
+
getContractInstance(_address: AztecAddress): Promise<ContractInstance> {
|
|
95
|
+
throw new Error('Not available.');
|
|
96
|
+
}
|
|
97
|
+
|
|
96
98
|
getMembershipWitness(_blockNumber: number, _treeId: MerkleTreeId, _leafValue: Fr): Promise<Fr[] | undefined> {
|
|
97
99
|
throw new Error('Not available.');
|
|
98
100
|
}
|
|
@@ -159,7 +161,7 @@ export abstract class TypedOracle {
|
|
|
159
161
|
throw new Error('Not available.');
|
|
160
162
|
}
|
|
161
163
|
|
|
162
|
-
|
|
164
|
+
getL1ToL2MembershipWitness(_entryKey: Fr): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>> {
|
|
163
165
|
throw new Error('Not available.');
|
|
164
166
|
}
|
|
165
167
|
|
|
@@ -194,6 +196,8 @@ export abstract class TypedOracle {
|
|
|
194
196
|
_functionSelector: FunctionSelector,
|
|
195
197
|
_argsHash: Fr,
|
|
196
198
|
_sideffectCounter: number,
|
|
199
|
+
_isStaticCall: boolean,
|
|
200
|
+
_isDelegateCall: boolean,
|
|
197
201
|
): Promise<PrivateCallStackItem> {
|
|
198
202
|
throw new Error('Not available.');
|
|
199
203
|
}
|
|
@@ -202,6 +206,8 @@ export abstract class TypedOracle {
|
|
|
202
206
|
_targetContractAddress: AztecAddress,
|
|
203
207
|
_functionSelector: FunctionSelector,
|
|
204
208
|
_argsHash: Fr,
|
|
209
|
+
_isStaticCall: boolean,
|
|
210
|
+
_isDelegateCall: boolean,
|
|
205
211
|
): Promise<Fr[]> {
|
|
206
212
|
throw new Error('Not available.');
|
|
207
213
|
}
|
|
@@ -211,6 +217,8 @@ export abstract class TypedOracle {
|
|
|
211
217
|
_functionSelector: FunctionSelector,
|
|
212
218
|
_argsHash: Fr,
|
|
213
219
|
_sideffectCounter: number,
|
|
220
|
+
_isStaticCall: boolean,
|
|
221
|
+
_isDelegateCall: boolean,
|
|
214
222
|
): Promise<PublicCallRequest> {
|
|
215
223
|
throw new Error('Not available.');
|
|
216
224
|
}
|
package/src/avm/avm_context.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Fr } from '@aztec/foundation/fields';
|
|
|
3
3
|
|
|
4
4
|
import { AvmExecutionEnvironment } from './avm_execution_environment.js';
|
|
5
5
|
import { AvmMachineState } from './avm_machine_state.js';
|
|
6
|
-
import {
|
|
6
|
+
import { AvmPersistableStateManager } from './journal/journal.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* An execution context includes the information necessary to initiate AVM
|
|
@@ -12,13 +12,13 @@ import { AvmWorldStateJournal } from './journal/journal.js';
|
|
|
12
12
|
export class AvmContext {
|
|
13
13
|
/**
|
|
14
14
|
* Create a new AVM context
|
|
15
|
-
* @param
|
|
15
|
+
* @param persistableState - Manages world state and accrued substate during execution - (caching, fetching, tracing)
|
|
16
16
|
* @param environment - Contains constant variables provided by the kernel
|
|
17
17
|
* @param machineState - VM state that is modified on an instruction-by-instruction basis
|
|
18
18
|
* @returns new AvmContext instance
|
|
19
19
|
*/
|
|
20
20
|
constructor(
|
|
21
|
-
public
|
|
21
|
+
public persistableState: AvmPersistableStateManager,
|
|
22
22
|
public environment: AvmExecutionEnvironment,
|
|
23
23
|
public machineState: AvmMachineState,
|
|
24
24
|
) {}
|
|
@@ -37,7 +37,7 @@ export class AvmContext {
|
|
|
37
37
|
*/
|
|
38
38
|
public createNestedContractCallContext(address: AztecAddress, calldata: Fr[]): AvmContext {
|
|
39
39
|
const newExecutionEnvironment = this.environment.deriveEnvironmentForNestedCall(address, calldata);
|
|
40
|
-
const forkedWorldState = this.
|
|
40
|
+
const forkedWorldState = this.persistableState.fork();
|
|
41
41
|
const machineState = AvmMachineState.fromState(this.machineState);
|
|
42
42
|
return new AvmContext(forkedWorldState, newExecutionEnvironment, machineState);
|
|
43
43
|
}
|
|
@@ -56,7 +56,7 @@ export class AvmContext {
|
|
|
56
56
|
*/
|
|
57
57
|
public createNestedContractStaticCallContext(address: AztecAddress, calldata: Fr[]): AvmContext {
|
|
58
58
|
const newExecutionEnvironment = this.environment.deriveEnvironmentForNestedStaticCall(address, calldata);
|
|
59
|
-
const forkedWorldState = this.
|
|
59
|
+
const forkedWorldState = this.persistableState.fork();
|
|
60
60
|
const machineState = AvmMachineState.fromState(this.machineState);
|
|
61
61
|
return new AvmContext(forkedWorldState, newExecutionEnvironment, machineState);
|
|
62
62
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
3
|
|
|
3
4
|
import { strict as assert } from 'assert';
|
|
@@ -12,6 +13,7 @@ export abstract class MemoryValue {
|
|
|
12
13
|
public abstract div(rhs: MemoryValue): MemoryValue;
|
|
13
14
|
|
|
14
15
|
public abstract equals(rhs: MemoryValue): boolean;
|
|
16
|
+
public abstract lt(rhs: MemoryValue): boolean;
|
|
15
17
|
|
|
16
18
|
// We need this to be able to build an instance of the subclasses.
|
|
17
19
|
public abstract build(n: bigint): MemoryValue;
|
|
@@ -19,6 +21,9 @@ export abstract class MemoryValue {
|
|
|
19
21
|
// Use sparingly.
|
|
20
22
|
public abstract toBigInt(): bigint;
|
|
21
23
|
|
|
24
|
+
// To Buffer
|
|
25
|
+
public abstract toBuffer(): Buffer;
|
|
26
|
+
|
|
22
27
|
// To field
|
|
23
28
|
public toFr(): Fr {
|
|
24
29
|
return new Fr(this.toBigInt());
|
|
@@ -33,8 +38,6 @@ export abstract class IntegralValue extends MemoryValue {
|
|
|
33
38
|
public abstract or(rhs: IntegralValue): IntegralValue;
|
|
34
39
|
public abstract xor(rhs: IntegralValue): IntegralValue;
|
|
35
40
|
public abstract not(): IntegralValue;
|
|
36
|
-
|
|
37
|
-
public abstract lt(rhs: IntegralValue): boolean;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
/**
|
|
@@ -111,6 +114,10 @@ function UnsignedIntegerClassFactory(bits: number) {
|
|
|
111
114
|
public toBigInt(): bigint {
|
|
112
115
|
return this.n;
|
|
113
116
|
}
|
|
117
|
+
|
|
118
|
+
public toBuffer(): Buffer {
|
|
119
|
+
return toBufferBE(this.n, bits / 8);
|
|
120
|
+
}
|
|
114
121
|
};
|
|
115
122
|
}
|
|
116
123
|
|
|
@@ -127,7 +134,7 @@ export class Field extends MemoryValue {
|
|
|
127
134
|
public static readonly MODULUS: bigint = Fr.MODULUS;
|
|
128
135
|
private readonly rep: Fr;
|
|
129
136
|
|
|
130
|
-
constructor(v: number | bigint | Fr) {
|
|
137
|
+
constructor(v: number | bigint | Fr | Buffer) {
|
|
131
138
|
super();
|
|
132
139
|
this.rep = new Fr(v);
|
|
133
140
|
}
|
|
@@ -156,9 +163,17 @@ export class Field extends MemoryValue {
|
|
|
156
163
|
return this.rep.equals(rhs.rep);
|
|
157
164
|
}
|
|
158
165
|
|
|
166
|
+
public lt(rhs: Field): boolean {
|
|
167
|
+
return this.rep.lt(rhs.rep);
|
|
168
|
+
}
|
|
169
|
+
|
|
159
170
|
public toBigInt(): bigint {
|
|
160
171
|
return this.rep.toBigInt();
|
|
161
172
|
}
|
|
173
|
+
|
|
174
|
+
public toBuffer(): Buffer {
|
|
175
|
+
return this.rep.toBuffer();
|
|
176
|
+
}
|
|
162
177
|
}
|
|
163
178
|
|
|
164
179
|
export enum TypeTag {
|
package/src/avm/avm_simulator.ts
CHANGED
|
@@ -17,8 +17,27 @@ export class AvmSimulator {
|
|
|
17
17
|
* Fetch the bytecode and execute it in the current context.
|
|
18
18
|
*/
|
|
19
19
|
public async execute(): Promise<AvmContractCallResults> {
|
|
20
|
-
const
|
|
21
|
-
|
|
20
|
+
const selector = this.context.environment.temporaryFunctionSelector;
|
|
21
|
+
const bytecode = await this.context.persistableState.hostStorage.contractsDb.getBytecode(
|
|
22
|
+
this.context.environment.address,
|
|
23
|
+
selector,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// This assumes that we will not be able to send messages to accounts without code
|
|
27
|
+
// Pending classes and instances impl details
|
|
28
|
+
if (!bytecode) {
|
|
29
|
+
throw new NoBytecodeForContractError(this.context.environment.address);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return await this.executeBytecode(bytecode);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Executes the provided bytecode in the current context.
|
|
37
|
+
* This method is useful for testing and debugging.
|
|
38
|
+
*/
|
|
39
|
+
public async executeBytecode(bytecode: Buffer): Promise<AvmContractCallResults> {
|
|
40
|
+
return await this.executeInstructions(decodeFromBytecode(bytecode));
|
|
22
41
|
}
|
|
23
42
|
|
|
24
43
|
/**
|
|
@@ -35,7 +54,7 @@ export class AvmSimulator {
|
|
|
35
54
|
const instruction = instructions[this.context.machineState.pc];
|
|
36
55
|
assert(!!instruction); // This should never happen
|
|
37
56
|
|
|
38
|
-
this.log(
|
|
57
|
+
this.log.debug(`@${this.context.machineState.pc} ${instruction.toString()}`);
|
|
39
58
|
// Execute the instruction.
|
|
40
59
|
// Normal returns and reverts will return normally here.
|
|
41
60
|
// "Exceptional halts" will throw.
|
|
@@ -65,25 +84,4 @@ export class AvmSimulator {
|
|
|
65
84
|
return results;
|
|
66
85
|
}
|
|
67
86
|
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Fetch contract bytecode from world state and decode into executable instructions.
|
|
71
|
-
*/
|
|
72
|
-
private async fetchAndDecodeBytecode(): Promise<Instruction[]> {
|
|
73
|
-
// NOTE: the following is mocked as getPublicBytecode does not exist yet
|
|
74
|
-
|
|
75
|
-
const selector = this.context.environment.temporaryFunctionSelector;
|
|
76
|
-
const bytecode = await this.context.worldState.hostStorage.contractsDb.getBytecode(
|
|
77
|
-
this.context.environment.address,
|
|
78
|
-
selector,
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
// This assumes that we will not be able to send messages to accounts without code
|
|
82
|
-
// Pending classes and instances impl details
|
|
83
|
-
if (!bytecode) {
|
|
84
|
-
throw new NoBytecodeForContractError(this.context.environment.address);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return decodeFromBytecode(bytecode);
|
|
88
|
-
}
|
|
89
87
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SiblingPath } from '@aztec/circuit-types';
|
|
2
|
+
import { GlobalVariables, L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/circuits.js';
|
|
2
3
|
import { FunctionSelector } from '@aztec/foundation/abi';
|
|
3
4
|
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
@@ -7,32 +8,44 @@ import { Fr } from '@aztec/foundation/fields';
|
|
|
7
8
|
import { mock } from 'jest-mock-extended';
|
|
8
9
|
import merge from 'lodash.merge';
|
|
9
10
|
|
|
10
|
-
import { CommitmentsDB, PublicContractsDB, PublicStateDB } from '../../index.js';
|
|
11
|
+
import { CommitmentsDB, MessageLoadOracleInputs, PublicContractsDB, PublicStateDB } from '../../index.js';
|
|
11
12
|
import { AvmContext } from '../avm_context.js';
|
|
12
13
|
import { AvmExecutionEnvironment } from '../avm_execution_environment.js';
|
|
13
14
|
import { AvmMachineState } from '../avm_machine_state.js';
|
|
14
15
|
import { HostStorage } from '../journal/host_storage.js';
|
|
15
|
-
import {
|
|
16
|
+
import { AvmPersistableStateManager } from '../journal/journal.js';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Create a new AVM context with default values.
|
|
19
20
|
*/
|
|
20
21
|
export function initContext(overrides?: {
|
|
21
|
-
|
|
22
|
+
persistableState?: AvmPersistableStateManager;
|
|
22
23
|
env?: AvmExecutionEnvironment;
|
|
23
24
|
machineState?: AvmMachineState;
|
|
24
25
|
}): AvmContext {
|
|
25
26
|
return new AvmContext(
|
|
26
|
-
overrides?.
|
|
27
|
+
overrides?.persistableState || initMockPersistableStateManager(),
|
|
27
28
|
overrides?.env || initExecutionEnvironment(),
|
|
28
29
|
overrides?.machineState || initMachineState(),
|
|
29
30
|
);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
/** Creates an empty
|
|
33
|
-
export function
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
/** Creates an empty host storage with mocked dbs. */
|
|
34
|
+
export function initHostStorage(overrides?: {
|
|
35
|
+
publicDb?: PublicStateDB;
|
|
36
|
+
contractsDb?: PublicContractsDB;
|
|
37
|
+
commitmentsDb?: CommitmentsDB;
|
|
38
|
+
}): HostStorage {
|
|
39
|
+
return new HostStorage(
|
|
40
|
+
overrides?.publicDb || mock<PublicStateDB>(),
|
|
41
|
+
overrides?.contractsDb || mock<PublicContractsDB>(),
|
|
42
|
+
overrides?.commitmentsDb || mock<CommitmentsDB>(),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Creates an empty state manager with mocked storage. */
|
|
47
|
+
export function initMockPersistableStateManager(): AvmPersistableStateManager {
|
|
48
|
+
return new AvmPersistableStateManager(initHostStorage());
|
|
36
49
|
}
|
|
37
50
|
|
|
38
51
|
/**
|
|
@@ -88,3 +101,15 @@ export function initMachineState(overrides?: Partial<AvmMachineState>): AvmMachi
|
|
|
88
101
|
export function allSameExcept(original: any, overrides: any): any {
|
|
89
102
|
return merge({}, original, overrides);
|
|
90
103
|
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Create an empty L1ToL2Message oracle input
|
|
107
|
+
*/
|
|
108
|
+
export function initL1ToL2MessageOracleInput(
|
|
109
|
+
leafIndex?: bigint,
|
|
110
|
+
): MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT> {
|
|
111
|
+
return new MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>(
|
|
112
|
+
leafIndex ?? 0n,
|
|
113
|
+
new SiblingPath(L1_TO_L2_MSG_TREE_HEIGHT, Array(L1_TO_L2_MSG_TREE_HEIGHT)),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
@@ -6,15 +6,9 @@ import { CommitmentsDB, PublicContractsDB, PublicStateDB } from '../../public/db
|
|
|
6
6
|
* A wrapper around the node dbs
|
|
7
7
|
*/
|
|
8
8
|
export class HostStorage {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
constructor(publicStateDb: PublicStateDB, contractsDb: PublicContractsDB, commitmentsDb: CommitmentsDB) {
|
|
16
|
-
this.publicStateDb = publicStateDb;
|
|
17
|
-
this.contractsDb = contractsDb;
|
|
18
|
-
this.commitmentsDb = commitmentsDb;
|
|
19
|
-
}
|
|
9
|
+
constructor(
|
|
10
|
+
public readonly publicStateDb: PublicStateDB,
|
|
11
|
+
public readonly contractsDb: PublicContractsDB,
|
|
12
|
+
public readonly commitmentsDb: CommitmentsDB,
|
|
13
|
+
) {}
|
|
20
14
|
}
|