Skip to content

Commit

Permalink
feat: avm logup (#5577)
Browse files Browse the repository at this point in the history
relevant codegen pr AztecProtocol/powdr#54
  • Loading branch information
Maddiaa0 committed Apr 9, 2024
1 parent fb66426 commit 7e4e9b9
Show file tree
Hide file tree
Showing 23 changed files with 624 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class incl_main_tag_err_lookup_settings {
* @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed
*
*/
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 2;
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4;

/**
* @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class incl_mem_tag_err_lookup_settings {
* @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed
*
*/
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 2;
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4;

/**
* @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class lookup_byte_lengths_lookup_settings {
* @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed
*
*/
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 2;
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4;

/**
* @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class lookup_byte_operations_lookup_settings {
* @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed
*
*/
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 2;
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4;

/**
* @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ template <typename Flavor> class SumcheckProver {
pow_univariate.partially_evaluate(round_challenge);
round.round_size = round.round_size >> 1; // TODO(#224)(Cody): Maybe partially_evaluate should do this and
// release memory? // All but final round
// We operate on partially_evaluated_polynomials in place.
// We operate on partially_evaluated_polynomials in place.
for (size_t round_idx = 1; round_idx < multivariate_d; round_idx++) {
// Write the round univariate to the transcript
round_univariate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ template <typename Flavor> class SumcheckProverRound {
{
BB_OP_COUNT_TIME();

// Compute the constant contribution of pow polynomials for each edge. This is the product of the partial
// Compute the constant contribution of pow polynomials for each edge. This is the product of the partial
// evaluation result c_l (i.e. pow(u_0,...,u_{l-1})) where u_0,...,u_{l-1} are the verifier challenges from
// previous rounds) and the elements of pow(\vec{β}) not containing β_0,..., β_l.
std::vector<FF> pow_challenges(round_size >> 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ template <typename Flavor> bool UltraVerifier_<Flavor>::verify_proof(const HonkP
transcript);
auto pcs_verified = key->pcs_verification_key->pairing_check(pairing_points[0], pairing_points[1]);
return sumcheck_verified.value() && pcs_verified;
;
}

template class UltraVerifier_<UltraFlavor>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,7 @@ class AvmCircuitBuilder {
polys.avm_mem_val[i] = rows[i].avm_mem_val;
polys.avm_mem_w_in_tag[i] = rows[i].avm_mem_w_in_tag;
polys.perm_main_alu[i] = rows[i].perm_main_alu;
polys.perm_main_bin[i] = rows[i].perm_main_bin;
polys.perm_main_mem_a[i] = rows[i].perm_main_mem_a;
polys.perm_main_mem_b[i] = rows[i].perm_main_mem_b;
polys.perm_main_mem_c[i] = rows[i].perm_main_mem_c;
polys.perm_main_mem_ind_a[i] = rows[i].perm_main_mem_ind_a;
polys.perm_main_mem_ind_b[i] = rows[i].perm_main_mem_ind_b;
polys.perm_main_mem_ind_c[i] = rows[i].perm_main_mem_ind_c;
polys.lookup_byte_lengths[i] = rows[i].lookup_byte_lengths;
polys.lookup_byte_operations[i] = rows[i].lookup_byte_operations;
polys.incl_main_tag_err[i] = rows[i].incl_main_tag_err;
polys.incl_mem_tag_err[i] = rows[i].incl_mem_tag_err;

polys.lookup_byte_lengths_counts[i] = rows[i].lookup_byte_lengths_counts;
polys.lookup_byte_operations_counts[i] = rows[i].lookup_byte_operations_counts;
polys.incl_main_tag_err_counts[i] = rows[i].incl_main_tag_err_counts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ AvmProver AvmComposer::create_prover(CircuitConstructor& circuit_constructor)
compute_witness(circuit_constructor);
compute_commitment_key(circuit_constructor.get_circuit_subgroup_size());

AvmProver output_state(proving_key, commitment_key);
AvmProver output_state(proving_key, proving_key->commitment_key);

return output_state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AvmComposer {

void compute_commitment_key(size_t circuit_size)
{
commitment_key = std::make_shared<CommitmentKey>(circuit_size);
proving_key->commitment_key = std::make_shared<CommitmentKey>(circuit_size);
};
};

Expand Down
100 changes: 96 additions & 4 deletions barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "barretenberg/relations/generated/avm/avm_binary.hpp"
#include "barretenberg/relations/generated/avm/avm_main.hpp"
#include "barretenberg/relations/generated/avm/avm_mem.hpp"
#include "barretenberg/relations/generated/avm/incl_main_tag_err.hpp"
#include "barretenberg/relations/generated/avm/incl_mem_tag_err.hpp"
#include "barretenberg/relations/generated/avm/lookup_byte_lengths.hpp"
#include "barretenberg/relations/generated/avm/lookup_byte_operations.hpp"
#include "barretenberg/relations/generated/avm/perm_main_alu.hpp"
#include "barretenberg/relations/generated/avm/perm_main_bin.hpp"
#include "barretenberg/relations/generated/avm/perm_main_mem_a.hpp"
Expand Down Expand Up @@ -52,6 +56,19 @@ class AvmFlavor {
// the unshifted and one for the shifted
static constexpr size_t NUM_ALL_ENTITIES = 159;

using GrandProductRelations = std::tuple<perm_main_alu_relation<FF>,
perm_main_bin_relation<FF>,
perm_main_mem_a_relation<FF>,
perm_main_mem_b_relation<FF>,
perm_main_mem_c_relation<FF>,
perm_main_mem_ind_a_relation<FF>,
perm_main_mem_ind_b_relation<FF>,
perm_main_mem_ind_c_relation<FF>,
incl_main_tag_err_relation<FF>,
incl_mem_tag_err_relation<FF>,
lookup_byte_lengths_relation<FF>,
lookup_byte_operations_relation<FF>>;

using Relations = std::tuple<Avm_vm::avm_alu<FF>,
Avm_vm::avm_binary<FF>,
Avm_vm::avm_main<FF>,
Expand All @@ -63,15 +80,19 @@ class AvmFlavor {
perm_main_mem_c_relation<FF>,
perm_main_mem_ind_a_relation<FF>,
perm_main_mem_ind_b_relation<FF>,
perm_main_mem_ind_c_relation<FF>>;
perm_main_mem_ind_c_relation<FF>,
incl_main_tag_err_relation<FF>,
incl_mem_tag_err_relation<FF>,
lookup_byte_lengths_relation<FF>,
lookup_byte_operations_relation<FF>>;

static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();

// BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
// random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
// length = 3
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1;
static constexpr size_t NUM_RELATIONS = std::tuple_size<Relations>::value;
static constexpr size_t NUM_RELATIONS = std::tuple_size_v<Relations>;

template <size_t NUM_INSTANCES>
using ProtogalaxyTupleOfTuplesOfUnivariates =
Expand Down Expand Up @@ -377,7 +398,6 @@ class AvmFlavor {
incl_main_tag_err_counts,
incl_mem_tag_err_counts };
};
RefVector<DataType> get_sorted_polynomials() { return {}; };
};

template <typename DataType> class AllEntities {
Expand Down Expand Up @@ -899,9 +919,56 @@ class AvmFlavor {

// The plookup wires that store plookup read data.
std::array<PolynomialHandle, 0> get_table_column_wires() { return {}; };

void compute_logderivative_inverses(const RelationParameters<FF>& relation_parameters)
{
ProverPolynomials prover_polynomials = ProverPolynomials(*this);

bb::compute_logderivative_inverse<AvmFlavor, perm_main_alu_relation<FF>>(
prover_polynomials, relation_parameters, this->circuit_size);
bb::compute_logderivative_inverse<AvmFlavor, perm_main_bin_relation<FF>>(
prover_polynomials, relation_parameters, this->circuit_size);
bb::compute_logderivative_inverse<AvmFlavor, perm_main_mem_a_relation<FF>>(
prover_polynomials, relation_parameters, this->circuit_size);
bb::compute_logderivative_inverse<AvmFlavor, perm_main_mem_b_relation<FF>>(
prover_polynomials, relation_parameters, this->circuit_size);
bb::compute_logderivative_inverse<AvmFlavor, perm_main_mem_c_relation<FF>>(
prover_polynomials, relation_parameters, this->circuit_size);
bb::compute_logderivative_inverse<AvmFlavor, perm_main_mem_ind_a_relation<FF>>(
prover_polynomials, relation_parameters, this->circuit_size);
bb::compute_logderivative_inverse<AvmFlavor, perm_main_mem_ind_b_relation<FF>>(
prover_polynomials, relation_parameters, this->circuit_size);
bb::compute_logderivative_inverse<AvmFlavor, perm_main_mem_ind_c_relation<FF>>(
prover_polynomials, relation_parameters, this->circuit_size);
bb::compute_logderivative_inverse<AvmFlavor, incl_main_tag_err_relation<FF>>(
prover_polynomials, relation_parameters, this->circuit_size);
bb::compute_logderivative_inverse<AvmFlavor, incl_mem_tag_err_relation<FF>>(
prover_polynomials, relation_parameters, this->circuit_size);
bb::compute_logderivative_inverse<AvmFlavor, lookup_byte_lengths_relation<FF>>(
prover_polynomials, relation_parameters, this->circuit_size);
bb::compute_logderivative_inverse<AvmFlavor, lookup_byte_operations_relation<FF>>(
prover_polynomials, relation_parameters, this->circuit_size);
}
};

using VerificationKey = VerificationKey_<PrecomputedEntities<Commitment>, VerifierCommitmentKey>;
class VerificationKey : public VerificationKey_<PrecomputedEntities<Commitment>, VerifierCommitmentKey> {
public:
VerificationKey() = default;
VerificationKey(const size_t circuit_size, const size_t num_public_inputs)
: VerificationKey_(circuit_size, num_public_inputs)
{}

VerificationKey(ProvingKey& proving_key)
{
this->pcs_verification_key = std::make_shared<VerifierCommitmentKey>();
this->circuit_size = proving_key.circuit_size;
this->log_circuit_size = numeric::get_msb(this->circuit_size);

for (auto [polynomial, commitment] : zip_view(proving_key.get_precomputed_polynomials(), this->get_all())) {
commitment = proving_key.commitment_key->commit(polynomial);
}
}
};

using FoldedPolynomials = AllEntities<std::vector<FF>>;

Expand All @@ -923,6 +990,20 @@ class AvmFlavor {
ProverPolynomials(ProverPolynomials&& o) noexcept = default;
ProverPolynomials& operator=(ProverPolynomials&& o) noexcept = default;
~ProverPolynomials() = default;

// NOTE: copied from goblin ultra
ProverPolynomials(ProvingKey& proving_key)
{
for (auto [prover_poly, key_poly] : zip_view(this->get_unshifted(), proving_key.get_all())) {
ASSERT(flavor_get_label(*this, prover_poly) == flavor_get_label(proving_key, key_poly));
prover_poly = key_poly.share();
}
for (auto [prover_poly, key_poly] : zip_view(this->get_shifted(), proving_key.get_to_be_shifted())) {
ASSERT(flavor_get_label(*this, prover_poly) == (flavor_get_label(proving_key, key_poly) + "_shift"));
prover_poly = key_poly.shifted();
}
}

[[nodiscard]] size_t get_polynomial_size() const { return avm_alu_alu_sel.size(); }
/**
* @brief Returns the evaluations of all prover polynomials at one point on the boolean hypercube, which
Expand Down Expand Up @@ -963,6 +1044,12 @@ class AvmFlavor {
*/
using ExtendedEdges = ProverUnivariates<MAX_PARTIAL_RELATION_LENGTH>;

/**
* @brief A container for the witness commitments.
*
*/
using WitnessCommitments = WitnessEntities<Commitment>;

class CommitmentLabels : public AllEntities<std::string> {
private:
using Base = AllEntities<std::string>;
Expand Down Expand Up @@ -1252,6 +1339,8 @@ class AvmFlavor {
Commitment avm_mem_tag_err;
Commitment avm_mem_val;
Commitment avm_mem_w_in_tag;

// Perm inverses
Commitment perm_main_alu;
Commitment perm_main_bin;
Commitment perm_main_mem_a;
Expand All @@ -1260,10 +1349,13 @@ class AvmFlavor {
Commitment perm_main_mem_ind_a;
Commitment perm_main_mem_ind_b;
Commitment perm_main_mem_ind_c;
// Lookup inverses
Commitment lookup_byte_lengths;
Commitment lookup_byte_operations;
Commitment incl_main_tag_err;
Commitment incl_mem_tag_err;

// Lookup counts
Commitment lookup_byte_lengths_counts;
Commitment lookup_byte_operations_counts;
Commitment incl_main_tag_err_counts;
Expand Down

0 comments on commit 7e4e9b9

Please sign in to comment.