1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
31using tracegen::ExecutionTraceBuilder;
32using tracegen::PublicDataTreeTraceBuilder;
33using tracegen::TestTraceContainer;
35using simulation::EventEmitter;
36using simulation::MerkleDB;
37using simulation::MockExecutionIdManager;
38using simulation::MockFieldGreaterThan;
39using simulation::MockIndexedTreeCheck;
40using simulation::MockL1ToL2MessageTreeCheck;
41using simulation::MockLowLevelMerkleDB;
42using simulation::MockMerkleCheck;
43using simulation::MockNoteHashTreeCheck;
44using simulation::MockPoseidon2;
45using simulation::MockWrittenPublicDataSlotsTreeCheck;
46using simulation::PublicDataTreeCheck;
49using testing::NiceMock;
57TEST(SLoadConstrainingTest, PositiveTest)
59 TestTraceContainer
trace({
60 { { C::execution_sel_execute_sload, 1 },
61 { C::execution_register_0_, 42 },
62 { C::execution_register_1_, 1 },
63 { C::execution_register_2_, 27 },
64 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
65 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
66 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::FF) },
69 check_relation<sload>(trace);
72TEST(SLoadConstrainingTest, NegativeInvalidOutputTag)
74 TestTraceContainer
trace({
75 { { C::execution_sel_execute_sload, 1 },
76 { C::execution_register_0_, 42 },
77 { C::execution_register_1_, 1 },
78 { C::execution_register_2_, 27 },
79 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
80 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
81 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U32) },
87TEST(SLoadConstrainingTest, NegativeSloadSuccess)
89 TestTraceContainer
trace({
90 { { C::execution_sel_execute_sload, 1 },
91 { C::execution_register_0_, 42 },
92 { C::execution_register_1_, 1 },
93 { C::execution_register_2_, 27 },
94 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
95 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
96 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::FF) },
98 { C::execution_sel_opcode_error, 1 } },
101 check_relation<sload>(trace);
103 "INFALLIBLE_OPCODES_SUCCESS");
106TEST(SLoadConstrainingTest, Interactions)
109 NiceMock<MockFieldGreaterThan>
field_gt;
113 NiceMock<MockLowLevelMerkleDB> low_level_merkle_db;
115 NiceMock<MockNoteHashTreeCheck> note_hash_tree_check;
116 NiceMock<MockL1ToL2MessageTreeCheck> l1_to_l2_message_tree_check;
118 EventEmitter<PublicDataTreeCheckEvent> public_data_tree_check_event_emitter;
119 PublicDataTreeCheck public_data_tree_check(
126 public_data_tree_check,
128 note_hash_tree_check,
130 l1_to_l2_message_tree_check);
133 trees.public_data_tree.root = 42;
134 EXPECT_CALL(low_level_merkle_db, get_tree_roots()).WillRepeatedly(Return(trees));
138 TestTraceContainer
trace({
139 { { C::execution_sel_execute_sload, 1 },
140 { C::execution_register_0_,
slot },
141 { C::execution_register_1_,
FF(contract_address) },
142 { C::execution_register_2_,
value },
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::FF) },
145 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::FF) },
147 { C::execution_prev_public_data_tree_root, trees.public_data_tree.root } },
150 PublicDataTreeTraceBuilder public_data_tree_trace_builder;
151 public_data_tree_trace_builder.process(public_data_tree_check_event_emitter.dump_events(),
trace);
153 check_relation<sload>(trace);
154 check_interaction<ExecutionTraceBuilder, lookup_sload_storage_read_settings>(trace);
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
#define AVM_EXEC_OP_ID_SLOAD
FieldGreaterThan field_gt
IndexedTreeCheck indexed_tree_check
StrictMock< MockHighLevelMerkleDB > merkle_db
static constexpr size_t SR_INFALLIBLE_OPCODES_SUCCESS
Native Poseidon2 hash function implementation.
ExecutionIdManager execution_id_manager
TEST(AvmFixedVKTests, FixedVKCommitments)
Test that the fixed VK commitments agree with the ones computed from precomputed columns.
std::variant< PublicDataTreeReadWriteEvent, CheckPointEventType > PublicDataTreeCheckEvent
crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams > poseidon2
NiceMock< MockExecution > execution
NiceMock< MockWrittenPublicDataSlotsTreeCheck > written_public_data_slots_tree_check