1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
29using ::testing::Return;
30using ::testing::StrictMock;
35using simulation::EventEmitter;
36using simulation::MockExecutionIdManager;
37using simulation::MockGreaterThan;
38using simulation::Poseidon2;
39using simulation::Poseidon2HashEvent;
40using simulation::Poseidon2PermutationEvent;
41using simulation::Poseidon2PermutationMemoryEvent;
42using tracegen::BytecodeTraceBuilder;
43using tracegen::Poseidon2TraceBuilder;
44using tracegen::TestTraceContainer;
51TEST(BytecodeHashingConstrainingTest, EmptyRow)
56TEST(BytecodeHashingConstrainingTest, SingleBytecodeHash)
58 TestTraceContainer
trace({
59 { { C::precomputed_first_row, 1 } },
64 { { .bytecode_id = 1, .bytecode_length = 62, .bytecode_fields =
random_fields(2) } },
trace);
66 check_relation<bc_hashing>(
trace);
69TEST(BytecodeHashingConstrainingTest, MultipleBytecodeHash)
71 TestTraceContainer
trace({
72 { { C::precomputed_first_row, 1 } },
77 { { .bytecode_id = 1, .bytecode_length = 62, .bytecode_fields =
random_fields(2) },
78 { .bytecode_id = 2, .bytecode_length = 62000, .bytecode_fields =
random_fields(2000) } },
81 check_relation<bc_hashing>(
trace);
84TEST(BytecodeHashingConstrainingTest, PoseidonInteractions)
90 StrictMock<MockGreaterThan>
mock_gt;
93 .WillRepeatedly(Return(0));
98 TestTraceContainer
trace({
99 { { C::precomputed_first_row, 1 } },
108 Poseidon2TraceBuilder poseidon2_builder;
109 BytecodeTraceBuilder bytecode_builder;
112 bytecode_builder.process_hashing(
113 { { .bytecode_id = 1, .bytecode_length = 62, .bytecode_fields = fields } },
trace);
118 check_relation<bc_hashing>(
trace);
121TEST(BytecodeHashingConstrainingTest, BytecodeInteractions)
123 TestTraceContainer
trace({
124 { { C::precomputed_first_row, 1 } },
131 builder.process_hashing({ { .bytecode_id = 1, .bytecode_length = 40, .bytecode_fields = fields } },
trace);
139 check_relation<bc_hashing>(
trace);
142TEST(BytecodeHashingConstrainingTest, NegativeInvalidStartAfterLatch)
144 TestTraceContainer
trace({
145 { { C::precomputed_first_row, 1 } },
149 builder.process_hashing({ { .bytecode_id = 1, .bytecode_length = 62, .bytecode_fields =
random_fields(2) },
150 { .bytecode_id = 2, .bytecode_length = 93, .bytecode_fields =
random_fields(3) } },
155 trace.
set(Column::bc_hashing_start, 3, 0);
159TEST(BytecodeHashingConstrainingTest, NegativeInvalidPCIncrement)
161 TestTraceContainer
trace({
162 { { C::precomputed_first_row, 1 } },
168 { .bytecode_id = 1, .bytecode_length = 62, .bytecode_fields =
random_fields(2) },
174 trace.
set(Column::bc_hashing_pc_index, 2, 10);
178TEST(BytecodeHashingConstrainingTest, NegativeChainOutput)
180 TestTraceContainer
trace({
181 { { C::precomputed_first_row, 1 } },
187 { .bytecode_id = 1, .bytecode_length = 62, .bytecode_fields =
random_fields(2) },
193 trace.
set(Column::bc_hashing_incremental_hash, 2, 123);
195 "CHAIN_OUTPUT_TO_INCR");
199TEST(BytecodeHashingConstrainingTest, NegativeLatchNotSel)
201 TestTraceContainer
trace;
204 { C::bc_hashing_latch, 1 },
205 { C::bc_hashing_sel, 1 },
211 "SEL_TOGGLED_AT_LATCH");
214TEST(BytecodeHashingConstrainingTest, NegativeBytecodeInteraction)
216 TestTraceContainer
trace({
217 { { C::precomputed_first_row, 1 } },
225 builder.process_hashing({ { .bytecode_id = 1, .bytecode_length = 40, .bytecode_fields = fields } },
trace);
231 trace.
set(Column::bc_hashing_pc_index, 2, 0);
233 trace.
set(Column::bc_hashing_incremental_hash, 1, 10);
236 (check_interaction<BytecodeTraceBuilder, lookup_bc_hashing_get_packed_field_settings>(
trace)),
237 "Failed.*GET_PACKED_FIELD. Could not find tuple in destination.");
240 "Failed.*IV_IS_LEN. Could not find tuple in destination.");
static constexpr size_t SR_SEL_TOGGLED_AT_LATCH
static constexpr size_t SR_START_AFTER_LATCH
static constexpr size_t SR_CHAIN_OUTPUT_TO_INCR
static constexpr size_t SR_PC_INCREMENTS
void set(Column col, uint32_t row, const FF &value)
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
Implements a parallelized batch insertion indexed tree Accepts template argument of the type of store...
NoopEventEmitter< Poseidon2PermutationEvent > perm_event_emitter
NoopEventEmitter< Poseidon2PermutationMemoryEvent > perm_mem_event_emitter
NiceMock< MockGreaterThan > mock_gt
EventEmitter< Poseidon2HashEvent > hash_event_emitter
NiceMock< MockExecutionIdManager > mock_execution_id_manager
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage)
void check_interaction(tracegen::TestTraceContainer &trace)
TEST(TxExecutionConstrainingTest, WriteTreeValue)
crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams > poseidon2
std::vector< FF > encode_bytecode(std::span< const uint8_t > bytecode)
std::vector< uint8_t > random_bytes(size_t n)
TestTraceContainer empty_trace()
std::vector< FF > random_fields(size_t n)
lookup_settings< lookup_bc_hashing_get_packed_field_settings_ > lookup_bc_hashing_get_packed_field_settings
lookup_settings< lookup_bc_hashing_iv_is_len_settings_ > lookup_bc_hashing_iv_is_len_settings
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept