@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,3 +1,5 @@
|
|
|
1
|
+
import { type Bufferable, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
2
|
+
|
|
1
3
|
import { AvmExecutionError, AvmParsingError, InvalidOpcodeError, InvalidProgramCounterError } from '../errors.js';
|
|
2
4
|
import {
|
|
3
5
|
Add,
|
|
@@ -53,106 +55,102 @@ import { MAX_OPCODE_VALUE, Opcode } from './instruction_serialization.js';
|
|
|
53
55
|
|
|
54
56
|
export type InstructionDeserializer = (buf: BufferCursor | Buffer) => Instruction;
|
|
55
57
|
|
|
56
|
-
export interface Serializable {
|
|
57
|
-
serialize(): Buffer;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
58
|
export interface Deserializable {
|
|
61
59
|
deserialize: InstructionDeserializer;
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
export type InstructionSet = Map<Opcode, InstructionDeserializer>;
|
|
65
63
|
export const INSTRUCTION_SET = new Map<Opcode, InstructionDeserializer>([
|
|
66
|
-
[Opcode.ADD_8, Add.as(Add.wireFormat8).
|
|
67
|
-
[Opcode.ADD_16, Add.as(Add.wireFormat16).
|
|
68
|
-
[Opcode.SUB_8, Sub.as(Sub.wireFormat8).
|
|
69
|
-
[Opcode.SUB_16, Sub.as(Sub.wireFormat16).
|
|
70
|
-
[Opcode.MUL_8, Mul.as(Mul.wireFormat8).
|
|
71
|
-
[Opcode.MUL_16, Mul.as(Mul.wireFormat16).
|
|
72
|
-
[Opcode.DIV_8, Div.as(Div.wireFormat8).
|
|
73
|
-
[Opcode.DIV_16, Div.as(Div.wireFormat16).
|
|
74
|
-
[Opcode.FDIV_8, FieldDiv.as(FieldDiv.wireFormat8).
|
|
75
|
-
[Opcode.FDIV_16, FieldDiv.as(FieldDiv.wireFormat16).
|
|
76
|
-
[Opcode.EQ_8, Eq.as(Eq.wireFormat8).
|
|
77
|
-
[Opcode.EQ_16, Eq.as(Eq.wireFormat16).
|
|
78
|
-
[Opcode.LT_8, Lt.as(Lt.wireFormat8).
|
|
79
|
-
[Opcode.LT_16, Lt.as(Lt.wireFormat16).
|
|
80
|
-
[Opcode.LTE_8, Lte.as(Lte.wireFormat8).
|
|
81
|
-
[Opcode.LTE_16, Lte.as(Lte.wireFormat16).
|
|
82
|
-
[Opcode.AND_8, And.as(And.wireFormat8).
|
|
83
|
-
[Opcode.AND_16, And.as(And.wireFormat16).
|
|
84
|
-
[Opcode.OR_8, Or.as(Or.wireFormat8).
|
|
85
|
-
[Opcode.OR_16, Or.as(Or.wireFormat16).
|
|
86
|
-
[Opcode.XOR_8, Xor.as(Xor.wireFormat8).
|
|
87
|
-
[Opcode.XOR_16, Xor.as(Xor.wireFormat16).
|
|
88
|
-
[Opcode.NOT_8, Not.as(Not.wireFormat8).
|
|
89
|
-
[Opcode.NOT_16, Not.as(Not.wireFormat16).
|
|
90
|
-
[Opcode.SHL_8, Shl.as(Shl.wireFormat8).
|
|
91
|
-
[Opcode.SHL_16, Shl.as(Shl.wireFormat16).
|
|
92
|
-
[Opcode.SHR_8, Shr.as(Shr.wireFormat8).
|
|
93
|
-
[Opcode.SHR_16, Shr.as(Shr.wireFormat16).
|
|
94
|
-
[Opcode.CAST_8, Cast.as(Cast.wireFormat8).
|
|
95
|
-
[Opcode.CAST_16, Cast.as(Cast.wireFormat16).
|
|
64
|
+
[Opcode.ADD_8, Add.as(Add.wireFormat8).fromBuffer],
|
|
65
|
+
[Opcode.ADD_16, Add.as(Add.wireFormat16).fromBuffer],
|
|
66
|
+
[Opcode.SUB_8, Sub.as(Sub.wireFormat8).fromBuffer],
|
|
67
|
+
[Opcode.SUB_16, Sub.as(Sub.wireFormat16).fromBuffer],
|
|
68
|
+
[Opcode.MUL_8, Mul.as(Mul.wireFormat8).fromBuffer],
|
|
69
|
+
[Opcode.MUL_16, Mul.as(Mul.wireFormat16).fromBuffer],
|
|
70
|
+
[Opcode.DIV_8, Div.as(Div.wireFormat8).fromBuffer],
|
|
71
|
+
[Opcode.DIV_16, Div.as(Div.wireFormat16).fromBuffer],
|
|
72
|
+
[Opcode.FDIV_8, FieldDiv.as(FieldDiv.wireFormat8).fromBuffer],
|
|
73
|
+
[Opcode.FDIV_16, FieldDiv.as(FieldDiv.wireFormat16).fromBuffer],
|
|
74
|
+
[Opcode.EQ_8, Eq.as(Eq.wireFormat8).fromBuffer],
|
|
75
|
+
[Opcode.EQ_16, Eq.as(Eq.wireFormat16).fromBuffer],
|
|
76
|
+
[Opcode.LT_8, Lt.as(Lt.wireFormat8).fromBuffer],
|
|
77
|
+
[Opcode.LT_16, Lt.as(Lt.wireFormat16).fromBuffer],
|
|
78
|
+
[Opcode.LTE_8, Lte.as(Lte.wireFormat8).fromBuffer],
|
|
79
|
+
[Opcode.LTE_16, Lte.as(Lte.wireFormat16).fromBuffer],
|
|
80
|
+
[Opcode.AND_8, And.as(And.wireFormat8).fromBuffer],
|
|
81
|
+
[Opcode.AND_16, And.as(And.wireFormat16).fromBuffer],
|
|
82
|
+
[Opcode.OR_8, Or.as(Or.wireFormat8).fromBuffer],
|
|
83
|
+
[Opcode.OR_16, Or.as(Or.wireFormat16).fromBuffer],
|
|
84
|
+
[Opcode.XOR_8, Xor.as(Xor.wireFormat8).fromBuffer],
|
|
85
|
+
[Opcode.XOR_16, Xor.as(Xor.wireFormat16).fromBuffer],
|
|
86
|
+
[Opcode.NOT_8, Not.as(Not.wireFormat8).fromBuffer],
|
|
87
|
+
[Opcode.NOT_16, Not.as(Not.wireFormat16).fromBuffer],
|
|
88
|
+
[Opcode.SHL_8, Shl.as(Shl.wireFormat8).fromBuffer],
|
|
89
|
+
[Opcode.SHL_16, Shl.as(Shl.wireFormat16).fromBuffer],
|
|
90
|
+
[Opcode.SHR_8, Shr.as(Shr.wireFormat8).fromBuffer],
|
|
91
|
+
[Opcode.SHR_16, Shr.as(Shr.wireFormat16).fromBuffer],
|
|
92
|
+
[Opcode.CAST_8, Cast.as(Cast.wireFormat8).fromBuffer],
|
|
93
|
+
[Opcode.CAST_16, Cast.as(Cast.wireFormat16).fromBuffer],
|
|
96
94
|
// Execution Environment
|
|
97
|
-
[Opcode.GETENVVAR_16, GetEnvVar.as(GetEnvVar.wireFormat16).
|
|
98
|
-
[CalldataCopy.opcode, Instruction.
|
|
99
|
-
[SuccessCopy.opcode, Instruction.
|
|
100
|
-
[Opcode.RETURNDATASIZE, Instruction.
|
|
101
|
-
[Opcode.RETURNDATACOPY, Instruction.
|
|
95
|
+
[Opcode.GETENVVAR_16, GetEnvVar.as(GetEnvVar.wireFormat16).fromBuffer],
|
|
96
|
+
[CalldataCopy.opcode, Instruction.fromBuffer.bind(CalldataCopy)],
|
|
97
|
+
[SuccessCopy.opcode, Instruction.fromBuffer.bind(SuccessCopy)],
|
|
98
|
+
[Opcode.RETURNDATASIZE, Instruction.fromBuffer.bind(ReturndataSize)],
|
|
99
|
+
[Opcode.RETURNDATACOPY, Instruction.fromBuffer.bind(ReturndataCopy)],
|
|
102
100
|
|
|
103
101
|
// Machine State - Internal Control Flow
|
|
104
|
-
[Jump.opcode, Instruction.
|
|
105
|
-
[JumpI.opcode, Instruction.
|
|
106
|
-
[InternalCall.opcode, Instruction.
|
|
107
|
-
[InternalReturn.opcode, Instruction.
|
|
108
|
-
[Opcode.SET_8, Set.as(Set.wireFormat8).
|
|
109
|
-
[Opcode.SET_16, Set.as(Set.wireFormat16).
|
|
110
|
-
[Opcode.SET_32, Set.as(Set.wireFormat32).
|
|
111
|
-
[Opcode.SET_64, Set.as(Set.wireFormat64).
|
|
112
|
-
[Opcode.SET_128, Set.as(Set.wireFormat128).
|
|
113
|
-
[Opcode.SET_FF, Set.as(Set.wireFormatFF).
|
|
114
|
-
[Opcode.MOV_8, Mov.as(Mov.wireFormat8).
|
|
115
|
-
[Opcode.MOV_16, Mov.as(Mov.wireFormat16).
|
|
102
|
+
[Jump.opcode, Instruction.fromBuffer.bind(Jump)],
|
|
103
|
+
[JumpI.opcode, Instruction.fromBuffer.bind(JumpI)],
|
|
104
|
+
[InternalCall.opcode, Instruction.fromBuffer.bind(InternalCall)],
|
|
105
|
+
[InternalReturn.opcode, Instruction.fromBuffer.bind(InternalReturn)],
|
|
106
|
+
[Opcode.SET_8, Set.as(Set.wireFormat8).fromBuffer],
|
|
107
|
+
[Opcode.SET_16, Set.as(Set.wireFormat16).fromBuffer],
|
|
108
|
+
[Opcode.SET_32, Set.as(Set.wireFormat32).fromBuffer],
|
|
109
|
+
[Opcode.SET_64, Set.as(Set.wireFormat64).fromBuffer],
|
|
110
|
+
[Opcode.SET_128, Set.as(Set.wireFormat128).fromBuffer],
|
|
111
|
+
[Opcode.SET_FF, Set.as(Set.wireFormatFF).fromBuffer],
|
|
112
|
+
[Opcode.MOV_8, Mov.as(Mov.wireFormat8).fromBuffer],
|
|
113
|
+
[Opcode.MOV_16, Mov.as(Mov.wireFormat16).fromBuffer],
|
|
116
114
|
|
|
117
115
|
// World State
|
|
118
|
-
[SLoad.opcode, Instruction.
|
|
119
|
-
[SStore.opcode, Instruction.
|
|
120
|
-
[NoteHashExists.opcode, Instruction.
|
|
121
|
-
[EmitNoteHash.opcode, Instruction.
|
|
122
|
-
[NullifierExists.opcode, Instruction.
|
|
123
|
-
[EmitNullifier.opcode, Instruction.
|
|
124
|
-
[L1ToL2MessageExists.opcode, Instruction.
|
|
116
|
+
[SLoad.opcode, Instruction.fromBuffer.bind(SLoad)], // Public Storage
|
|
117
|
+
[SStore.opcode, Instruction.fromBuffer.bind(SStore)], // Public Storage
|
|
118
|
+
[NoteHashExists.opcode, Instruction.fromBuffer.bind(NoteHashExists)], // Notes & Nullifiers
|
|
119
|
+
[EmitNoteHash.opcode, Instruction.fromBuffer.bind(EmitNoteHash)], // Notes & Nullifiers
|
|
120
|
+
[NullifierExists.opcode, Instruction.fromBuffer.bind(NullifierExists)], // Notes & Nullifiers
|
|
121
|
+
[EmitNullifier.opcode, Instruction.fromBuffer.bind(EmitNullifier)], // Notes & Nullifiers
|
|
122
|
+
[L1ToL2MessageExists.opcode, Instruction.fromBuffer.bind(L1ToL2MessageExists)], // Messages
|
|
125
123
|
|
|
126
124
|
// Accrued Substate
|
|
127
|
-
[EmitUnencryptedLog.opcode, Instruction.
|
|
128
|
-
[SendL2ToL1Message.opcode, Instruction.
|
|
129
|
-
[GetContractInstance.opcode, Instruction.
|
|
125
|
+
[EmitUnencryptedLog.opcode, Instruction.fromBuffer.bind(EmitUnencryptedLog)],
|
|
126
|
+
[SendL2ToL1Message.opcode, Instruction.fromBuffer.bind(SendL2ToL1Message)],
|
|
127
|
+
[GetContractInstance.opcode, Instruction.fromBuffer.bind(GetContractInstance)],
|
|
130
128
|
|
|
131
129
|
// Control Flow - Contract Calls
|
|
132
|
-
[Call.opcode, Instruction.
|
|
133
|
-
[StaticCall.opcode, Instruction.
|
|
134
|
-
[Return.opcode, Instruction.
|
|
135
|
-
[Opcode.REVERT_8, Revert.as(Revert.wireFormat8).
|
|
136
|
-
[Opcode.REVERT_16, Revert.as(Revert.wireFormat16).
|
|
130
|
+
[Call.opcode, Instruction.fromBuffer.bind(Call)],
|
|
131
|
+
[StaticCall.opcode, Instruction.fromBuffer.bind(StaticCall)],
|
|
132
|
+
[Return.opcode, Instruction.fromBuffer.bind(Return)],
|
|
133
|
+
[Opcode.REVERT_8, Revert.as(Revert.wireFormat8).fromBuffer],
|
|
134
|
+
[Opcode.REVERT_16, Revert.as(Revert.wireFormat16).fromBuffer],
|
|
137
135
|
|
|
138
136
|
// Misc
|
|
139
|
-
[DebugLog.opcode, Instruction.
|
|
137
|
+
[DebugLog.opcode, Instruction.fromBuffer.bind(DebugLog)],
|
|
140
138
|
|
|
141
139
|
// Gadgets
|
|
142
|
-
[EcAdd.opcode, Instruction.
|
|
143
|
-
[Poseidon2.opcode, Instruction.
|
|
144
|
-
[Sha256Compression.opcode, Instruction.
|
|
145
|
-
[KeccakF1600.opcode, Instruction.
|
|
140
|
+
[EcAdd.opcode, Instruction.fromBuffer.bind(EcAdd)],
|
|
141
|
+
[Poseidon2.opcode, Instruction.fromBuffer.bind(Poseidon2)],
|
|
142
|
+
[Sha256Compression.opcode, Instruction.fromBuffer.bind(Sha256Compression)],
|
|
143
|
+
[KeccakF1600.opcode, Instruction.fromBuffer.bind(KeccakF1600)],
|
|
146
144
|
|
|
147
145
|
// Conversions
|
|
148
|
-
[ToRadixBE.opcode, Instruction.
|
|
146
|
+
[ToRadixBE.opcode, Instruction.fromBuffer.bind(ToRadixBE)],
|
|
149
147
|
]);
|
|
150
148
|
|
|
151
149
|
/**
|
|
152
150
|
* Serializes an array of instructions to bytecode.
|
|
153
151
|
*/
|
|
154
|
-
export function encodeToBytecode(instructions:
|
|
155
|
-
return
|
|
152
|
+
export function encodeToBytecode(instructions: Bufferable[]): Buffer {
|
|
153
|
+
return serializeToBuffer(instructions);
|
|
156
154
|
}
|
|
157
155
|
|
|
158
156
|
// For testing only
|
|
@@ -2,7 +2,7 @@ import type { Fr } from '@aztec/foundation/fields';
|
|
|
2
2
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
|
|
5
|
-
import type { PublicContractsDBInterface } from '
|
|
5
|
+
import type { PublicContractsDBInterface } from './db_interfaces.js';
|
|
6
6
|
|
|
7
7
|
export async function getPublicFunctionDebugName(
|
|
8
8
|
db: PublicContractsDBInterface,
|
|
@@ -10,11 +10,11 @@ import { NativeWorldStateService } from '@aztec/world-state';
|
|
|
10
10
|
|
|
11
11
|
import { BaseAvmSimulationTester } from '../avm/fixtures/base_avm_simulation_tester.js';
|
|
12
12
|
import { DEFAULT_BLOCK_NUMBER, getContractFunctionAbi, getFunctionSelector } from '../avm/fixtures/index.js';
|
|
13
|
-
import {
|
|
14
|
-
import { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
|
|
13
|
+
import { PublicContractsDB } from '../public_db_sources.js';
|
|
15
14
|
import { MeasuredPublicTxSimulator } from '../public_tx_simulator/measured_public_tx_simulator.js';
|
|
16
15
|
import type { PublicTxResult } from '../public_tx_simulator/public_tx_simulator.js';
|
|
17
16
|
import { TestExecutorMetrics } from '../test_executor_metrics.js';
|
|
17
|
+
import { SimpleContractDataSource } from './simple_contract_data_source.js';
|
|
18
18
|
import { createTxForPublicCalls } from './utils.js';
|
|
19
19
|
|
|
20
20
|
const TIMESTAMP = new Fr(99833);
|
|
@@ -47,11 +47,9 @@ export class PublicTxSimulationTester extends BaseAvmSimulationTester {
|
|
|
47
47
|
) {
|
|
48
48
|
super(contractDataSource, merkleTree);
|
|
49
49
|
|
|
50
|
-
const treesDB = new PublicTreesDB(merkleTree);
|
|
51
50
|
const contractsDB = new PublicContractsDB(contractDataSource);
|
|
52
|
-
|
|
53
51
|
this.simulator = new MeasuredPublicTxSimulator(
|
|
54
|
-
|
|
52
|
+
merkleTree,
|
|
55
53
|
contractsDB,
|
|
56
54
|
globals,
|
|
57
55
|
/*doMerkleOperations=*/ true,
|
|
@@ -4,7 +4,7 @@ import type { ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
|
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
6
6
|
|
|
7
|
-
import { getFunctionSelector } from '
|
|
7
|
+
import { getFunctionSelector } from '../avm/fixtures/index.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* This class is used during public/avm testing to function as a database of
|
|
@@ -24,9 +24,11 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
24
24
|
import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
25
25
|
import {
|
|
26
26
|
AppendOnlyTreeSnapshot,
|
|
27
|
+
type BatchInsertionResult,
|
|
27
28
|
type IndexedTreeId,
|
|
28
29
|
MerkleTreeId,
|
|
29
30
|
type MerkleTreeLeafType,
|
|
31
|
+
type MerkleTreeWriteOperations,
|
|
30
32
|
NullifierLeaf,
|
|
31
33
|
NullifierLeafPreimage,
|
|
32
34
|
PublicDataTreeLeaf,
|
|
@@ -35,11 +37,11 @@ import {
|
|
|
35
37
|
getTreeName,
|
|
36
38
|
merkleTreeIds,
|
|
37
39
|
} from '@aztec/stdlib/trees';
|
|
40
|
+
import { TreeSnapshots } from '@aztec/stdlib/tx';
|
|
38
41
|
|
|
39
42
|
import { strict as assert } from 'assert';
|
|
40
43
|
|
|
41
44
|
import type { PublicContractsDBInterface } from './db_interfaces.js';
|
|
42
|
-
import { PublicTreesDB } from './public_db_sources.js';
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
47
|
* A public contracts database that forwards requests and collects AVM hints.
|
|
@@ -101,10 +103,10 @@ export class HintingPublicContractsDB implements PublicContractsDBInterface {
|
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
/**
|
|
104
|
-
* A
|
|
106
|
+
* A low-level merkle DB that collects hints.
|
|
105
107
|
*/
|
|
106
|
-
export class
|
|
107
|
-
private static readonly log: Logger = createLogger('
|
|
108
|
+
export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
109
|
+
private static readonly log: Logger = createLogger('simulator:hinting-merkle-db');
|
|
108
110
|
// This stack is only for debugging purposes.
|
|
109
111
|
// The top of the stack is the current checkpoint id.
|
|
110
112
|
// We need the stack to be non-empty and use 0 as an arbitrary initial checkpoint id.
|
|
@@ -113,19 +115,31 @@ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
|
113
115
|
private nextCheckpointId: number = 1;
|
|
114
116
|
private checkpointActionCounter: number = 0; // yes, a side-effect counter.
|
|
115
117
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
public static async create(db: MerkleTreeWriteOperations, hints: AvmExecutionHints) {
|
|
119
|
+
const hintingTreesDB = new HintingMerkleWriteOperations(db, hints);
|
|
120
|
+
const startStateReference = await db.getStateReference();
|
|
121
|
+
hints.startingTreeRoots = new TreeSnapshots(
|
|
122
|
+
startStateReference.l1ToL2MessageTree,
|
|
123
|
+
startStateReference.partial.noteHashTree,
|
|
124
|
+
startStateReference.partial.nullifierTree,
|
|
125
|
+
startStateReference.partial.publicDataTree,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
return hintingTreesDB;
|
|
118
129
|
}
|
|
119
130
|
|
|
131
|
+
// Use create() to instantiate.
|
|
132
|
+
private constructor(private db: MerkleTreeWriteOperations, private hints: AvmExecutionHints) {}
|
|
133
|
+
|
|
120
134
|
// Getters.
|
|
121
|
-
public
|
|
122
|
-
const path = await
|
|
135
|
+
public async getSiblingPath<N extends number>(treeId: MerkleTreeId, index: bigint): Promise<SiblingPath<N>> {
|
|
136
|
+
const path = await this.db.getSiblingPath<N>(treeId, index);
|
|
123
137
|
const key = await this.getHintKey(treeId);
|
|
124
138
|
this.hints.getSiblingPathHints.push(new AvmGetSiblingPathHint(key, treeId, index, path.toFields()));
|
|
125
139
|
return Promise.resolve(path);
|
|
126
140
|
}
|
|
127
141
|
|
|
128
|
-
public
|
|
142
|
+
public async getPreviousValueIndex<ID extends IndexedTreeId>(
|
|
129
143
|
treeId: ID,
|
|
130
144
|
value: bigint,
|
|
131
145
|
): Promise<
|
|
@@ -135,7 +149,7 @@ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
|
135
149
|
}
|
|
136
150
|
| undefined
|
|
137
151
|
> {
|
|
138
|
-
const result = await
|
|
152
|
+
const result = await this.db.getPreviousValueIndex(treeId, value);
|
|
139
153
|
if (result === undefined) {
|
|
140
154
|
throw new Error(
|
|
141
155
|
`getPreviousValueIndex(${getTreeName(
|
|
@@ -150,11 +164,11 @@ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
|
150
164
|
return result;
|
|
151
165
|
}
|
|
152
166
|
|
|
153
|
-
public
|
|
167
|
+
public async getLeafPreimage<ID extends IndexedTreeId>(
|
|
154
168
|
treeId: ID,
|
|
155
169
|
index: bigint,
|
|
156
170
|
): Promise<IndexedTreeLeafPreimage | undefined> {
|
|
157
|
-
const preimage = await
|
|
171
|
+
const preimage = await this.db.getLeafPreimage<ID>(treeId, index);
|
|
158
172
|
if (preimage) {
|
|
159
173
|
const key = await this.getHintKey(treeId);
|
|
160
174
|
|
|
@@ -179,14 +193,14 @@ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
|
179
193
|
return preimage;
|
|
180
194
|
}
|
|
181
195
|
|
|
182
|
-
public
|
|
196
|
+
public async getLeafValue<ID extends MerkleTreeId>(
|
|
183
197
|
treeId: ID,
|
|
184
198
|
index: bigint,
|
|
185
199
|
): Promise<MerkleTreeLeafType<typeof treeId> | undefined> {
|
|
186
200
|
// Use getLeafPreimage for PublicDataTree and NullifierTree.
|
|
187
201
|
assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
|
|
188
202
|
|
|
189
|
-
const value = await
|
|
203
|
+
const value = await this.db.getLeafValue<ID>(treeId, index);
|
|
190
204
|
if (value) {
|
|
191
205
|
const key = await this.getHintKey(treeId);
|
|
192
206
|
// We can cast to Fr because we know the type of the tree.
|
|
@@ -199,7 +213,7 @@ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
|
199
213
|
// State modification.
|
|
200
214
|
// FIXME(fcarreiro): This is a horrible interface (in the merkle ops). It's receiving the leaves as buffers,
|
|
201
215
|
// from a leaf class that is NOT the one that will be used to write. Make this type safe.
|
|
202
|
-
public
|
|
216
|
+
public async sequentialInsert<TreeHeight extends number, ID extends IndexedTreeId>(
|
|
203
217
|
treeId: ID,
|
|
204
218
|
leaves: Buffer[],
|
|
205
219
|
): Promise<SequentialInsertionResult<TreeHeight>> {
|
|
@@ -210,11 +224,10 @@ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
|
210
224
|
|
|
211
225
|
const beforeState = await this.getHintKey(treeId);
|
|
212
226
|
|
|
213
|
-
const result = await
|
|
227
|
+
const result = await this.db.sequentialInsert<TreeHeight, ID>(treeId, leaves);
|
|
214
228
|
|
|
215
229
|
const afterState = await this.getHintKey(treeId);
|
|
216
|
-
|
|
217
|
-
HintingPublicTreesDB.logTreeChange(beforeState, afterState, treeId);
|
|
230
|
+
HintingMerkleWriteOperations.logTreeChange('sequentialInsert', beforeState, afterState, treeId);
|
|
218
231
|
|
|
219
232
|
switch (treeId) {
|
|
220
233
|
case MerkleTreeId.PUBLIC_DATA_TREE:
|
|
@@ -265,10 +278,7 @@ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
|
265
278
|
return result;
|
|
266
279
|
}
|
|
267
280
|
|
|
268
|
-
public
|
|
269
|
-
treeId: ID,
|
|
270
|
-
leaves: MerkleTreeLeafType<ID>[],
|
|
271
|
-
): Promise<void> {
|
|
281
|
+
public async appendLeaves<ID extends MerkleTreeId>(treeId: ID, leaves: MerkleTreeLeafType<ID>[]): Promise<void> {
|
|
272
282
|
// Use sequentialInsert for PublicDataTree and NullifierTree.
|
|
273
283
|
assert(treeId == MerkleTreeId.NOTE_HASH_TREE || treeId == MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
|
|
274
284
|
|
|
@@ -279,39 +289,39 @@ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
|
279
289
|
}
|
|
280
290
|
}
|
|
281
291
|
|
|
282
|
-
public
|
|
292
|
+
public async createCheckpoint(): Promise<void> {
|
|
283
293
|
const actionCounter = this.checkpointActionCounter++;
|
|
284
294
|
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
285
295
|
const treesStateHash = await this.getTreesStateHash();
|
|
286
296
|
|
|
287
|
-
await
|
|
297
|
+
await this.db.createCheckpoint();
|
|
288
298
|
this.checkpointStack.push(this.nextCheckpointId++);
|
|
289
299
|
const newCheckpointId = this.getCurrentCheckpointId();
|
|
290
300
|
|
|
291
301
|
this.hints.createCheckpointHints.push(new AvmCreateCheckpointHint(actionCounter, oldCheckpointId, newCheckpointId));
|
|
292
302
|
|
|
293
|
-
|
|
303
|
+
HintingMerkleWriteOperations.log.trace(
|
|
294
304
|
`[createCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
|
|
295
305
|
);
|
|
296
306
|
}
|
|
297
307
|
|
|
298
|
-
public
|
|
308
|
+
public async commitCheckpoint(): Promise<void> {
|
|
299
309
|
const actionCounter = this.checkpointActionCounter++;
|
|
300
310
|
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
301
311
|
const treesStateHash = await this.getTreesStateHash();
|
|
302
312
|
|
|
303
|
-
await
|
|
313
|
+
await this.db.commitCheckpoint();
|
|
304
314
|
this.checkpointStack.pop();
|
|
305
315
|
const newCheckpointId = this.getCurrentCheckpointId();
|
|
306
316
|
|
|
307
317
|
this.hints.commitCheckpointHints.push(new AvmCommitCheckpointHint(actionCounter, oldCheckpointId, newCheckpointId));
|
|
308
318
|
|
|
309
|
-
|
|
319
|
+
HintingMerkleWriteOperations.log.trace(
|
|
310
320
|
`[commitCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
|
|
311
321
|
);
|
|
312
322
|
}
|
|
313
323
|
|
|
314
|
-
public
|
|
324
|
+
public async revertCheckpoint(): Promise<void> {
|
|
315
325
|
const actionCounter = this.checkpointActionCounter++;
|
|
316
326
|
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
317
327
|
const treesStateHash = await this.getTreesStateHash();
|
|
@@ -324,7 +334,7 @@ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
|
324
334
|
[MerkleTreeId.ARCHIVE]: await this.getHintKey(MerkleTreeId.ARCHIVE),
|
|
325
335
|
};
|
|
326
336
|
|
|
327
|
-
await
|
|
337
|
+
await this.db.revertCheckpoint();
|
|
328
338
|
this.checkpointStack.pop();
|
|
329
339
|
const newCheckpointId = this.getCurrentCheckpointId();
|
|
330
340
|
|
|
@@ -340,17 +350,17 @@ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
|
340
350
|
AvmRevertCheckpointHint.create(actionCounter, oldCheckpointId, newCheckpointId, beforeState, afterState),
|
|
341
351
|
);
|
|
342
352
|
|
|
343
|
-
|
|
353
|
+
HintingMerkleWriteOperations.log.trace(
|
|
344
354
|
`[revertCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
|
|
345
355
|
);
|
|
346
356
|
for (const treeId of merkleTreeIds()) {
|
|
347
|
-
|
|
357
|
+
HintingMerkleWriteOperations.logTreeChange('revertCheckpoint', beforeState[treeId], afterState[treeId], treeId);
|
|
348
358
|
}
|
|
349
359
|
}
|
|
350
360
|
|
|
351
361
|
// Private methods.
|
|
352
362
|
private async getHintKey(treeId: MerkleTreeId): Promise<AppendOnlyTreeSnapshot> {
|
|
353
|
-
const treeInfo = await
|
|
363
|
+
const treeInfo = await this.db.getTreeInfo(treeId);
|
|
354
364
|
return new AppendOnlyTreeSnapshot(Fr.fromBuffer(treeInfo.root), Number(treeInfo.size));
|
|
355
365
|
}
|
|
356
366
|
|
|
@@ -360,18 +370,19 @@ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
|
360
370
|
|
|
361
371
|
// For logging/debugging purposes.
|
|
362
372
|
private async getTreesStateHash(): Promise<Fr> {
|
|
363
|
-
const stateReferenceFields = (await
|
|
373
|
+
const stateReferenceFields = (await this.db.getStateReference()).toFields();
|
|
364
374
|
return Fr.fromBuffer(sha256Trunc(Buffer.concat(stateReferenceFields.map(field => field.toBuffer()))));
|
|
365
375
|
}
|
|
366
376
|
|
|
367
377
|
private static logTreeChange(
|
|
378
|
+
action: string,
|
|
368
379
|
beforeState: AppendOnlyTreeSnapshot,
|
|
369
380
|
afterState: AppendOnlyTreeSnapshot,
|
|
370
381
|
treeId: MerkleTreeId,
|
|
371
382
|
) {
|
|
372
383
|
const treeName = getTreeName(treeId);
|
|
373
|
-
|
|
374
|
-
`[${
|
|
384
|
+
HintingMerkleWriteOperations.log.trace(
|
|
385
|
+
`[${action}] ${treeName} tree state: ${beforeState.root}, ${beforeState.nextAvailableLeafIndex} -> ${afterState.root}, ${afterState.nextAvailableLeafIndex}.`,
|
|
375
386
|
);
|
|
376
387
|
}
|
|
377
388
|
|
|
@@ -384,15 +395,69 @@ export class HintingPublicTreesDB extends PublicTreesDB {
|
|
|
384
395
|
|
|
385
396
|
const beforeState = await this.getHintKey(treeId);
|
|
386
397
|
|
|
387
|
-
await
|
|
398
|
+
await this.db.appendLeaves<ID>(treeId, [leaf]);
|
|
388
399
|
|
|
389
400
|
const afterState = await this.getHintKey(treeId);
|
|
390
401
|
|
|
391
|
-
|
|
392
|
-
HintingPublicTreesDB.logTreeChange(beforeState, afterState, treeId);
|
|
402
|
+
HintingMerkleWriteOperations.logTreeChange('appendLeaves', beforeState, afterState, treeId);
|
|
393
403
|
|
|
394
404
|
this.hints.appendLeavesHints.push(new AvmAppendLeavesHint(beforeState, afterState, treeId, [leaf as Fr]));
|
|
395
405
|
|
|
396
406
|
return await this.getSiblingPath<N>(treeId, BigInt(beforeState.nextAvailableLeafIndex));
|
|
397
407
|
}
|
|
408
|
+
|
|
409
|
+
// Non-hinted required methods from MerkleTreeWriteOperations interface
|
|
410
|
+
public async getTreeInfo(treeId: MerkleTreeId) {
|
|
411
|
+
return await this.db.getTreeInfo(treeId);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
public async getStateReference() {
|
|
415
|
+
return await this.db.getStateReference();
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
public getInitialHeader() {
|
|
419
|
+
return this.db.getInitialHeader();
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
public async updateArchive(header: any): Promise<void> {
|
|
423
|
+
return await this.db.updateArchive(header);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
public async batchInsert<
|
|
427
|
+
TreeHeight extends number,
|
|
428
|
+
SubtreeSiblingPathHeight extends number,
|
|
429
|
+
ID extends IndexedTreeId,
|
|
430
|
+
>(
|
|
431
|
+
treeId: ID,
|
|
432
|
+
leaves: Buffer[],
|
|
433
|
+
subtreeHeight: number,
|
|
434
|
+
): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>> {
|
|
435
|
+
return await this.db.batchInsert<TreeHeight, SubtreeSiblingPathHeight, ID>(treeId, leaves, subtreeHeight);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
public async close(): Promise<void> {
|
|
439
|
+
return await this.db.close();
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
public async findLeafIndices<ID extends MerkleTreeId>(
|
|
443
|
+
treeId: ID,
|
|
444
|
+
values: MerkleTreeLeafType<ID>[],
|
|
445
|
+
): Promise<(bigint | undefined)[]> {
|
|
446
|
+
return await this.db.findLeafIndices(treeId, values);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
public async findLeafIndicesAfter<ID extends MerkleTreeId>(
|
|
450
|
+
treeId: ID,
|
|
451
|
+
values: MerkleTreeLeafType<ID>[],
|
|
452
|
+
startIndex: bigint,
|
|
453
|
+
): Promise<(bigint | undefined)[]> {
|
|
454
|
+
return await this.db.findLeafIndicesAfter(treeId, values, startIndex);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
public async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
|
|
458
|
+
treeId: ID,
|
|
459
|
+
leafIndices: bigint[],
|
|
460
|
+
): Promise<(bigint | undefined)[]> {
|
|
461
|
+
return await this.db.getBlockNumbersForLeafIndices(treeId, leafIndices);
|
|
462
|
+
}
|
|
398
463
|
}
|
package/src/public/index.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export * from './public_db_sources.js';
|
|
1
|
+
export { PublicContractsDB } from './public_db_sources.js';
|
|
2
|
+
export { type PublicTxResult, PublicTxSimulator, TelemetryPublicTxSimulator } from './public_tx_simulator/index.js';
|
|
4
3
|
export { PublicProcessor, PublicProcessorFactory } from './public_processor/public_processor.js';
|
|
5
|
-
export { SideEffectTrace } from './side_effect_trace.js';
|
|
6
|
-
export { PublicTxSimulationTester } from './fixtures/index.js';
|
|
7
|
-
export * from './avm/index.js';
|
|
8
4
|
export { getCallRequestsWithCalldataByPhase } from './utils.js';
|