Skip to content

Commit

Permalink
Remove create_prover.
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Mar 1, 2024
1 parent 24a53a9 commit 791a6d8
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 64 deletions.
5 changes: 4 additions & 1 deletion barretenberg/cpp/scripts/ultra_honk_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ cd build/
./bin/ultra_honk_tests
./bin/goblin_tests
./bin/client_ivc_tests
./bin/stdlib_recursion_tests
./bin/stdlib_recursion_tests --gtest_filter=Goblin*
./bin/stdlib_recursion_tests --gtest_filter=Honk*
./bin/stdlib_recursion_tests --gtest_filter=Proto*
./bin/stdlib_recursion_tests --gtest_filter=RecursiveMerge*
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,22 @@ template <typename Builder> void generate_basic_arithmetic_circuit(Builder& buil
}

// ultrahonk
inline UltraProver get_prover(UltraComposer& composer,
inline UltraProver get_prover([[maybe_unused]] UltraComposer& composer,
void (*test_circuit_function)(UltraComposer::CircuitBuilder&, size_t),
size_t num_iterations)
{
UltraComposer::CircuitBuilder builder;
test_circuit_function(builder, num_iterations);
auto instance = std::make_shared<UltraComposer::ProverInstance>(builder);
return composer.create_prover(instance);
return UltraProver(builder);
}

inline GoblinUltraProver get_prover(GoblinUltraComposer& composer,
inline GoblinUltraProver get_prover([[maybe_unused]] GoblinUltraComposer& composer,
void (*test_circuit_function)(GoblinUltraComposer::CircuitBuilder&, size_t),
size_t num_iterations)
{
GoblinUltraComposer::CircuitBuilder builder;
test_circuit_function(builder, num_iterations);
auto instance = std::make_shared<GoblinUltraComposer::ProverInstance>(builder);
return composer.create_prover(instance);
return GoblinUltraProver(builder);
}

// standard plonk
Expand Down
7 changes: 3 additions & 4 deletions barretenberg/cpp/src/barretenberg/goblin/goblin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "barretenberg/ultra_honk/merge_prover.hpp"
#include "barretenberg/ultra_honk/merge_verifier.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"
#include "barretenberg/ultra_honk/ultra_prover.hpp"

namespace bb {

Expand Down Expand Up @@ -103,9 +104,8 @@ class Goblin {
}

// Construct a Honk proof for the main circuit
GoblinUltraComposer composer;
auto instance = std::make_shared<GoblinUltraProverInstance>(circuit_builder);
auto prover = composer.create_prover(instance);
GoblinUltraProver prover(instance);
auto ultra_proof = prover.construct_proof();

// Construct and store the merge proof to be recursively verified on the next call to accumulate
Expand Down Expand Up @@ -229,9 +229,8 @@ class Goblin {
// }

// Construct a Honk proof for the main circuit
GoblinUltraComposer composer;
auto instance = std::make_shared<GoblinUltraProverInstance>(circuit_builder);
auto prover = composer.create_prover(instance);
GoblinUltraProver prover(instance);
auto ultra_proof = prover.construct_proof();

accumulator = { ultra_proof, instance->verification_key };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ class GoblinRecursionTests : public ::testing::Test {

using Curve = curve::BN254;
using FF = Curve::ScalarField;
using GoblinUltraBuilder = GoblinUltraCircuitBuilder;
using KernelInput = Goblin::AccumulationOutput;
using ProverInstance = ProverInstance_<GoblinUltraFlavor>;
using VerifierInstance = VerifierInstance_<GoblinUltraFlavor>;

static Goblin::AccumulationOutput construct_accumulator(GoblinUltraBuilder& builder)
static Goblin::AccumulationOutput construct_accumulator(GoblinUltraCircuitBuilder& builder)
{
GoblinUltraComposer composer;
auto prover_instance = std::make_shared<ProverInstance>(builder);
auto verifier_instance = std::make_shared<VerifierInstance>(prover_instance->verification_key);
auto prover = composer.create_prover(prover_instance);
GoblinUltraProver prover(prover_instance);
auto ultra_proof = prover.construct_proof();
return { ultra_proof, verifier_instance->verification_key };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi
// Define types for the inner circuit, i.e. the circuit whose proof will be recursively verified
using InnerFlavor = GoblinUltraFlavor;
using InnerComposer = GoblinUltraComposer;
using InnerProver = GoblinUltraProver;
using InnerBuilder = typename InnerComposer::CircuitBuilder;
using InnerProverInstance = ProverInstance_<InnerFlavor>;
using InnerCurve = bn254<InnerBuilder>;
Expand All @@ -34,6 +35,8 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi
using OuterBuilder = BuilderType;
using OuterFlavor =
std::conditional_t<std::same_as<BuilderType, GoblinUltraCircuitBuilder>, GoblinUltraFlavor, UltraFlavor>;
using OuterProver =
std::conditional_t<std::same_as<BuilderType, GoblinUltraCircuitBuilder>, GoblinUltraProver, UltraProver>;
using OuterProverInstance = ProverInstance_<OuterFlavor>;
using RecursiveFlavor = GoblinUltraRecursiveFlavor_<OuterBuilder>;
using RecursiveVerifier = UltraRecursiveVerifier_<RecursiveFlavor>;
Expand Down Expand Up @@ -151,9 +154,8 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi
OuterBuilder outer_circuit;

// Compute native verification key
InnerComposer inner_composer;
auto instance = std::make_shared<InnerProverInstance>(inner_circuit);
auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK
InnerProver prover(instance); // A prerequisite for computing VK
auto verification_key = instance->verification_key;
// Instantiate the recursive verifier using the native verification key
RecursiveVerifier verifier{ &outer_circuit, verification_key };
Expand Down Expand Up @@ -181,7 +183,7 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi
// Generate a proof over the inner circuit
InnerComposer inner_composer;
auto instance = std::make_shared<InnerProverInstance>(inner_circuit);
auto inner_prover = inner_composer.create_prover(instance);
InnerProver inner_prover(instance);
auto inner_proof = inner_prover.construct_proof();

// Create a recursive verification circuit for the proof of the inner circuit
Expand Down Expand Up @@ -213,7 +215,7 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi
{
auto composer = get_outer_composer<OuterBuilder>();
auto instance = std::make_shared<OuterProverInstance>(outer_circuit);
auto prover = composer.create_prover(instance);
OuterProver prover(instance);
auto verifier = composer.create_verifier(instance->verification_key);
auto proof = prover.construct_proof();
bool verified = verifier.verify_proof(proof);
Expand All @@ -234,9 +236,8 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi
auto inner_circuit = create_inner_circuit();

// Generate a proof over the inner circuit
InnerComposer inner_composer;
auto instance = std::make_shared<InnerProverInstance>(inner_circuit);
auto inner_prover = inner_composer.create_prover(instance);
InnerProver inner_prover(instance);
auto inner_proof = inner_prover.construct_proof();

// Arbitrarily tamper with the proof to be verified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class RecursiveMergeVerifierTest : public testing::Test {
{
GoblinUltraComposer composer;
auto instance = std::make_shared<InnerProverInstance>(outer_circuit);
auto prover = composer.create_prover(instance);
GoblinUltraProver prover(instance);
auto verifier = composer.create_verifier(instance->verification_key);
auto proof = prover.construct_proof();
bool verified = verifier.verify_proof(proof);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
using NativeFlavor = typename RecursiveFlavor::NativeFlavor;
using Composer = ::bb::UltraComposer_<NativeFlavor>;
using Builder = typename RecursiveFlavor::CircuitBuilder;
using Prover = UltraProver_<NativeFlavor>;
using ProverInstance = ::bb::ProverInstance_<NativeFlavor>;
using VerifierInstance = ::bb::VerifierInstance_<NativeFlavor>;
using RecursiveVerifierInstance = ::bb::stdlib::recursion::honk::RecursiveVerifierInstance_<RecursiveFlavor>;
Expand Down Expand Up @@ -204,7 +205,7 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
{
auto composer = Composer();
auto instance = std::make_shared<ProverInstance>(folding_circuit);
auto prover = composer.create_prover(instance);
Prover prover(instance);
auto verifier = composer.create_verifier(instance->verification_key);
auto proof = prover.construct_proof();
bool verified = verifier.verify_proof(proof);
Expand Down Expand Up @@ -294,7 +295,7 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
{
auto composer = Composer();
auto instance = std::make_shared<ProverInstance>(decider_circuit);
auto prover = composer.create_prover(instance);
Prover prover(instance);
auto verifier = composer.create_verifier(instance->verification_key);
auto proof = prover.construct_proof();
bool verified = verifier.verify_proof(proof);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace bb::stdlib::recursion::honk {
*
* @tparam Builder
*/
template <typename BuilderType> class RecursiveVerifierTest : public testing::Test {
template <typename BuilderType> class HonkRecursiveVerifierTest : public testing::Test {

// Define types relevant for testing
using UltraComposer = UltraComposer_<UltraFlavor>;
Expand All @@ -25,6 +25,7 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te
using InnerFlavor = UltraFlavor;
using InnerProverInstance = ProverInstance_<InnerFlavor>;
using InnerComposer = UltraComposer;
using InnerProver = UltraProver;
using InnerBuilder = typename InnerComposer::CircuitBuilder;
using InnerCurve = bn254<InnerBuilder>;
using Commitment = InnerFlavor::Commitment;
Expand All @@ -36,6 +37,8 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te
using OuterBuilder = BuilderType;
using OuterFlavor =
std::conditional_t<std::same_as<BuilderType, GoblinUltraCircuitBuilder>, GoblinUltraFlavor, UltraFlavor>;
using OuterProver =
std::conditional_t<std::same_as<BuilderType, GoblinUltraCircuitBuilder>, GoblinUltraProver, UltraProver>;
using OuterProverInstance = ProverInstance_<OuterFlavor>;

using VerificationKey = typename RecursiveVerifier::VerificationKey;
Expand Down Expand Up @@ -136,9 +139,8 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te
create_inner_circuit(inner_circuit);

// Compute native verification key
InnerComposer inner_composer;
auto instance = std::make_shared<InnerProverInstance>(inner_circuit);
auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK
InnerProver prover(instance); // A prerequisite for computing VK
auto verification_key = instance->verification_key;
// Instantiate the recursive verifier using the native verification key
RecursiveVerifier verifier{ &outer_circuit, verification_key };
Expand Down Expand Up @@ -166,7 +168,7 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te
// Generate a proof over the inner circuit
InnerComposer inner_composer;
auto instance = std::make_shared<InnerProverInstance>(inner_circuit);
auto inner_prover = inner_composer.create_prover(instance);
InnerProver inner_prover(instance);
auto inner_proof = inner_prover.construct_proof();

// Create a recursive verification circuit for the proof of the inner circuit
Expand Down Expand Up @@ -198,7 +200,7 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te
{
auto composer = get_outer_composer<OuterBuilder>();
auto instance = std::make_shared<OuterProverInstance>(outer_circuit);
auto prover = composer.create_prover(instance);
OuterProver prover(instance);
auto verifier = composer.create_verifier(instance->verification_key);
auto proof = prover.construct_proof();
bool verified = verifier.verify_proof(proof);
Expand All @@ -220,9 +222,8 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te
create_inner_circuit(inner_circuit);

// Generate a proof over the inner circuit
InnerComposer inner_composer;
auto instance = std::make_shared<InnerProverInstance>(inner_circuit);
auto inner_prover = inner_composer.create_prover(instance);
InnerProver inner_prover(instance);
auto inner_proof = inner_prover.construct_proof();

// Arbitrarily tamper with the proof to be verified
Expand All @@ -244,24 +245,24 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te
// Run the recursive verifier tests with conventional Ultra builder and Goblin builder
using BuilderTypes = testing::Types<UltraCircuitBuilder, GoblinUltraCircuitBuilder>;

TYPED_TEST_SUITE(RecursiveVerifierTest, BuilderTypes);
TYPED_TEST_SUITE(HonkRecursiveVerifierTest, BuilderTypes);

HEAVY_TYPED_TEST(RecursiveVerifierTest, InnerCircuit)
HEAVY_TYPED_TEST(HonkRecursiveVerifierTest, InnerCircuit)
{
TestFixture::test_inner_circuit();
}

HEAVY_TYPED_TEST(RecursiveVerifierTest, RecursiveVerificationKey)
HEAVY_TYPED_TEST(HonkRecursiveVerifierTest, RecursiveVerificationKey)
{
TestFixture::test_recursive_verification_key_creation();
}

HEAVY_TYPED_TEST(RecursiveVerifierTest, SingleRecursiveVerification)
HEAVY_TYPED_TEST(HonkRecursiveVerifierTest, SingleRecursiveVerification)
{
TestFixture::test_recursive_verification();
};

HEAVY_TYPED_TEST(RecursiveVerifierTest, SingleRecursiveVerificationFailure)
HEAVY_TYPED_TEST(HonkRecursiveVerifierTest, SingleRecursiveVerificationFailure)
{
TestFixture::test_recursive_verification_fails();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TEST_F(DataBusComposerTests, CallDataRead)
// Construct and verify Honk proof
auto instance = std::make_shared<ProverInstance_<GoblinUltraFlavor>>(builder);
// For debugging, use "instance_inspector::print_databus_info(instance)"
auto prover = composer.create_prover(instance);
GoblinUltraProver prover(instance);
auto verifier = composer.create_verifier(instance->verification_key);
auto proof = prover.construct_proof();
bool verified = verifier.verify_proof(proof);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class GoblinUltraHonkComposerTests : public ::testing::Test {
bool construct_and_verify_honk_proof(auto& composer, auto& builder)
{
auto instance = std::make_shared<ProverInstance_<GoblinUltraFlavor>>(builder);
auto prover = composer.create_prover(instance);
GoblinUltraProver prover(instance);
auto verifier = composer.create_verifier(instance->verification_key);
auto proof = prover.construct_proof();
bool verified = verifier.verify_proof(proof);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ TEST_F(GoblinUltraTranscriptTests, ProverManifestConsistency)
generate_test_circuit(builder);

// Automatically generate a transcript manifest by constructing a proof
auto composer = GoblinUltraComposer();
auto instance = std::make_shared<ProverInstance>(builder);
auto prover = composer.create_prover(instance);
GoblinUltraProver prover(instance);
auto proof = prover.construct_proof();

// Check that the prover generated manifest agrees with the manifest hard coded in this suite
Expand All @@ -174,7 +173,7 @@ TEST_F(GoblinUltraTranscriptTests, VerifierManifestConsistency)
// Automatically generate a transcript manifest in the prover by constructing a proof
auto composer = GoblinUltraComposer();
auto instance = std::make_shared<ProverInstance>(builder);
auto prover = composer.create_prover(instance);
GoblinUltraProver prover(instance);
auto proof = prover.construct_proof();

// Automatically generate a transcript manifest in the verifier by verifying a proof
Expand Down Expand Up @@ -225,7 +224,7 @@ TEST_F(GoblinUltraTranscriptTests, StructureTest)
// Automatically generate a transcript manifest by constructing a proof
auto composer = GoblinUltraComposer();
auto instance = std::make_shared<ProverInstance>(builder);
auto prover = composer.create_prover(instance);
GoblinUltraProver prover(instance);
auto proof = prover.construct_proof();
auto verifier = composer.create_verifier(instance->verification_key);
EXPECT_TRUE(verifier.verify_proof(proof));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@

namespace bb {

template <IsUltraFlavor Flavor>
UltraProver_<Flavor> UltraComposer_<Flavor>::create_prover(const std::shared_ptr<ProverInstance>& instance,
const std::shared_ptr<Transcript>& transcript)
{
UltraProver_<Flavor> output_state(instance, transcript);

return output_state;
}

template <IsUltraFlavor Flavor>
UltraVerifier_<Flavor> UltraComposer_<Flavor>::create_verifier(const std::shared_ptr<VerificationKey>& verification_key,
const std::shared_ptr<Transcript>& transcript)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ template <IsUltraFlavor Flavor_> class UltraComposer_ {
using ProverInstances = ProverInstances_<Flavor>;
using VerifierInstances = VerifierInstances_<Flavor>;

UltraProver_<Flavor> create_prover(const std::shared_ptr<ProverInstance>&,
const std::shared_ptr<Transcript>& transcript = std::make_shared<Transcript>());

UltraVerifier_<Flavor> create_verifier(
const std::shared_ptr<VerificationKey>&,
const std::shared_ptr<Transcript>& transcript = std::make_shared<Transcript>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace {
auto& engine = numeric::get_debug_randomness();
}

using ProverInstance = typename UltraComposer::ProverInstance;
using ProverInstance = ProverInstance_<UltraFlavor>;

std::vector<uint32_t> add_variables(auto& circuit_builder, std::vector<bb::fr> variables)
{
Expand All @@ -36,7 +36,7 @@ std::vector<uint32_t> add_variables(auto& circuit_builder, std::vector<bb::fr> v
void prove_and_verify(auto& circuit_builder, auto& composer, bool expected_result)
{
auto instance = std::make_shared<ProverInstance>(circuit_builder);
auto prover = composer.create_prover(instance);
UltraProver prover(instance);
auto verifier = composer.create_verifier(instance->verification_key);
auto proof = prover.construct_proof();
bool verified = verifier.verify_proof(proof);
Expand Down Expand Up @@ -68,9 +68,8 @@ TEST_F(UltraHonkComposerTests, ANonZeroPolynomialIsAGoodPolynomial)
{
auto circuit_builder = UltraCircuitBuilder();

auto composer = UltraComposer();
auto instance = std::make_shared<ProverInstance>(circuit_builder);
auto prover = composer.create_prover(instance);
UltraProver prover(instance);
auto proof = prover.construct_proof();
auto proving_key = instance->proving_key;

Expand Down Expand Up @@ -201,7 +200,7 @@ TEST_F(UltraHonkComposerTests, create_gates_from_plookup_accumulators)
}
auto composer = UltraComposer();
auto instance = std::make_shared<ProverInstance>(circuit_builder);
auto prover = composer.create_prover(instance);
UltraProver prover(instance);
auto verifier = composer.create_verifier(instance->verification_key);
auto proof = prover.construct_proof();

Expand Down
Loading

0 comments on commit 791a6d8

Please sign in to comment.