1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
26using tracegen::ExecutionTraceBuilder;
27using tracegen::GreaterThanTraceBuilder;
28using tracegen::NoteHashTreeCheckTraceBuilder;
29using tracegen::TestTraceContainer;
31using simulation::EventEmitter;
32using simulation::GreaterThan;
33using simulation::GreaterThanEvent;
34using simulation::MockFieldGreaterThan;
35using simulation::MockMerkleCheck;
36using simulation::MockPoseidon2;
37using simulation::MockRangeCheck;
38using simulation::NoteHashTreeCheck;
41using testing::NiceMock;
48TEST(NoteHashExistsConstrainingTest, PositiveExists)
50 TestTraceContainer
trace({
51 { { C::execution_sel_execute_notehash_exists, 1 },
52 { C::execution_register_0_, 42 },
53 { C::execution_register_1_, 27 },
54 { C::execution_register_2_, 1 },
55 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
56 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
57 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
58 { C::execution_note_hash_leaf_in_range, 1 },
62 check_relation<notehash_exists>(
trace);
65TEST(NoteHashExistsConstrainingTest, OutOfRange)
67 TestTraceContainer
trace({
68 { { C::execution_sel_execute_notehash_exists, 1 },
69 { C::execution_register_0_, 42 },
71 { C::execution_register_2_, 0 },
72 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
73 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
74 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
75 { C::execution_note_hash_leaf_in_range, 0 },
80 check_relation<notehash_exists>(
trace);
83 trace.
set(C::execution_register_2_, 0, 1);
87TEST(NoteHashExistsConstrainingTest, NegativeInvalidOutputTag)
89 TestTraceContainer
trace({ {
90 { C::execution_sel_execute_notehash_exists, 1 },
91 { C::execution_register_0_, 42 },
92 { C::execution_register_1_, 27 },
93 { C::execution_register_2_, 1 },
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::U64) },
96 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U8) },
99 "NOTEHASH_EXISTS_U1_OUTPUT_TAG");
102TEST(NoteHashExistsConstrainingTest, NegativeNoteHashExistsSuccess)
104 TestTraceContainer
trace({ {
105 { C::execution_sel_execute_notehash_exists, 1 },
106 { C::execution_sel_opcode_error, 1 },
110 "NOTE_HASH_EXISTS_SUCCESS");
113TEST(NoteHashExistsConstrainingTest, Interactions)
116 NiceMock<MockMerkleCheck> merkle_check;
117 NiceMock<MockFieldGreaterThan>
field_gt;
120 EventEmitter<GreaterThanEvent> greater_than_event_emitter;
121 GreaterThan greater_than(
field_gt, range_check, greater_than_event_emitter);
122 EventEmitter<NoteHashTreeCheckEvent> note_hash_tree_check_event_emitter;
123 NoteHashTreeCheck note_hash_tree_check(27,
poseidon2, merkle_check, note_hash_tree_check_event_emitter);
125 FF requested_note_hash = 42;
126 FF actual_leaf_value = 43;
128 uint64_t leaf_index = 27;
130 AppendOnlyTreeSnapshot note_hash_tree_snapshot = AppendOnlyTreeSnapshot{
132 .nextAvailableLeafIndex = 128,
136 note_hash_tree_check.note_hash_exists(
137 requested_note_hash, actual_leaf_value, leaf_index, {}, note_hash_tree_snapshot);
139 TestTraceContainer
trace({ {
140 { C::execution_sel_execute_notehash_exists, 1 },
141 { C::execution_register_0_, requested_note_hash },
142 { C::execution_register_1_, leaf_index },
143 { C::execution_register_2_, 0 },
144 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
145 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
146 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
147 { C::execution_note_hash_leaf_in_range, 1 },
148 { C::execution_sel_opcode_error, 0 },
151 { C::execution_prev_note_hash_tree_root, note_hash_tree_snapshot.root },
154 NoteHashTreeCheckTraceBuilder note_hash_tree_check_trace_builder;
155 note_hash_tree_check_trace_builder.process(note_hash_tree_check_event_emitter.dump_events(),
trace);
157 GreaterThanTraceBuilder greater_than_trace_builder;
158 greater_than_trace_builder.process(greater_than_event_emitter.dump_events(),
trace);
160 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)
#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
NiceMock< MockFieldGreaterThan > field_gt