Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions barretenberg/cpp/pil/vm2/alu.pil
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

include "constants_gen.pil";
include "execution.pil";
include "ff_gt.pil";
Expand All @@ -10,6 +9,7 @@ pol commit sel;

pol commit sel_op_add;
pol commit sel_op_lt;
pol commit sel_op_eq;
pol commit op_id;

pol commit ia;
Expand All @@ -26,6 +26,10 @@ sel = 0;
// carry flag
pol commit cf;

// Generic helper column
// Current use: EQ (inverse of a-b)
pol commit helper1;

// maximum bits the number can hold (i.e. 8 for a u8):
pol commit max_bits;
// maximum value the number can hold (i.e. 255 for a u8), we 'mod' by max_value + 1
Expand All @@ -42,7 +46,9 @@ sel_is_ff * (1 - sel_is_ff) = 0;
// TODO(MW): Add other ops like: sel_op_add * AVM_EXEC_OP_ID_ALU_ADD + sel_op_sub * AVM_EXEC_OP_ID_ALU_SUB + sel_op_mul * AVM_EXEC_OP_ID_ALU_MUL - op_id = 0;
// Note that the op_ids below represent a binary decomposition (see constants_gen.pil):
#[OP_ID_CHECK]
sel_op_add * constants.AVM_EXEC_OP_ID_ALU_ADD + sel_op_lt * constants.AVM_EXEC_OP_ID_ALU_LT - op_id = 0;
op_id = sel_op_add * constants.AVM_EXEC_OP_ID_ALU_ADD
+ sel_op_lt * constants.AVM_EXEC_OP_ID_ALU_LT
+ sel_op_eq * constants.AVM_EXEC_OP_ID_ALU_EQ;

#[REGISTER_TAG_VALUE]
execution.sel_alu {
Expand All @@ -68,7 +74,7 @@ CHECK_TAG_FF * (TAG_FF_DIFF * (sel_is_ff * (1 - tag_ff_diff_inv) + tag_ff_diff_i
// TAG CHECKING

// Will become e.g. sel_op_add * ia_tag + (comparison ops) * MEM_TAG_U1 + ....
pol EXPECTED_C_TAG = sel_op_add * ia_tag + sel_op_lt * constants.MEM_TAG_U1;
pol EXPECTED_C_TAG = sel_op_add * ia_tag + (sel_op_lt + sel_op_eq) * constants.MEM_TAG_U1;

// No error handling here since, as a memory write, the type of c is handled by the VM:
#[C_TAG_CHECK]
Expand Down Expand Up @@ -114,3 +120,16 @@ pol commit lt_abs_diff;
sel_op_lt * ( IS_NOT_FF * ( (A_LT_B - A_GTE_B) * ic + A_GTE_B ) - lt_abs_diff ) = 0;
#[LT_RANGE]
sel_op_lt { lt_abs_diff, max_bits } in range_check.sel { range_check.value, range_check.rng_chk_bits };


// EQ

pol DIFF = ia - ib;

// Use helper1 to invert DIFF.
// ic is a boolean output and ic == 1 <==> a == b.
// Important: ic boolean constraint is enforced as part of write to memory due to ic_tag == U1 as enforced by #[C_TAG_CHECK].

// sel_op_eq == 1 => [ic == 1 <==> DIFF == 0]
#[EQ_OP_MAIN]
sel_op_eq * (DIFF * (ic * (1 - helper1) + helper1) - 1 + ic) = 0;
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void compute_row_evaluations(State& state) noexcept
{
using PGInternal = ProtogalaxyProverInternal<DeciderProvingKeys_<Flavor, 2>>;
using Polys = Flavor::ProverPolynomials;
using Alphas = Flavor::RelationSeparator;
using Alphas = Flavor::SubrelationSeparators;
using Params = RelationParameters<FF>;

const size_t dyadic_size = 1 << state.range(0);
Expand Down
10 changes: 5 additions & 5 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,19 @@ TEST_F(ECCVMTests, CommittedSumcheck)

// Run Sumcheck on the ECCVM Prover polynomials
using SumcheckProver = SumcheckProver<ECCVMFlavor, CONST_ECCVM_LOG_N>;
SumcheckProver sumcheck_prover(pk->circuit_size, prover_transcript);
SumcheckProver sumcheck_prover(
pk->circuit_size, pk->polynomials, prover_transcript, alpha, gate_challenges, relation_parameters);

ZKData zk_sumcheck_data = ZKData(CONST_ECCVM_LOG_N, prover_transcript);

auto prover_output =
sumcheck_prover.prove(pk->polynomials, relation_parameters, alpha, gate_challenges, zk_sumcheck_data);
auto prover_output = sumcheck_prover.prove(zk_sumcheck_data);

std::shared_ptr<Transcript> verifier_transcript = std::make_shared<Transcript>();
verifier_transcript->load_proof(prover_transcript->export_proof());

// Execute Sumcheck Verifier
SumcheckVerifier<Flavor, CONST_ECCVM_LOG_N> sumcheck_verifier(verifier_transcript);
SumcheckOutput<ECCVMFlavor> verifier_output = sumcheck_verifier.verify(relation_parameters, alpha, gate_challenges);
SumcheckVerifier<Flavor, CONST_ECCVM_LOG_N> sumcheck_verifier(verifier_transcript, alpha);
SumcheckOutput<ECCVMFlavor> verifier_output = sumcheck_verifier.verify(relation_parameters, gate_challenges);

// Evaluate prover's round univariates at corresponding challenges and compare them with the claimed evaluations
// computed by the verifier
Expand Down
4 changes: 3 additions & 1 deletion barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class ECCVMFlavor {
using Commitment = typename G1::affine_element;
using CommitmentKey = bb::CommitmentKey<Curve>;
using VerifierCommitmentKey = bb::VerifierCommitmentKey<Curve>;
using RelationSeparator = FF;
using MSM = bb::eccvm::MSM<CycleGroup>;
using Transcript = NativeTranscript;

Expand Down Expand Up @@ -96,6 +95,9 @@ class ECCVMFlavor {
using Relations = Relations_<FF>;
using LookupRelation = ECCVMLookupRelation<FF>;

static constexpr size_t NUM_SUBRELATIONS = compute_number_of_subrelations<Relations>();
using SubrelationSeparators = std::array<FF, NUM_SUBRELATIONS - 1>;

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`
Expand Down
8 changes: 6 additions & 2 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,20 @@ void ECCVMProver::execute_relation_check_rounds()

using Sumcheck = SumcheckProver<Flavor, CONST_ECCVM_LOG_N>;

Sumcheck sumcheck(key->circuit_size, transcript);
// Each linearly independent subrelation contribution is multiplied by `alpha^i`, where
// i = 0, ..., NUM_SUBRELATIONS- 1.
FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");

std::vector<FF> gate_challenges(CONST_ECCVM_LOG_N);
for (size_t idx = 0; idx < gate_challenges.size(); idx++) {
gate_challenges[idx] = transcript->template get_challenge<FF>("Sumcheck:gate_challenge_" + std::to_string(idx));
}

Sumcheck sumcheck(key->circuit_size, key->polynomials, transcript, alpha, gate_challenges, relation_parameters);

zk_sumcheck_data = ZKData(key->log_circuit_size, transcript, key->commitment_key);

sumcheck_output = sumcheck.prove(key->polynomials, relation_parameters, alpha, gate_challenges, zk_sumcheck_data);
sumcheck_output = sumcheck.prove(zk_sumcheck_data);
}

/**
Expand Down
22 changes: 11 additions & 11 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ namespace bb {
class ECCVMProver {
public:
using Flavor = ECCVMFlavor;
using FF = typename Flavor::FF;
using BF = typename Flavor::BF;
using Commitment = typename Flavor::Commitment;
using PCS = typename Flavor::PCS;
using CommitmentKey = typename Flavor::CommitmentKey;
using ProvingKey = typename Flavor::ProvingKey;
using Polynomial = typename Flavor::Polynomial;
using CommitmentLabels = typename Flavor::CommitmentLabels;
using Transcript = typename Flavor::Transcript;
using FF = Flavor::FF;
using BF = Flavor::BF;
using Commitment = Flavor::Commitment;
using PCS = Flavor::PCS;
using CommitmentKey = Flavor::CommitmentKey;
using ProvingKey = Flavor::ProvingKey;
using Polynomial = Flavor::Polynomial;
using CommitmentLabels = Flavor::CommitmentLabels;
using Transcript = Flavor::Transcript;
using TranslationEvaluations = bb::TranslationEvaluations_<FF>;
using CircuitBuilder = typename Flavor::CircuitBuilder;
using CircuitBuilder = Flavor::CircuitBuilder;
using ZKData = ZKSumcheckData<Flavor>;
using SmallSubgroupIPA = SmallSubgroupIPAProver<Flavor>;
using OpeningClaim = ProverOpeningClaim<typename Flavor::Curve>;
using OpeningClaim = ProverOpeningClaim<Flavor::Curve>;

explicit ECCVMProver(CircuitBuilder& builder,
const std::shared_ptr<Transcript>& transcript,
Expand Down
10 changes: 7 additions & 3 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ bool ECCVMVerifier::verify_proof(const ECCVMProof& proof)
transcript->template receive_from_prover<Commitment>(commitment_labels.lookup_inverses);
commitments.z_perm = transcript->template receive_from_prover<Commitment>(commitment_labels.z_perm);

// Each linearly independent subrelation contribution is multiplied by `alpha^i`, where
// i = 0, ..., NUM_SUBRELATIONS- 1.
const FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");

// Execute Sumcheck Verifier
SumcheckVerifier<Flavor, CONST_ECCVM_LOG_N> sumcheck(transcript);
FF alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
SumcheckVerifier<Flavor, CONST_ECCVM_LOG_N> sumcheck(transcript, alpha);

std::vector<FF> gate_challenges(CONST_ECCVM_LOG_N);
for (size_t idx = 0; idx < gate_challenges.size(); idx++) {
gate_challenges[idx] = transcript->template get_challenge<FF>("Sumcheck:gate_challenge_" + std::to_string(idx));
Expand All @@ -66,7 +70,7 @@ bool ECCVMVerifier::verify_proof(const ECCVMProof& proof)

libra_commitments[0] = transcript->template receive_from_prover<Commitment>("Libra:concatenation_commitment");

auto sumcheck_output = sumcheck.verify(relation_parameters, alpha, gate_challenges);
auto sumcheck_output = sumcheck.verify(relation_parameters, gate_challenges);

libra_commitments[1] = transcript->template receive_from_prover<Commitment>("Libra:grand_sum_commitment");
libra_commitments[2] = transcript->template receive_from_prover<Commitment>("Libra:quotient_commitment");
Expand Down
20 changes: 10 additions & 10 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_verifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
namespace bb {
class ECCVMVerifier {
using Flavor = ECCVMFlavor;
using FF = typename Flavor::FF;
using Curve = typename Flavor::Curve;
using Commitment = typename Flavor::Commitment;
using CommitmentLabels = typename Flavor::CommitmentLabels;
using Transcript = typename Flavor::Transcript;
using ProvingKey = typename Flavor::ProvingKey;
using VerificationKey = typename Flavor::VerificationKey;
using VerifierCommitments = typename Flavor::VerifierCommitments;
using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey;
using PCS = typename Flavor::PCS;
using FF = Flavor::FF;
using Curve = Flavor::Curve;
using Commitment = Flavor::Commitment;
using CommitmentLabels = Flavor::CommitmentLabels;
using Transcript = Flavor::Transcript;
using ProvingKey = Flavor::ProvingKey;
using VerificationKey = Flavor::VerificationKey;
using VerifierCommitments = Flavor::VerifierCommitments;
using VerifierCommitmentKey = Flavor::VerifierCommitmentKey;
using PCS = Flavor::PCS;

public:
explicit ECCVMVerifier(const std::shared_ptr<Transcript>& transcript)
Expand Down
43 changes: 1 addition & 42 deletions barretenberg/cpp/src/barretenberg/flavor/flavor_concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,49 +57,8 @@ concept IsRecursiveFlavor = IsAnyOf<T, UltraRecursiveFlavor_<UltraCircuitBuilder
AvmRecursiveFlavor,
avm2::AvmRecursiveFlavor>;

// These concepts are relevant for Sumcheck, where the logic is different for BN254 and Grumpkin Flavors
// This concept is relevant for the Sumcheck Prover, where the logic differs between BN254 and Grumpkin
template <typename T> concept IsGrumpkinFlavor = IsAnyOf<T, ECCVMFlavor, ECCVMRecursiveFlavor>;
template <typename T> concept IsECCVMRecursiveFlavor = IsAnyOf<T, ECCVMRecursiveFlavor>;

#ifdef STARKNET_GARAGA_FLAVORS
template <typename T> concept IsFoldingFlavor = IsAnyOf<T, UltraFlavor,
// Note(md): must be here to use oink prover
UltraKeccakFlavor,
UltraStarknetFlavor,
UltraKeccakZKFlavor,
UltraStarknetZKFlavor,
UltraRollupFlavor,
UltraZKFlavor,
MegaFlavor,
MegaZKFlavor,
UltraRecursiveFlavor_<UltraCircuitBuilder>,
UltraRecursiveFlavor_<MegaCircuitBuilder>,
UltraRollupRecursiveFlavor_<UltraCircuitBuilder>,
MegaRecursiveFlavor_<UltraCircuitBuilder>,
MegaRecursiveFlavor_<MegaCircuitBuilder>,
MegaZKRecursiveFlavor_<MegaCircuitBuilder>,
MegaZKRecursiveFlavor_<UltraCircuitBuilder>>;
#else
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1426): Rename this.
template <typename T> concept IsFoldingFlavor = IsAnyOf<T, UltraFlavor,
// Note(md): must be here to use oink prover
UltraKeccakFlavor,
UltraKeccakZKFlavor,
UltraRollupFlavor,
UltraZKFlavor,
MegaFlavor,
MegaZKFlavor,
UltraRecursiveFlavor_<UltraCircuitBuilder>,
UltraRecursiveFlavor_<MegaCircuitBuilder>,
UltraZKRecursiveFlavor_<UltraCircuitBuilder>,
UltraZKRecursiveFlavor_<MegaCircuitBuilder>,
UltraRollupRecursiveFlavor_<UltraCircuitBuilder>,
MegaRecursiveFlavor_<UltraCircuitBuilder>,
MegaRecursiveFlavor_<MegaCircuitBuilder>,
MegaZKRecursiveFlavor_<MegaCircuitBuilder>,
MegaZKRecursiveFlavor_<UltraCircuitBuilder>>;
#endif

template <typename Container, typename Element>
inline std::string flavor_get_label(Container&& container, const Element& element) {
for (auto [label, data] : zip_view(container.get_labels(), container.get_all())) {
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/flavor/mega_flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class MegaFlavor {
// subrelation. This is because using powers of alpha would increase the degree of Protogalaxy polynomial $G$ (the
// combiner) too much.
static constexpr size_t NUM_SUBRELATIONS = compute_number_of_subrelations<Relations>();
using RelationSeparator = std::array<FF, NUM_SUBRELATIONS - 1>;
using SubrelationSeparators = std::array<FF, NUM_SUBRELATIONS - 1>;

template <size_t NUM_KEYS>
using ProtogalaxyTupleOfTuplesOfUnivariatesNoOptimisticSkipping =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ template <typename BuilderType> class MegaRecursiveFlavor_ {
// For instances of this flavour, used in folding, we need a unique sumcheck batching challenge for each
// subrelation. This is because using powers of alpha would increase the degree of Protogalaxy polynomial $G$ (the
// combiner) to much.
static constexpr size_t NUM_SUBRELATIONS = compute_number_of_subrelations<Relations>();
using RelationSeparator = std::array<FF, NUM_SUBRELATIONS - 1>;
static constexpr size_t NUM_SUBRELATIONS = MegaFlavor::NUM_SUBRELATIONS;
using SubrelationSeparators = std::array<FF, NUM_SUBRELATIONS - 1>;

// define the container for storing the univariate contribution from each relation in Sumcheck
using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values<Relations>());
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/flavor/ultra_flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class UltraFlavor {
// For instances of this flavour, used in folding, we need a unique sumcheck batching challenge for each
// subrelation. This is because using powers of alpha would increase the degree of Protogalaxy polynomial $G$ (the
// combiner) too much.
using RelationSeparator = std::array<FF, NUM_SUBRELATIONS - 1>;
using SubrelationSeparators = std::array<FF, NUM_SUBRELATIONS - 1>;

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ template <typename BuilderType> class UltraRecursiveFlavor_ {
// For instances of this flavour, used in folding, we need a unique sumcheck batching challenges for each
// subrelation to avoid increasing the degree of Protogalaxy polynomial $G$ (the
// combiner) too much.
static constexpr size_t NUM_SUBRELATIONS = compute_number_of_subrelations<Relations>();
using RelationSeparator = std::array<FF, NUM_SUBRELATIONS - 1>;
static constexpr size_t NUM_SUBRELATIONS = NativeFlavor::NUM_SUBRELATIONS;
using SubrelationSeparators = std::array<FF, NUM_SUBRELATIONS - 1>;

// define the container for storing the univariate contribution from each relation in Sumcheck
using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values<Relations>());
Expand Down
12 changes: 6 additions & 6 deletions barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PGInternalTest : public ProtogalaxyProverInternal<DeciderProvingKeys_<Flav
const DeciderPKs& keys,
const GateSeparatorPolynomial<FF>& gate_separators,
const UnivariateRelationParametersNoOptimisticSkipping& relation_parameters,
const UnivariateRelationSeparator& alphas)
const UnivariateSubrelationSeparators& alphas)
{
TupleOfTuplesOfUnivariatesNoOptimisticSkipping accumulators;
return compute_combiner_no_optimistic_skipping(
Expand All @@ -62,7 +62,7 @@ class PGInternalTest : public ProtogalaxyProverInternal<DeciderProvingKeys_<Flav
const DeciderPKs& keys,
const GateSeparatorPolynomial<FF>& gate_separators,
const UnivariateRelationParametersNoOptimisticSkipping& relation_parameters,
const UnivariateRelationSeparator& alphas,
const UnivariateSubrelationSeparators& alphas,
TupleOfTuplesOfUnivariatesNoOptimisticSkipping& univariate_accumulators)
{
PROFILE_THIS();
Expand Down Expand Up @@ -208,7 +208,7 @@ TEST(Protogalaxy, CombinerOn2Keys)
}

DeciderProvingKeys keys{ keys_data };
PGInternalTest::UnivariateRelationSeparator alphas;
PGInternalTest::UnivariateSubrelationSeparators alphas;
alphas.fill(bb::Univariate<FF, 12>(FF(0))); // focus on the arithmetic relation only
GateSeparatorPolynomial<FF> gate_separators({ 2 }, /*log_num_monomials=*/1);
PGInternalTest::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters_no_skpping;
Expand Down Expand Up @@ -242,7 +242,7 @@ TEST(Protogalaxy, CombinerOn2Keys)
}

DeciderProvingKeys keys{ keys_data };
PGInternalTest::UnivariateRelationSeparator alphas;
PGInternalTest::UnivariateSubrelationSeparators alphas;
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) {
Expand Down Expand Up @@ -346,7 +346,7 @@ TEST(Protogalaxy, CombinerOptimizationConsistency)
}

DeciderProvingKeys keys{ keys_data };
PGInternalTest::UnivariateRelationSeparator alphas;
PGInternalTest::UnivariateSubrelationSeparators alphas;
alphas.fill(bb::Univariate<FF, UNIVARIATE_LENGTH>(FF(0))); // focus on the arithmetic relation only
GateSeparatorPolynomial<FF> gate_separators({ 2 }, /*log_num_monomials=*/1);

Expand Down Expand Up @@ -431,7 +431,7 @@ TEST(Protogalaxy, CombinerOptimizationConsistency)
}

DeciderProvingKeys keys{ keys_data };
PGInternalTest::UnivariateRelationSeparator alphas;
PGInternalTest::UnivariateSubrelationSeparators alphas;
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) {
Expand Down
Loading
Loading