@aztec/simulator 0.55.1 → 0.57.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 +2 -5
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +6 -37
- package/dest/acvm/oracle/typed_oracle.d.ts +3 -6
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +1 -10
- package/dest/avm/avm_execution_environment.d.ts +2 -11
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +3 -22
- package/dest/avm/avm_gas.d.ts +2 -2
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +31 -116
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +6 -6
- package/dest/avm/avm_memory_types.d.ts +38 -9
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +27 -13
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +5 -6
- package/dest/avm/bytecode_utils.d.ts +1 -2
- package/dest/avm/bytecode_utils.d.ts.map +1 -1
- package/dest/avm/bytecode_utils.js +3 -17
- package/dest/avm/errors.d.ts +1 -1
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +12 -3
- package/dest/avm/fixtures/index.d.ts +4 -16
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +11 -27
- package/dest/avm/journal/index.d.ts +0 -1
- package/dest/avm/journal/index.d.ts.map +1 -1
- package/dest/avm/journal/index.js +1 -2
- package/dest/avm/journal/journal.d.ts +6 -5
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +18 -16
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +37 -30
- package/dest/avm/opcodes/addressing_mode.d.ts +3 -2
- package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/avm/opcodes/addressing_mode.js +25 -21
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +6 -5
- package/dest/avm/opcodes/bitwise.d.ts +10 -4
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +26 -18
- package/dest/avm/opcodes/commitment.d.ts.map +1 -1
- package/dest/avm/opcodes/commitment.js +6 -5
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +8 -7
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +6 -5
- package/dest/avm/opcodes/control_flow.js +6 -6
- package/dest/avm/opcodes/conversion.d.ts +3 -2
- package/dest/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/avm/opcodes/conversion.js +21 -13
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/avm/opcodes/ec_add.js +8 -7
- package/dest/avm/opcodes/environment_getters.d.ts +27 -63
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +76 -80
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +27 -16
- package/dest/avm/opcodes/hashing.d.ts +5 -5
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +47 -40
- package/dest/avm/opcodes/index.d.ts +3 -0
- package/dest/avm/opcodes/index.d.ts.map +1 -1
- package/dest/avm/opcodes/index.js +4 -1
- package/dest/avm/opcodes/instruction.d.ts +2 -6
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +3 -9
- package/dest/avm/opcodes/instruction_impl.d.ts +0 -26
- package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction_impl.js +1 -51
- package/dest/avm/opcodes/memory.d.ts +5 -12
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +40 -53
- package/dest/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/avm/opcodes/misc.js +6 -5
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
- package/dest/avm/opcodes/multi_scalar_mul.js +17 -16
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +11 -9
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +5 -25
- package/dest/avm/serialization/instruction_serialization.d.ts +40 -54
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +41 -57
- package/dest/avm/test_utils.d.ts +8 -8
- package/dest/avm/test_utils.d.ts.map +1 -1
- package/dest/avm/test_utils.js +15 -15
- package/dest/client/client_execution_context.d.ts +6 -30
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +31 -53
- package/dest/client/index.d.ts +0 -1
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -2
- package/dest/client/private_execution.d.ts +2 -2
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +5 -19
- package/dest/client/simulator.d.ts +3 -4
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +1 -1
- package/dest/client/test_utils.d.ts.map +1 -1
- package/dest/client/test_utils.js +12 -6
- package/dest/client/unconstrained_execution.d.ts +2 -2
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +3 -3
- package/dest/common/debug_fn_name.d.ts +4 -0
- package/dest/common/debug_fn_name.d.ts.map +1 -0
- package/dest/common/debug_fn_name.js +15 -0
- package/dest/common/index.d.ts +0 -1
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +1 -2
- package/dest/public/enqueued_call_simulator.d.ts +43 -0
- package/dest/public/enqueued_call_simulator.d.ts.map +1 -0
- package/dest/public/enqueued_call_simulator.js +154 -0
- package/dest/public/enqueued_calls_processor.d.ts +44 -0
- package/dest/public/enqueued_calls_processor.d.ts.map +1 -0
- package/dest/public/enqueued_calls_processor.js +218 -0
- package/dest/public/execution.d.ts +10 -8
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +15 -8
- package/dest/public/executor.d.ts +4 -7
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +10 -14
- package/dest/public/hints_builder.d.ts +4 -3
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +5 -5
- package/dest/public/index.d.ts +3 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +3 -3
- package/dest/public/public_db_sources.d.ts +17 -24
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +58 -65
- package/dest/public/public_kernel.d.ts +3 -9
- package/dest/public/public_kernel.d.ts.map +1 -1
- package/dest/public/public_kernel.js +13 -40
- package/dest/public/public_kernel_circuit_simulator.d.ts +5 -11
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +1 -1
- package/dest/public/public_kernel_tail_simulator.d.ts +19 -0
- package/dest/public/public_kernel_tail_simulator.d.ts.map +1 -0
- package/dest/public/public_kernel_tail_simulator.js +45 -0
- package/dest/public/public_processor.d.ts +9 -5
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +34 -48
- package/dest/public/public_processor_metrics.d.ts +3 -3
- package/dest/public/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor_metrics.js +1 -1
- package/dest/public/side_effect_errors.d.ts +4 -0
- package/dest/public/side_effect_errors.d.ts.map +1 -0
- package/dest/public/side_effect_errors.js +7 -0
- package/dest/public/side_effect_trace.d.ts +2 -2
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +56 -35
- package/dest/public/side_effect_trace_interface.d.ts +1 -1
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/package.json +12 -9
- package/src/acvm/oracle/oracle.ts +7 -85
- package/src/acvm/oracle/typed_oracle.ts +2 -31
- package/src/avm/avm_execution_environment.ts +2 -24
- package/src/avm/avm_gas.ts +30 -115
- package/src/avm/avm_machine_state.ts +5 -5
- package/src/avm/avm_memory_types.ts +41 -14
- package/src/avm/avm_simulator.ts +4 -5
- package/src/avm/bytecode_utils.ts +2 -17
- package/src/avm/errors.ts +11 -3
- package/src/avm/fixtures/index.ts +13 -46
- package/src/avm/journal/index.ts +0 -1
- package/src/avm/journal/journal.ts +22 -22
- package/src/avm/opcodes/accrued_substate.ts +36 -44
- package/src/avm/opcodes/addressing_mode.ts +27 -24
- package/src/avm/opcodes/arithmetic.ts +5 -7
- package/src/avm/opcodes/bitwise.ts +23 -20
- package/src/avm/opcodes/commitment.ts +6 -7
- package/src/avm/opcodes/comparators.ts +7 -9
- package/src/avm/opcodes/contract.ts +5 -7
- package/src/avm/opcodes/control_flow.ts +5 -5
- package/src/avm/opcodes/conversion.ts +19 -12
- package/src/avm/opcodes/ec_add.ts +14 -16
- package/src/avm/opcodes/environment_getters.ts +73 -99
- package/src/avm/opcodes/external_calls.ts +27 -20
- package/src/avm/opcodes/hashing.ts +52 -52
- package/src/avm/opcodes/index.ts +3 -0
- package/src/avm/opcodes/instruction.ts +3 -10
- package/src/avm/opcodes/instruction_impl.ts +0 -62
- package/src/avm/opcodes/memory.ts +37 -67
- package/src/avm/opcodes/misc.ts +5 -7
- package/src/avm/opcodes/multi_scalar_mul.ts +16 -19
- package/src/avm/opcodes/storage.ts +10 -8
- package/src/avm/serialization/bytecode_serialization.ts +11 -35
- package/src/avm/serialization/instruction_serialization.ts +3 -19
- package/src/avm/test_utils.ts +20 -16
- package/src/client/client_execution_context.ts +40 -96
- package/src/client/index.ts +0 -1
- package/src/client/private_execution.ts +9 -9
- package/src/client/simulator.ts +2 -3
- package/src/client/test_utils.ts +36 -9
- package/src/client/unconstrained_execution.ts +3 -8
- package/src/common/debug_fn_name.ts +22 -0
- package/src/common/index.ts +0 -1
- package/src/public/enqueued_call_simulator.ts +335 -0
- package/src/public/enqueued_calls_processor.ts +388 -0
- package/src/public/execution.ts +16 -12
- package/src/public/executor.ts +8 -22
- package/src/public/hints_builder.ts +21 -21
- package/src/public/index.ts +3 -2
- package/src/public/public_db_sources.ts +62 -67
- package/src/public/public_kernel.ts +15 -49
- package/src/public/public_kernel_circuit_simulator.ts +6 -10
- package/src/public/public_kernel_tail_simulator.ts +106 -0
- package/src/public/public_processor.ts +65 -86
- package/src/public/public_processor_metrics.ts +3 -3
- package/src/public/side_effect_errors.ts +6 -0
- package/src/public/side_effect_trace.ts +77 -39
- package/src/public/side_effect_trace_interface.ts +2 -2
- package/dest/avm/journal/host_storage.d.ts +0 -13
- package/dest/avm/journal/host_storage.d.ts.map +0 -1
- package/dest/avm/journal/host_storage.js +0 -13
- package/dest/avm/opcodes/context_getters.d.ts +0 -15
- package/dest/avm/opcodes/context_getters.d.ts.map +0 -1
- package/dest/avm/opcodes/context_getters.js +0 -19
- package/dest/client/execution_result.d.ts +0 -104
- package/dest/client/execution_result.d.ts.map +0 -1
- package/dest/client/execution_result.js +0 -136
- package/dest/common/return_values.d.ts +0 -11
- package/dest/common/return_values.d.ts.map +0 -1
- package/dest/common/return_values.js +0 -13
- package/dest/public/abstract_phase_manager.d.ts +0 -93
- package/dest/public/abstract_phase_manager.d.ts.map +0 -1
- package/dest/public/abstract_phase_manager.js +0 -285
- package/dest/public/app_logic_phase_manager.d.ts +0 -25
- package/dest/public/app_logic_phase_manager.d.ts.map +0 -1
- package/dest/public/app_logic_phase_manager.js +0 -52
- package/dest/public/phase_manager_factory.d.ts +0 -18
- package/dest/public/phase_manager_factory.d.ts.map +0 -1
- package/dest/public/phase_manager_factory.js +0 -56
- package/dest/public/setup_phase_manager.d.ts +0 -25
- package/dest/public/setup_phase_manager.d.ts.map +0 -1
- package/dest/public/setup_phase_manager.js +0 -39
- package/dest/public/tail_phase_manager.d.ts +0 -23
- package/dest/public/tail_phase_manager.d.ts.map +0 -1
- package/dest/public/tail_phase_manager.js +0 -50
- package/dest/public/teardown_phase_manager.d.ts +0 -27
- package/dest/public/teardown_phase_manager.d.ts.map +0 -1
- package/dest/public/teardown_phase_manager.js +0 -56
- package/src/avm/journal/host_storage.ts +0 -14
- package/src/avm/opcodes/context_getters.ts +0 -23
- package/src/client/execution_result.ts +0 -228
- package/src/common/return_values.ts +0 -18
- package/src/public/abstract_phase_manager.ts +0 -522
- package/src/public/app_logic_phase_manager.ts +0 -81
- package/src/public/phase_manager_factory.ts +0 -126
- package/src/public/setup_phase_manager.ts +0 -61
- package/src/public/tail_phase_manager.ts +0 -127
- package/src/public/teardown_phase_manager.ts +0 -86
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
import { type AvmContext } from '../avm_context.js';
|
|
2
|
-
import { type MemoryValue } from '../avm_memory_types.js';
|
|
3
1
|
import { OperandType } from '../serialization/instruction_serialization.js';
|
|
4
|
-
import { Addressing } from './addressing_mode.js';
|
|
5
2
|
import { Instruction } from './instruction.js';
|
|
6
3
|
|
|
7
|
-
/** Wire format that informs deserialization for instructions with two operands. */
|
|
8
|
-
export const TwoOperandWireFormat8 = [
|
|
9
|
-
OperandType.UINT8,
|
|
10
|
-
OperandType.UINT8,
|
|
11
|
-
OperandType.UINT8,
|
|
12
|
-
OperandType.UINT8,
|
|
13
|
-
OperandType.UINT8,
|
|
14
|
-
];
|
|
15
|
-
export const TwoOperandWireFormat16 = [
|
|
16
|
-
OperandType.UINT8,
|
|
17
|
-
OperandType.UINT8,
|
|
18
|
-
OperandType.UINT8,
|
|
19
|
-
OperandType.UINT16,
|
|
20
|
-
OperandType.UINT16,
|
|
21
|
-
];
|
|
22
|
-
|
|
23
4
|
/** Wire format that informs deserialization for instructions with three operands. */
|
|
24
5
|
export const ThreeOperandWireFormat8 = [
|
|
25
6
|
OperandType.UINT8,
|
|
@@ -38,25 +19,6 @@ export const ThreeOperandWireFormat16 = [
|
|
|
38
19
|
OperandType.UINT16,
|
|
39
20
|
];
|
|
40
21
|
|
|
41
|
-
/**
|
|
42
|
-
* Covers (de)serialization for an instruction with:
|
|
43
|
-
* indirect, inTag, and two operands.
|
|
44
|
-
*/
|
|
45
|
-
export abstract class TwoOperandInstruction extends Instruction {
|
|
46
|
-
// Informs (de)serialization. See Instruction.deserialize.
|
|
47
|
-
static readonly wireFormat8: OperandType[] = TwoOperandWireFormat8;
|
|
48
|
-
static readonly wireFormat16: OperandType[] = TwoOperandWireFormat16;
|
|
49
|
-
|
|
50
|
-
constructor(
|
|
51
|
-
protected indirect: number,
|
|
52
|
-
protected inTag: number,
|
|
53
|
-
protected aOffset: number,
|
|
54
|
-
protected dstOffset: number,
|
|
55
|
-
) {
|
|
56
|
-
super();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
22
|
/**
|
|
61
23
|
* Covers (de)serialization for an instruction with:
|
|
62
24
|
* indirect, inTag, and three operands.
|
|
@@ -75,27 +37,3 @@ export abstract class ThreeOperandInstruction extends Instruction {
|
|
|
75
37
|
super();
|
|
76
38
|
}
|
|
77
39
|
}
|
|
78
|
-
|
|
79
|
-
export abstract class GetterInstruction extends Instruction {
|
|
80
|
-
// Informs (de)serialization. See Instruction.deserialize.
|
|
81
|
-
static readonly wireFormat: OperandType[] = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT32];
|
|
82
|
-
|
|
83
|
-
constructor(protected indirect: number, protected dstOffset: number) {
|
|
84
|
-
super();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public async execute(context: AvmContext): Promise<void> {
|
|
88
|
-
const memoryOperations = { writes: 1, indirect: this.indirect };
|
|
89
|
-
const memory = context.machineState.memory.track(this.type);
|
|
90
|
-
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
91
|
-
|
|
92
|
-
const [dstOffset] = Addressing.fromWire(this.indirect).resolve([this.dstOffset], memory);
|
|
93
|
-
|
|
94
|
-
memory.set(dstOffset, this.getValue(context));
|
|
95
|
-
|
|
96
|
-
memory.assert(memoryOperations);
|
|
97
|
-
context.machineState.incrementPc();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
protected abstract getValue(env: AvmContext): MemoryValue;
|
|
101
|
-
}
|
|
@@ -3,7 +3,6 @@ import { Field, TaggedMemory } from '../avm_memory_types.js';
|
|
|
3
3
|
import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
|
|
4
4
|
import { Addressing } from './addressing_mode.js';
|
|
5
5
|
import { Instruction } from './instruction.js';
|
|
6
|
-
import { TwoOperandInstruction } from './instruction_impl.js';
|
|
7
6
|
|
|
8
7
|
export class Set extends Instruction {
|
|
9
8
|
static readonly type: string = 'SET';
|
|
@@ -63,85 +62,57 @@ export class Set extends Instruction {
|
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
public async execute(context: AvmContext): Promise<void> {
|
|
66
|
-
const memoryOperations = { writes: 1, indirect: this.indirect };
|
|
67
65
|
const memory = context.machineState.memory.track(this.type);
|
|
68
|
-
context.machineState.consumeGas(this.gasCost(
|
|
66
|
+
context.machineState.consumeGas(this.gasCost());
|
|
69
67
|
|
|
70
|
-
const
|
|
68
|
+
const operands = [this.dstOffset];
|
|
69
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
70
|
+
const [dstOffset] = addressing.resolve(operands, memory);
|
|
71
71
|
const res = TaggedMemory.buildFromTagTruncating(this.value, this.inTag);
|
|
72
72
|
memory.set(dstOffset, res);
|
|
73
73
|
|
|
74
|
-
memory.assert(
|
|
74
|
+
memory.assert({ writes: 1, addressing });
|
|
75
75
|
context.machineState.incrementPc();
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export class
|
|
80
|
-
static readonly type: string = '
|
|
81
|
-
static readonly opcode
|
|
82
|
-
|
|
83
|
-
static readonly
|
|
79
|
+
export class Cast extends Instruction {
|
|
80
|
+
static readonly type: string = 'CAST';
|
|
81
|
+
static readonly opcode = Opcode.CAST_8;
|
|
82
|
+
|
|
83
|
+
static readonly wireFormat8 = [
|
|
84
|
+
OperandType.UINT8,
|
|
85
|
+
OperandType.UINT8,
|
|
86
|
+
OperandType.UINT8,
|
|
84
87
|
OperandType.UINT8,
|
|
85
88
|
OperandType.UINT8,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
OperandType.
|
|
89
|
-
OperandType.
|
|
89
|
+
];
|
|
90
|
+
static readonly wireFormat16 = [
|
|
91
|
+
OperandType.UINT8,
|
|
92
|
+
OperandType.UINT8,
|
|
93
|
+
OperandType.UINT8,
|
|
94
|
+
OperandType.UINT16,
|
|
95
|
+
OperandType.UINT16,
|
|
90
96
|
];
|
|
91
97
|
|
|
92
|
-
constructor(
|
|
93
|
-
private indirect: number,
|
|
94
|
-
private aOffset: number,
|
|
95
|
-
private bOffset: number,
|
|
96
|
-
private condOffset: number,
|
|
97
|
-
private dstOffset: number,
|
|
98
|
-
) {
|
|
98
|
+
constructor(private indirect: number, private dstTag: number, private srcOffset: number, private dstOffset: number) {
|
|
99
99
|
super();
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
public async execute(context: AvmContext): Promise<void> {
|
|
103
|
-
const memoryOperations = { reads: 3, writes: 1, indirect: this.indirect };
|
|
104
|
-
const memory = context.machineState.memory.track(this.type);
|
|
105
|
-
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
106
|
-
|
|
107
|
-
const [aOffset, bOffset, condOffset, dstOffset] = Addressing.fromWire(this.indirect).resolve(
|
|
108
|
-
[this.aOffset, this.bOffset, this.condOffset, this.dstOffset],
|
|
109
|
-
memory,
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const a = memory.get(aOffset);
|
|
113
|
-
const b = memory.get(bOffset);
|
|
114
|
-
const cond = memory.get(condOffset);
|
|
115
|
-
|
|
116
|
-
// TODO: reconsider toBigInt() here
|
|
117
|
-
memory.set(dstOffset, cond.toBigInt() > 0 ? a : b);
|
|
118
|
-
|
|
119
|
-
memory.assert(memoryOperations);
|
|
120
|
-
context.machineState.incrementPc();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export class Cast extends TwoOperandInstruction {
|
|
125
|
-
static readonly type: string = 'CAST';
|
|
126
|
-
static readonly opcode = Opcode.CAST_8;
|
|
127
|
-
|
|
128
|
-
constructor(indirect: number, dstTag: number, srcOffset: number, dstOffset: number) {
|
|
129
|
-
super(indirect, dstTag, srcOffset, dstOffset);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
public async execute(context: AvmContext): Promise<void> {
|
|
133
|
-
const memoryOperations = { reads: 1, writes: 1, indirect: this.indirect };
|
|
134
103
|
const memory = context.machineState.memory.track(this.type);
|
|
135
|
-
context.machineState.consumeGas(this.gasCost(
|
|
104
|
+
context.machineState.consumeGas(this.gasCost());
|
|
136
105
|
|
|
137
|
-
const
|
|
106
|
+
const operands = [this.srcOffset, this.dstOffset];
|
|
107
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
108
|
+
const [srcOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
138
109
|
|
|
139
110
|
const a = memory.get(srcOffset);
|
|
140
|
-
const casted = TaggedMemory.buildFromTagTruncating(a.toBigInt(), this.
|
|
111
|
+
const casted = TaggedMemory.buildFromTagTruncating(a.toBigInt(), this.dstTag);
|
|
141
112
|
|
|
142
113
|
memory.set(dstOffset, casted);
|
|
143
114
|
|
|
144
|
-
memory.assert(
|
|
115
|
+
memory.assert({ reads: 1, writes: 1, addressing });
|
|
145
116
|
context.machineState.incrementPc();
|
|
146
117
|
}
|
|
147
118
|
}
|
|
@@ -169,17 +140,18 @@ export class Mov extends Instruction {
|
|
|
169
140
|
}
|
|
170
141
|
|
|
171
142
|
public async execute(context: AvmContext): Promise<void> {
|
|
172
|
-
const memoryOperations = { reads: 1, writes: 1, indirect: this.indirect };
|
|
173
143
|
const memory = context.machineState.memory.track(this.type);
|
|
174
|
-
context.machineState.consumeGas(this.gasCost(
|
|
144
|
+
context.machineState.consumeGas(this.gasCost());
|
|
175
145
|
|
|
176
|
-
const
|
|
146
|
+
const operands = [this.srcOffset, this.dstOffset];
|
|
147
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
148
|
+
const [srcOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
177
149
|
|
|
178
150
|
const a = memory.get(srcOffset);
|
|
179
151
|
|
|
180
152
|
memory.set(dstOffset, a);
|
|
181
153
|
|
|
182
|
-
memory.assert(
|
|
154
|
+
memory.assert({ reads: 1, writes: 1, addressing });
|
|
183
155
|
context.machineState.incrementPc();
|
|
184
156
|
}
|
|
185
157
|
}
|
|
@@ -208,21 +180,19 @@ export class CalldataCopy extends Instruction {
|
|
|
208
180
|
public async execute(context: AvmContext): Promise<void> {
|
|
209
181
|
const memory = context.machineState.memory.track(this.type);
|
|
210
182
|
// We don't need to check tags here because: (1) the calldata is NOT in memory, and (2) we are the ones writing to destination.
|
|
211
|
-
const [cdStartOffset, copySizeOffset, dstOffset]
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
);
|
|
183
|
+
const operands = [this.cdStartOffset, this.copySizeOffset, this.dstOffset];
|
|
184
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
185
|
+
const [cdStartOffset, copySizeOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
215
186
|
|
|
216
187
|
const cdStart = memory.get(cdStartOffset).toNumber();
|
|
217
188
|
const copySize = memory.get(copySizeOffset).toNumber();
|
|
218
|
-
|
|
219
|
-
context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: copySize }));
|
|
189
|
+
context.machineState.consumeGas(this.gasCost(copySize));
|
|
220
190
|
|
|
221
191
|
const transformedData = context.environment.calldata.slice(cdStart, cdStart + copySize).map(f => new Field(f));
|
|
222
192
|
|
|
223
193
|
memory.setSlice(dstOffset, transformedData);
|
|
224
194
|
|
|
225
|
-
memory.assert(
|
|
195
|
+
memory.assert({ reads: 2, writes: copySize, addressing });
|
|
226
196
|
context.machineState.incrementPc();
|
|
227
197
|
}
|
|
228
198
|
}
|
package/src/avm/opcodes/misc.ts
CHANGED
|
@@ -33,17 +33,15 @@ export class DebugLog extends Instruction {
|
|
|
33
33
|
|
|
34
34
|
public async execute(context: AvmContext): Promise<void> {
|
|
35
35
|
const memory = context.machineState.memory.track(this.type);
|
|
36
|
-
const [messageOffset, fieldsOffset, fieldsSizeOffset]
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
36
|
+
const operands = [this.messageOffset, this.fieldsOffset, this.fieldsSizeOffset];
|
|
37
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
38
|
+
const [messageOffset, fieldsOffset, fieldsSizeOffset] = addressing.resolve(operands, memory);
|
|
40
39
|
|
|
41
40
|
const fieldsSize = memory.get(fieldsSizeOffset).toNumber();
|
|
42
41
|
memory.checkTagsRange(TypeTag.UINT8, messageOffset, this.messageSize);
|
|
43
42
|
memory.checkTagsRange(TypeTag.FIELD, fieldsOffset, fieldsSize);
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
44
|
+
context.machineState.consumeGas(this.gasCost());
|
|
47
45
|
|
|
48
46
|
const rawMessage = memory.getSlice(messageOffset, this.messageSize);
|
|
49
47
|
const fields = memory.getSlice(fieldsOffset, fieldsSize);
|
|
@@ -57,7 +55,7 @@ export class DebugLog extends Instruction {
|
|
|
57
55
|
|
|
58
56
|
DebugLog.logger.verbose(formattedStr);
|
|
59
57
|
|
|
60
|
-
memory.assert(
|
|
58
|
+
memory.assert({ reads: 1 + fieldsSize + this.messageSize, addressing });
|
|
61
59
|
context.machineState.incrementPc();
|
|
62
60
|
}
|
|
63
61
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Fq, Point } from '@aztec/circuits.js';
|
|
2
2
|
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
3
3
|
|
|
4
|
-
import { strict as assert } from 'assert';
|
|
5
|
-
|
|
6
4
|
import { type AvmContext } from '../avm_context.js';
|
|
7
5
|
import { Field, TypeTag } from '../avm_memory_types.js';
|
|
8
6
|
import { InstructionExecutionError } from '../errors.js';
|
|
@@ -37,16 +35,17 @@ export class MultiScalarMul extends Instruction {
|
|
|
37
35
|
public async execute(context: AvmContext): Promise<void> {
|
|
38
36
|
const memory = context.machineState.memory.track(this.type);
|
|
39
37
|
// Resolve indirects
|
|
40
|
-
const [pointsOffset, scalarsOffset, outputOffset
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
);
|
|
38
|
+
const operands = [this.pointsOffset, this.scalarsOffset, this.outputOffset, this.pointsLengthOffset];
|
|
39
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
40
|
+
const [pointsOffset, scalarsOffset, outputOffset, pointsLengthOffset] = addressing.resolve(operands, memory);
|
|
44
41
|
|
|
45
42
|
// Length of the points vector should be U32
|
|
46
|
-
memory.checkTag(TypeTag.UINT32,
|
|
43
|
+
memory.checkTag(TypeTag.UINT32, pointsLengthOffset);
|
|
47
44
|
// Get the size of the unrolled (x, y , inf) points vector
|
|
48
|
-
const pointsReadLength = memory.get(
|
|
49
|
-
|
|
45
|
+
const pointsReadLength = memory.get(pointsLengthOffset).toNumber();
|
|
46
|
+
if (pointsReadLength % 3 !== 0) {
|
|
47
|
+
throw new InstructionExecutionError(`Points vector offset should be a multiple of 3, was ${pointsReadLength}`);
|
|
48
|
+
}
|
|
50
49
|
// Divide by 3 since each point is represented as a triplet to get the number of points
|
|
51
50
|
const numPoints = pointsReadLength / 3;
|
|
52
51
|
// The tag for each triplet will be (Field, Field, Uint8)
|
|
@@ -54,21 +53,15 @@ export class MultiScalarMul extends Instruction {
|
|
|
54
53
|
const offset = pointsOffset + i * 3;
|
|
55
54
|
// Check (Field, Field)
|
|
56
55
|
memory.checkTagsRange(TypeTag.FIELD, offset, 2);
|
|
57
|
-
// Check
|
|
58
|
-
memory.checkTag(TypeTag.
|
|
56
|
+
// Check Uint1 (inf flag)
|
|
57
|
+
memory.checkTag(TypeTag.UINT1, offset + 2);
|
|
59
58
|
}
|
|
60
59
|
// Get the unrolled (x, y, inf) representing the points
|
|
61
60
|
const pointsVector = memory.getSlice(pointsOffset, pointsReadLength);
|
|
62
61
|
|
|
63
62
|
// The size of the scalars vector is twice the NUMBER of points because of the scalar limb decomposition
|
|
64
63
|
const scalarReadLength = numPoints * 2;
|
|
65
|
-
|
|
66
|
-
const memoryOperations = {
|
|
67
|
-
reads: 1 + pointsReadLength + scalarReadLength /* points and scalars */,
|
|
68
|
-
writes: 3 /* output triplet */,
|
|
69
|
-
indirect: this.indirect,
|
|
70
|
-
};
|
|
71
|
-
context.machineState.consumeGas(this.gasCost(memoryOperations));
|
|
64
|
+
context.machineState.consumeGas(this.gasCost(pointsReadLength));
|
|
72
65
|
// Get the unrolled scalar (lo & hi) representing the scalars
|
|
73
66
|
const scalarsVector = memory.getSlice(scalarsOffset, scalarReadLength);
|
|
74
67
|
memory.checkTagsRange(TypeTag.FIELD, scalarsOffset, scalarReadLength);
|
|
@@ -108,7 +101,11 @@ export class MultiScalarMul extends Instruction {
|
|
|
108
101
|
|
|
109
102
|
memory.setSlice(outputOffset, output);
|
|
110
103
|
|
|
111
|
-
memory.assert(
|
|
104
|
+
memory.assert({
|
|
105
|
+
reads: 1 + pointsReadLength + scalarReadLength /* points and scalars */,
|
|
106
|
+
writes: 3 /* output triplet */,
|
|
107
|
+
addressing,
|
|
108
|
+
});
|
|
112
109
|
context.machineState.incrementPc();
|
|
113
110
|
}
|
|
114
111
|
}
|
|
@@ -32,11 +32,12 @@ export class SStore extends BaseStorageInstruction {
|
|
|
32
32
|
throw new StaticCallAlterationError();
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const memoryOperations = { reads: 2, indirect: this.indirect };
|
|
36
35
|
const memory = context.machineState.memory.track(this.type);
|
|
37
|
-
context.machineState.consumeGas(this.gasCost(
|
|
36
|
+
context.machineState.consumeGas(this.gasCost());
|
|
38
37
|
|
|
39
|
-
const
|
|
38
|
+
const operands = [this.aOffset, this.bOffset];
|
|
39
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
40
|
+
const [srcOffset, slotOffset] = addressing.resolve(operands, memory);
|
|
40
41
|
memory.checkTag(TypeTag.FIELD, slotOffset);
|
|
41
42
|
memory.checkTag(TypeTag.FIELD, srcOffset);
|
|
42
43
|
|
|
@@ -44,7 +45,7 @@ export class SStore extends BaseStorageInstruction {
|
|
|
44
45
|
const value = memory.get(srcOffset).toFr();
|
|
45
46
|
context.persistableState.writeStorage(context.environment.storageAddress, slot, value);
|
|
46
47
|
|
|
47
|
-
memory.assert(
|
|
48
|
+
memory.assert({ reads: 2, addressing });
|
|
48
49
|
context.machineState.incrementPc();
|
|
49
50
|
}
|
|
50
51
|
}
|
|
@@ -58,11 +59,12 @@ export class SLoad extends BaseStorageInstruction {
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
public async execute(context: AvmContext): Promise<void> {
|
|
61
|
-
const memoryOperations = { writes: 1, reads: 1, indirect: this.indirect };
|
|
62
62
|
const memory = context.machineState.memory.track(this.type);
|
|
63
|
-
context.machineState.consumeGas(this.gasCost(
|
|
63
|
+
context.machineState.consumeGas(this.gasCost());
|
|
64
64
|
|
|
65
|
-
const
|
|
65
|
+
const operands = [this.aOffset, this.bOffset];
|
|
66
|
+
const addressing = Addressing.fromWire(this.indirect, operands.length);
|
|
67
|
+
const [slotOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
66
68
|
memory.checkTag(TypeTag.FIELD, slotOffset);
|
|
67
69
|
|
|
68
70
|
const slot = memory.get(slotOffset).toFr();
|
|
@@ -70,6 +72,6 @@ export class SLoad extends BaseStorageInstruction {
|
|
|
70
72
|
memory.set(dstOffset, new Field(value));
|
|
71
73
|
|
|
72
74
|
context.machineState.incrementPc();
|
|
73
|
-
memory.assert(
|
|
75
|
+
memory.assert({ writes: 1, reads: 1, addressing });
|
|
74
76
|
}
|
|
75
77
|
}
|
|
@@ -1,33 +1,26 @@
|
|
|
1
|
-
import { PedersenCommitment } from '../opcodes/commitment.js';
|
|
2
|
-
import { DAGasLeft, L2GasLeft } from '../opcodes/context_getters.js';
|
|
3
|
-
import { EcAdd } from '../opcodes/ec_add.js';
|
|
4
|
-
import { Keccak, KeccakF1600, Pedersen, Poseidon2, Sha256 } from '../opcodes/hashing.js';
|
|
5
1
|
import {
|
|
6
2
|
Add,
|
|
7
|
-
Address,
|
|
8
3
|
And,
|
|
9
|
-
BlockNumber,
|
|
10
|
-
CMov,
|
|
11
4
|
Call,
|
|
12
5
|
CalldataCopy,
|
|
13
6
|
Cast,
|
|
14
|
-
ChainId,
|
|
15
7
|
DebugLog,
|
|
16
8
|
Div,
|
|
9
|
+
EcAdd,
|
|
17
10
|
EmitNoteHash,
|
|
18
11
|
EmitNullifier,
|
|
19
12
|
EmitUnencryptedLog,
|
|
20
13
|
Eq,
|
|
21
|
-
FeePerDAGas,
|
|
22
|
-
FeePerL2Gas,
|
|
23
14
|
FieldDiv,
|
|
24
|
-
FunctionSelector,
|
|
25
15
|
GetContractInstance,
|
|
16
|
+
GetEnvVar,
|
|
26
17
|
Instruction,
|
|
27
18
|
InternalCall,
|
|
28
19
|
InternalReturn,
|
|
29
20
|
Jump,
|
|
30
21
|
JumpI,
|
|
22
|
+
Keccak,
|
|
23
|
+
KeccakF1600,
|
|
31
24
|
L1ToL2MessageExists,
|
|
32
25
|
Lt,
|
|
33
26
|
Lte,
|
|
@@ -37,22 +30,21 @@ import {
|
|
|
37
30
|
NoteHashExists,
|
|
38
31
|
NullifierExists,
|
|
39
32
|
Or,
|
|
33
|
+
Pedersen,
|
|
34
|
+
PedersenCommitment,
|
|
35
|
+
Poseidon2,
|
|
40
36
|
Return,
|
|
41
37
|
Revert,
|
|
42
38
|
SLoad,
|
|
43
39
|
SStore,
|
|
44
40
|
SendL2ToL1Message,
|
|
45
|
-
Sender,
|
|
46
41
|
Set,
|
|
42
|
+
Sha256Compression,
|
|
47
43
|
Shl,
|
|
48
44
|
Shr,
|
|
49
45
|
StaticCall,
|
|
50
|
-
StorageAddress,
|
|
51
46
|
Sub,
|
|
52
|
-
Timestamp,
|
|
53
47
|
ToRadixLE,
|
|
54
|
-
TransactionFee,
|
|
55
|
-
Version,
|
|
56
48
|
Xor,
|
|
57
49
|
} from '../opcodes/index.js';
|
|
58
50
|
import { MultiScalarMul } from '../opcodes/multi_scalar_mul.js';
|
|
@@ -104,25 +96,10 @@ const INSTRUCTION_SET = () =>
|
|
|
104
96
|
[Opcode.SHR_16, Shr.as(Shr.wireFormat16).deserialize],
|
|
105
97
|
[Opcode.CAST_8, Cast.as(Cast.wireFormat8).deserialize],
|
|
106
98
|
[Opcode.CAST_16, Cast.as(Cast.wireFormat16).deserialize],
|
|
107
|
-
|
|
108
|
-
[
|
|
109
|
-
[Sender.opcode, Instruction.deserialize.bind(Sender)],
|
|
110
|
-
[FunctionSelector.opcode, Instruction.deserialize.bind(FunctionSelector)],
|
|
111
|
-
[TransactionFee.opcode, Instruction.deserialize.bind(TransactionFee)],
|
|
112
|
-
// Execution Environment - Globals
|
|
113
|
-
[ChainId.opcode, Instruction.deserialize.bind(ChainId)],
|
|
114
|
-
[Version.opcode, Instruction.deserialize.bind(Version)],
|
|
115
|
-
[BlockNumber.opcode, Instruction.deserialize.bind(BlockNumber)],
|
|
116
|
-
[Timestamp.opcode, Instruction.deserialize.bind(Timestamp)],
|
|
117
|
-
[FeePerL2Gas.opcode, Instruction.deserialize.bind(FeePerL2Gas)],
|
|
118
|
-
[FeePerDAGas.opcode, Instruction.deserialize.bind(FeePerDAGas)],
|
|
119
|
-
// Execution Environment - Calldata
|
|
99
|
+
// Execution Environment
|
|
100
|
+
[Opcode.GETENVVAR_16, GetEnvVar.as(GetEnvVar.wireFormat16).deserialize],
|
|
120
101
|
[CalldataCopy.opcode, Instruction.deserialize.bind(CalldataCopy)],
|
|
121
102
|
|
|
122
|
-
// Machine State
|
|
123
|
-
// Machine State - Gas
|
|
124
|
-
[L2GasLeft.opcode, Instruction.deserialize.bind(L2GasLeft)],
|
|
125
|
-
[DAGasLeft.opcode, Instruction.deserialize.bind(DAGasLeft)],
|
|
126
103
|
// Machine State - Internal Control Flow
|
|
127
104
|
[Jump.opcode, Instruction.deserialize.bind(Jump)],
|
|
128
105
|
[JumpI.opcode, Instruction.deserialize.bind(JumpI)],
|
|
@@ -136,7 +113,6 @@ const INSTRUCTION_SET = () =>
|
|
|
136
113
|
[Opcode.SET_FF, Set.as(Set.wireFormatFF).deserialize],
|
|
137
114
|
[Opcode.MOV_8, Mov.as(Mov.wireFormat8).deserialize],
|
|
138
115
|
[Opcode.MOV_16, Mov.as(Mov.wireFormat16).deserialize],
|
|
139
|
-
[CMov.opcode, Instruction.deserialize.bind(CMov)],
|
|
140
116
|
|
|
141
117
|
// World State
|
|
142
118
|
[SLoad.opcode, Instruction.deserialize.bind(SLoad)], // Public Storage
|
|
@@ -167,7 +143,7 @@ const INSTRUCTION_SET = () =>
|
|
|
167
143
|
[EcAdd.opcode, Instruction.deserialize.bind(EcAdd)],
|
|
168
144
|
[Keccak.opcode, Instruction.deserialize.bind(Keccak)],
|
|
169
145
|
[Poseidon2.opcode, Instruction.deserialize.bind(Poseidon2)],
|
|
170
|
-
[
|
|
146
|
+
[Sha256Compression.opcode, Instruction.deserialize.bind(Sha256Compression)],
|
|
171
147
|
[Pedersen.opcode, Instruction.deserialize.bind(Pedersen)],
|
|
172
148
|
[MultiScalarMul.opcode, Instruction.deserialize.bind(MultiScalarMul)],
|
|
173
149
|
[PedersenCommitment.opcode, Instruction.deserialize.bind(PedersenCommitment)],
|
|
@@ -39,21 +39,8 @@ export enum Opcode {
|
|
|
39
39
|
CAST_8,
|
|
40
40
|
CAST_16,
|
|
41
41
|
// Execution environment
|
|
42
|
-
|
|
43
|
-
STORAGEADDRESS,
|
|
44
|
-
SENDER,
|
|
45
|
-
FUNCTIONSELECTOR,
|
|
46
|
-
TRANSACTIONFEE,
|
|
47
|
-
CHAINID,
|
|
48
|
-
VERSION,
|
|
49
|
-
BLOCKNUMBER,
|
|
50
|
-
TIMESTAMP,
|
|
51
|
-
FEEPERL2GAS,
|
|
52
|
-
FEEPERDAGAS,
|
|
42
|
+
GETENVVAR_16,
|
|
53
43
|
CALLDATACOPY,
|
|
54
|
-
// Gas
|
|
55
|
-
L2GASLEFT,
|
|
56
|
-
DAGASLEFT,
|
|
57
44
|
// Control flow
|
|
58
45
|
JUMP_16,
|
|
59
46
|
JUMPI_16,
|
|
@@ -68,7 +55,6 @@ export enum Opcode {
|
|
|
68
55
|
SET_FF,
|
|
69
56
|
MOV_8,
|
|
70
57
|
MOV_16,
|
|
71
|
-
CMOV,
|
|
72
58
|
// World state
|
|
73
59
|
SLOAD,
|
|
74
60
|
SSTORE,
|
|
@@ -92,16 +78,14 @@ export enum Opcode {
|
|
|
92
78
|
// Gadgets
|
|
93
79
|
KECCAK,
|
|
94
80
|
POSEIDON2,
|
|
95
|
-
|
|
81
|
+
SHA256COMPRESSION,
|
|
82
|
+
KECCAKF1600,
|
|
96
83
|
PEDERSEN, // temp - may be removed, but alot of contracts rely on it
|
|
97
84
|
ECADD,
|
|
98
85
|
MSM,
|
|
99
86
|
PEDERSENCOMMITMENT,
|
|
100
87
|
// Conversion
|
|
101
88
|
TORADIXLE,
|
|
102
|
-
// Future Gadgets -- pending changes in noir
|
|
103
|
-
SHA256COMPRESSION,
|
|
104
|
-
KECCAKF1600, // Here for when we eventually support this
|
|
105
89
|
}
|
|
106
90
|
|
|
107
91
|
// Possible types for an instruction's operand in its wire format. (Keep in sync with CPP code.
|
package/src/avm/test_utils.ts
CHANGED
|
@@ -4,12 +4,11 @@ import { type ContractInstanceWithAddress } from '@aztec/types/contracts';
|
|
|
4
4
|
import { type jest } from '@jest/globals';
|
|
5
5
|
import { mock } from 'jest-mock-extended';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type WorldStateDB } from '../public/public_db_sources.js';
|
|
8
8
|
import { type PublicSideEffectTraceInterface } from '../public/side_effect_trace_interface.js';
|
|
9
|
-
import { type HostStorage } from './journal/host_storage.js';
|
|
10
9
|
|
|
11
|
-
export function mockGetBytecode(
|
|
12
|
-
(
|
|
10
|
+
export function mockGetBytecode(worldStateDB: WorldStateDB, bytecode: Buffer) {
|
|
11
|
+
(worldStateDB as jest.Mocked<WorldStateDB>).getBytecode.mockResolvedValue(bytecode);
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
export function mockTraceFork(trace: PublicSideEffectTraceInterface, nestedTrace?: PublicSideEffectTraceInterface) {
|
|
@@ -18,18 +17,18 @@ export function mockTraceFork(trace: PublicSideEffectTraceInterface, nestedTrace
|
|
|
18
17
|
);
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
export function mockStorageRead(
|
|
22
|
-
(
|
|
20
|
+
export function mockStorageRead(worldStateDB: WorldStateDB, value: Fr) {
|
|
21
|
+
(worldStateDB as jest.Mocked<WorldStateDB>).storageRead.mockResolvedValue(value);
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
export function mockStorageReadWithMap(
|
|
26
|
-
(
|
|
24
|
+
export function mockStorageReadWithMap(worldStateDB: WorldStateDB, mockedStorage: Map<bigint, Fr>) {
|
|
25
|
+
(worldStateDB as jest.Mocked<WorldStateDB>).storageRead.mockImplementation((_address, slot) =>
|
|
27
26
|
Promise.resolve(mockedStorage.get(slot.toBigInt()) ?? Fr.ZERO),
|
|
28
27
|
);
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
export function mockNoteHashExists(
|
|
32
|
-
(
|
|
30
|
+
export function mockNoteHashExists(worldStateDB: WorldStateDB, _leafIndex: Fr, value?: Fr) {
|
|
31
|
+
(worldStateDB as jest.Mocked<WorldStateDB>).getCommitmentValue.mockImplementation((index: bigint) => {
|
|
33
32
|
if (index == _leafIndex.toBigInt()) {
|
|
34
33
|
return Promise.resolve(value);
|
|
35
34
|
} else {
|
|
@@ -39,12 +38,17 @@ export function mockNoteHashExists(hs: HostStorage, _leafIndex: Fr, value?: Fr)
|
|
|
39
38
|
});
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
export function mockNullifierExists(
|
|
43
|
-
(
|
|
41
|
+
export function mockNullifierExists(worldStateDB: WorldStateDB, leafIndex: Fr, _value?: Fr) {
|
|
42
|
+
(worldStateDB as jest.Mocked<WorldStateDB>).getNullifierIndex.mockResolvedValue(leafIndex.toBigInt());
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
export function mockL1ToL2MessageExists(
|
|
47
|
-
|
|
45
|
+
export function mockL1ToL2MessageExists(
|
|
46
|
+
worldStateDB: WorldStateDB,
|
|
47
|
+
leafIndex: Fr,
|
|
48
|
+
value: Fr,
|
|
49
|
+
valueAtOtherIndices?: Fr,
|
|
50
|
+
) {
|
|
51
|
+
(worldStateDB as jest.Mocked<WorldStateDB>).getL1ToL2LeafValue.mockImplementation((index: bigint) => {
|
|
48
52
|
if (index == leafIndex.toBigInt()) {
|
|
49
53
|
return Promise.resolve(value);
|
|
50
54
|
} else {
|
|
@@ -55,6 +59,6 @@ export function mockL1ToL2MessageExists(hs: HostStorage, leafIndex: Fr, value: F
|
|
|
55
59
|
});
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
export function mockGetContractInstance(
|
|
59
|
-
(
|
|
62
|
+
export function mockGetContractInstance(worldStateDB: WorldStateDB, contractInstance: ContractInstanceWithAddress) {
|
|
63
|
+
(worldStateDB as jest.Mocked<WorldStateDB>).getContractInstance.mockResolvedValue(contractInstance);
|
|
60
64
|
}
|