Skip to content

Commit a38f353

Browse files
authored
fix: Bitwise lookup (#12471)
1 parent 9f57048 commit a38f353

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

barretenberg/cpp/src/barretenberg/vm2/constraining/relations/bitwise.test.cpp

+40-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
#include "barretenberg/vm2/constraining/testing/check_relation.hpp"
99
#include "barretenberg/vm2/generated/flavor_settings.hpp"
1010
#include "barretenberg/vm2/generated/relations/bitwise.hpp"
11+
#include "barretenberg/vm2/generated/relations/lookups_bitwise.hpp"
1112
#include "barretenberg/vm2/testing/fixtures.hpp"
1213
#include "barretenberg/vm2/testing/macros.hpp"
1314
#include "barretenberg/vm2/tracegen/bitwise_trace.hpp"
15+
#include "barretenberg/vm2/tracegen/lib/lookup_into_bitwise.hpp"
16+
#include "barretenberg/vm2/tracegen/lib/lookup_into_indexed_by_clk.hpp"
17+
#include "barretenberg/vm2/tracegen/precomputed_trace.hpp"
1418
#include "barretenberg/vm2/tracegen/test_trace_container.hpp"
1519

1620
namespace bb::avm2::constraining {
@@ -22,6 +26,12 @@ using FF = AvmFlavorSettings::FF;
2226
using C = Column;
2327
using bitwise = bb::avm2::bitwise<FF>;
2428

29+
using tracegen::LookupIntoBitwise;
30+
using tracegen::LookupIntoIndexedByClk;
31+
using tracegen::PrecomputedTraceBuilder;
32+
using lookup_bitwise_byte_operations = bb::avm2::lookup_bitwise_byte_operations_relation<FF>;
33+
using lookup_bitwise_integral_tag_length = bb::avm2::lookup_bitwise_integral_tag_length_relation<FF>;
34+
2535
TEST(BitwiseConstrainingTest, EmptyRow)
2636
{
2737
check_relation<bitwise>(testing::empty_trace());
@@ -315,5 +325,34 @@ TEST(BitwiseConstrainingTest, NegativeWrongAccumulation)
315325
EXPECT_THROW_WITH_MESSAGE(check_relation<bitwise>(trace, bitwise::SR_BITW_ACC_REL_C), "BITW_ACC_REL_C");
316326
}
317327

328+
TEST(BitwiseConstrainingTest, MixedOperationsInteractions)
329+
{
330+
TestTraceContainer trace;
331+
BitwiseTraceBuilder builder;
332+
PrecomputedTraceBuilder precomputed_builder;
333+
334+
builder.process(
335+
{
336+
{ .operation = BitwiseOperation::OR, .tag = MemoryTag::U1, .a = 1, .b = 0, .res = 1 },
337+
{ .operation = BitwiseOperation::AND, .tag = MemoryTag::U32, .a = 13793, .b = 10590617, .res = 4481 },
338+
{ .operation = BitwiseOperation::XOR, .tag = MemoryTag::U16, .a = 5323, .b = 321, .res = 5514 },
339+
{ .operation = BitwiseOperation::XOR, .tag = MemoryTag::U32, .a = 13793, .b = 10590617, .res = 10595448 },
340+
{ .operation = BitwiseOperation::AND, .tag = MemoryTag::U8, .a = 85, .b = 175, .res = 5 },
341+
{ .operation = BitwiseOperation::AND, .tag = MemoryTag::U8, .a = 85, .b = 175, .res = 5 },
342+
},
343+
trace);
344+
345+
precomputed_builder.process_misc(trace, 256 * 256 * 3);
346+
precomputed_builder.process_bitwise(trace);
347+
precomputed_builder.process_integral_tag_length(trace);
348+
349+
LookupIntoBitwise<lookup_bitwise_byte_operations::Settings>().process(trace);
350+
LookupIntoIndexedByClk<lookup_bitwise_integral_tag_length::Settings>().process(trace);
351+
352+
check_relation<bitwise>(trace);
353+
check_interaction<lookup_bitwise_byte_operations>(trace);
354+
check_interaction<lookup_bitwise_integral_tag_length>(trace);
355+
}
356+
318357
} // namespace
319-
} // namespace bb::avm2::constraining
358+
} // namespace bb::avm2::constraining

barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ TraceContainer AvmTraceGenHelper::generate_trace(EventsContainer&& events)
246246
std::make_unique<LookupIntoIndexedByClk<lookup_range_check_r5_is_u16_settings>>(),
247247
std::make_unique<LookupIntoIndexedByClk<lookup_range_check_r6_is_u16_settings>>(),
248248
std::make_unique<LookupIntoIndexedByClk<lookup_range_check_r7_is_u16_settings>>(),
249-
std::make_unique<LookupIntoIndexedByClk<lookup_bitwise_byte_operations_settings>>(),
249+
std::make_unique<LookupIntoBitwise<lookup_bitwise_byte_operations_settings>>(),
250250
std::make_unique<LookupIntoIndexedByClk<lookup_bitwise_integral_tag_length_settings>>(),
251251
std::make_unique<LookupIntoIndexedByClk<lookup_bc_decomposition_bytes_to_read_as_unary_settings>>(),
252252
std::make_unique<LookupIntoIndexedByClk<lookup_bc_decomposition_bytes_are_bytes_settings>>(),

0 commit comments

Comments
 (0)