Skip to content

Commit

Permalink
feat: representation of a grumpkin verifier commitment key inside a b…
Browse files Browse the repository at this point in the history
…n254 circuit (#6593)

This PR creates a representation of Grumpkin `VerifierCommitmentKey`
inside a bn254 circuit and ensure consistency with native part. This is
necessary to enable IPA verification in the recursive setting. I took a
minimalist approach and excluded the `pippenger_runtime_state` as we
will initially do MSMs in the IPA verifier via `batch_mul`. This is
because pippenger needs to be rewritten to be usable in a recursive
settings. I also restricted access to the `VerifierSrs` via member
functions in the native `VerifierCommitmentKey`. This work is a step
towards the ECCVM recursive verifier.
  • Loading branch information
maramihali authored May 22, 2024
1 parent 2d10848 commit 1d84975
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 7 deletions.
1 change: 1 addition & 0 deletions barretenberg/cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ add_subdirectory(barretenberg/crypto)
add_subdirectory(barretenberg/dsl)
add_subdirectory(barretenberg/ecc)
add_subdirectory(barretenberg/eccvm)
add_subdirectory(barretenberg/eccvm_recursion)
add_subdirectory(barretenberg/env)
add_subdirectory(barretenberg/execution_trace)
add_subdirectory(barretenberg/examples)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ template <typename Curve_> class IPA {
/*finite_field_additions_per_iteration=*/0,
/*finite_field_multiplications_per_iteration=*/log_poly_degree);

auto* srs_elements = vk->srs->get_monomial_points();
auto* srs_elements = vk->get_monomial_points();

// Copy the G_vector to local memory.
std::vector<Commitment> G_vec_local(poly_length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ template <typename Curve> class ShplonkVerifier_ {
}

// [G] += G₀⋅[1] = [G] + (∑ⱼ ρʲ ⋅ vⱼ / ( r − xⱼ ))⋅[1]
G_commitment += vk->srs->get_first_g1() * G_commitment_constant;
G_commitment += vk->get_first_g1() * G_commitment_constant;
}

// Return opening pair (z, 0) and commitment [G]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ template <> class VerifierCommitmentKey<curve::BN254> {
using Commitment = typename Curve::AffineElement;

public:
std::shared_ptr<bb::srs::factories::VerifierCrs<Curve>> srs;

VerifierCommitmentKey()
{
srs::init_crs_factory("../srs_db/ignition");
srs = srs::get_crs_factory<Curve>()->get_verifier_crs();
};

Commitment get_first_g1() { return srs->get_first_g1(); }

/**
* @brief verifies a pairing equation over 2 points using the verifier SRS
*
Expand All @@ -58,6 +58,9 @@ template <> class VerifierCommitmentKey<curve::BN254> {

return (result == Curve::TargetField::one());
}

private:
std::shared_ptr<bb::srs::factories::VerifierCrs<Curve>> srs;
};

/**
Expand All @@ -71,8 +74,6 @@ template <> class VerifierCommitmentKey<curve::Grumpkin> {
using Commitment = typename Curve::AffineElement;

public:
VerifierCommitmentKey() = delete;

/**
* @brief Construct a new IPA Verification Key object from existing SRS
*
Expand All @@ -92,7 +93,13 @@ template <> class VerifierCommitmentKey<curve::Grumpkin> {
srs = srs::get_crs_factory<Curve>()->get_verifier_crs(num_points);
}

Commitment get_first_g1() { return srs->get_first_g1(); }

Commitment* get_monomial_points() { return srs->get_monomial_points(); }

bb::scalar_multiplication::pippenger_runtime_state<Curve> pippenger_runtime_state;

private:
std::shared_ptr<bb::srs::factories::VerifierCrs<Curve>> srs;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ template <typename PCS> class ZeroMorphVerifier_ {
auto builder = multivariate_challenge[0].get_context();
first_g1 = Commitment(builder, vk->srs->get_first_g1());
} else {
first_g1 = vk->srs->get_first_g1();
first_g1 = vk->get_first_g1();
}
auto opening_claim = compute_univariate_evaluation_opening_claim(unshifted_commitments,
to_be_shifted_commitments,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
barretenberg_module(eccvm_recursion stdlib_circuit_builders commitment_schemes stdlib_primitives)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once
#include "barretenberg/commitment_schemes/verification_key.hpp"
#include "barretenberg/stdlib/primitives/curves/bn254.hpp"
#include "barretenberg/stdlib/primitives/group/cycle_group.hpp"
namespace bb {

/**
* @brief Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit
*
* @tparam Builder
*/
template <typename Builder> class VerifierCommitmentKey<stdlib::bn254<Builder>> {
using Commitment = stdlib::cycle_group<Builder>;

public:
/**
* @brief Construct a new Verifier Commitment Key object from its native counterpart. instantiated on Grumpkin. This
* will potentially be part of the ECCVMRecursiveFlavor once implemented.
*
* @details The Grumpkin SRS points will be initialised as constants in the circuit but might be subsequently turned
* into constant witnesses to make operations in the circuit more efficient.
*/
VerifierCommitmentKey([[maybe_unused]] Builder* builder,
size_t num_points,
std::shared_ptr<VerifierCommitmentKey<curve::Grumpkin>>& native_pcs_verification_key)
: first_g1(Commitment(native_pcs_verification_key->get_first_g1()))
{

auto* native_points = native_pcs_verification_key->get_monomial_points();
for (size_t i = 0; i < num_points; i++) {
monomial_points.emplace_back(Commitment(native_points[i]));
}
}

Commitment get_first_g1() { return first_g1; }
std::vector<Commitment> get_monomial_points() { return monomial_points; }

private:
Commitment first_g1;
std::vector<Commitment> monomial_points;
};
} // namespace bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

#include "barretenberg/eccvm_recursion/verifier_commitment_key.hpp"
#include <gtest/gtest.h>
namespace bb {
template <typename Builder> class RecursiveVeriferCommitmentKeyTest : public testing::Test {
public:
using native_VK = VerifierCommitmentKey<curve::Grumpkin>;
using VK = VerifierCommitmentKey<stdlib::bn254<Builder>>;
static void SetUpTestSuite()
{
srs::init_crs_factory("../srs_db/ignition");
srs::init_grumpkin_crs_factory("../srs_db/grumpkin");
}

/**
* @brief Instantiante a recursive verifier commitment key from a Grumpkin native key and check consistency.
*
*/
static void test_equality()
{
size_t num_points = 4096;
Builder builder;
auto native_vk = std::make_shared<native_VK>(num_points);
auto recursive_vk = std::make_shared<VK>(&builder, num_points, native_vk);
EXPECT_EQ(native_vk->get_first_g1(), recursive_vk->get_first_g1().get_value());
auto* native_monomial_points = native_vk->get_monomial_points();
auto recursive_monomial_points = recursive_vk->get_monomial_points();
for (size_t i = 0; i < num_points; i++) {
EXPECT_EQ(native_monomial_points[i], recursive_monomial_points[i].get_value());
}
}
};

using Builders = testing::Types<UltraCircuitBuilder, GoblinUltraCircuitBuilder>;

TYPED_TEST_SUITE(RecursiveVeriferCommitmentKeyTest, Builders);

TYPED_TEST(RecursiveVeriferCommitmentKeyTest, EqualityTest)
{
TestFixture::test_equality();
};
} // namespace bb

0 comments on commit 1d84975

Please sign in to comment.