Skip to content

Commit

Permalink
chore: Split up stdlib/recursion (#8054)
Browse files Browse the repository at this point in the history
A single target contained many stdlib verifiers. I split that up to make
working on these faster. I also move the Goblin VM verifiers into
stdlib/ for consistency. I also removed some template instatiations of
the Protogalaxy that are not needed.
  • Loading branch information
codygunton authored Aug 20, 2024
1 parent 5bff26b commit ec03e40
Show file tree
Hide file tree
Showing 91 changed files with 140 additions and 158 deletions.
6 changes: 3 additions & 3 deletions barretenberg/cpp/scripts/analyze_client_ivc_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
to_keep = [
"construct_circuits(t)",
"ProverInstance(Circuit&)(t)",
"ProtogalaxyProver::fold_instances(t)",
"ProtogalaxyProver::prove(t)",
"Decider::construct_proof(t)",
"ECCVMProver(CircuitBuilder&)(t)",
"ECCVMProver::construct_proof(t)",
Expand Down Expand Up @@ -64,7 +64,7 @@
time_ms = bench[key]/1e6
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/sum_of_kept_times_ms:>8.2%}")

print('\nBreakdown of ProtogalaxyProver::fold_instances:')
print('\nBreakdown of ProtogalaxyProver::prove:')
protogalaxy_round_labels = [
"ProtoGalaxyProver_::preparation_round(t)",
"ProtoGalaxyProver_::perturbator_round(t)",
Expand All @@ -77,7 +77,7 @@
time_ms = 0
else:
time_ms = bench[key]/1e6
total_time_ms = bench["ProtogalaxyProver::fold_instances(t)"]/1e6
total_time_ms = bench["ProtogalaxyProver::prove(t)"]/1e6
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/total_time_ms:>8.2%}")

# Extract a set of components from the benchmark data and display timings and relative percentages
Expand Down
6 changes: 3 additions & 3 deletions barretenberg/cpp/scripts/analyze_protogalaxy_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Single out an independent set of functions accounting for most of BENCHMARK's real_time
to_keep = [
"ProtogalaxyProver::fold_instances(t)",
"ProtogalaxyProver::prove(t)",
]
with open(PREFIX/PROTOGALAXY_BENCH_JSON, "r") as read_file:
read_result = json.load(read_file)
Expand Down Expand Up @@ -45,7 +45,7 @@
time_ms = bench[key]/1e6
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/sum_of_kept_times_ms:>8.2%}")

print('\nBreakdown of ProtogalaxyProver::fold_instances:')
print('\nBreakdown of ProtogalaxyProver::prove:')
protogalaxy_round_labels = [
"ProtoGalaxyProver_::preparation_round(t)",
"ProtoGalaxyProver_::perturbator_round(t)",
Expand All @@ -55,7 +55,7 @@
max_label_length = max(len(label) for label in protogalaxy_round_labels)
for key in protogalaxy_round_labels:
time_ms = bench[key]/1e6
total_time_ms = bench["ProtogalaxyProver::fold_instances(t)"]/1e6
total_time_ms = bench["ProtogalaxyProver::prove(t)"]/1e6
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/total_time_ms:>8.2%}")


25 changes: 0 additions & 25 deletions barretenberg/cpp/scripts/ultra_honk_tests.sh

This file was deleted.

13 changes: 7 additions & 6 deletions barretenberg/cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ add_subdirectory(barretenberg/crypto)
add_subdirectory(barretenberg/dsl)
add_subdirectory(barretenberg/ecc)
add_subdirectory(barretenberg/eccvm)
add_subdirectory(barretenberg/eccvm_recursion)
add_subdirectory(barretenberg/env)
add_subdirectory(barretenberg/execution_trace)
add_subdirectory(barretenberg/examples)
Expand All @@ -84,7 +83,6 @@ add_subdirectory(barretenberg/stdlib_circuit_builders)
add_subdirectory(barretenberg/sumcheck)
add_subdirectory(barretenberg/transcript)
add_subdirectory(barretenberg/translator_vm)
add_subdirectory(barretenberg/translator_vm_recursion)
add_subdirectory(barretenberg/ultra_honk)
add_subdirectory(barretenberg/vm)
add_subdirectory(barretenberg/wasi)
Expand Down Expand Up @@ -122,7 +120,6 @@ set(BARRETENBERG_TARGET_OBJECTS
$<TARGET_OBJECTS:dsl_objects>
$<TARGET_OBJECTS:ecc_objects>
$<TARGET_OBJECTS:eccvm_objects>
$<TARGET_OBJECTS:eccvm_recursion_objects>
$<TARGET_OBJECTS:execution_trace_objects>
$<TARGET_OBJECTS:simple_example_objects>
$<TARGET_OBJECTS:flavor_objects>
Expand All @@ -138,20 +135,24 @@ set(BARRETENBERG_TARGET_OBJECTS
$<TARGET_OBJECTS:stdlib_blake2s_objects>
$<TARGET_OBJECTS:stdlib_blake3s_objects>
$<TARGET_OBJECTS:stdlib_circuit_builders_objects>
$<TARGET_OBJECTS:stdlib_client_ivc_verifier_objects>
$<TARGET_OBJECTS:stdlib_eccvm_verifier_objects>
$<TARGET_OBJECTS:stdlib_honk_verifier_objects>
$<TARGET_OBJECTS:stdlib_goblin_verifier_objects>
$<TARGET_OBJECTS:stdlib_keccak_objects>
$<TARGET_OBJECTS:crypto_merkle_tree_objects>
$<TARGET_OBJECTS:stdlib_pedersen_commitment_objects>
$<TARGET_OBJECTS:stdlib_pedersen_hash_objects>
$<TARGET_OBJECTS:stdlib_plonk_recursion_objects>
$<TARGET_OBJECTS:stdlib_poseidon2_objects>
$<TARGET_OBJECTS:stdlib_primitives_objects>
$<TARGET_OBJECTS:stdlib_honk_recursion_objects>
$<TARGET_OBJECTS:stdlib_plonk_recursion_objects>
$<TARGET_OBJECTS:stdlib_protogalaxy_verifier_objects>
$<TARGET_OBJECTS:stdlib_schnorr_objects>
$<TARGET_OBJECTS:stdlib_sha256_objects>
$<TARGET_OBJECTS:stdlib_translator_vm_verifier_objects>
$<TARGET_OBJECTS:sumcheck_objects>
$<TARGET_OBJECTS:transcript_objects>
$<TARGET_OBJECTS:translator_vm_objects>
$<TARGET_OBJECTS:translator_vm_recursion_objects>
$<TARGET_OBJECTS:ultra_honk_objects>)

if(NOT DISABLE_AZTEC_VM)
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/aztec_ivc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(aztec_ivc goblin)
barretenberg_module(aztec_ivc stdlib_protogalaxy_verifier stdlib_goblin_verifier)
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void AztecIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr<Verifica
initialized = true;
} else { // Otherwise, fold the new instance into the accumulator
FoldingProver folding_prover({ fold_output.accumulator, prover_instance });
fold_output = folding_prover.fold_instances();
fold_output = folding_prover.prove();

// Add fold proof and corresponding verification key to the verification queue
verification_queue.emplace_back(fold_output.proof, instance_vk);
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp"
#include "barretenberg/plonk_honk_shared/types/aggregation_object_type.hpp"
#include "barretenberg/serialize/cbind.hpp"
#include "barretenberg/stdlib/honk_recursion/verifier/client_ivc_recursive_verifier.hpp"
#include "barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_keccak.hpp"

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(aztec_ivc_bench aztec_ivc stdlib_honk_recursion stdlib_sha256 crypto_merkle_tree stdlib_primitives)
barretenberg_module(aztec_ivc_bench aztec_ivc stdlib_honk_verifier stdlib_sha256 crypto_merkle_tree stdlib_primitives)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(client_ivc_bench client_ivc stdlib_honk_recursion stdlib_sha256 crypto_merkle_tree stdlib_primitives)
barretenberg_module(client_ivc_bench client_ivc stdlib_honk_verifier stdlib_sha256 crypto_merkle_tree stdlib_primitives)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(goblin_bench eccvm translator_vm stdlib_honk_recursion stdlib_sha256 crypto_merkle_tree)
barretenberg_module(goblin_bench eccvm)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
barretenberg_module(
protogalaxy_bench
stdlib_honk_recursion
)
stdlib_protogalaxy_verifier
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ template <typename Flavor, size_t k> void fold_k(State& state) noexcept

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

// We stick to just k=1 for compile-time reasons.
BENCHMARK(fold_k<UltraFlavor, 1>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);
BENCHMARK(fold_k<MegaFlavor, 1>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);

} // namespace bb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
barretenberg_module(
protogalaxy_round_bench
stdlib_honk_recursion
stdlib_protogalaxy_verifier
)
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,11 @@ void _bench_round(::benchmark::State& state, void (*F)(ProtoGalaxyProver_<Prover
}
}

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

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

BENCHMARK_CAPTURE(bench_round_ultra, preparation, [](auto& prover) { prover.preparation_round(); })
-> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_ultra, perturbator, [](auto& prover) { prover.perturbator_round(); })
-> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_ultra, combiner_quotient, [](auto& prover) { prover.combiner_quotient_round(); })
-> DenseRange(14, 20) -> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_ultra, accumulator_update, [](auto& prover) { prover.accumulator_update_round(); })
-> DenseRange(14, 20) -> Unit(kMillisecond);

BENCHMARK_CAPTURE(bench_round_mega, preparation, [](auto& prover) { prover.preparation_round(); }) -> DenseRange(14, 20)
-> Unit(kMillisecond);
BENCHMARK_CAPTURE(bench_round_mega, perturbator, [](auto& prover) { prover.perturbator_round(); }) -> DenseRange(14, 20)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(simulator_bench stdlib_honk_recursion stdlib_sha256 crypto_merkle_tree)
barretenberg_module(simulator_bench stdlib_honk_verifier stdlib_sha256 crypto_merkle_tree)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(client_ivc goblin)
barretenberg_module(client_ivc stdlib_protogalaxy_verifier stdlib_goblin_verifier)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr<Verific
initialized = true;
} else { // Otherwise, fold the new instance into the accumulator
FoldingProver folding_prover({ fold_output.accumulator, prover_instance });
fold_output = folding_prover.fold_instances();
fold_output = folding_prover.prove();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "barretenberg/commitment_schemes/ipa/ipa.hpp"
#include "barretenberg/commitment_schemes/kzg/kzg.hpp"
#include "barretenberg/srs/global_crs.hpp"
#include "barretenberg/stdlib/honk_recursion/transcript/transcript.hpp"
#include "barretenberg/stdlib/primitives/curves/bn254.hpp"
#include "barretenberg/stdlib/primitives/curves/grumpkin.hpp"
#include "barretenberg/stdlib/transcript/transcript.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp"
#include <gtest/gtest.h>

Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/dsl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set(DSL_DEPENDENCIES
stdlib_poseidon2
crypto_merkle_tree
stdlib_schnorr
stdlib_honk_recursion)
stdlib_honk_verifier)

if (NOT WASM)
list(APPEND DSL_DEPENDENCIES libdeflate::libdeflate_static)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "honk_recursion_constraint.hpp"
#include "barretenberg/flavor/flavor.hpp"
#include "barretenberg/plonk_honk_shared/types/aggregation_object_type.hpp"
#include "barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.hpp"
#include "barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.hpp"
#include "barretenberg/stdlib/plonk_recursion/aggregation_state/aggregation_state.hpp"
#include "barretenberg/stdlib/primitives/bigfield/constants.hpp"
#include "barretenberg/stdlib/primitives/curves/bn254.hpp"
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/goblin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(goblin stdlib_honk_recursion ultra_honk eccvm translator_vm stdlib_sha256 crypto_merkle_tree stdlib_primitives)
barretenberg_module(goblin ultra_honk eccvm translator_vm stdlib_honk_verifier stdlib_pedersen_commitment stdlib_sha256 )
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/goblin/goblin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "barretenberg/goblin/types.hpp"
#include "barretenberg/plonk_honk_shared/instance_inspector.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/stdlib/honk_recursion/verifier/merge_recursive_verifier.hpp"
#include "barretenberg/stdlib/goblin_verifier/merge_recursive_verifier.hpp"
#include "barretenberg/stdlib_circuit_builders/mega_circuit_builder.hpp"
#include "barretenberg/stdlib_circuit_builders/mega_flavor.hpp"
#include "barretenberg/translator_vm/translator_circuit_builder.hpp"
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include "barretenberg/srs/global_crs.hpp"
#include "barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp"
#include "barretenberg/stdlib/hash/sha256/sha256.hpp"
#include "barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.hpp"
#include "barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.hpp"
#include "barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.hpp"
#include "barretenberg/stdlib/primitives/curves/secp256k1.hpp"
#include "barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp"
#include "barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.hpp"
#include "barretenberg/stdlib_circuit_builders/mega_flavor.hpp"
#include "barretenberg/stdlib_circuit_builders/mock_circuits.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
FoldingProver folding_prover(prover_instances);
FoldingVerifier folding_verifier(verifier_instances);

auto [prover_accumulator, folding_proof] = folding_prover.fold_instances();
auto [prover_accumulator, folding_proof] = folding_prover.prove();
auto verifier_accumulator = folding_verifier.verify_folding_proof(folding_proof);
return { prover_accumulator, verifier_accumulator };
}
Expand Down Expand Up @@ -549,7 +549,7 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
ProtoGalaxyProver_<ProverInstances_<Flavor, total_insts>> folding_prover(get<0>(insts));
ProtoGalaxyVerifier_<VerifierInstances_<Flavor, total_insts>> folding_verifier(get<1>(insts));

auto [prover_accumulator, folding_proof] = folding_prover.fold_instances();
auto [prover_accumulator, folding_proof] = folding_prover.prove();
auto verifier_accumulator = folding_verifier.verify_folding_proof(folding_proof);
check_accumulator_target_sum_manual(prover_accumulator, true);

Expand All @@ -558,7 +558,7 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
};
} // namespace

using FlavorTypes = testing::Types<UltraFlavor, MegaFlavor>;
using FlavorTypes = testing::Types<MegaFlavor>;
TYPED_TEST_SUITE(ProtoGalaxyTests, FlavorTypes);

TYPED_TEST(ProtoGalaxyTests, PerturbatorCoefficients)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ template <class ProverInstances_> class ProtoGalaxyProver_ {
void finalise_and_send_instance(std::shared_ptr<Instance>, const std::string& domain_separator);

/**
* @brief Run the folding prover protocol to produce a new accumulator and a folding proof to be verified by the
* folding verifier.
* @brief Execute the folding prover.
*
* TODO(https://github.com/AztecProtocol/barretenberg/issues/753): fold goblin polynomials
* @todo TODO(https://github.com/AztecProtocol/barretenberg/issues/753): fold goblin polynomials
* @return FoldingResult is a pair consisting of an accumulator and a folding proof, which is a proof that the
* accumulator was computed correctly.
*/
BB_PROFILE FoldingResult<Flavor> fold_instances();
BB_PROFILE FoldingResult<Flavor> prove();

/**
* @brief For a new round challenge δ at each iteration of the ProtoGalaxy protocol, compute the vector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ template <class ProverInstances> void ProtoGalaxyProver_<ProverInstances>::accum
};

template <class ProverInstances>
FoldingResult<typename ProverInstances::Flavor> ProtoGalaxyProver_<ProverInstances>::fold_instances()
FoldingResult<typename ProverInstances::Flavor> ProtoGalaxyProver_<ProverInstances>::prove()
{
BB_OP_COUNT_TIME_NAME("ProtogalaxyProver::fold_instances");
BB_OP_COUNT_TIME_NAME("ProtogalaxyProver::prove");
// Ensure instances are all of the same size
for (size_t idx = 0; idx < ProverInstances::NUM - 1; ++idx) {
if (instances[idx]->proving_key.circuit_size != instances[idx + 1]->proving_key.circuit_size) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Note: this is split up from protogalaxy_prover_impl.hpp for compile performance reasons
#include "protogalaxy_prover_impl.hpp"

// TODO(https://github.com/AztecProtocol/barretenberg/issues/1076) Remove this instantiation.
namespace bb {
template class ProtoGalaxyProver_<ProverInstances_<UltraFlavor, 2>>;
} // namespace bb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "barretenberg/ecc/curves/bn254/g1.hpp"
#include "ecc_msm_relation.hpp"

namespace bb {
Expand Down
10 changes: 8 additions & 2 deletions barretenberg/cpp/src/barretenberg/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
add_subdirectory(hash)
add_subdirectory(client_ivc_verifier)
add_subdirectory(commitment)
add_subdirectory(encryption)
add_subdirectory(eccvm_verifier)
add_subdirectory(goblin_verifier)
add_subdirectory(primitives)
add_subdirectory(honk_recursion)
add_subdirectory(plonk_recursion)
add_subdirectory(honk_verifier)
add_subdirectory(transcript)
add_subdirectory(translator_vm_verifier)
add_subdirectory(plonk_recursion)
add_subdirectory(protogalaxy_verifier)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
barretenberg_module(
stdlib_client_ivc_verifier
stdlib_goblin_verifier
client_ivc
)
Loading

0 comments on commit ec03e40

Please sign in to comment.