Skip to content

Commit

Permalink
fix: Bitwise lookup (#12471)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant authored Mar 6, 2025
1 parent 9f57048 commit a38f353
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
#include "barretenberg/vm2/constraining/testing/check_relation.hpp"
#include "barretenberg/vm2/generated/flavor_settings.hpp"
#include "barretenberg/vm2/generated/relations/bitwise.hpp"
#include "barretenberg/vm2/generated/relations/lookups_bitwise.hpp"
#include "barretenberg/vm2/testing/fixtures.hpp"
#include "barretenberg/vm2/testing/macros.hpp"
#include "barretenberg/vm2/tracegen/bitwise_trace.hpp"
#include "barretenberg/vm2/tracegen/lib/lookup_into_bitwise.hpp"
#include "barretenberg/vm2/tracegen/lib/lookup_into_indexed_by_clk.hpp"
#include "barretenberg/vm2/tracegen/precomputed_trace.hpp"
#include "barretenberg/vm2/tracegen/test_trace_container.hpp"

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

using tracegen::LookupIntoBitwise;
using tracegen::LookupIntoIndexedByClk;
using tracegen::PrecomputedTraceBuilder;
using lookup_bitwise_byte_operations = bb::avm2::lookup_bitwise_byte_operations_relation<FF>;
using lookup_bitwise_integral_tag_length = bb::avm2::lookup_bitwise_integral_tag_length_relation<FF>;

TEST(BitwiseConstrainingTest, EmptyRow)
{
check_relation<bitwise>(testing::empty_trace());
Expand Down Expand Up @@ -315,5 +325,34 @@ TEST(BitwiseConstrainingTest, NegativeWrongAccumulation)
EXPECT_THROW_WITH_MESSAGE(check_relation<bitwise>(trace, bitwise::SR_BITW_ACC_REL_C), "BITW_ACC_REL_C");
}

TEST(BitwiseConstrainingTest, MixedOperationsInteractions)
{
TestTraceContainer trace;
BitwiseTraceBuilder builder;
PrecomputedTraceBuilder precomputed_builder;

builder.process(
{
{ .operation = BitwiseOperation::OR, .tag = MemoryTag::U1, .a = 1, .b = 0, .res = 1 },
{ .operation = BitwiseOperation::AND, .tag = MemoryTag::U32, .a = 13793, .b = 10590617, .res = 4481 },
{ .operation = BitwiseOperation::XOR, .tag = MemoryTag::U16, .a = 5323, .b = 321, .res = 5514 },
{ .operation = BitwiseOperation::XOR, .tag = MemoryTag::U32, .a = 13793, .b = 10590617, .res = 10595448 },
{ .operation = BitwiseOperation::AND, .tag = MemoryTag::U8, .a = 85, .b = 175, .res = 5 },
{ .operation = BitwiseOperation::AND, .tag = MemoryTag::U8, .a = 85, .b = 175, .res = 5 },
},
trace);

precomputed_builder.process_misc(trace, 256 * 256 * 3);
precomputed_builder.process_bitwise(trace);
precomputed_builder.process_integral_tag_length(trace);

LookupIntoBitwise<lookup_bitwise_byte_operations::Settings>().process(trace);
LookupIntoIndexedByClk<lookup_bitwise_integral_tag_length::Settings>().process(trace);

check_relation<bitwise>(trace);
check_interaction<lookup_bitwise_byte_operations>(trace);
check_interaction<lookup_bitwise_integral_tag_length>(trace);
}

} // namespace
} // namespace bb::avm2::constraining
} // namespace bb::avm2::constraining
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ TraceContainer AvmTraceGenHelper::generate_trace(EventsContainer&& events)
std::make_unique<LookupIntoIndexedByClk<lookup_range_check_r5_is_u16_settings>>(),
std::make_unique<LookupIntoIndexedByClk<lookup_range_check_r6_is_u16_settings>>(),
std::make_unique<LookupIntoIndexedByClk<lookup_range_check_r7_is_u16_settings>>(),
std::make_unique<LookupIntoIndexedByClk<lookup_bitwise_byte_operations_settings>>(),
std::make_unique<LookupIntoBitwise<lookup_bitwise_byte_operations_settings>>(),
std::make_unique<LookupIntoIndexedByClk<lookup_bitwise_integral_tag_length_settings>>(),
std::make_unique<LookupIntoIndexedByClk<lookup_bc_decomposition_bytes_to_read_as_unary_settings>>(),
std::make_unique<LookupIntoIndexedByClk<lookup_bc_decomposition_bytes_are_bytes_settings>>(),
Expand Down

0 comments on commit a38f353

Please sign in to comment.