1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
25using tracegen::ExecutionTraceBuilder;
26using tracegen::GreaterThanTraceBuilder;
27using tracegen::L1ToL2MessageTreeCheckTraceBuilder;
28using tracegen::TestTraceContainer;
30using simulation::EventEmitter;
31using simulation::GreaterThan;
32using simulation::GreaterThanEvent;
33using simulation::L1ToL2MessageTreeCheck;
34using simulation::L1ToL2MessageTreeCheckEvent;
35using simulation::MockFieldGreaterThan;
36using simulation::MockMerkleCheck;
37using simulation::MockRangeCheck;
39using testing::NiceMock;
45TEST(L1ToL2MessageExistsConstrainingTest, PositiveExists)
47 TestTraceContainer
trace({
48 { { C::execution_sel_execute_l1_to_l2_message_exists, 1 },
49 { C::execution_register_0_, 42 },
50 { C::execution_register_1_, 27 },
51 { C::execution_register_2_, 1 },
52 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
53 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
54 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
55 { C::execution_l1_to_l2_msg_leaf_in_range, 1 },
59 check_relation<l1_to_l2_message_exists>(
trace);
62TEST(L1ToL2MessageExistsConstrainingTest, OutOfRange)
65 TestTraceContainer
trace({
66 { { C::execution_sel_execute_l1_to_l2_message_exists, 1 },
67 { C::execution_register_0_, 42 },
68 { C::execution_register_1_, leaf_index },
69 { C::execution_register_2_, 0 },
70 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
71 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
72 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
73 { C::execution_l1_to_l2_msg_leaf_in_range, 0 },
78 check_relation<l1_to_l2_message_exists>(
trace);
81 trace.
set(C::execution_register_2_, 0, 1);
85TEST(L1ToL2MessageExistsConstrainingTest, NegativeInvalidOutputTag)
87 TestTraceContainer
trace({ {
88 { C::execution_sel_execute_l1_to_l2_message_exists, 1 },
89 { C::execution_register_0_, 42 },
90 { C::execution_register_1_, 27 },
91 { C::execution_register_2_, 1 },
92 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
93 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
94 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U8) },
98 "L1_TO_L2_MSG_EXISTS_U1_OUTPUT_TAG");
101TEST(L1ToL2MessageExistsConstrainingTest, NegativeL1ToL2MessageExistsSuccess)
103 TestTraceContainer
trace({ {
104 { C::execution_sel_execute_l1_to_l2_message_exists, 1 },
105 { C::execution_sel_opcode_error, 1 },
110 "L1_TO_L2_MSG_EXISTS_SUCCESS");
113TEST(L1ToL2MessageExistsConstrainingTest, Interactions)
115 NiceMock<MockMerkleCheck> merkle_check;
116 NiceMock<MockFieldGreaterThan>
field_gt;
119 EventEmitter<GreaterThanEvent> greater_than_event_emitter;
120 GreaterThan greater_than(
field_gt, range_check, greater_than_event_emitter);
121 EventEmitter<L1ToL2MessageTreeCheckEvent> l1_to_l2_message_tree_check_event_emitter;
122 L1ToL2MessageTreeCheck l1_to_l2_message_tree_check(merkle_check, l1_to_l2_message_tree_check_event_emitter);
124 FF requested_msg_hash = 42;
125 FF actual_leaf_value = 43;
127 uint64_t leaf_index = 27;
129 AppendOnlyTreeSnapshot l1_to_l2_message_tree_snapshot = AppendOnlyTreeSnapshot{
131 .nextAvailableLeafIndex = 128,
135 l1_to_l2_message_tree_check.exists(
136 requested_msg_hash, actual_leaf_value, leaf_index, {}, l1_to_l2_message_tree_snapshot);
138 TestTraceContainer
trace({ {
139 { C::execution_sel_execute_l1_to_l2_message_exists, 1 },
140 { C::execution_register_0_, requested_msg_hash },
141 { C::execution_register_1_, leaf_index },
142 { C::execution_register_2_, 0 },
143 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
144 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
145 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
146 { C::execution_l1_to_l2_msg_leaf_in_range, 1 },
147 { C::execution_sel_opcode_error, 0 },
150 { C::execution_l1_l2_tree_root, l1_to_l2_message_tree_snapshot.root },
153 L1ToL2MessageTreeCheckTraceBuilder l1_to_l2_message_tree_check_trace_builder;
154 l1_to_l2_message_tree_check_trace_builder.process(l1_to_l2_message_tree_check_event_emitter.dump_events(),
trace);
156 GreaterThanTraceBuilder greater_than_trace_builder;
157 greater_than_trace_builder.process(greater_than_event_emitter.dump_events(),
trace);
159 check_relation<l1_to_l2_message_exists>(
trace);
#define L1_TO_L2_MSG_TREE_LEAF_COUNT
#define AVM_EXEC_OP_ID_L1_TO_L2_MESSAGE_EXISTS
static constexpr size_t SR_L1_TO_L2_MSG_EXISTS_U1_OUTPUT_TAG
static constexpr size_t SR_L1_TO_L2_MSG_EXISTS_SUCCESS
void set(Column col, uint32_t row, const FF &value)
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage)
void check_interaction(tracegen::TestTraceContainer &trace)
TEST(TxExecutionConstrainingTest, WriteTreeValue)
lookup_settings< lookup_l1_to_l2_message_exists_l1_to_l2_msg_leaf_index_in_range_settings_ > lookup_l1_to_l2_message_exists_l1_to_l2_msg_leaf_index_in_range_settings
lookup_settings< lookup_l1_to_l2_message_exists_l1_to_l2_msg_read_settings_ > lookup_l1_to_l2_message_exists_l1_to_l2_msg_read_settings
NiceMock< MockFieldGreaterThan > field_gt