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 Honk UltraComposer #4875

Merged
merged 20 commits into from
Mar 4, 2024
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
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 @@ -5,7 +5,7 @@
#include "barretenberg/common/op_count_google_bench.hpp"
#include "barretenberg/goblin/mock_circuits.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"
#include "barretenberg/ultra_honk/ultra_verifier.hpp"

using namespace benchmark;
using namespace bb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "barretenberg/goblin/goblin.hpp"
#include "barretenberg/goblin/mock_circuits.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"

using namespace benchmark;
using namespace bb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "barretenberg/srs/factories/file_crs_factory.hpp"

#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"

#include <chrono>
#include <cstdlib>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using StandardPlonk = bb::plonk::StandardComposer;
static void construct_proof_standard_power_of_2(State& state) noexcept
{
auto log2_of_gates = static_cast<size_t>(state.range(0));
bb::mock_proofs::construct_proof_with_specified_num_iterations<bb::plonk::StandardComposer>(
bb::mock_proofs::construct_proof_with_specified_num_iterations<bb::plonk::StandardProver>(
state, &bb::mock_proofs::generate_basic_arithmetic_circuit<bb::StandardCircuitBuilder>, log2_of_gates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@

#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"
#include "barretenberg/protogalaxy/protogalaxy_prover.hpp"
#include "barretenberg/sumcheck/instance/instances.hpp"
#include "barretenberg/sumcheck/instance/prover_instance.hpp"

using namespace benchmark;

namespace bb {

// Fold one instance into an accumulator.
template <typename Composer> void fold_one(State& state) noexcept
template <typename Flavor> void fold_one(State& state) noexcept
{
using Flavor = typename Composer::Flavor;
using Instance = ProverInstance_<Flavor>;
using ProverInstance = ProverInstance_<Flavor>;
using Instance = ProverInstance;
using Instances = ProverInstances_<Flavor, 2>;
using ProtoGalaxyProver = ProtoGalaxyProver_<Instances>;
using Builder = typename Flavor::CircuitBuilder;

bb::srs::init_crs_factory("../srs_db/ignition");

auto log2_num_gates = static_cast<size_t>(state.range(0));
Composer composer;

const auto construct_instance = [&]() {
Builder builder;
Expand All @@ -30,21 +31,21 @@ template <typename Composer> void fold_one(State& state) noexcept
static_assert(std::same_as<Flavor, UltraFlavor>);
bb::mock_proofs::generate_basic_arithmetic_circuit(builder, log2_num_gates);
}
return composer.create_prover_instance(builder);
return std::make_shared<ProverInstance>(builder);
};

std::shared_ptr<Instance> instance_1 = construct_instance();
std::shared_ptr<Instance> instance_2 = construct_instance();

ProtoGalaxyProver folding_prover = composer.create_folding_prover({ instance_1, instance_2 });
ProtoGalaxyProver folding_prover({ instance_1, instance_2 });

for (auto _ : state) {
auto proof = folding_prover.fold_instances();
}
}

BENCHMARK(fold_one<UltraComposer>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);
BENCHMARK(fold_one<GoblinUltraComposer>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);
BENCHMARK(fold_one<UltraFlavor>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);
BENCHMARK(fold_one<GoblinUltraFlavor>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);
} // namespace bb

BENCHMARK_MAIN();
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"
#include "barretenberg/protogalaxy/protogalaxy_prover.hpp"
#include "barretenberg/sumcheck/instance/instances.hpp"

using namespace benchmark;

namespace bb {

template <typename Composer>
void _bench_round(::benchmark::State& state,
void (*F)(ProtoGalaxyProver_<ProverInstances_<typename Composer::Flavor, 2>>&))
template <typename Flavor>
void _bench_round(::benchmark::State& state, void (*F)(ProtoGalaxyProver_<ProverInstances_<Flavor, 2>>&))
{
using Flavor = typename Composer::Flavor;
using Builder = typename Flavor::CircuitBuilder;
using ProverInstance = ProverInstance_<Flavor>;
using Instances = ProverInstances_<Flavor, 2>;
using ProtoGalaxyProver = ProtoGalaxyProver_<Instances>;

bb::srs::init_crs_factory("../srs_db/ignition");
auto log2_num_gates = static_cast<size_t>(state.range(0));
auto composer = Composer();

const auto construct_instance = [&]() {
Builder builder;
Expand All @@ -27,13 +28,13 @@ void _bench_round(::benchmark::State& state,
static_assert(std::same_as<Flavor, UltraFlavor>);
bb::mock_proofs::generate_basic_arithmetic_circuit(builder, log2_num_gates);
}
return composer.create_prover_instance(builder);
return std::make_shared<ProverInstance>(builder);
};

auto prover_instance_1 = construct_instance();
auto prover_instance_2 = construct_instance();
std::shared_ptr<ProverInstance> prover_instance_1 = construct_instance();
std::shared_ptr<ProverInstance> prover_instance_2 = construct_instance();

auto folding_prover = composer.create_folding_prover({ prover_instance_1, prover_instance_2 });
ProtoGalaxyProver folding_prover({ prover_instance_1, prover_instance_2 });

// prepare the prover state
folding_prover.state.accumulator = prover_instance_1;
Expand All @@ -50,13 +51,13 @@ void _bench_round(::benchmark::State& state,

void bench_round_ultra(::benchmark::State& state, void (*F)(ProtoGalaxyProver_<ProverInstances_<UltraFlavor, 2>>&))
{
_bench_round<UltraComposer>(state, F);
_bench_round<UltraFlavor>(state, F);
}

void bench_round_goblin_ultra(::benchmark::State& state,
void (*F)(ProtoGalaxyProver_<ProverInstances_<GoblinUltraFlavor, 2>>&))
{
_bench_round<GoblinUltraComposer>(state, F);
_bench_round<GoblinUltraFlavor>(state, F);
}

BENCHMARK_CAPTURE(bench_round_ultra, preparation, [](auto& prover) { prover.preparation_round(); })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"

using namespace benchmark;
using namespace bb;
Expand All @@ -14,7 +13,7 @@ static void construct_proof_goblinultrahonk(State& state,
void (*test_circuit_function)(GoblinUltraCircuitBuilder&, size_t)) noexcept
{
size_t num_iterations = 10; // 10x the circuit
bb::mock_proofs::construct_proof_with_specified_num_iterations<GoblinUltraComposer>(
bb::mock_proofs::construct_proof_with_specified_num_iterations<GoblinUltraProver>(
state, test_circuit_function, num_iterations);
}

Expand All @@ -24,7 +23,7 @@ static void construct_proof_goblinultrahonk(State& state,
static void construct_proof_goblinultrahonk_power_of_2(State& state) noexcept
{
auto log2_of_gates = static_cast<size_t>(state.range(0));
bb::mock_proofs::construct_proof_with_specified_num_iterations<GoblinUltraComposer>(
bb::mock_proofs::construct_proof_with_specified_num_iterations<GoblinUltraProver>(
state, &bb::mock_proofs::generate_basic_arithmetic_circuit<GoblinUltraCircuitBuilder>, log2_of_gates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "barretenberg/stdlib/primitives/field/field.hpp"
#include "barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp"
#include "barretenberg/stdlib/primitives/witness/witness.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"

#include "barretenberg/ultra_honk/ultra_prover.hpp"

namespace bb::mock_proofs {
Expand Down Expand Up @@ -47,46 +47,27 @@ template <typename Builder> void generate_basic_arithmetic_circuit(Builder& buil
}
}

// ultrahonk
inline UltraProver get_prover(UltraComposer& composer,
void (*test_circuit_function)(UltraComposer::CircuitBuilder&, size_t),
size_t num_iterations)
template <typename Prover>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only real complication this PR. I had to add some type aliases in the Plonk settings code to make this work.

Prover get_prover(void (*test_circuit_function)(typename Prover::Flavor::CircuitBuilder&, size_t),
size_t num_iterations)
{
UltraComposer::CircuitBuilder builder;
test_circuit_function(builder, num_iterations);
std::shared_ptr<UltraComposer::ProverInstance> instance = composer.create_prover_instance(builder);
return composer.create_prover(instance);
}

inline GoblinUltraProver get_prover(GoblinUltraComposer& composer,
void (*test_circuit_function)(GoblinUltraComposer::CircuitBuilder&, size_t),
size_t num_iterations)
{
GoblinUltraComposer::CircuitBuilder builder;
test_circuit_function(builder, num_iterations);
std::shared_ptr<GoblinUltraComposer::ProverInstance> instance = composer.create_prover_instance(builder);
return composer.create_prover(instance);
}
using Flavor = typename Prover::Flavor;
using Builder = typename Flavor::CircuitBuilder;

// standard plonk
inline plonk::Prover get_prover(plonk::StandardComposer& composer,
void (*test_circuit_function)(StandardCircuitBuilder&, size_t),
size_t num_iterations)
{
StandardCircuitBuilder builder;
Builder builder;
test_circuit_function(builder, num_iterations);
return composer.create_prover(builder);
}
// This is gross but it's going away soon.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soon, from what? Plonk getting removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have a UH smart contract. Sean is working on this.

if constexpr (IsPlonkFlavor<Flavor>) {
// If Flavor is Ultra, alias UltraComposer, otherwise alias StandardComposer
using Composer = std::
conditional_t<std::same_as<Flavor, plonk::flavor::Ultra>, plonk::UltraComposer, plonk::StandardComposer>;
Composer composer;
return composer.create_prover(builder);
} else {
return Prover(builder);
}
};

// ultraplonk
inline plonk::UltraProver get_prover(plonk::UltraComposer& composer,
void (*test_circuit_function)(UltraComposer::CircuitBuilder&, size_t),
size_t num_iterations)
{
plonk::UltraComposer::CircuitBuilder builder;
test_circuit_function(builder, num_iterations);
return composer.create_prover(builder);
}
/**
* @brief Performs proof constuction for benchmarks based on a provided circuit function
*
Expand All @@ -97,20 +78,18 @@ inline plonk::UltraProver get_prover(plonk::UltraComposer& composer,
* @param state
* @param test_circuit_function
*/
template <typename Composer>
void construct_proof_with_specified_num_iterations(benchmark::State& state,
void (*test_circuit_function)(typename Composer::CircuitBuilder&,
size_t),
size_t num_iterations)
template <typename Prover>
void construct_proof_with_specified_num_iterations(
benchmark::State& state,
void (*test_circuit_function)(typename Prover::Flavor::CircuitBuilder&, size_t),
size_t num_iterations)
{
srs::init_crs_factory("../srs_db/ignition");

Composer composer;

for (auto _ : state) {
// Construct circuit and prover; don't include this part in measurement
state.PauseTiming();
auto prover = get_prover(composer, test_circuit_function, num_iterations);
Prover prover = get_prover<Prover>(test_circuit_function, num_iterations);
state.ResumeTiming();

// Construct proof
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"

using namespace benchmark;
using namespace bb;
Expand All @@ -14,7 +13,7 @@ static void construct_proof_ultrahonk(State& state,
void (*test_circuit_function)(UltraCircuitBuilder&, size_t)) noexcept
{
size_t num_iterations = 10; // 10x the circuit
bb::mock_proofs::construct_proof_with_specified_num_iterations<UltraComposer>(
bb::mock_proofs::construct_proof_with_specified_num_iterations<UltraProver>(
state, test_circuit_function, num_iterations);
}

Expand All @@ -24,7 +23,7 @@ static void construct_proof_ultrahonk(State& state,
static void construct_proof_ultrahonk_power_of_2(State& state) noexcept
{
auto log2_of_gates = static_cast<size_t>(state.range(0));
bb::mock_proofs::construct_proof_with_specified_num_iterations<UltraComposer>(
bb::mock_proofs::construct_proof_with_specified_num_iterations<UltraProver>(
state, &bb::mock_proofs::generate_basic_arithmetic_circuit<UltraCircuitBuilder>, log2_of_gates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/common/op_count_google_bench.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"

#include "barretenberg/ultra_honk/ultra_prover.hpp"

using namespace benchmark;
Expand Down Expand Up @@ -58,10 +58,9 @@ BB_PROFILE static void test_round(State& state, size_t index) noexcept
auto log2_num_gates = static_cast<size_t>(state.range(0));
bb::srs::init_crs_factory("../srs_db/ignition");

GoblinUltraComposer composer;
// TODO(https://github.com/AztecProtocol/barretenberg/issues/761) benchmark both sparse and dense circuits
GoblinUltraProver prover = bb::mock_proofs::get_prover(
composer, &bb::mock_proofs::generate_basic_arithmetic_circuit<GoblinUltraCircuitBuilder>, log2_num_gates);
auto prover = bb::mock_proofs::get_prover<GoblinUltraProver>(
&bb::mock_proofs::generate_basic_arithmetic_circuit<GoblinUltraCircuitBuilder>, log2_num_gates);
for (auto _ : state) {
test_round_inner(state, prover, index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static void construct_proof_ultraplonk(State& state,
void (*test_circuit_function)(UltraCircuitBuilder&, size_t)) noexcept
{
size_t num_iterations = 10; // 10x the circuit
bb::mock_proofs::construct_proof_with_specified_num_iterations<plonk::UltraComposer>(
bb::mock_proofs::construct_proof_with_specified_num_iterations<plonk::UltraProver>(
state, test_circuit_function, num_iterations);
}

Expand All @@ -22,7 +22,7 @@ static void construct_proof_ultraplonk(State& state,
static void construct_proof_ultraplonk_power_of_2(State& state) noexcept
{
auto log2_of_gates = static_cast<size_t>(state.range(0));
bb::mock_proofs::construct_proof_with_specified_num_iterations<plonk::UltraComposer>(
bb::mock_proofs::construct_proof_with_specified_num_iterations<plonk::UltraProver>(
state, &bb::mock_proofs::generate_basic_arithmetic_circuit<UltraCircuitBuilder>, log2_of_gates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ BB_PROFILE static void test_round(State& state, size_t index) noexcept
bb::srs::init_crs_factory("../srs_db/ignition");
for (auto _ : state) {
state.PauseTiming();
plonk::UltraComposer composer;
// TODO: https://github.com/AztecProtocol/barretenberg/issues/761 benchmark both sparse and dense circuits
plonk::UltraProver prover = bb::mock_proofs::get_prover(
composer, &bb::stdlib::generate_ecdsa_verification_test_circuit<UltraCircuitBuilder>, 10);
auto prover = bb::mock_proofs::get_prover<plonk::UltraProver>(
&bb::stdlib::generate_ecdsa_verification_test_circuit<UltraCircuitBuilder>, 10);
test_round_inner(state, prover, index);
// NOTE: google bench is very finnicky, must end in ResumeTiming() for correctness
state.ResumeTiming();
Expand Down
Loading
Loading