1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
20using tracegen::ExecutionTraceBuilder;
21using tracegen::PublicInputsTraceBuilder;
22using tracegen::TestTraceContainer;
24using testing::PublicInputsBuilder;
30TEST(SendL2ToL1MsgConstrainingTest, Positive)
33 TestTraceContainer
trace({ {
34 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
35 { C::execution_register_0_, 42 },
36 { C::execution_register_1_, 27 },
37 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
38 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
40 { C::execution_sel_write_l2_to_l1_msg, 1 },
41 { C::execution_sel_opcode_error, 0 },
42 { C::execution_public_inputs_index,
44 { C::execution_prev_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs },
45 { C::execution_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs + 1 },
49 check_relation<send_l2_to_l1_msg>(
trace);
52TEST(SendL2ToL1MsgConstrainingTest, LimitReached)
55 TestTraceContainer
trace({ {
56 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
57 { C::execution_register_0_, 42 },
58 { C::execution_register_1_, 27 },
59 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
60 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
61 { C::execution_sel_l2_to_l1_msg_limit_error, 1 },
62 { C::execution_remaining_l2_to_l1_msgs_inv, 0 },
63 { C::execution_sel_write_l2_to_l1_msg, 0 },
64 { C::execution_sel_opcode_error, 1 },
65 { C::execution_public_inputs_index,
67 { C::execution_prev_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs },
68 { C::execution_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs },
71 check_relation<send_l2_to_l1_msg>(
trace);
74 trace.
set(C::execution_sel_opcode_error, 0, 0);
77 trace.
set(C::execution_sel_opcode_error, 0, 1);
80 trace.
set(C::execution_num_l2_to_l1_messages, 0, prev_num_l2_to_l1_msgs + 1);
83 "EMIT_L2_TO_L1_MSG_NUM_L2_TO_L1_MSGS_EMITTED_INCREASE");
86TEST(SendL2ToL1MsgConstrainingTest, Discard)
88 uint64_t prev_num_l2_to_l1_msgs = 0;
89 TestTraceContainer
trace({ {
90 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
91 { C::execution_register_0_, 42 },
92 { C::execution_register_1_, 27 },
93 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
94 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
96 { C::execution_sel_write_l2_to_l1_msg, 0 },
97 { C::execution_sel_opcode_error, 0 },
98 { C::execution_public_inputs_index,
100 { C::execution_discard, 1 },
101 { C::execution_prev_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs },
102 { C::execution_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs + 1 },
105 check_relation<send_l2_to_l1_msg>(
trace);
108 trace.
set(C::execution_num_l2_to_l1_messages, 0, prev_num_l2_to_l1_msgs);
111 "EMIT_L2_TO_L1_MSG_NUM_L2_TO_L1_MSGS_EMITTED_INCREASE");
114TEST(SendL2ToL1MsgConstrainingTest, Interactions)
116 uint64_t prev_num_l2_to_l1_msgs = 0;
120 AvmAccumulatedData accumulated_data = {};
122 accumulated_data.l2ToL1Msgs[0] = {
125 .recipient = recipient,
128 .contractAddress = address,
130 AvmAccumulatedDataArrayLengths array_lengths = { .l2ToL1Msgs = 1 };
131 auto public_inputs = PublicInputsBuilder()
132 .set_accumulated_data(accumulated_data)
133 .set_accumulated_data_array_lengths(array_lengths)
136 TestTraceContainer
trace({ {
137 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
138 { C::execution_register_0_, recipient },
139 { C::execution_register_1_, content },
140 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
141 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
143 { C::execution_sel_write_l2_to_l1_msg, 1 },
144 { C::execution_sel_opcode_error, 0 },
145 { C::execution_public_inputs_index,
147 { C::execution_contract_address, address },
148 { C::execution_prev_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs },
149 { C::execution_num_l2_to_l1_messages, prev_num_l2_to_l1_msgs + 1 },
153 PublicInputsTraceBuilder public_inputs_builder;
154 public_inputs_builder.process_public_inputs(
trace, public_inputs);
155 public_inputs_builder.process_public_inputs_aux_precomputed(
trace);
160 check_relation<send_l2_to_l1_msg>(
trace);
161 check_interaction<ExecutionTraceBuilder, lookup_send_l2_to_l1_msg_write_l2_to_l1_msg_settings>(
trace);
164TEST(SendL2ToL1MsgConstrainingTest, NegativeShouldErrorIfStatic)
166 TestTraceContainer
trace({ {
167 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
168 { C::execution_sel_l2_to_l1_msg_limit_error, 0 },
169 { C::execution_is_static, 1 },
170 { C::execution_sel_opcode_error, 1 },
176 trace.
set(C::execution_sel_opcode_error, 0, 0);
181TEST(SendL2ToL1MsgConstrainingTest, NegativeShouldNotWriteIfDiscard)
183 TestTraceContainer
trace({ {
184 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
185 { C::execution_sel_opcode_error, 0 },
186 { C::execution_discard, 1 },
187 { C::execution_sel_write_l2_to_l1_msg, 0 },
192 trace.
set(C::execution_sel_write_l2_to_l1_msg, 0, 1);
195 "SEND_L2_TO_L1_MSG_CONDITION");
198TEST(SendL2ToL1MsgConstrainingTest, NegativeShouldNumL2ToL1MessagesIncrease)
200 TestTraceContainer
trace({ {
201 { C::execution_sel_execute_send_l2_to_l1_msg, 1 },
202 { C::execution_sel_opcode_error, 0 },
203 { C::execution_prev_num_l2_to_l1_messages, 0 },
204 { C::execution_num_l2_to_l1_messages, 1 },
206 check_relation<send_l2_to_l1_msg>(
trace,
210 trace.
set(C::execution_prev_num_l2_to_l1_messages, 0, 1);
213 "EMIT_L2_TO_L1_MSG_NUM_L2_TO_L1_MSGS_EMITTED_INCREASE");
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX
#define MAX_L2_TO_L1_MSGS_PER_TX
#define AVM_EXEC_OP_ID_SENDL2TOL1MSG
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
uint32_t get_num_rows() const
void set(Column col, uint32_t row, const FF &value)
PrecomputedTraceBuilder precomputed_builder
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage)
TEST(TxExecutionConstrainingTest, WriteTreeValue)