1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
27using tracegen::ExecutionTraceBuilder;
28using tracegen::GreaterThanTraceBuilder;
29using tracegen::NoteHashTreeCheckTraceBuilder;
30using tracegen::TestTraceContainer;
32using simulation::EventEmitter;
33using simulation::GreaterThan;
34using simulation::GreaterThanEvent;
35using simulation::MockFieldGreaterThan;
36using simulation::MockMerkleCheck;
37using simulation::MockPoseidon2;
38using simulation::MockRangeCheck;
39using simulation::NoteHashTreeCheck;
42using testing::NiceMock;
49TEST(NoteHashExistsConstrainingTest, PositiveExists)
51 TestTraceContainer
trace({
52 { { C::execution_sel_execute_notehash_exists, 1 },
53 { C::execution_register_0_, 42 },
54 { C::execution_register_1_, 27 },
55 { C::execution_register_2_, 1 },
56 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
57 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
58 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
59 { C::execution_note_hash_leaf_in_range, 1 },
63 check_relation<notehash_exists>(
trace);
66TEST(NoteHashExistsConstrainingTest, OutOfRange)
68 TestTraceContainer
trace({
69 { { C::execution_sel_execute_notehash_exists, 1 },
70 { C::execution_register_0_, 42 },
72 { C::execution_register_2_, 0 },
73 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
74 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
75 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
76 { C::execution_note_hash_leaf_in_range, 0 },
81 check_relation<notehash_exists>(
trace);
84 trace.
set(C::execution_register_2_, 0, 1);
88TEST(NoteHashExistsConstrainingTest, NegativeInvalidOutputTag)
90 TestTraceContainer
trace({ {
91 { C::execution_sel_execute_notehash_exists, 1 },
92 { C::execution_register_0_, 42 },
93 { C::execution_register_1_, 27 },
94 { C::execution_register_2_, 1 },
95 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
96 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
97 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U8) },
100 "NOTEHASH_EXISTS_U1_OUTPUT_TAG");
103TEST(NoteHashExistsConstrainingTest, NegativeNoteHashExistsSuccess)
105 TestTraceContainer
trace({ {
106 { C::execution_sel_execute_notehash_exists, 1 },
107 { C::execution_sel_opcode_error, 1 },
111 "NOTE_HASH_EXISTS_SUCCESS");
114TEST(NoteHashExistsConstrainingTest, Interactions)
117 NiceMock<MockMerkleCheck> merkle_check;
118 NiceMock<MockFieldGreaterThan>
field_gt;
123 EventEmitter<NoteHashTreeCheckEvent> note_hash_tree_check_event_emitter;
124 NoteHashTreeCheck note_hash_tree_check(27,
poseidon2, merkle_check, note_hash_tree_check_event_emitter);
126 FF requested_note_hash = 42;
127 FF actual_leaf_value = 43;
129 uint64_t leaf_index = 27;
131 AppendOnlyTreeSnapshot note_hash_tree_snapshot = AppendOnlyTreeSnapshot{
133 .nextAvailableLeafIndex = 128,
137 note_hash_tree_check.note_hash_exists(
138 requested_note_hash, actual_leaf_value, leaf_index, {}, note_hash_tree_snapshot);
140 TestTraceContainer
trace({ {
141 { C::execution_sel_execute_notehash_exists, 1 },
142 { C::execution_register_0_, requested_note_hash },
143 { C::execution_register_1_, leaf_index },
144 { C::execution_register_2_, 0 },
145 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
146 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
147 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
148 { C::execution_note_hash_leaf_in_range, 1 },
149 { C::execution_sel_opcode_error, 0 },
152 { C::execution_prev_note_hash_tree_root, note_hash_tree_snapshot.root },
155 NoteHashTreeCheckTraceBuilder note_hash_tree_check_trace_builder;
156 note_hash_tree_check_trace_builder.process(note_hash_tree_check_event_emitter.dump_events(),
trace);
158 GreaterThanTraceBuilder greater_than_trace_builder;
161 check_relation<notehash_exists>(
trace);
#define AVM_EXEC_OP_ID_NOTEHASH_EXISTS
#define NOTE_HASH_TREE_LEAF_COUNT
static constexpr size_t SR_NOTEHASH_EXISTS_U1_OUTPUT_TAG
static constexpr size_t SR_NOTE_HASH_EXISTS_SUCCESS
void set(Column col, uint32_t row, const FF &value)
testing::StrictMock< MockGreaterThan > greater_than
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage)
void check_interaction(tracegen::TestTraceContainer &trace)
TEST(TxExecutionConstrainingTest, WriteTreeValue)
crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams > poseidon2
std::variant< NoteHashTreeReadWriteEvent, CheckPointEventType > NoteHashTreeCheckEvent
lookup_settings< lookup_notehash_exists_note_hash_read_settings_ > lookup_notehash_exists_note_hash_read_settings
lookup_settings< lookup_notehash_exists_note_hash_leaf_index_in_range_settings_ > lookup_notehash_exists_note_hash_leaf_index_in_range_settings
FieldGreaterThan field_gt
NoopEventEmitter< GreaterThanEvent > greater_than_event_emitter