1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
22using tracegen::TestTraceContainer;
30TEST(ExecutionConstrainingTest, EmptyRow)
48TEST(ExecutionConstrainingTest, Continuity)
51 TestTraceContainer
trace({
52 {{ C::precomputed_first_row, 1 }},
53 {{ C::execution_sel, 1 }},
54 {{ C::execution_sel, 1 }},
55 {{ C::execution_sel, 1 }, { C::execution_enqueued_call_end, 1 }},
62 trace.
set(C::execution_enqueued_call_end, 3, 0);
66TEST(ExecutionConstrainingTest, ContinuityBrokenFirstRow)
69 TestTraceContainer
trace({
70 {{ C::execution_sel, 0 }},
71 {{ C::execution_sel, 1 }},
72 {{ C::execution_sel, 1 }},
73 {{ C::execution_sel, 1 }, { C::execution_enqueued_call_end, 1 }},
80TEST(ExecutionConstrainingTest, ContinuityBrokenInMiddle)
83 TestTraceContainer
trace({
84 {{ C::execution_sel, 1 }},
85 {{ C::execution_sel, 0 }},
86 {{ C::execution_sel, 1 }},
87 {{ C::execution_sel, 1 }, { C::execution_enqueued_call_end, 1 }},
94TEST(ExecutionConstrainingTest, TreeStateNotChanged)
96 TestTraceContainer
trace({
98 { C::precomputed_first_row, 1 },
101 { C::execution_sel, 1 },
102 { C::execution_prev_note_hash_tree_root, 10 },
103 { C::execution_prev_note_hash_tree_size, 9 },
104 { C::execution_prev_num_note_hashes_emitted, 8 },
105 { C::execution_prev_nullifier_tree_root, 7 },
106 { C::execution_prev_nullifier_tree_size, 6 },
107 { C::execution_prev_num_nullifiers_emitted, 5 },
108 { C::execution_prev_public_data_tree_root, 4 },
109 { C::execution_prev_public_data_tree_size, 3 },
110 { C::execution_prev_written_public_data_slots_tree_root, 2 },
111 { C::execution_prev_written_public_data_slots_tree_size, 1 },
112 { C::execution_prev_retrieved_bytecodes_tree_root, 12 },
113 { C::execution_prev_retrieved_bytecodes_tree_size, 13 },
114 { C::execution_note_hash_tree_root, 10 },
115 { C::execution_note_hash_tree_size, 9 },
116 { C::execution_num_note_hashes_emitted, 8 },
117 { C::execution_nullifier_tree_root, 7 },
118 { C::execution_nullifier_tree_size, 6 },
119 { C::execution_num_nullifiers_emitted, 5 },
120 { C::execution_public_data_tree_root, 4 },
121 { C::execution_public_data_tree_size, 3 },
122 { C::execution_written_public_data_slots_tree_root, 2 },
123 { C::execution_written_public_data_slots_tree_size, 1 },
124 { C::execution_retrieved_bytecodes_tree_root, 12 },
125 { C::execution_retrieved_bytecodes_tree_size, 13 },
129 check_relation<execution>(trace,
144 trace.
set(C::execution_note_hash_tree_root, 1, 100);
146 "NOTE_HASH_TREE_ROOT_NOT_CHANGED");
149 trace.
set(C::execution_note_hash_tree_size, 1, 100);
151 "NOTE_HASH_TREE_SIZE_NOT_CHANGED");
154 trace.
set(C::execution_num_note_hashes_emitted, 1, 100);
156 "NUM_NOTE_HASHES_EMITTED_NOT_CHANGED");
159 trace.
set(C::execution_nullifier_tree_root, 1, 100);
161 "NULLIFIER_TREE_ROOT_NOT_CHANGED");
164 trace.
set(C::execution_nullifier_tree_size, 1, 100);
166 "NULLIFIER_TREE_SIZE_NOT_CHANGED");
169 trace.
set(C::execution_prev_num_nullifiers_emitted, 1, 100);
171 "NUM_NULLIFIERS_EMITTED_NOT_CHANGED");
174 trace.
set(C::execution_public_data_tree_root, 1, 100);
176 "PUBLIC_DATA_TREE_ROOT_NOT_CHANGED");
179 trace.
set(C::execution_public_data_tree_size, 1, 100);
181 "PUBLIC_DATA_TREE_SIZE_NOT_CHANGED");
184 trace.
set(C::execution_written_public_data_slots_tree_root, 1, 100);
187 "WRITTEN_PUBLIC_DATA_SLOTS_TREE_ROOT_NOT_CHANGED");
190 trace.
set(C::execution_written_public_data_slots_tree_size, 1, 100);
193 "WRITTEN_PUBLIC_DATA_SLOTS_TREE_SIZE_NOT_CHANGED");
196 trace.
set(C::execution_retrieved_bytecodes_tree_root, 1, 100);
198 "RETRIEVED_BYTECODES_TREE_ROOT_NOT_CHANGED");
201 trace.
set(C::execution_retrieved_bytecodes_tree_size, 1, 100);
203 "RETRIEVED_BYTECODES_TREE_SIZE_NOT_CHANGED");
206TEST(ExecutionConstrainingTest, SideEffectStateNotChanged)
208 TestTraceContainer
trace({
210 { C::precomputed_first_row, 1 },
213 { C::execution_sel, 1 },
214 { C::execution_prev_num_public_log_fields, 10 },
215 { C::execution_prev_num_l2_to_l1_messages, 11 },
216 { C::execution_num_public_log_fields, 10 },
217 { C::execution_num_l2_to_l1_messages, 11 },
221 check_relation<execution>(
225 trace.
set(C::execution_num_public_log_fields, 1, 100);
227 "NUM_PUBLIC_LOGS_NOT_CHANGED");
230 trace.
set(C::execution_num_l2_to_l1_messages, 1, 100);
232 "NUM_L2_TO_L1_MESSAGES_NOT_CHANGED");
235TEST(ExecutionConstrainingTest, NoFetchingNoInstrFetchError)
238 TestTraceContainer
trace({
239 { { C::execution_sel_bytecode_retrieval_success, 0 }, { C::execution_sel_instruction_fetching_failure, 0 } },
245 trace.
set(C::execution_sel_instruction_fetching_failure, 0, 1);
247 "NO_FETCHING_NO_INSTR_FETCH_ERROR");
250 trace.
set(C::execution_sel_bytecode_retrieval_success, 0, 1);
254TEST(ExecutionConstrainingTest, NoAddressingErrorIfNotResolving)
258 TestTraceContainer
trace({
259 { { C::execution_sel_instruction_fetching_success, 0 }, { C::execution_sel_addressing_error, 0 } },
265 trace.
set(C::execution_sel_addressing_error, 0, 1);
267 "NO_ADDRESSING_ERROR_IF_NOT_RESOLVING");
270 trace.
set(C::execution_sel_instruction_fetching_success, 0, 1);
274TEST(ExecutionConstrainingTest, NoRegisterReadErrorIfNotReading)
279 TestTraceContainer
trace({
280 { { C::execution_sel_read_registers, 0 }, { C::execution_sel_register_read_error, 0 } },
286 trace.
set(C::execution_sel_register_read_error, 0, 1);
288 "REGISTER_READ_TAG_CHECK");
291TEST(ExecutionConstrainingTest, NoOogIfNoGasCheck)
294 TestTraceContainer
trace({
295 { { C::execution_sel_check_gas, 0 }, { C::execution_sel_out_of_gas, 0 } },
301 trace.
set(C::execution_sel_out_of_gas, 0, 1);
305 trace.
set(C::execution_sel_check_gas, 0, 1);
309TEST(ExecutionConstrainingTest, NoOpcodeErrorIfNotExecuting)
312 TestTraceContainer
trace({
313 { { C::execution_sel_execute_opcode, 0 }, { C::execution_sel_opcode_error, 0 } },
319 trace.
set(C::execution_sel_opcode_error, 0, 1);
321 "NO_OPCODE_ERROR_IF_NOT_EXECUTING");
324 trace.
set(C::execution_sel_execute_opcode, 0, 1);
328TEST(ExecutionConstrainingTest, SubtraceIdDecomposition)
334 TestTraceContainer
trace;
335 const uint8_t enum_length =
static_cast<uint8_t
>(SubtraceSel::MAX) + 1;
337 for (uint8_t i = 0; i < enum_length; i++) {
344 { subtrace_selector, 1 },
345 { C::execution_subtrace_id, subtrace_id },
346 { C::execution_sel_execute_opcode, 1 },
352 for (uint8_t i = 0; i < enum_length; i++) {
358 "SUBTRACE_ID_DECOMPOSITION");
364 "SUBTRACE_ID_DECOMPOSITION");
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
static constexpr size_t SR_NO_ADDRESSING_ERROR_IF_NOT_RESOLVING
static constexpr size_t SR_NUM_L2_TO_L1_MESSAGES_NOT_CHANGED
static constexpr size_t SR_RETRIEVED_BYTECODES_TREE_ROOT_NOT_CHANGED
static constexpr size_t SR_WRITTEN_PUBLIC_DATA_SLOTS_TREE_SIZE_NOT_CHANGED
static constexpr size_t SR_NULLIFIER_TREE_SIZE_NOT_CHANGED
static constexpr size_t SR_NO_OPCODE_ERROR_IF_NOT_EXECUTING
static constexpr size_t SR_NUM_NULLIFIERS_EMITTED_NOT_CHANGED
static constexpr size_t SR_PUBLIC_DATA_TREE_SIZE_NOT_CHANGED
static constexpr size_t SR_NOTE_HASH_TREE_ROOT_NOT_CHANGED
static constexpr size_t SR_TRACE_CONTINUITY
static constexpr size_t SR_NO_FETCHING_NO_INSTR_FETCH_ERROR
static constexpr size_t SR_SUBTRACE_ID_DECOMPOSITION
static constexpr size_t SR_NULLIFIER_TREE_ROOT_NOT_CHANGED
static constexpr size_t SR_NUM_PUBLIC_LOGS_NOT_CHANGED
static constexpr size_t SR_PUBLIC_DATA_TREE_ROOT_NOT_CHANGED
static constexpr size_t SR_WRITTEN_PUBLIC_DATA_SLOTS_TREE_ROOT_NOT_CHANGED
static constexpr size_t SR_NOTE_HASH_TREE_SIZE_NOT_CHANGED
static constexpr size_t SR_RETRIEVED_BYTECODES_TREE_SIZE_NOT_CHANGED
static constexpr size_t SR_NUM_NOTE_HASHES_EMITTED_NOT_CHANGED
static constexpr size_t SR_NO_OOG_IF_NO_GAS_CHECK
static constexpr size_t SR_REGISTER_READ_TAG_CHECK
void set(Column col, uint32_t row, const FF &value)
TEST(AvmFixedVKTests, FixedVKCommitments)
Test that the fixed VK commitments agree with the ones computed from precomputed columns.
TestTraceContainer empty_trace()
Column get_subtrace_selector(SubtraceSel subtrace_sel)
Get the column selector for a given subtrace selector.
FF get_subtrace_id(SubtraceSel subtrace_sel)
Get the subtrace ID for a given subtrace enum.
NiceMock< MockExecution > execution