1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
23using simulation::EventEmitter;
24using simulation::FieldGreaterThan;
25using simulation::FieldGreaterThanEvent;
26using simulation::MockRangeCheck;
28using tracegen::ExecutionTraceBuilder;
29using tracegen::PublicInputsTraceBuilder;
30using tracegen::TestTraceContainer;
32using testing::PublicInputsBuilder;
33using tracegen::FieldGreaterThanTraceBuilder;
39TEST(SendL2ToL1MsgConstrainingTest, Positive)
42 TestTraceContainer
trace({ {
43 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
45 { C::execution_register_0_, 42 },
46 { C::execution_register_1_, 27 },
47 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
48 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
50 { C::execution_sel_write_l2_to_l1_msg, 1 },
51 { C::execution_sel_opcode_error, 0 },
52 { C::execution_public_inputs_index,
54 { C::execution_prev_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs },
55 { C::execution_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs + 1 },
59 check_relation<send_l2_to_l1_msg>(trace);
62TEST(SendL2ToL1MsgConstrainingTest, LimitReached)
65 TestTraceContainer
trace({ {
66 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
68 { C::execution_register_0_, 42 },
69 { C::execution_register_1_, 27 },
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::FF) },
72 { C::execution_sel_l2_to_l1_msg_limit_error, 1 },
73 { C::execution_remaining_l2_to_l1_msgs_inv, 0 },
74 { C::execution_sel_write_l2_to_l1_msg, 0 },
75 { C::execution_sel_opcode_error, 1 },
76 { C::execution_public_inputs_index,
78 { C::execution_prev_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs },
79 { C::execution_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs },
82 check_relation<send_l2_to_l1_msg>(trace);
85 trace.
set(C::execution_sel_opcode_error, 0, 0);
88 trace.
set(C::execution_sel_opcode_error, 0, 1);
91 trace.
set(C::execution_num_l2_to_l1_messages, 0, prev_num_l2_to_l1_msgs + 1);
94 "EMIT_L2_TO_L1_MSG_NUM_L2_TO_L1_MSGS_EMITTED_INCREASE");
97TEST(SendL2ToL1MsgConstrainingTest, Discard)
99 uint64_t prev_num_l2_to_l1_msgs = 0;
100 TestTraceContainer
trace({ {
101 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
103 { C::execution_register_0_, 42 },
104 { C::execution_register_1_, 27 },
105 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
106 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
108 { C::execution_sel_write_l2_to_l1_msg, 0 },
109 { C::execution_sel_opcode_error, 0 },
110 { C::execution_public_inputs_index,
112 { C::execution_discard, 1 },
113 { C::execution_prev_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs },
114 { C::execution_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs + 1 },
117 check_relation<send_l2_to_l1_msg>(trace);
120 trace.
set(C::execution_num_l2_to_l1_messages, 0, prev_num_l2_to_l1_msgs);
123 "EMIT_L2_TO_L1_MSG_NUM_L2_TO_L1_MSGS_EMITTED_INCREASE");
126TEST(SendL2ToL1MsgConstrainingTest, Interactions)
128 uint64_t prev_num_l2_to_l1_msgs = 0;
132 AvmAccumulatedData accumulated_data = {};
134 MockRangeCheck mock_range_check;
135 EventEmitter<FieldGreaterThanEvent> ff_gt_event_emitter;
136 FieldGreaterThan
field_gt(mock_range_check, ff_gt_event_emitter);
140 accumulated_data.l2_to_l1_msgs[0] = {
143 .recipient = recipient,
148 AvmAccumulatedDataArrayLengths array_lengths = { .l2_to_l1_msgs = 1 };
149 auto public_inputs = PublicInputsBuilder()
150 .set_accumulated_data(accumulated_data)
151 .set_accumulated_data_array_lengths(array_lengths)
154 TestTraceContainer
trace({ {
155 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
157 { C::execution_register_0_, recipient },
158 { C::execution_register_1_, content },
159 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
160 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
162 { C::execution_sel_write_l2_to_l1_msg, 1 },
163 { C::execution_sel_opcode_error, 0 },
164 { C::execution_public_inputs_index,
166 { C::execution_contract_address,
address },
167 { C::execution_prev_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs },
168 { C::execution_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs + 1 },
182 check_relation<send_l2_to_l1_msg>(trace);
188TEST(SendL2ToL1MsgConstrainingTest, NegativeShouldErrorIfRecipientTooLarge)
190 TestTraceContainer
trace({ {
191 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
193 { C::execution_sel_too_large_recipient_error, 1 },
194 { C::execution_sel_l2_to_l1_msg_limit_error, 0 },
195 { C::execution_is_static, 0 },
196 { C::execution_sel_opcode_error, 1 },
201 trace.
set(C::execution_sel_opcode_error, 0, 0);
206TEST(SendL2ToL1MsgConstrainingTest, NegativeShouldErrorIfStatic)
208 TestTraceContainer
trace({ {
209 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
211 { C::execution_sel_l2_to_l1_msg_limit_error, 0 },
212 { C::execution_is_static, 1 },
213 { C::execution_sel_opcode_error, 1 },
219 trace.
set(C::execution_sel_opcode_error, 0, 0);
224TEST(SendL2ToL1MsgConstrainingTest, NegativeShouldNotWriteIfDiscard)
226 TestTraceContainer
trace({ {
227 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
229 { C::execution_sel_opcode_error, 0 },
230 { C::execution_discard, 1 },
231 { C::execution_sel_write_l2_to_l1_msg, 0 },
236 trace.
set(C::execution_sel_write_l2_to_l1_msg, 0, 1);
239 "SEND_L2_TO_L1_MSG_CONDITION");
242TEST(SendL2ToL1MsgConstrainingTest, NegativeShouldNumL2ToL1MessagesIncrease)
244 TestTraceContainer
trace({ {
245 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
247 { C::execution_sel_opcode_error, 0 },
248 { C::execution_prev_num_l2_to_l1_messages, 0 },
249 { C::execution_num_l2_to_l1_messages, 1 },
251 check_relation<send_l2_to_l1_msg>(trace,
255 trace.
set(C::execution_prev_num_l2_to_l1_messages, 0, 1);
258 "EMIT_L2_TO_L1_MSG_NUM_L2_TO_L1_MSGS_EMITTED_INCREASE");
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX
#define MAX_ETH_ADDRESS_VALUE
#define MAX_L2_TO_L1_MSGS_PER_TX
#define AVM_EXEC_OP_ID_SENDL2TOL1MSG
FieldGreaterThan field_gt
static constexpr size_t SR_OPCODE_ERROR
static constexpr size_t SR_EMIT_L2_TO_L1_MSG_NUM_L2_TO_L1_MSGS_EMITTED_INCREASE
static constexpr size_t SR_SEND_L2_TO_L1_MSG_CONDITION
bool ff_gt(const FF &a, const FF &b) override
Computes the result of a > b (in a constrained way).
void process(const simulation::EventEmitterInterface< simulation::FieldGreaterThanEvent >::Container &events, TraceContainer &trace)
Processes FieldGreaterThanEvent events and generates trace rows for the ff_gt gadget.
void process_misc(TraceContainer &trace, const uint32_t num_rows=PRECOMPUTED_TRACE_SIZE)
uint32_t get_num_rows() const
void set(Column col, uint32_t row, const FF &value)
PrecomputedTraceBuilder precomputed_builder
FieldGreaterThanTraceBuilder field_gt_builder
void check_interaction(tracegen::TestTraceContainer &trace)
TEST(AvmFixedVKTests, FixedVKCommitments)
Test that the fixed VK commitments agree with the ones computed from precomputed columns.
lookup_settings< lookup_send_l2_to_l1_msg_recipient_check_settings_ > lookup_send_l2_to_l1_msg_recipient_check_settings
lookup_settings< lookup_send_l2_to_l1_msg_write_l2_to_l1_msg_settings_ > lookup_send_l2_to_l1_msg_write_l2_to_l1_msg_settings
constexpr field invert() const noexcept
tracegen::PublicInputsTraceBuilder public_inputs_builder