Skip to content

Commit

Permalink
Small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Rumata888 committed Nov 28, 2023
1 parent 4fb61db commit 5bdcfed
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ void accumulate_logderivative_permutation_subrelation_contributions(ContainerOve
// To get the inverses (1 / read_term), (1 / write_term), we have a commitment to the product ofinver ses
// i.e. permutation_inverses = (1 / read_term) * (1 / write_term)
// The purpose of this next section is to derive individual inverse terms using `permutation_inverses`
// i.e. (1 / read_term) = permutation_inverse * write_term
// (1 / write_term) = permutation_inverse * read_term
// i.e. (1 / read_term) = permutation_inverses * write_term
// (1 / write_term) = permutation_inverses * read_term
permutation_terms[0] = permutation_relation.template compute_read_term<Accumulator, 0>(in, params);
permutation_terms[1] = permutation_relation.template compute_write_term<Accumulator, 0>(in, params);

Expand Down Expand Up @@ -242,8 +242,8 @@ void accumulate_logderivative_permutation_subrelation_contributions(ContainerOve
std::get<1>(accumulator) +=
permutation_relation.template compute_read_term_predicate<Accumulator, 0>(in) * denominator_accumulator[0];

// each predicate is degree-1, `lookup_read_counts` is degree-1
// degree of relation = NUM_TOTAL_TERMS + 2
// each predicate is degree-1
// degree of relation = NUM_TOTAL_TERMS + 1
std::get<1>(accumulator) -=
permutation_relation.template compute_write_term_predicate<Accumulator, 0>(in) * denominator_accumulator[1];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @file avm_template_circuit_builder.hpp
* @author Rumata888
* @brief A circuit builder for the AVM toy version used to showcase permutation and lookup mechanisms for PIL
*
*/
#pragma once

#include "barretenberg/ecc/curves/bn254/fr.hpp"
Expand Down Expand Up @@ -51,25 +57,29 @@ template <typename Flavor> class AVMTemplateCircuitBuilder {
polys.permutation_set_column_2[i] = wires[1][i];
polys.permutation_set_column_3[i] = wires[2][i];
polys.permutation_set_column_4[i] = wires[3][i];
// By default the permutation is over all rows where we place data
polys.enable_set_permutation[i] = 1;
}
return polys;
}

/**
* @brief Check that the circuit is correct (proof should work)
*
*/
bool check_circuit()
{
// For now only gamma and beta are used
const FF gamma = FF::random_element();
const FF beta = FF::random_element();
const FF beta_sqr = beta.sqr();
const FF beta_cube = beta_sqr * beta;
proof_system::RelationParameters<typename Flavor::FF> params{
.eta = 0,
.beta = beta,
.gamma = gamma,
.public_input_delta = 0,
.lookup_grand_product_delta = 0,
.beta_sqr = beta_sqr,
.beta_cube = beta_cube,
.beta_sqr = 0,
.beta_cube = 0,
.eccvm_set_permutation_delta = 0,
};

Expand All @@ -79,30 +89,6 @@ template <typename Flavor> class AVMTemplateCircuitBuilder {
compute_logderivative_inverse<Flavor, honk::sumcheck::GenericPermutationRelation<FF>>(
polynomials, params, num_rows);

// const auto evaluate_relation = [&]<typename Relation>(const std::string& relation_name) {
// typename Relation::SumcheckArrayOfValuesOverSubrelations result;
// for (auto& r : result) {
// r = 0;
// }
// constexpr size_t NUM_SUBRELATIONS = result.size();

// for (size_t i = 0; i < num_rows; ++i) {
// Relation::accumulate(result, polynomials.get_row(i), params, 1);

// bool x = true;
// for (size_t j = 0; j < NUM_SUBRELATIONS; ++j) {
// if (result[j] != 0) {
// info("Relation ", relation_name, ", subrelation index ", j, " failed at row ", i);
// x = false;
// }
// }
// if (!x) {
// return false;
// }
// }
// return true;
// };

using PermutationRelation = honk::sumcheck::GenericPermutationRelation<FF>;
typename honk::sumcheck::GenericPermutationRelation<typename Flavor::FF>::SumcheckArrayOfValuesOverSubrelations
permutation_result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ TYPED_TEST(AVMTemplateCircuitBuilderTests, BaseCase)
column_1.emplace_back(FF::random_element());
}
for (size_t i = 0; i < 16; i++) {
// Put the same values but in inverse order
circuit_builder.add_row({ column_0[i], column_1[i], column_0[15 - i], column_1[15 - i] });
}

// Test that the permutation with correct values works
bool result = circuit_builder.check_circuit();
EXPECT_EQ(result, true);
// And that it fails with incorrct values
circuit_builder.wires[0][5] = FF::random_element();
result = circuit_builder.check_circuit();
EXPECT_EQ(result, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
namespace proof_system::honk::sumcheck {

/**
* @brief Expression for ECCVM lookup tables.
* @details We use log-derivative lookup tables for the following case:
* Table writes: ECCVMPointTable columns: we define Straus point table:
* { {0, -15[P]}, {1, -13[P]}, ..., {15, 15[P]} }
* write source: { precompute_round, precompute_tx, precompute_ty }
* Table reads: ECCVMMSM columns. Each row adds up to 4 points into MSM accumulator
* read source: { msm_slice1, msm_x1, msm_y1 }, ..., { msm_slice4, msm_x4, msm_y4 }
* @param evals transformed to `evals + C(in(X)...)*scaling_factor`
* @brief Expression for generic log-derivative-based set permutation.
* @param accumulator transformed to `evals + C(in(X)...)*scaling_factor`
* @param in an std::array containing the fully extended Accumulator edges.
* @param parameters contains beta, gamma, and public_input_delta, ....
* @param relation_params contains beta, gamma, and public_input_delta, ....
* @param scaling_factor optional term to scale the evaluation before adding to evals.
*/
template <typename FF>
Expand Down

0 comments on commit 5bdcfed

Please sign in to comment.