Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Get rid of ECCVM composer #5562

Merged
merged 16 commits into from
Apr 8, 2024
Merged
2 changes: 1 addition & 1 deletion barretenberg/cpp/scripts/analyze_client_ivc_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"ProverInstance(Circuit&)(t)",
"ProtogalaxyProver::fold_instances(t)",
"Decider::construct_proof(t)",
"ECCVMComposer::create_prover(t)",
"ECCVMProver(CircuitBuilder&)(t)",
"ECCVMProver::construct_proof(t)",
"GoblinTranslatorProver::construct_proof(t)",
"Goblin::merge(t)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <benchmark/benchmark.h>

#include "barretenberg/eccvm/eccvm_circuit_builder.hpp"
#include "barretenberg/eccvm/eccvm_composer.hpp"
#include "barretenberg/eccvm/eccvm_prover.hpp"
#include "barretenberg/eccvm/eccvm_verifier.hpp"

using namespace benchmark;
using namespace bb;

using Flavor = ECCVMFlavor;
using Builder = ECCVMCircuitBuilder;
using Composer = ECCVMComposer;

namespace {

Expand Down Expand Up @@ -49,8 +49,7 @@ void eccvm_generate_prover(State& state) noexcept
size_t target_num_gates = 1 << static_cast<size_t>(state.range(0));
for (auto _ : state) {
Builder builder = generate_trace(target_num_gates);
Composer composer;
auto prover = composer.create_prover(builder);
ECCVMProver prover(builder);
};
}

Expand All @@ -60,8 +59,7 @@ void eccvm_prove(State& state) noexcept

size_t target_num_gates = 1 << static_cast<size_t>(state.range(0));
Builder builder = generate_trace(target_num_gates);
Composer composer;
auto prover = composer.create_prover(builder);
ECCVMProver prover(builder);
for (auto _ : state) {
auto proof = prover.construct_proof();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ template <> class VerifierCommitmentKey<curve::Grumpkin> {
VerifierCommitmentKey(size_t num_points, const std::shared_ptr<bb::srs::factories::CrsFactory<Curve>>& crs_factory)
: pippenger_runtime_state(num_points)
, srs(crs_factory->get_verifier_crs(num_points))

{}

VerifierCommitmentKey(size_t num_points)
: pippenger_runtime_state(num_points)
{
srs::init_grumpkin_crs_factory("../srs_db/grumpkin");
srs = srs::get_crs_factory<Curve>()->get_verifier_crs(num_points);
}

bb::scalar_multiplication::pippenger_runtime_state<Curve> pippenger_runtime_state;
std::shared_ptr<bb::srs::factories::VerifierCrs<Curve>> srs;
};
Expand Down
133 changes: 0 additions & 133 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.cpp

This file was deleted.

82 changes: 0 additions & 82 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.hpp

This file was deleted.

48 changes: 15 additions & 33 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <vector>

#include "barretenberg/eccvm/eccvm_circuit_builder.hpp"
#include "barretenberg/eccvm/eccvm_composer.hpp"
#include "barretenberg/eccvm/eccvm_prover.hpp"
#include "barretenberg/eccvm/eccvm_verifier.hpp"
#include "barretenberg/numeric/uint256/uint256.hpp"
#include "barretenberg/plonk_honk_shared/library/grand_product_delta.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
Expand All @@ -13,31 +14,20 @@
#include "barretenberg/sumcheck/sumcheck_round.hpp"

using namespace bb;
using G1 = bb::g1;
using Fr = bb::fr;

template <typename Flavor> class ECCVMComposerTests : public ::testing::Test {
class ECCVMComposerTests : public ::testing::Test {
protected:
// TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialized for every test.
void SetUp() override
{
if constexpr (std::is_same<Flavor, ECCVMFlavor>::value) {
srs::init_grumpkin_crs_factory("../srs_db/grumpkin");
} else {
srs::init_crs_factory("../srs_db/ignition");
}
};
void SetUp() override { srs::init_grumpkin_crs_factory("../srs_db/grumpkin"); };
};

using FlavorTypes = ::testing::Types<ECCVMFlavor>;
TYPED_TEST_SUITE(ECCVMComposerTests, FlavorTypes);

namespace {
auto& engine = numeric::get_debug_randomness();
}
template <typename Flavor> ECCVMCircuitBuilder generate_circuit(numeric::RNG* engine = nullptr)
ECCVMCircuitBuilder generate_circuit(numeric::RNG* engine = nullptr)
{
std::shared_ptr<ECCOpQueue> op_queue = std::make_shared<ECCOpQueue>();
using G1 = typename Flavor::CycleGroup;
using Fr = typename G1::Fr;

auto generators = G1::derive_generators("test generators", 3);

Expand Down Expand Up @@ -65,28 +55,21 @@ template <typename Flavor> ECCVMCircuitBuilder generate_circuit(numeric::RNG* en
return builder;
}

TYPED_TEST(ECCVMComposerTests, BaseCase)
TEST_F(ECCVMComposerTests, BaseCase)
{
using Flavor = TypeParam;

auto builder = generate_circuit<Flavor>(&engine);

auto composer = ECCVMComposer_<Flavor>();
auto prover = composer.create_prover(builder);

ECCVMCircuitBuilder builder = generate_circuit(&engine);
ECCVMProver prover(builder);
auto proof = prover.construct_proof();
auto verifier = composer.create_verifier(builder);
ECCVMVerifier verifier(prover.key);
bool verified = verifier.verify_proof(proof);

ASSERT_TRUE(verified);
}

TYPED_TEST(ECCVMComposerTests, EqFails)
TEST_F(ECCVMComposerTests, EqFails)
{
using Flavor = TypeParam;
using G1 = typename Flavor::CycleGroup;
using ECCVMOperation = eccvm::VMOperation<G1>;
auto builder = generate_circuit<Flavor>(&engine);
auto builder = generate_circuit(&engine);
// Tamper with the eq op such that the expected value is incorect
builder.op_queue->raw_ops.emplace_back(ECCVMOperation{ .add = false,
.mul = false,
Expand All @@ -97,11 +80,10 @@ TYPED_TEST(ECCVMComposerTests, EqFails)
.z2 = 0,
.mul_scalar_full = 0 });
builder.op_queue->num_transcript_rows++;
auto composer = ECCVMComposer_<Flavor>();
auto prover = composer.create_prover(builder);
ECCVMProver prover(builder);

auto proof = prover.construct_proof();
auto verifier = composer.create_verifier(builder);
ECCVMVerifier verifier(prover.key);
bool verified = verifier.verify_proof(proof);
ASSERT_FALSE(verified);
}
Loading
Loading