Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
composer_lib.test.cpp
Go to the documentation of this file.
5
6#include <array>
7#include <gtest/gtest.h>
8
9using namespace bb;
10
11class ComposerLibTests : public ::testing::Test {
12 public:
14 using FF = typename Flavor::FF;
15
16 protected:
18};
19
25TEST_F(ComposerLibTests, LookupReadCounts)
26{
28 using Flavor = UltraFlavor;
29 using FF = typename Flavor::FF;
30 using Polynomial = typename Flavor::Polynomial;
31 auto UINT32_XOR = plookup::MultiTableId::UINT32_XOR;
32
34
35 // define some very simply inputs to XOR
36 FF left{ 1 };
37 FF right{ 5 };
38
39 auto left_idx = builder.add_variable(left);
40 auto right_idx = builder.add_variable(right);
41
42 // create a single lookup from the uint32 XOR table
43 auto accumulators = plookup::get_lookup_accumulators(UINT32_XOR, left, right, /*is_2_to_1_lookup*/ true);
44 builder.create_gates_from_plookup_accumulators(UINT32_XOR, accumulators, left_idx, right_idx);
45
46 EXPECT_EQ(builder.lookup_tables.size(), 2); // we only used two tables, first for 6 bits, second for 2 bits
47 EXPECT_EQ(builder.lookup_tables[0].size(), 4096); // first table has size 64*64 (6 bit operands)
48 EXPECT_EQ(builder.lookup_tables[1].size(), 16); // first table has size 4*4 (2 bit operands)
49
50 size_t circuit_size = 8192;
51
52 Polynomial read_counts{ circuit_size };
53 Polynomial read_tags{ circuit_size };
54
55 builder.blocks.compute_offsets(/*is_structured=*/false);
56 construct_lookup_read_counts<Flavor>(read_counts, read_tags, builder, circuit_size);
57
58 // The table polys are constructed at the start of the lookup gates block, thus so to are the counts/tags
59 size_t offset = builder.blocks.lookup.trace_offset();
60
61 // The uint32 XOR lookup table is constructed for 6 bit operands via double for loop that iterates through the left
62 // operand externally (0 to 63) then the right operand internally (0 to 63). Computing (1 XOR 5) will thus result in
63 // 1 lookup from the (1*64 + 5)th index in the table and 4 lookups from the (0*64 + 0)th index (for the remaining 4
64 // 6-bits limbs that are all 0) and one lookup from second table from the (64 * 64 + 0) index (for last 2 bits).
65 // The counts and tags at all other indices should be zero.
66 for (auto [idx, count, tag] : zip_polys(read_counts, read_tags)) {
67 if (idx == (0 + offset)) {
68 EXPECT_EQ(count, 4);
69 EXPECT_EQ(tag, 1);
70 } else if (idx == (69 + offset)) {
71 EXPECT_EQ(count, 1);
72 EXPECT_EQ(tag, 1);
73 } else if (idx == (64 * 64 + offset)) {
74 EXPECT_EQ(count, 1);
75 EXPECT_EQ(tag, 1);
76 } else {
77 EXPECT_EQ(count, 0);
78 EXPECT_EQ(tag, 0);
79 }
80 idx++;
81 }
82}
typename Flavor::FF FF
static void SetUpTestSuite()
Curve::ScalarField FF
bb::Polynomial< FF > Polynomial
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
Curve::ScalarField FF
AluTraceBuilder builder
Definition alu.test.cpp:123
ssize_t offset
Definition engine.cpp:36
ReadData< bb::fr > get_lookup_accumulators(const MultiTableId id, const fr &key_a, const fr &key_b, const bool is_2_to_1_lookup)
Given a table ID and the key(s) for a key-value lookup, return the lookup accumulators.
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
TEST_F(IPATest, ChallengesAreZero)
Definition ipa.test.cpp:123
typename Flavor::FF FF
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
auto zip_polys(Poly &&poly, Polys &&... polys)