Skip to content

Commit

Permalink
feat: Isolate Plonk dependencies (#5068)
Browse files Browse the repository at this point in the history
This PR improves the linking structure of the library by breaking
dependencies on plonk. Namely only modules that construct plonk proofs
should depend on plonk. This is also an incremental step toward removing
plonk. Everything is in service of that.
  • Loading branch information
codygunton authored Mar 13, 2024
1 parent 5948996 commit 5cbbd7d
Show file tree
Hide file tree
Showing 101 changed files with 275 additions and 445 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ jobs:
- *setup_env
- run:
name: "Test"
command: cond_spot_run_test barretenberg-x86_64-linux-clang-assert 32 ./scripts/run_tests 3 stdlib_recursion_tests --gtest_filter=-*turbo*
command: cond_spot_run_test barretenberg-x86_64-linux-clang-assert 32 ./scripts/run_tests 3 stdlib_plonk_recursion_tests --gtest_filter=-*turbo*
aztec_manifest_key: barretenberg-x86_64-linux-clang-assert

barretenberg-acir-tests-bb:
Expand Down
14 changes: 7 additions & 7 deletions barretenberg/cpp/scripts/ultra_honk_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ set -eu
# Move above script dir.
cd $(dirname $0)/..

cmake --preset clang16
cmake --build --preset clang16
cmake --preset clang16-dbg-fast
cmake --build --preset clang16-dbg-fast

cd build/

Expand All @@ -17,9 +17,9 @@ cd build/
./bin/translator_vm_tests
./bin/protogalaxy_tests
./bin/ultra_honk_tests
./bin/stdlib_honk_recursion_tests --gtest_filter=Goblin*
./bin/stdlib_honk_recursion_tests --gtest_filter=Honk*
./bin/stdlib_honk_recursion_tests --gtest_filter=Proto*
./bin/stdlib_honk_recursion_tests --gtest_filter=RecursiveMerge*
./bin/goblin_tests
./bin/client_ivc_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*
./bin/client_ivc_tests
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ set(BARRETENBERG_TARGET_OBJECTS
$<TARGET_OBJECTS:stdlib_pedersen_hash_objects>
$<TARGET_OBJECTS:stdlib_poseidon2_objects>
$<TARGET_OBJECTS:stdlib_primitives_objects>
$<TARGET_OBJECTS:stdlib_recursion_objects>
$<TARGET_OBJECTS:stdlib_honk_recursion_objects>
$<TARGET_OBJECTS:stdlib_plonk_recursion_objects>
$<TARGET_OBJECTS:stdlib_schnorr_objects>
$<TARGET_OBJECTS:stdlib_sha256_objects>
$<TARGET_OBJECTS:sumcheck_objects>
Expand Down
10 changes: 5 additions & 5 deletions barretenberg/cpp/src/barretenberg/barretenberg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
#include "stdlib/merkle_tree/nullifier_tree/nullifier_leaf.hpp"
#include "stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp"
#include "stdlib/merkle_tree/nullifier_tree/nullifier_tree.hpp"
#include "stdlib/plonk_recursion/aggregation_state/aggregation_state.hpp"
#include "stdlib/plonk_recursion/aggregation_state/native_aggregation_state.hpp"
#include "stdlib/plonk_recursion/verification_key/verification_key.hpp"
#include "stdlib/plonk_recursion/verifier/program_settings.hpp"
#include "stdlib/plonk_recursion/verifier/verifier.hpp"
#include "stdlib/primitives/address/address.hpp"
#include "stdlib/primitives/bigfield/bigfield.hpp"
#include "stdlib/primitives/biggroup/biggroup.hpp"
Expand All @@ -67,8 +72,3 @@
#include "stdlib/primitives/packed_byte_array/packed_byte_array.hpp"
#include "stdlib/primitives/uint/uint.hpp"
#include "stdlib/primitives/witness/witness.hpp"
#include "stdlib/recursion/aggregation_state/aggregation_state.hpp"
#include "stdlib/recursion/aggregation_state/native_aggregation_state.hpp"
#include "stdlib/recursion/verification_key/verification_key.hpp"
#include "stdlib/recursion/verifier/program_settings.hpp"
#include "stdlib/recursion/verifier/verifier.hpp"
1 change: 1 addition & 0 deletions barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ add_subdirectory(merkle_tree_bench)
add_subdirectory(indexed_tree_bench)
add_subdirectory(append_only_tree_bench)
add_subdirectory(ultra_bench)
add_subdirectory(stdlib_hash)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(client_ivc_bench client_ivc stdlib_recursion stdlib_sha256 crypto_merkle_tree stdlib_primitives)
barretenberg_module(client_ivc_bench client_ivc stdlib_honk_recursion stdlib_sha256 crypto_merkle_tree stdlib_primitives)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(goblin_bench ultra_honk eccvm stdlib_recursion stdlib_sha256 crypto_merkle_tree stdlib_primitives)
barretenberg_module(goblin_bench eccvm stdlib_honk_recursion stdlib_sha256 crypto_merkle_tree)
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <benchmark/benchmark.h>

#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/eccvm/eccvm_composer.hpp"
#include "barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

#include <benchmark/benchmark.h>

#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/common/op_count_google_bench.hpp"
#include "barretenberg/goblin/goblin.hpp"
#include "barretenberg/goblin/mock_circuits.hpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/benchmark/ultra_bench/mock_circuits.hpp"
#include "barretenberg/plonk/composer/standard_composer.hpp"
#include "barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp"

Expand All @@ -13,8 +13,8 @@ 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::StandardProver>(
state, &bb::mock_proofs::generate_basic_arithmetic_circuit<bb::StandardCircuitBuilder>, log2_of_gates);
bb::mock_circuits::construct_proof_with_specified_num_iterations<bb::plonk::StandardProver>(
state, &bb::mock_circuits::generate_basic_arithmetic_circuit<bb::StandardCircuitBuilder>, log2_of_gates);
}

BENCHMARK(construct_proof_standard_power_of_2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
barretenberg_module(protogalaxy_bench ultra_honk protogalaxy stdlib_primitives)
barretenberg_module(
protogalaxy_bench
stdlib_honk_recursion
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <benchmark/benchmark.h>

#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/proof_system/circuit_builder/mock_circuits.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/protogalaxy/protogalaxy_prover.hpp"
#include "barretenberg/sumcheck/instance/instances.hpp"
Expand All @@ -25,12 +25,7 @@ template <typename Flavor> void fold_one(State& state) noexcept

const auto construct_instance = [&]() {
Builder builder;
if constexpr (std::same_as<Flavor, GoblinUltraFlavor>) {
GoblinMockCircuits::construct_arithmetic_circuit(builder, log2_num_gates);
} else {
static_assert(std::same_as<Flavor, UltraFlavor>);
bb::mock_proofs::generate_basic_arithmetic_circuit(builder, log2_num_gates);
}
MockCircuits::construct_arithmetic_circuit(builder, log2_num_gates);
return std::make_shared<ProverInstance>(builder);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
barretenberg_module(protogalaxy_round_bench ultra_honk protogalaxy stdlib_primitives)
barretenberg_module(
protogalaxy_round_bench
stdlib_honk_recursion
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <benchmark/benchmark.h>

#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/proof_system/circuit_builder/mock_circuits.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/protogalaxy/protogalaxy_prover.hpp"
#include "barretenberg/sumcheck/instance/instances.hpp"
Expand All @@ -22,12 +22,7 @@ void _bench_round(::benchmark::State& state, void (*F)(ProtoGalaxyProver_<Prover

const auto construct_instance = [&]() {
Builder builder;
if constexpr (std::same_as<Flavor, GoblinUltraFlavor>) {
GoblinMockCircuits::construct_arithmetic_circuit(builder, log2_num_gates);
} else {
static_assert(std::same_as<Flavor, UltraFlavor>);
bb::mock_proofs::generate_basic_arithmetic_circuit(builder, log2_num_gates);
}
MockCircuits::construct_arithmetic_circuit(builder, log2_num_gates);
return std::make_shared<ProverInstance>(builder);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
barretenberg_module(
hash_benchmarks
stdlib_primitives
crypto_sha256
stdlib_sha256
stdlib_blake3s
stdlib_pedersen_hash
plonk
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp"
#include "barretenberg/plonk/composer/ultra_composer.hpp"
#include "barretenberg/srs/factories/file_crs_factory.hpp"
#include "barretenberg/stdlib/hash/pedersen/pedersen.hpp"
#include "barretenberg/stdlib/primitives/field/field.hpp"
#include "pedersen.hpp"

#include <benchmark/benchmark.h>

#define BARRETENBERG_SRS_PATH "../srs_db/ignition"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
barretenberg_module(ultra_bench
barretenberg_module(
ultra_bench
ultra_honk
stdlib_sha256
stdlib_keccak
crypto_merkle_tree
stdlib_recursion)
plonk
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <benchmark/benchmark.h>

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

using namespace benchmark;
Expand All @@ -13,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<GoblinUltraProver>(
bb::mock_circuits::construct_proof_with_specified_num_iterations<GoblinUltraProver>(
state, test_circuit_function, num_iterations);
}

Expand All @@ -23,8 +23,8 @@ 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<GoblinUltraProver>(
state, &bb::mock_proofs::generate_basic_arithmetic_circuit<GoblinUltraCircuitBuilder>, log2_of_gates);
bb::mock_circuits::construct_proof_with_specified_num_iterations<GoblinUltraProver>(
state, &bb::mock_circuits::generate_basic_arithmetic_circuit<GoblinUltraCircuitBuilder>, log2_of_gates);
}

// Define benchmarks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
#pragma once
#include <benchmark/benchmark.h>
#include <cstddef>

#include "barretenberg/crypto/merkle_tree/membership.hpp"
#include "barretenberg/crypto/merkle_tree/memory_store.hpp"
#include "barretenberg/crypto/merkle_tree/memory_tree.hpp"
#include "barretenberg/crypto/merkle_tree/merkle_tree.hpp"
#include "barretenberg/goblin/mock_circuits.hpp"
#include "barretenberg/plonk/composer/standard_composer.hpp"
#include "barretenberg/plonk/composer/ultra_composer.hpp"
#include "barretenberg/proof_system/types/circuit_type.hpp"
#include "barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp"
#include "barretenberg/stdlib/hash/keccak/keccak.hpp"
#include "barretenberg/stdlib/hash/sha256/sha256.hpp"
#include "barretenberg/stdlib/primitives/bool/bool.hpp"
#include "barretenberg/stdlib/primitives/curves/secp256k1.hpp"
#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_prover.hpp"

namespace bb::mock_proofs {
namespace bb::mock_circuits {

/**
* @brief Generate test circuit with basic arithmetic operations
Expand Down Expand Up @@ -97,4 +86,4 @@ void construct_proof_with_specified_num_iterations(
}
}

} // namespace bb::mock_proofs
} // namespace bb::mock_circuits
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <benchmark/benchmark.h>

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

using namespace benchmark;
Expand All @@ -13,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<UltraProver>(
bb::mock_circuits::construct_proof_with_specified_num_iterations<UltraProver>(
state, test_circuit_function, num_iterations);
}

Expand All @@ -23,8 +23,8 @@ 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<UltraProver>(
state, &bb::mock_proofs::generate_basic_arithmetic_circuit<UltraCircuitBuilder>, log2_of_gates);
bb::mock_circuits::construct_proof_with_specified_num_iterations<UltraProver>(
state, &bb::mock_circuits::generate_basic_arithmetic_circuit<UltraCircuitBuilder>, log2_of_gates);
}

// Define benchmarks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include <benchmark/benchmark.h>

#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/benchmark/ultra_bench/mock_circuits.hpp"
#include "barretenberg/common/op_count_google_bench.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"

#include "barretenberg/ultra_honk/ultra_prover.hpp"

using namespace benchmark;
Expand Down Expand Up @@ -59,8 +58,8 @@ BB_PROFILE static void test_round(State& state, size_t index) noexcept
bb::srs::init_crs_factory("../srs_db/ignition");

// TODO(https://github.com/AztecProtocol/barretenberg/issues/761) benchmark both sparse and dense circuits
auto prover = bb::mock_proofs::get_prover<GoblinUltraProver>(
&bb::mock_proofs::generate_basic_arithmetic_circuit<GoblinUltraCircuitBuilder>, log2_num_gates);
auto prover = bb::mock_circuits::get_prover<GoblinUltraProver>(
&bb::mock_circuits::generate_basic_arithmetic_circuit<GoblinUltraCircuitBuilder>, log2_num_gates);
for (auto _ : state) {
state.PauseTiming();
test_round_inner(state, prover, index);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/benchmark/ultra_bench/mock_circuits.hpp"
#include "barretenberg/plonk/composer/ultra_composer.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"

Expand All @@ -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::UltraProver>(
bb::mock_circuits::construct_proof_with_specified_num_iterations<plonk::UltraProver>(
state, test_circuit_function, num_iterations);
}

Expand All @@ -22,8 +22,8 @@ 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::UltraProver>(
state, &bb::mock_proofs::generate_basic_arithmetic_circuit<UltraCircuitBuilder>, log2_of_gates);
bb::mock_circuits::construct_proof_with_specified_num_iterations<plonk::UltraProver>(
state, &bb::mock_circuits::generate_basic_arithmetic_circuit<UltraCircuitBuilder>, log2_of_gates);
}

// Define benchmarks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <benchmark/benchmark.h>

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

using namespace benchmark;
Expand Down Expand Up @@ -53,7 +53,7 @@ BB_PROFILE static void test_round(State& state, size_t index) noexcept
for (auto _ : state) {
state.PauseTiming();
// TODO: https://github.com/AztecProtocol/barretenberg/issues/761 benchmark both sparse and dense circuits
auto prover = bb::mock_proofs::get_prover<plonk::UltraProver>(
auto prover = bb::mock_circuits::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
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(widgets_bench polynomials proof_system transcript stdlib_primitives)
barretenberg_module(widgets_bench polynomials proof_system transcript stdlib_primitives plonk)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp"
#include "barretenberg/benchmark/ultra_bench/mock_circuits.hpp"
#include "barretenberg/flavor/goblin_ultra.hpp"
#include "barretenberg/flavor/ultra.hpp"
#include "barretenberg/plonk/composer/standard_composer.hpp"
Expand Down Expand Up @@ -39,7 +39,7 @@ BasicPlonkKeyAndTranscript get_plonk_key_and_transcript()
bb::srs::init_crs_factory("../srs_db/ignition");
auto inner_composer = plonk::UltraComposer();
auto builder = typename plonk::UltraComposer::CircuitBuilder();
bb::mock_proofs::generate_basic_arithmetic_circuit(builder, 16);
bb::mock_circuits::generate_basic_arithmetic_circuit(builder, 16);
UltraProver inner_prover = inner_composer.create_prover(builder);
#ifdef GET_PER_ROW_TIME
if (!(inner_prover.key->circuit_size == WIDGET_BENCH_TEST_CIRCUIT_SIZE)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp"
#include "barretenberg/circuit_checker/circuit_checker.hpp"
#include "barretenberg/stdlib/primitives/bigfield/constants.hpp"
#include <gtest/gtest.h>

using namespace bb;
Expand Down Expand Up @@ -67,7 +68,7 @@ TEST(GoblinUltraCircuitBuilder, BaseCase)
*/
TEST(GoblinUltraCircuitBuilder, GoblinSimple)
{
const size_t CHUNK_SIZE = plonk::NUM_LIMB_BITS_IN_FIELD_SIMULATION * 2;
const size_t CHUNK_SIZE = stdlib::NUM_LIMB_BITS_IN_FIELD_SIMULATION * 2;

auto builder = GoblinUltraCircuitBuilder();

Expand Down
Loading

0 comments on commit 5cbbd7d

Please sign in to comment.