Skip to content

Commit

Permalink
refactor(bb): removed powers of eta in lookup and auxiliary relations…
Browse files Browse the repository at this point in the history
… (#4695)

We previously were using powers of the plookup "eta" challenge in our
lookup and auxiliary relations, to construct random linear combinations.

With protogalaxy, this becomes inefficient as each challenge is
represented by a degree-1 Univariate polynomial. i.e. eta^3 is degree-3,
while a completely independent challenge is degree-1.

Usages of eta^2 and eta^3 have been replaced with new challenges eta_two
and eta_three

Now that the `CircuitChecker` uses relations, we update these as
appropriately but also have to change `stdlib_plonk_recursion_tests` to
construct and verify full proof as the widgets do not reflect changes on
`eta`

---------

Co-authored-by: maramihali <mara@aztecprotocol.com>
  • Loading branch information
2 people authored and AztecBot committed Mar 26, 2024
1 parent f78e4f5 commit 9bf8f99
Show file tree
Hide file tree
Showing 26 changed files with 265 additions and 219 deletions.
37 changes: 26 additions & 11 deletions cpp/src/barretenberg/circuit_checker/ultra_circuit_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ bool UltraCircuitChecker::check_block(Builder& builder,
auto values = init_empty_values<Builder>();
Params params;
params.eta = memory_data.eta; // used in Auxiliary relation for RAM/ROM consistency
params.eta_two = memory_data.eta_two;
params.eta_three = memory_data.eta_three;

// Perform checks on each gate defined in the builder
bool result = true;
Expand Down Expand Up @@ -179,10 +181,11 @@ void UltraCircuitChecker::populate_values(
}
};

// A lambda function for computing a memory record term of the form w3 * eta^3 + w2 * eta^2 + w1 * eta
auto compute_memory_record_term = [](const FF& w_1, const FF& w_2, const FF& w_3, const FF& eta) {
return ((w_3 * eta + w_2) * eta + w_1) * eta;
};
// A lambda function for computing a memory record term of the form w3 * eta_three + w2 * eta_two + w1 * eta
auto compute_memory_record_term =
[](const FF& w_1, const FF& w_2, const FF& w_3, const FF& eta, const FF& eta_two, FF& eta_three) {
return (w_3 * eta_three + w_2 * eta_two + w_1 * eta);
};

// Set wire values. Wire 4 is treated specially since it may contain memory records
values.w_l = builder.get_variable(block.w_l()[idx]);
Expand All @@ -191,9 +194,13 @@ void UltraCircuitChecker::populate_values(
// Note: memory_data contains indices into the block to which RAM/ROM gates were added so we need to check that we
// are indexing into the correct block before updating the w_4 value.
if (block.has_ram_rom && memory_data.read_record_gates.contains(idx)) {
values.w_4 = compute_memory_record_term(values.w_l, values.w_r, values.w_o, memory_data.eta);
values.w_4 = compute_memory_record_term(
values.w_l, values.w_r, values.w_o, memory_data.eta, memory_data.eta_two, memory_data.eta_three);
} else if (block.has_ram_rom && memory_data.write_record_gates.contains(idx)) {
values.w_4 = compute_memory_record_term(values.w_l, values.w_r, values.w_o, memory_data.eta) + FF::one();
values.w_4 =
compute_memory_record_term(
values.w_l, values.w_r, values.w_o, memory_data.eta, memory_data.eta_two, memory_data.eta_three) +
FF::one();
} else {
values.w_4 = builder.get_variable(block.w_4()[idx]);
}
Expand All @@ -204,12 +211,20 @@ void UltraCircuitChecker::populate_values(
values.w_r_shift = builder.get_variable(block.w_r()[idx + 1]);
values.w_o_shift = builder.get_variable(block.w_o()[idx + 1]);
if (block.has_ram_rom && memory_data.read_record_gates.contains(idx + 1)) {
values.w_4_shift =
compute_memory_record_term(values.w_l_shift, values.w_r_shift, values.w_o_shift, memory_data.eta);
values.w_4_shift = compute_memory_record_term(values.w_l_shift,
values.w_r_shift,
values.w_o_shift,
memory_data.eta,
memory_data.eta_two,
memory_data.eta_three);
} else if (block.has_ram_rom && memory_data.write_record_gates.contains(idx + 1)) {
values.w_4_shift =
compute_memory_record_term(values.w_l_shift, values.w_r_shift, values.w_o_shift, memory_data.eta) +
FF::one();
values.w_4_shift = compute_memory_record_term(values.w_l_shift,
values.w_r_shift,
values.w_o_shift,
memory_data.eta,
memory_data.eta_two,
memory_data.eta_three) +
FF::one();
} else {
values.w_4_shift = builder.get_variable(block.w_4()[idx + 1]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ class UltraCircuitChecker {
* @brief Struct for managing memory record data for ensuring RAM/ROM correctness
*/
struct MemoryCheckData {
FF eta = FF::random_element(); // randomness for constructing wire 4 mem records
// randomness for constructing wire 4 mem records
FF eta = FF::random_element();
FF eta_two = FF::random_element();
FF eta_three = FF::random_element();

std::unordered_set<size_t> read_record_gates; // row indices for gates containing RAM/ROM read mem record
std::unordered_set<size_t> write_record_gates; // row indices for gates containing RAM/ROM write mem record
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/honk/proof_system/types/proof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace bb {

using HonkProof = std::vector<bb::fr>;
using HonkProof = std::vector<bb::fr>; // this can be fr?

template <typename Builder> using StdlibProof = std::vector<bb::stdlib::field_t<Builder>>;

Expand Down
39 changes: 20 additions & 19 deletions cpp/src/barretenberg/protogalaxy/combiner.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,23 @@ TEST(Protogalaxy, CombinerOn2Instances)
}

ProverInstances instances{ instance_data };
instances.alphas.fill(bb::Univariate<FF, 13>(FF(0))); // focus on the arithmetic relation only
instances.alphas.fill(bb::Univariate<FF, 12>(FF(0))); // focus on the arithmetic relation only
auto pow_polynomial = PowPolynomial(std::vector<FF>{ 2 });
auto result = prover.compute_combiner(instances, pow_polynomial);
auto expected_result = Univariate<FF, 13>(std::array<FF, 13>{ 87706,
13644570,
76451738,
226257946,
static_cast<uint64_t>(500811930),
static_cast<uint64_t>(937862426),
static_cast<uint64_t>(1575158170),
static_cast<uint64_t>(2450447898),
static_cast<uint64_t>(3601480346),
static_cast<uint64_t>(5066004250),
static_cast<uint64_t>(6881768346),
static_cast<uint64_t>(9086521370),
static_cast<uint64_t>(11718012058) });
auto expected_result = Univariate<FF, 12>(std::array<FF, 12>{
87706,
13644570,
76451738,
226257946,
static_cast<uint64_t>(500811930),
static_cast<uint64_t>(937862426),
static_cast<uint64_t>(1575158170),
static_cast<uint64_t>(2450447898),
static_cast<uint64_t>(3601480346),
static_cast<uint64_t>(5066004250),
static_cast<uint64_t>(6881768346),
static_cast<uint64_t>(9086521370),
});
EXPECT_EQ(result, expected_result);
} else {
std::vector<std::shared_ptr<ProverInstance>> instance_data(NUM_INSTANCES);
Expand All @@ -84,7 +85,7 @@ TEST(Protogalaxy, CombinerOn2Instances)
}

ProverInstances instances{ instance_data };
instances.alphas.fill(bb::Univariate<FF, 13>(FF(0))); // focus on the arithmetic relation only
instances.alphas.fill(bb::Univariate<FF, 12>(FF(0))); // focus on the arithmetic relation only

const auto create_add_gate = [](auto& polys, const size_t idx, FF w_l, FF w_r) {
polys.w_l[idx] = w_l;
Expand Down Expand Up @@ -133,7 +134,7 @@ TEST(Protogalaxy, CombinerOn2Instances)
auto pow_polynomial = PowPolynomial(std::vector<FF>{ 2 });
auto result = prover.compute_combiner(instances, pow_polynomial);
auto expected_result =
Univariate<FF, 13>(std::array<FF, 13>{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660, 792 });
Univariate<FF, 12>(std::array<FF, 12>{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660 });

EXPECT_EQ(result, expected_result);
}
Expand Down Expand Up @@ -175,7 +176,7 @@ TEST(Protogalaxy, CombinerOn4Instances)
}

ProverInstances instances{ instance_data };
instances.alphas.fill(bb::Univariate<FF, 43>(FF(0))); // focus on the arithmetic relation only
instances.alphas.fill(bb::Univariate<FF, 40>(FF(0))); // focus on the arithmetic relation only

zero_all_selectors(instances[0]->prover_polynomials);
zero_all_selectors(instances[1]->prover_polynomials);
Expand All @@ -184,9 +185,9 @@ TEST(Protogalaxy, CombinerOn4Instances)

auto pow_polynomial = PowPolynomial(std::vector<FF>{ 2 });
auto result = prover.compute_combiner(instances, pow_polynomial);
std::array<FF, 43> zeroes;
std::array<FF, 40> zeroes;
std::fill(zeroes.begin(), zeroes.end(), 0);
auto expected_result = Univariate<FF, 43>(zeroes);
auto expected_result = Univariate<FF, 40>(zeroes);
EXPECT_EQ(result, expected_result);
};
run_test();
Expand Down
16 changes: 9 additions & 7 deletions cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
auto instance = std::make_shared<ProverInstance>(builder);

instance->relation_parameters.eta = FF::random_element();
instance->relation_parameters.eta_two = FF::random_element();
instance->relation_parameters.eta_three = FF::random_element();
instance->relation_parameters.beta = FF::random_element();
instance->relation_parameters.gamma = FF::random_element();

instance->proving_key->compute_sorted_accumulator_polynomials(instance->relation_parameters.eta);
instance->proving_key->compute_sorted_accumulator_polynomials(instance->relation_parameters.eta,
instance->relation_parameters.eta_two,
instance->relation_parameters.eta_three);
if constexpr (IsGoblinFlavor<Flavor>) {
instance->proving_key->compute_logderivative_inverse(instance->relation_parameters);
}
Expand Down Expand Up @@ -219,13 +223,12 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
static void test_combiner_quotient()
{
auto compressed_perturbator = FF(2); // F(\alpha) in the paper
auto combiner =
bb::Univariate<FF, 13>(std::array<FF, 13>{ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 });
auto combiner = bb::Univariate<FF, 12>(std::array<FF, 12>{ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 });
auto combiner_quotient = ProtoGalaxyProver::compute_combiner_quotient(compressed_perturbator, combiner);

// K(i) = (G(i) - ( L_0(i) * F(\alpha)) / Z(i), i = {2,.., 13} for ProverInstances::NUM = 2
// K(i) = (G(i) - (1 - i) * F(\alpha)) / i * (i - 1)
auto expected_evals = bb::Univariate<FF, 13, 2>(std::array<FF, 11>{
auto expected_evals = bb::Univariate<FF, 12, 2>(std::array<FF, 10>{
(FF(22) - (FF(1) - FF(2)) * compressed_perturbator) / (FF(2) * FF(2 - 1)),
(FF(23) - (FF(1) - FF(3)) * compressed_perturbator) / (FF(3) * FF(3 - 1)),
(FF(24) - (FF(1) - FF(4)) * compressed_perturbator) / (FF(4) * FF(4 - 1)),
Expand All @@ -236,7 +239,6 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
(FF(29) - (FF(1) - FF(9)) * compressed_perturbator) / (FF(9) * FF(9 - 1)),
(FF(30) - (FF(1) - FF(10)) * compressed_perturbator) / (FF(10) * FF(10 - 1)),
(FF(31) - (FF(1) - FF(11)) * compressed_perturbator) / (FF(11) * FF(11 - 1)),
(FF(32) - (FF(1) - FF(12)) * compressed_perturbator) / (FF(12) * FF(12 - 1)),
});

for (size_t idx = 2; idx < 7; idx++) {
Expand All @@ -263,7 +265,7 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
ProverInstances instances{ { instance1, instance2 } };
ProtoGalaxyProver::combine_relation_parameters(instances);

bb::Univariate<FF, 12> expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 } };
bb::Univariate<FF, 11> expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 } };
EXPECT_EQ(instances.relation_parameters.eta, expected_eta);
}

Expand All @@ -285,7 +287,7 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
ProverInstances instances{ { instance1, instance2 } };
ProtoGalaxyProver::combine_alpha(instances);

bb::Univariate<FF, 13> expected_alpha{ { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26 } };
bb::Univariate<FF, 12> expected_alpha{ { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 } };
for (const auto& alpha : instances.alphas) {
EXPECT_EQ(alpha, expected_alpha);
}
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ std::shared_ptr<typename ProverInstances::Instance> ProtoGalaxyProver_<ProverIns
auto& combined_relation_parameters = instances.relation_parameters;
auto folded_relation_parameters = bb::RelationParameters<FF>{
combined_relation_parameters.eta.evaluate(challenge),
combined_relation_parameters.eta_two.evaluate(challenge),
combined_relation_parameters.eta_three.evaluate(challenge),
combined_relation_parameters.beta.evaluate(challenge),
combined_relation_parameters.gamma.evaluate(challenge),
combined_relation_parameters.public_input_delta.evaluate(challenge),
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ std::shared_ptr<typename VerifierInstances::Instance> ProtoGalaxyVerifier_<Verif
for (size_t inst_idx = 0; inst_idx < VerifierInstances::NUM; inst_idx++) {
auto instance = instances[inst_idx];
expected_parameters.eta += instance->relation_parameters.eta * lagranges[inst_idx];
expected_parameters.eta_two += instance->relation_parameters.eta_two * lagranges[inst_idx];
expected_parameters.eta_three += instance->relation_parameters.eta_three * lagranges[inst_idx];
expected_parameters.beta += instance->relation_parameters.beta * lagranges[inst_idx];
expected_parameters.gamma += instance->relation_parameters.gamma * lagranges[inst_idx];
expected_parameters.public_input_delta +=
Expand Down
Loading

0 comments on commit 9bf8f99

Please sign in to comment.