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;
50TEST(NoteHashExistsConstrainingTest, PositiveExists)
52 TestTraceContainer
trace({
53 { { C::execution_sel_execute_notehash_exists, 1 },
54 { C::execution_register_0_, 42 },
55 { C::execution_register_1_, 27 },
56 { C::execution_register_2_, 1 },
57 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
58 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
59 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
60 { C::execution_note_hash_leaf_in_range, 1 },
64 check_relation<notehash_exists>(trace);
67TEST(NoteHashExistsConstrainingTest, OutOfRange)
69 TestTraceContainer
trace({
70 { { C::execution_sel_execute_notehash_exists, 1 },
71 { C::execution_register_0_, 42 },
73 { C::execution_register_2_, 0 },
74 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
75 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
76 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
77 { C::execution_note_hash_leaf_in_range, 0 },
82 check_relation<notehash_exists>(trace);
85 trace.
set(C::execution_register_2_, 0, 1);
89TEST(NoteHashExistsConstrainingTest, NegativeInvalidOutputTag)
91 TestTraceContainer
trace({ {
92 { C::execution_sel_execute_notehash_exists, 1 },
93 { C::execution_register_0_, 42 },
94 { C::execution_register_1_, 27 },
95 { C::execution_register_2_, 1 },
96 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
97 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
98 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U8) },
101 "NOTEHASH_EXISTS_U1_OUTPUT_TAG");
104TEST(NoteHashExistsConstrainingTest, NegativeNoteHashExistsSuccess)
106 TestTraceContainer
trace({ {
107 { C::execution_sel_execute_notehash_exists, 1 },
108 { C::execution_sel_opcode_error, 1 },
112 "INFALLIBLE_OPCODES_SUCCESS");
115TEST(NoteHashExistsConstrainingTest, Interactions)
118 NiceMock<MockMerkleCheck> merkle_check;
119 NiceMock<MockFieldGreaterThan>
field_gt;
124 EventEmitter<NoteHashTreeCheckEvent> note_hash_tree_check_event_emitter;
125 NoteHashTreeCheck note_hash_tree_check(27,
poseidon2, merkle_check, note_hash_tree_check_event_emitter);
127 FF requested_note_hash = 42;
128 FF actual_leaf_value = 43;
130 uint64_t leaf_index = 27;
132 AppendOnlyTreeSnapshot note_hash_tree_snapshot = AppendOnlyTreeSnapshot{
134 .next_available_leaf_index = 128,
138 note_hash_tree_check.note_hash_exists(
139 requested_note_hash, actual_leaf_value, leaf_index, {}, note_hash_tree_snapshot);
141 TestTraceContainer
trace({ {
142 { C::execution_sel_execute_notehash_exists, 1 },
143 { C::execution_register_0_, requested_note_hash },
144 { C::execution_register_1_, leaf_index },
145 { C::execution_register_2_, 0 },
146 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
147 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
148 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
149 { C::execution_note_hash_leaf_in_range, 1 },
150 { C::execution_sel_opcode_error, 0 },
153 { C::execution_prev_note_hash_tree_root, note_hash_tree_snapshot.root },
156 NoteHashTreeCheckTraceBuilder note_hash_tree_check_trace_builder;
157 note_hash_tree_check_trace_builder.process(note_hash_tree_check_event_emitter.dump_events(),
trace);
159 GreaterThanTraceBuilder greater_than_trace_builder;
162 check_relation<notehash_exists>(trace);
FieldGreaterThan field_gt
#define AVM_EXEC_OP_ID_NOTEHASH_EXISTS
#define NOTE_HASH_TREE_LEAF_COUNT
static constexpr size_t SR_INFALLIBLE_OPCODES_SUCCESS
static constexpr size_t SR_NOTEHASH_EXISTS_U1_OUTPUT_TAG
bool gt(const FF &a, const FF &b) override
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
NoopEventEmitter< GreaterThanEvent > greater_than_event_emitter
NiceMock< MockExecution > execution