Skip to content

Commit

Permalink
Composer has no functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Mar 1, 2024
1 parent 25f1723 commit 4d64451
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 38 deletions.
6 changes: 2 additions & 4 deletions barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ void ClientIVC::initialize(ClientCircuit& circuit)
ClientIVC::FoldProof ClientIVC::accumulate(ClientCircuit& circuit)
{
goblin.merge(circuit); // Add recursive merge verifier and construct new merge proof
Composer composer;
prover_instance = std::make_shared<ProverInstance>(circuit);
auto folding_prover = composer.create_folding_prover({ prover_fold_output.accumulator, prover_instance });
FoldingProver folding_prover({ prover_fold_output.accumulator, prover_instance });
prover_fold_output = folding_prover.fold_instances();
return prover_fold_output.folding_data;
}
Expand All @@ -59,8 +58,7 @@ bool ClientIVC::verify(Proof& proof, const std::vector<VerifierAccumulator>& ver
bool goblin_verified = goblin.verify(proof.goblin_proof);

// Decider verification
Composer composer;
auto folding_verifier = composer.create_folding_verifier({ verifier_instances[0], verifier_instances[1] });
ClientIVC::FoldingVerifier folding_verifier({ verifier_instances[0], verifier_instances[1] });
auto verifier_accumulator = folding_verifier.verify_folding_proof(proof.fold_proof);

ClientIVC::DeciderVerifier decider_verifier(verifier_accumulator);
Expand Down
10 changes: 7 additions & 3 deletions barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ class ClientIVC {
using FoldProof = std::vector<FF>;
using ProverAccumulator = std::shared_ptr<ProverInstance_<Flavor>>;
using VerifierAccumulator = std::shared_ptr<VerifierInstance_<Flavor>>;
using ProverInstance = ProverInstance_<GoblinUltraFlavor>;
using VerifierInstance = VerifierInstance_<GoblinUltraFlavor>;
using ProverInstance = ProverInstance_<Flavor>;
using VerifierInstance = VerifierInstance_<Flavor>;
using ClientCircuit = GoblinUltraCircuitBuilder; // can only be GoblinUltra
using DeciderProver = DeciderProver_<Flavor>;
using DeciderVerifier = DeciderVerifier_<Flavor>;
using ProverInstances = ProverInstances_<Flavor>;
using FoldingProver = ProtoGalaxyProver_<ProverInstances>;
using VerifierInstances = VerifierInstances_<Flavor>;
using FoldingVerifier = ProtoGalaxyVerifier_<VerifierInstances>;

// A full proof for the IVC scheme
struct Proof {
Expand All @@ -42,7 +46,7 @@ class ClientIVC {
};

private:
using ProverFoldOutput = FoldingResult<GoblinUltraFlavor>;
using ProverFoldOutput = FoldingResult<Flavor>;
using Composer = GoblinUltraComposer;
// Note: We need to save the last instance that was folded in order to compute its verification key, this will not
// be needed in the real IVC as they are provided as inputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class ClientIVCTests : public ::testing::Test {
bb::stdlib::recursion::honk::ProtoGalaxyRecursiveVerifier_<RecursiveVerifierInstances>;
using DeciderProver = ClientIVC::DeciderProver;
using DeciderVerifier = ClientIVC::DeciderVerifier;
using ProverInstances = ProverInstances_<Flavor>;
using FoldingProver = ProtoGalaxyProver_<ProverInstances>;
using VerifierInstances = VerifierInstances_<Flavor>;
using FoldingVerifier = ProtoGalaxyVerifier_<VerifierInstances>;

/**
* @brief Construct mock circuit with arithmetic gates and goblin ops
Expand Down Expand Up @@ -85,9 +89,8 @@ class ClientIVCTests : public ::testing::Test {
const std::shared_ptr<Flavor::VerificationKey>& verifier_inst_vk)
{
// Verify fold proof
Composer composer;
auto new_verifier_inst = std::make_shared<VerifierInstance>(verifier_inst_vk);
auto folding_verifier = composer.create_folding_verifier({ prev_verifier_accumulator, new_verifier_inst });
FoldingVerifier folding_verifier({ prev_verifier_accumulator, new_verifier_inst });
auto verifier_accumulator = folding_verifier.verify_folding_proof(fold_proof);

// Run decider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
using NativeDeciderVerifier = DeciderVerifier_<NativeFlavor>;
using NativeVerifierInstances = VerifierInstances_<NativeFlavor, 2>;
using NativeFoldingVerifier = ProtoGalaxyVerifier_<NativeVerifierInstances>;
using NativeProverInstances = ProverInstances_<NativeFlavor>;
using NativeFoldingProver = ProtoGalaxyProver_<NativeProverInstances>;

static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); }
/**
Expand Down Expand Up @@ -98,7 +100,7 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
};

static std::tuple<std::shared_ptr<ProverInstance>, std::shared_ptr<VerifierInstance>> fold_and_verify_native(
Composer& composer)
[[maybe_unused]] Composer& composer)
{
Builder builder1;
create_function_circuit(builder1);
Expand All @@ -110,8 +112,8 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
auto prover_instance_2 = std::make_shared<ProverInstance>(builder2);
auto verifier_instance_1 = std::make_shared<VerifierInstance>(prover_instance_1->verification_key);
auto verifier_instance_2 = std::make_shared<VerifierInstance>(prover_instance_2->verification_key);
auto folding_prover = composer.create_folding_prover({ prover_instance_1, prover_instance_2 });
auto folding_verifier = composer.create_folding_verifier({ verifier_instance_1, verifier_instance_2 });
NativeFoldingProver folding_prover({ prover_instance_1, prover_instance_2 });
NativeFoldingVerifier folding_verifier({ verifier_instance_1, verifier_instance_2 });

auto [prover_accumulator, folding_proof] = folding_prover.fold_instances();
auto verifier_accumulator = folding_verifier.verify_folding_proof(folding_proof);
Expand Down Expand Up @@ -171,13 +173,12 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
builder2.add_public_variable(FF(1));
create_function_circuit(builder2);

Composer composer = Composer();
auto prover_instance_1 = std::make_shared<ProverInstance>(builder1);
auto verifier_instance_1 = std::make_shared<VerifierInstance>(prover_instance_1->verification_key);
auto prover_instance_2 = std::make_shared<ProverInstance>(builder2);
auto verifier_instance_2 = std::make_shared<VerifierInstance>(prover_instance_2->verification_key);
// Generate a folding proof
auto folding_prover = composer.create_folding_prover({ prover_instance_1, prover_instance_2 });
NativeFoldingProver folding_prover({ prover_instance_1, prover_instance_2 });
auto folding_proof = folding_prover.fold_instances();

// Create a recursive folding verifier circuit for the folding proof of the two instances
Expand All @@ -190,7 +191,7 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes

// Perform native folding verification and ensure it returns the same result (either true or false) as
// calling check_circuit on the recursive folding verifier
auto native_folding_verifier = composer.create_folding_verifier({ verifier_instance_1, verifier_instance_2 });
NativeFoldingVerifier native_folding_verifier({ verifier_instance_1, verifier_instance_2 });
native_folding_verifier.verify_folding_proof(folding_proof.folding_data);

// Ensure that the underlying native and recursive folding verification algorithms agree by ensuring the
Expand Down Expand Up @@ -232,13 +233,12 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes

create_function_circuit(builder2);

Composer composer = Composer();
auto prover_instance_1 = std::make_shared<ProverInstance>(builder1);
auto verifier_instance_1 = std::make_shared<VerifierInstance>(prover_instance_1->verification_key);
auto prover_instance_2 = std::make_shared<ProverInstance>(builder2);
auto verifier_instance_2 = std::make_shared<VerifierInstance>(prover_instance_2->verification_key);
// Generate a folding proof
auto folding_prover = composer.create_folding_prover({ prover_instance_1, prover_instance_2 });
NativeFoldingProver folding_prover({ prover_instance_1, prover_instance_2 });
auto folding_proof = folding_prover.fold_instances();

// Create a recursive folding verifier circuit for the folding proof of the two instances
Expand All @@ -254,7 +254,7 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes

// Perform native folding verification and ensure it returns the same result (either true or false) as
// calling check_circuit on the recursive folding verifier
auto native_folding_verifier = composer.create_folding_verifier({ verifier_instance_1, verifier_instance_2 });
NativeFoldingVerifier native_folding_verifier({ verifier_instance_1, verifier_instance_2 });
auto verifier_accumulator = native_folding_verifier.verify_folding_proof(folding_proof.folding_data);

// Ensure that the underlying native and recursive folding verification algorithms agree by ensuring the
Expand Down Expand Up @@ -343,7 +343,7 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes

// Generate a folding proof with the incorrect polynomials which would result in the prover having the wrong
// target sum
auto folding_prover = composer.create_folding_prover({ prover_accumulator, prover_inst });
NativeFoldingProver folding_prover({ prover_accumulator, prover_inst });
auto folding_proof = folding_prover.fold_instances();

// Create a recursive folding verifier circuit for the folding proof of the two instances with the untampered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
using PowPolynomial = bb::PowPolynomial<FF>;
using DeciderProver = DeciderProver_<Flavor>;
using DeciderVerifier = DeciderVerifier_<Flavor>;
using FoldingProver = ProtoGalaxyProver_<ProverInstances>;
using FoldingVerifier = ProtoGalaxyVerifier_<VerifierInstances>;

static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); }

Expand Down Expand Up @@ -66,10 +68,10 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
static std::tuple<std::shared_ptr<ProverInstance>, std::shared_ptr<VerifierInstance>> fold_and_verify(
const std::vector<std::shared_ptr<ProverInstance>>& prover_instances,
const std::vector<std::shared_ptr<VerifierInstance>>& verifier_instances,
Composer& composer)
[[maybe_unused]] Composer& composer)
{
auto folding_prover = composer.create_folding_prover(prover_instances);
auto folding_verifier = composer.create_folding_verifier(verifier_instances);
FoldingProver folding_prover(prover_instances);
FoldingVerifier folding_verifier(verifier_instances);

auto [prover_accumulator, folding_proof] = folding_prover.fold_instances();
auto verifier_accumulator = folding_verifier.verify_folding_proof(folding_proof);
Expand Down
16 changes: 0 additions & 16 deletions barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@ template <IsUltraFlavor Flavor_> class UltraComposer_ {
using Transcript = typename Flavor::Transcript;
using ProverInstances = ProverInstances_<Flavor>;
using VerifierInstances = VerifierInstances_<Flavor>;

ProtoGalaxyProver_<ProverInstances> create_folding_prover(
const std::vector<std::shared_ptr<ProverInstance>>& instances)
{
ProtoGalaxyProver_<ProverInstances> output_state(instances);

return output_state;
};

ProtoGalaxyVerifier_<VerifierInstances> create_folding_verifier(
const std::vector<std::shared_ptr<VerifierInstance>>& instances)
{
ProtoGalaxyVerifier_<VerifierInstances> output_state(instances);

return output_state;
};
};

// TODO(#532): this pattern is weird; is this not instantiating the templates?
Expand Down

0 comments on commit 4d64451

Please sign in to comment.