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 },
61 { C::execution_note_hash_tree_leaf_count,
static_cast<uint64_t
>(NOTE_HASH_TREE_LEAF_COUNT) },
62 { C::execution_subtrace_operation_id, AVM_EXEC_OP_ID_NOTEHASH_EXISTS } },
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 },
72 { C::execution_register_1_, AVM_EXEC_OP_ID_NOTEHASH_EXISTS + 1 },
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 },
78 { C::execution_note_hash_tree_leaf_count,
static_cast<uint64_t
>(NOTE_HASH_TREE_LEAF_COUNT) },
79 { C::execution_subtrace_operation_id, AVM_EXEC_OP_ID_NOTEHASH_EXISTS } },
82 check_relation<notehash_exists>(trace);
85 trace.
set(C::execution_register_2_, 0, 1);
87 check_relation<notehash_exists>(trace),
91TEST(NoteHashExistsConstrainingTest, NegativeInvalidOutputTag)
93 TestTraceContainer
trace({ {
94 { C::execution_sel_execute_notehash_exists, 1 },
95 { C::execution_register_0_, 42 },
96 { C::execution_register_1_, 27 },
97 { C::execution_register_2_, 1 },
98 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
99 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
100 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U8) },
107TEST(NoteHashExistsConstrainingTest, NegativeNoteHashExistsSuccess)
109 TestTraceContainer
trace({ {
110 { C::execution_sel_execute_notehash_exists, 1 },
111 { C::execution_sel_opcode_error, 1 },
118TEST(NoteHashExistsConstrainingTest, Interactions)
122 NiceMock<MockFieldGreaterThan>
field_gt;
127 EventEmitter<NoteHashTreeCheckEvent> note_hash_tree_check_event_emitter;
128 NoteHashTreeCheck note_hash_tree_check(27,
poseidon2, merkle_check, note_hash_tree_check_event_emitter);
130 FF requested_note_hash = 42;
131 FF actual_leaf_value = 43;
133 uint64_t leaf_index = 27;
135 AppendOnlyTreeSnapshot note_hash_tree_snapshot = AppendOnlyTreeSnapshot{
137 .next_available_leaf_index = 128,
141 note_hash_tree_check.note_hash_exists(
142 requested_note_hash, actual_leaf_value, leaf_index, {}, note_hash_tree_snapshot);
144 TestTraceContainer
trace({ {
145 { C::execution_sel_execute_notehash_exists, 1 },
146 { C::execution_register_0_, requested_note_hash },
147 { C::execution_register_1_, leaf_index },
148 { C::execution_register_2_, 0 },
149 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
150 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U64) },
151 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
152 { C::execution_note_hash_leaf_in_range, 1 },
153 { C::execution_sel_opcode_error, 0 },
154 { C::execution_note_hash_tree_leaf_count,
static_cast<uint64_t
>(NOTE_HASH_TREE_LEAF_COUNT) },
155 { C::execution_subtrace_operation_id, AVM_EXEC_OP_ID_NOTEHASH_EXISTS },
156 { C::execution_prev_note_hash_tree_root, note_hash_tree_snapshot.root },
159 NoteHashTreeCheckTraceBuilder note_hash_tree_check_trace_builder;
160 note_hash_tree_check_trace_builder.process(note_hash_tree_check_event_emitter.dump_events(),
trace);
162 GreaterThanTraceBuilder greater_than_trace_builder;
165 check_relation<notehash_exists>(trace);
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
FieldGreaterThan field_gt
static std::string get_subrelation_label(size_t index)
static constexpr size_t SR_INFALLIBLE_OPCODES_SUCCESS
static constexpr size_t SR_NOTE_HASH_EXISTS_OUT_OF_RANGE_FALSE
static constexpr size_t SR_NOTEHASH_EXISTS_U1_OUTPUT_TAG
static std::string get_subrelation_label(size_t index)
bool gt(const FF &a, const FF &b) override
Computes whether a > b for field elements, delegating to the ff_gt gadget.
void set(Column col, uint32_t row, const FF &value, bool use_atomic_limbs=false)
void check_interaction(tracegen::TestTraceContainer &trace)
TEST(AvmFixedVKTests, FixedVKCommitments)
Test that the fixed VK commitments agree with the ones computed from precomputed columns.
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