diff --git a/barretenberg/cpp/scripts/ultra_honk_tests.sh b/barretenberg/cpp/scripts/ultra_honk_tests.sh index 654ba280c92..50928ccb78b 100755 --- a/barretenberg/cpp/scripts/ultra_honk_tests.sh +++ b/barretenberg/cpp/scripts/ultra_honk_tests.sh @@ -19,4 +19,7 @@ cd build/ ./bin/ultra_honk_tests ./bin/goblin_tests ./bin/client_ivc_tests -./bin/stdlib_recursion_tests \ No newline at end of file +./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* \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp index 41ff9f8ae75..f65385da92e 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp @@ -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; diff --git a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/goblin.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/goblin.bench.cpp index 8667c739dec..92f36e885f0 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/goblin.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/goblin.bench.cpp @@ -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; diff --git a/barretenberg/cpp/src/barretenberg/benchmark/pippenger_bench/main.cpp b/barretenberg/cpp/src/barretenberg/benchmark/pippenger_bench/main.cpp index cd6adb52b36..0fdf754812b 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/pippenger_bench/main.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/pippenger_bench/main.cpp @@ -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 #include diff --git a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/standard_plonk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/standard_plonk.bench.cpp index c4d85d3fde0..8ddd3d194a4 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/standard_plonk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/standard_plonk.bench.cpp @@ -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(state.range(0)); - bb::mock_proofs::construct_proof_with_specified_num_iterations( + bb::mock_proofs::construct_proof_with_specified_num_iterations( state, &bb::mock_proofs::generate_basic_arithmetic_circuit, log2_of_gates); } diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp index 0b5c2403cc5..cd369c29a70 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp @@ -2,17 +2,19 @@ #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 void fold_one(State& state) noexcept +template void fold_one(State& state) noexcept { - using Flavor = typename Composer::Flavor; - using Instance = ProverInstance_; + using ProverInstance = ProverInstance_; + using Instance = ProverInstance; using Instances = ProverInstances_; using ProtoGalaxyProver = ProtoGalaxyProver_; using Builder = typename Flavor::CircuitBuilder; @@ -20,7 +22,6 @@ template void fold_one(State& state) noexcept bb::srs::init_crs_factory("../srs_db/ignition"); auto log2_num_gates = static_cast(state.range(0)); - Composer composer; const auto construct_instance = [&]() { Builder builder; @@ -30,21 +31,21 @@ template void fold_one(State& state) noexcept static_assert(std::same_as); bb::mock_proofs::generate_basic_arithmetic_circuit(builder, log2_num_gates); } - return composer.create_prover_instance(builder); + return std::make_shared(builder); }; std::shared_ptr instance_1 = construct_instance(); std::shared_ptr 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)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); -BENCHMARK(fold_one)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); +BENCHMARK(fold_one)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); +BENCHMARK(fold_one)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); } // namespace bb BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp index 5efdccce9ce..14794ebb0a9 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp @@ -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 -void _bench_round(::benchmark::State& state, - void (*F)(ProtoGalaxyProver_>&)) +template +void _bench_round(::benchmark::State& state, void (*F)(ProtoGalaxyProver_>&)) { - using Flavor = typename Composer::Flavor; using Builder = typename Flavor::CircuitBuilder; + using ProverInstance = ProverInstance_; + using Instances = ProverInstances_; + using ProtoGalaxyProver = ProtoGalaxyProver_; bb::srs::init_crs_factory("../srs_db/ignition"); auto log2_num_gates = static_cast(state.range(0)); - auto composer = Composer(); const auto construct_instance = [&]() { Builder builder; @@ -27,13 +28,13 @@ void _bench_round(::benchmark::State& state, static_assert(std::same_as); bb::mock_proofs::generate_basic_arithmetic_circuit(builder, log2_num_gates); } - return composer.create_prover_instance(builder); + return std::make_shared(builder); }; - auto prover_instance_1 = construct_instance(); - auto prover_instance_2 = construct_instance(); + std::shared_ptr prover_instance_1 = construct_instance(); + std::shared_ptr 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; @@ -50,13 +51,13 @@ void _bench_round(::benchmark::State& state, void bench_round_ultra(::benchmark::State& state, void (*F)(ProtoGalaxyProver_>&)) { - _bench_round(state, F); + _bench_round(state, F); } void bench_round_goblin_ultra(::benchmark::State& state, void (*F)(ProtoGalaxyProver_>&)) { - _bench_round(state, F); + _bench_round(state, F); } BENCHMARK_CAPTURE(bench_round_ultra, preparation, [](auto& prover) { prover.preparation_round(); }) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/goblin_ultra_honk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/goblin_ultra_honk.bench.cpp index 98a42f0bab4..776a4752181 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/goblin_ultra_honk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/goblin_ultra_honk.bench.cpp @@ -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; @@ -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( + bb::mock_proofs::construct_proof_with_specified_num_iterations( state, test_circuit_function, num_iterations); } @@ -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(state.range(0)); - bb::mock_proofs::construct_proof_with_specified_num_iterations( + bb::mock_proofs::construct_proof_with_specified_num_iterations( state, &bb::mock_proofs::generate_basic_arithmetic_circuit, log2_of_gates); } diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_proofs.hpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_proofs.hpp index 29ff2fb135e..ab24f1b070d 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_proofs.hpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_proofs.hpp @@ -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 { @@ -47,46 +47,27 @@ template 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 +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 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 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. + if constexpr (IsPlonkFlavor) { + // If Flavor is Ultra, alias UltraComposer, otherwise alias StandardComposer + using Composer = std:: + conditional_t, 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 * @@ -97,20 +78,18 @@ inline plonk::UltraProver get_prover(plonk::UltraComposer& composer, * @param state * @param test_circuit_function */ -template -void construct_proof_with_specified_num_iterations(benchmark::State& state, - void (*test_circuit_function)(typename Composer::CircuitBuilder&, - size_t), - size_t num_iterations) +template +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(test_circuit_function, num_iterations); state.ResumeTiming(); // Construct proof diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp index 29139186659..d45ad85ebbe 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp @@ -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; @@ -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( + bb::mock_proofs::construct_proof_with_specified_num_iterations( state, test_circuit_function, num_iterations); } @@ -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(state.range(0)); - bb::mock_proofs::construct_proof_with_specified_num_iterations( + bb::mock_proofs::construct_proof_with_specified_num_iterations( state, &bb::mock_proofs::generate_basic_arithmetic_circuit, log2_of_gates); } diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp index 619ba60a8c1..11ad5e6e15f 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp @@ -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; @@ -58,10 +58,9 @@ BB_PROFILE static void test_round(State& state, size_t index) noexcept auto log2_num_gates = static_cast(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, log2_num_gates); + auto prover = bb::mock_proofs::get_prover( + &bb::mock_proofs::generate_basic_arithmetic_circuit, log2_num_gates); for (auto _ : state) { test_round_inner(state, prover, index); } diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk.bench.cpp index 6682aeb5d90..28ef3d8e25e 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk.bench.cpp @@ -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( + bb::mock_proofs::construct_proof_with_specified_num_iterations( state, test_circuit_function, num_iterations); } @@ -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(state.range(0)); - bb::mock_proofs::construct_proof_with_specified_num_iterations( + bb::mock_proofs::construct_proof_with_specified_num_iterations( state, &bb::mock_proofs::generate_basic_arithmetic_circuit, log2_of_gates); } diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk_rounds.bench.cpp index 8fa44c08809..08442500ab0 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk_rounds.bench.cpp @@ -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, 10); + auto prover = bb::mock_proofs::get_prover( + &bb::stdlib::generate_ecdsa_verification_test_circuit, 10); test_round_inner(state, prover, index); // NOTE: google bench is very finnicky, must end in ResumeTiming() for correctness state.ResumeTiming(); diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index a17021b803c..69408f8aee9 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -17,8 +17,7 @@ ClientIVC::ClientIVC() void ClientIVC::initialize(ClientCircuit& circuit) { goblin.merge(circuit); // Construct new merge proof - Composer composer; - prover_fold_output.accumulator = composer.create_prover_instance(circuit); + prover_fold_output.accumulator = std::make_shared(circuit); } /** @@ -31,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 = composer.create_prover_instance(circuit); - auto folding_prover = composer.create_folding_prover({ prover_fold_output.accumulator, prover_instance }); + prover_instance = std::make_shared(circuit); + FoldingProver folding_prover({ prover_fold_output.accumulator, prover_instance }); prover_fold_output = folding_prover.fold_instances(); return prover_fold_output.folding_data; } @@ -60,11 +58,10 @@ bool ClientIVC::verify(Proof& proof, const std::vector& 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); - auto decider_verifier = composer.create_decider_verifier(verifier_accumulator); + ClientIVC::DeciderVerifier decider_verifier(verifier_accumulator); bool decision = decider_verifier.verify_proof(proof.decider_proof); return goblin_verified && decision; } @@ -76,8 +73,7 @@ bool ClientIVC::verify(Proof& proof, const std::vector& ver */ HonkProof ClientIVC::decider_prove() const { - Composer composer; - auto decider_prover = composer.create_decider_prover(prover_fold_output.accumulator); + GoblinUltraDeciderProver decider_prover(prover_fold_output.accumulator); return decider_prover.construct_proof(); } diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp index 5c444ac9ec5..1d26519f323 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp @@ -2,7 +2,11 @@ #include "barretenberg/goblin/goblin.hpp" #include "barretenberg/goblin/mock_circuits.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" +#include "barretenberg/protogalaxy/decider_prover.hpp" +#include "barretenberg/protogalaxy/decider_verifier.hpp" +#include "barretenberg/protogalaxy/protogalaxy_prover.hpp" +#include "barretenberg/protogalaxy/protogalaxy_verifier.hpp" +#include "barretenberg/sumcheck/instance/instances.hpp" namespace bb { @@ -21,9 +25,15 @@ class ClientIVC { using FoldProof = std::vector; using ProverAccumulator = std::shared_ptr>; using VerifierAccumulator = std::shared_ptr>; - using ProverInstance = ProverInstance_; - using VerifierInstance = VerifierInstance_; + using ProverInstance = ProverInstance_; + using VerifierInstance = VerifierInstance_; using ClientCircuit = GoblinUltraCircuitBuilder; // can only be GoblinUltra + using DeciderProver = DeciderProver_; + using DeciderVerifier = DeciderVerifier_; + using ProverInstances = ProverInstances_; + using FoldingProver = ProtoGalaxyProver_; + using VerifierInstances = VerifierInstances_; + using FoldingVerifier = ProtoGalaxyVerifier_; // A full proof for the IVC scheme struct Proof { @@ -40,8 +50,7 @@ class ClientIVC { }; private: - using ProverFoldOutput = FoldingResult; - using Composer = GoblinUltraComposer; + using ProverFoldOutput = FoldingResult; // 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 diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index 1f985351bbf..67cbd8590ce 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -4,7 +4,6 @@ #include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" #include using namespace bb; @@ -20,7 +19,6 @@ class ClientIVCTests : public ::testing::Test { using Flavor = ClientIVC::Flavor; using FF = typename Flavor::FF; using Builder = ClientIVC::ClientCircuit; - using Composer = GoblinUltraComposer; using ProverAccumulator = ClientIVC::ProverAccumulator; using VerifierAccumulator = ClientIVC::VerifierAccumulator; using VerifierInstance = ClientIVC::VerifierInstance; @@ -32,6 +30,12 @@ class ClientIVCTests : public ::testing::Test { using RecursiveVerifierInstances = ::bb::stdlib::recursion::honk::RecursiveVerifierInstances_; using FoldingRecursiveVerifier = bb::stdlib::recursion::honk::ProtoGalaxyRecursiveVerifier_; + using DeciderProver = ClientIVC::DeciderProver; + using DeciderVerifier = ClientIVC::DeciderVerifier; + using ProverInstances = ProverInstances_; + using FoldingProver = ProtoGalaxyProver_; + using VerifierInstances = VerifierInstances_; + using FoldingVerifier = ProtoGalaxyVerifier_; /** * @brief Construct mock circuit with arithmetic gates and goblin ops @@ -83,14 +87,13 @@ class ClientIVCTests : public ::testing::Test { const std::shared_ptr& verifier_inst_vk) { // Verify fold proof - Composer composer; auto new_verifier_inst = std::make_shared(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 - auto decider_prover = composer.create_decider_prover(prover_accumulator); - auto decider_verifier = composer.create_decider_verifier(verifier_accumulator); + DeciderProver decider_prover(prover_accumulator); + DeciderVerifier decider_verifier(verifier_accumulator); auto decider_proof = decider_prover.construct_proof(); bool decision = decider_verifier.verify_proof(decider_proof); EXPECT_TRUE(decision); diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/mock_kernel_pinning.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/mock_kernel_pinning.test.cpp index 773496dbfb2..eebaa2e8185 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/mock_kernel_pinning.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/mock_kernel_pinning.test.cpp @@ -1,7 +1,7 @@ #include "barretenberg/client_ivc/client_ivc.hpp" #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" + #include using namespace bb; @@ -48,7 +48,6 @@ TEST_F(MockKernelTest, PinFoldingKernelSizes) { kernel_fold_proof, ivc.vks.first_kernel_vk }, { func_fold_proof, ivc.vks.func_vk }, kernel_acc); - GoblinUltraComposer composer; - auto instance = composer.create_prover_instance(kernel_circuit); + auto instance = std::make_shared(kernel_circuit); EXPECT_EQ(instance->proving_key->log_circuit_size, 17); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 1dece4eed0e..339d7f1f03a 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -10,13 +10,13 @@ #include "barretenberg/translator_vm/goblin_translator_composer.hpp" #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" +#include "barretenberg/ultra_honk/ultra_verifier.hpp" namespace bb { class Goblin { using GoblinUltraCircuitBuilder = bb::GoblinUltraCircuitBuilder; - using Commitment = GoblinUltraFlavor::Commitment; using FF = GoblinUltraFlavor::FF; @@ -24,8 +24,7 @@ class Goblin { using Builder = GoblinUltraCircuitBuilder; using Fr = bb::fr; using Transcript = NativeTranscript; - using GoblinUltraComposer = bb::UltraComposer_; - using GoblinUltraVerifier = bb::UltraVerifier_; + using GoblinUltraProverInstance = ProverInstance_; using OpQueue = bb::ECCOpQueue; using ECCVMFlavor = bb::ECCVMFlavor; using ECCVMBuilder = bb::ECCVMCircuitBuilder; @@ -104,11 +103,10 @@ class Goblin { } // Construct a Honk proof for the main circuit - GoblinUltraComposer composer; - auto instance = composer.create_prover_instance(circuit_builder); - auto verification_key = std::make_shared(instance->proving_key); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(circuit_builder); + GoblinUltraProver prover(instance); auto ultra_proof = prover.construct_proof(); + auto verification_key = std::make_shared(instance->proving_key); // Construct and store the merge proof to be recursively verified on the next call to accumulate MergeProver merge_prover{ circuit_builder.op_queue }; @@ -231,11 +229,10 @@ class Goblin { // } // Construct a Honk proof for the main circuit - GoblinUltraComposer composer; - auto instance = composer.create_prover_instance(circuit_builder); - auto verification_key = std::make_shared(instance->proving_key); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(circuit_builder); + GoblinUltraProver prover(instance); auto ultra_proof = prover.construct_proof(); + auto verification_key = std::make_shared(instance->proving_key); accumulator = { ultra_proof, verification_key }; diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin_recursion.test.cpp b/barretenberg/cpp/src/barretenberg/goblin/goblin_recursion.test.cpp index c731722d755..96463863ebb 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin_recursion.test.cpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin_recursion.test.cpp @@ -2,7 +2,6 @@ #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" #include @@ -18,15 +17,16 @@ class GoblinRecursionTests : public ::testing::Test { using Curve = curve::BN254; using FF = Curve::ScalarField; - using GoblinUltraBuilder = GoblinUltraCircuitBuilder; using KernelInput = Goblin::AccumulationOutput; + using ProverInstance = ProverInstance_; + using VerifierInstance = VerifierInstance_; - static Goblin::AccumulationOutput construct_accumulator(GoblinUltraBuilder& builder) + static Goblin::AccumulationOutput construct_accumulator(GoblinUltraCircuitBuilder& builder) { - GoblinUltraComposer composer; - auto prover_instance = composer.create_prover_instance(builder); - auto verifier_instance = composer.create_verifier_instance(prover_instance); - auto prover = composer.create_prover(prover_instance); + auto prover_instance = std::make_shared(builder); + auto verification_key = std::make_shared(prover_instance->proving_key); + auto verifier_instance = std::make_shared(verification_key); + GoblinUltraProver prover(prover_instance); auto ultra_proof = prover.construct_proof(); return { ultra_proof, verifier_instance->verification_key }; } diff --git a/barretenberg/cpp/src/barretenberg/goblin/mock_circuits_pinning.test.cpp b/barretenberg/cpp/src/barretenberg/goblin/mock_circuits_pinning.test.cpp index db0fc69b80d..0b9e06e0ff8 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/mock_circuits_pinning.test.cpp +++ b/barretenberg/cpp/src/barretenberg/goblin/mock_circuits_pinning.test.cpp @@ -1,7 +1,7 @@ #include "barretenberg/goblin/goblin.hpp" #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" + #include using namespace bb; @@ -13,6 +13,7 @@ using namespace bb; */ class MockCircuits : public ::testing::Test { protected: + using ProverInstance = ProverInstance_; static void SetUpTestSuite() { srs::init_crs_factory("../srs_db/ignition"); } }; @@ -22,8 +23,7 @@ TEST_F(MockCircuits, PinFunctionSizes) Goblin goblin; GoblinUltraCircuitBuilder app_circuit{ goblin.op_queue }; GoblinMockCircuits::construct_mock_function_circuit(app_circuit, large); - GoblinUltraComposer composer; - auto instance = composer.create_prover_instance(app_circuit); + auto instance = std::make_shared(app_circuit); if (large) { EXPECT_EQ(instance->proving_key->log_circuit_size, 19); } else { @@ -46,8 +46,8 @@ TEST_F(MockCircuits, PinRecursionKernelSizes) auto function_accum = goblin.accumulate(app_circuit); GoblinUltraCircuitBuilder kernel_circuit{ goblin.op_queue }; GoblinMockCircuits::construct_mock_recursion_kernel_circuit(kernel_circuit, function_accum, kernel_accum); - GoblinUltraComposer composer; - auto instance = composer.create_prover_instance(kernel_circuit); + + auto instance = std::make_shared(kernel_circuit); if (large) { EXPECT_EQ(instance->proving_key->log_circuit_size, 17); } else { diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/types.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/types.hpp index fbc2e45f7ca..392fe9d4790 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/types.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/types.hpp @@ -2,7 +2,6 @@ #include "barretenberg/plonk/composer/standard_composer.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" #include "barretenberg/crypto/merkle_tree/hash_path.hpp" #include "barretenberg/plonk/proof_system/prover/prover.hpp" diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/prover.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/prover.hpp index 9dbe3cd4d49..66c2ad83d9a 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/prover.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/prover.hpp @@ -12,6 +12,8 @@ namespace bb::plonk { template class ProverBase { public: + using Flavor = typename settings::Flavor; + ProverBase(std::shared_ptr input_key = nullptr, const transcript::Manifest& manifest = transcript::Manifest()); ProverBase(ProverBase&& other); @@ -100,6 +102,7 @@ template class ProverBase { }; typedef ProverBase Prover; +typedef Prover StandardProver; typedef ProverBase UltraProver; // TODO(Mike): maybe just return a templated proverbase so that I don't // need separate cases for ultra vs ultra_to_standard...??? // TODO(Cody): Make this into an issue? diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/prover_settings.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/prover_settings.hpp index 88dd0d26e89..44469d3c775 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/prover_settings.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/prover_settings.hpp @@ -13,6 +13,7 @@ class settings_base { class standard_settings : public settings_base { public: using Arithmetization = StandardArith; + using Flavor = plonk::flavor::Standard; static constexpr size_t num_challenge_bytes = 16; static constexpr transcript::HashType hash_type = transcript::HashType::PedersenBlake3s; static constexpr size_t program_width = 3; @@ -26,6 +27,7 @@ class standard_settings : public settings_base { class ultra_settings : public settings_base { public: + using Flavor = plonk::flavor::Ultra; static constexpr size_t num_challenge_bytes = 16; static constexpr transcript::HashType hash_type = transcript::HashType::PedersenBlake3s; static constexpr size_t program_width = 4; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.hpp index ef3cd372cee..062d19f96b8 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.hpp @@ -53,6 +53,7 @@ template class DeciderProver_ { HonkProof proof; }; -using DeciderProver = DeciderProver_; +using UltraDeciderProver = DeciderProver_; +using GoblinUltraDeciderProver = DeciderProver_; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.cpp index d140292bc4b..d635c15269f 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.cpp @@ -7,8 +7,8 @@ namespace bb { template -DeciderVerifier_::DeciderVerifier_(const std::shared_ptr& transcript, - const std::shared_ptr& accumulator) +DeciderVerifier_::DeciderVerifier_(const std::shared_ptr& accumulator, + const std::shared_ptr& transcript) : accumulator(accumulator) , pcs_verification_key(accumulator->verification_key->pcs_verification_key) , transcript(transcript) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.hpp index 3969b89d96c..eb896654430 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_verifier.hpp @@ -17,8 +17,8 @@ template class DeciderVerifier_ { public: explicit DeciderVerifier_(); - explicit DeciderVerifier_(const std::shared_ptr& transcript, - const std::shared_ptr& accumulator = nullptr); + explicit DeciderVerifier_(const std::shared_ptr& accumulator, + const std::shared_ptr& transcript = std::make_shared()); bool verify_proof(const HonkProof& proof); @@ -29,6 +29,7 @@ template class DeciderVerifier_ { std::shared_ptr transcript; }; -using DeciderVerifier = DeciderVerifier_; +using UltraDeciderVerifier = DeciderVerifier_; +using GoblinUltraDeciderVerifier = DeciderVerifier_; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp index b5615b0d0c3..ddde25cf774 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/goblin_verifier.test.cpp @@ -4,7 +4,7 @@ #include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" +#include "barretenberg/ultra_honk/ultra_prover.hpp" #include "barretenberg/ultra_honk/ultra_verifier.hpp" namespace bb::stdlib::recursion::honk { @@ -16,35 +16,27 @@ namespace bb::stdlib::recursion::honk { * * @tparam Builder Circuit builder for the recursive verifier circuit */ -template class GoblinRecursiveVerifierTest : public testing::Test { - - using UltraComposer = UltraComposer_; - using GoblinUltraComposer = UltraComposer_; +template class GoblinRecursiveVerifierTest : public testing::Test { // Define types for the inner circuit, i.e. the circuit whose proof will be recursively verified using InnerFlavor = GoblinUltraFlavor; - using InnerComposer = GoblinUltraComposer; - using InnerBuilder = typename InnerComposer::CircuitBuilder; + using InnerProver = GoblinUltraProver; + using InnerVerifier = GoblinUltraVerifier; + using InnerBuilder = typename InnerFlavor::CircuitBuilder; + using InnerProverInstance = ProverInstance_; using InnerCurve = bn254; using InnerCommitment = InnerFlavor::Commitment; using InnerFF = InnerFlavor::FF; // Types for recursive verifier circuit - using OuterBuilder = BuilderType; + using OuterBuilder = typename OuterFlavor::CircuitBuilder; + using OuterProver = UltraProver_; + using OuterVerifier = UltraVerifier_; + using OuterProverInstance = ProverInstance_; using RecursiveFlavor = GoblinUltraRecursiveFlavor_; using RecursiveVerifier = UltraRecursiveVerifier_; using VerificationKey = typename RecursiveVerifier::VerificationKey; - // Helper for getting composer for prover/verifier of recursive (outer) circuit - template static auto get_outer_composer() - { - if constexpr (IsGoblinBuilder) { - return GoblinUltraComposer(); - } else { - return UltraComposer(); - } - } - /** * @brief Create a non-trivial arbitrary inner circuit, the proof of which will be recursively verified * @@ -147,8 +139,8 @@ template class GoblinRecursiveVerifierTest : public testi OuterBuilder outer_circuit; // Compute native verification key - InnerComposer inner_composer; - auto instance = inner_composer.create_prover_instance(inner_circuit); + auto instance = std::make_shared(inner_circuit); + InnerProver prover(instance); // A prerequisite for computing VK auto verification_key = std::make_shared(instance->proving_key); // Instantiate the recursive verifier using the native verification key RecursiveVerifier verifier{ &outer_circuit, verification_key }; @@ -175,10 +167,9 @@ template class GoblinRecursiveVerifierTest : public testi auto inner_circuit = create_inner_circuit(); // Generate a proof over the inner circuit - InnerComposer inner_composer; - auto instance = inner_composer.create_prover_instance(inner_circuit); + auto instance = std::make_shared(inner_circuit); + InnerProver inner_prover(instance); auto verification_key = std::make_shared(instance->proving_key); - auto inner_prover = inner_composer.create_prover(instance); auto inner_proof = inner_prover.construct_proof(); // Create a recursive verification circuit for the proof of the inner circuit @@ -192,7 +183,7 @@ template class GoblinRecursiveVerifierTest : public testi // Check 1: Perform native verification then perform the pairing on the outputs of the recursive // verifier and check that the result agrees. - auto native_verifier = inner_composer.create_verifier(verification_key); + InnerVerifier native_verifier(verification_key); auto native_result = native_verifier.verify_proof(inner_proof); auto recursive_result = native_verifier.key->pcs_verification_key->pairing_check(pairing_points[0].get_value(), pairing_points[1].get_value()); @@ -208,12 +199,10 @@ template class GoblinRecursiveVerifierTest : public testi // Check 3: Construct and verify a proof of the recursive verifier circuit { - auto composer = get_outer_composer(); - auto instance = composer.create_prover_instance(outer_circuit); - auto prover = composer.create_prover(instance); - // TODO: github.com/AztecProtocol/barretenberg/issues/892 - auto verifier_instance = composer.create_verifier_instance(instance); - auto verifier = composer.create_verifier(verifier_instance->verification_key); + auto instance = std::make_shared(outer_circuit); + OuterProver prover(instance); + auto verification_key = std::make_shared(instance->proving_key); + OuterVerifier verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); @@ -233,9 +222,8 @@ template class GoblinRecursiveVerifierTest : public testi auto inner_circuit = create_inner_circuit(); // Generate a proof over the inner circuit - InnerComposer inner_composer; - auto instance = inner_composer.create_prover_instance(inner_circuit); - auto inner_prover = inner_composer.create_prover(instance); + auto instance = std::make_shared(inner_circuit); + InnerProver inner_prover(instance); auto inner_proof = inner_prover.construct_proof(); // Arbitrarily tamper with the proof to be verified @@ -258,9 +246,9 @@ template class GoblinRecursiveVerifierTest : public testi }; // Run the recursive verifier tests with conventional Ultra builder and Goblin builder -using BuilderTypes = testing::Types; +using Flavors = testing::Types; -TYPED_TEST_SUITE(GoblinRecursiveVerifierTest, BuilderTypes); +TYPED_TEST_SUITE(GoblinRecursiveVerifierTest, Flavors); HEAVY_TYPED_TEST(GoblinRecursiveVerifierTest, InnerCircuit) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/merge_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/merge_verifier.test.cpp index ca58db33acc..011f26e7c9d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/merge_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/merge_verifier.test.cpp @@ -2,7 +2,6 @@ #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/stdlib/recursion/honk/verifier/merge_recursive_verifier.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" namespace bb::stdlib::recursion::goblin { @@ -20,10 +19,9 @@ class RecursiveMergeVerifierTest : public testing::Test { using RecursiveMergeVerifier = MergeRecursiveVerifier_; // Define types relevant for inner circuit - using GoblinUltraComposer = UltraComposer_; using InnerFlavor = GoblinUltraFlavor; - using InnerComposer = GoblinUltraComposer; - using InnerBuilder = typename InnerComposer::CircuitBuilder; + using InnerProverInstance = ProverInstance_; + using InnerBuilder = typename InnerFlavor::CircuitBuilder; // Define additional types for testing purposes using Commitment = InnerFlavor::Commitment; @@ -80,12 +78,10 @@ class RecursiveMergeVerifierTest : public testing::Test { // Check 3: Construct and verify a (goblin) ultra honk proof of the Merge recursive verifier circuit { - GoblinUltraComposer composer; - auto instance = composer.create_prover_instance(outer_circuit); - auto prover = composer.create_prover(instance); - // TODO: github.com/AztecProtocol/barretenberg/issues/892 - auto verifier_instance = composer.create_verifier_instance(instance); - auto verifier = composer.create_verifier(verifier_instance->verification_key); + auto instance = std::make_shared(outer_circuit); + GoblinUltraProver prover(instance); + auto verification_key = std::make_shared(instance->proving_key); + GoblinUltraVerifier verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.test.cpp index 10f05b58fdf..fbf52ef504b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.test.cpp @@ -1,32 +1,42 @@ #include "barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.hpp" #include "barretenberg/common/test.hpp" #include "barretenberg/flavor/ultra_recursive.hpp" +#include "barretenberg/protogalaxy/decider_prover.hpp" +#include "barretenberg/protogalaxy/decider_verifier.hpp" +#include "barretenberg/protogalaxy/protogalaxy_prover.hpp" +#include "barretenberg/protogalaxy/protogalaxy_verifier.hpp" #include "barretenberg/stdlib/hash/blake3s/blake3s.hpp" #include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/stdlib/recursion/honk/verifier/decider_recursive_verifier.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" +#include "barretenberg/sumcheck/instance/instances.hpp" +#include "barretenberg/ultra_honk/ultra_prover.hpp" +#include "barretenberg/ultra_honk/ultra_verifier.hpp" namespace bb::stdlib::recursion::honk { template class ProtoGalaxyRecursiveTests : public testing::Test { public: using NativeFlavor = typename RecursiveFlavor::NativeFlavor; - using Composer = ::bb::UltraComposer_; using Builder = typename RecursiveFlavor::CircuitBuilder; + using Prover = UltraProver_; + using Verifier = UltraVerifier_; using ProverInstance = ::bb::ProverInstance_; using VerifierInstance = ::bb::VerifierInstance_; using RecursiveVerifierInstance = ::bb::stdlib::recursion::honk::RecursiveVerifierInstance_; using Curve = bn254; using Commitment = typename NativeFlavor::Commitment; using FF = typename NativeFlavor::FF; + using DeciderProver = DeciderProver_; using VerificationKey = typename NativeFlavor::VerificationKey; using RecursiveVerifierInstances = ::bb::stdlib::recursion::honk::RecursiveVerifierInstances_; using FoldingRecursiveVerifier = ProtoGalaxyRecursiveVerifier_; using DeciderRecursiveVerifier = DeciderRecursiveVerifier_; - using DeciderVerifier = DeciderVerifier_; + using NativeDeciderVerifier = DeciderVerifier_; using NativeVerifierInstances = VerifierInstances_; using NativeFoldingVerifier = ProtoGalaxyVerifier_; + using NativeProverInstances = ProverInstances_; + using NativeFoldingProver = ProtoGalaxyProver_; static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } /** @@ -95,8 +105,7 @@ template class ProtoGalaxyRecursiveTests : public tes } }; - static std::tuple, std::shared_ptr> fold_and_verify_native( - Composer& composer) + static std::tuple, std::shared_ptr> fold_and_verify_native() { Builder builder1; create_function_circuit(builder1); @@ -104,12 +113,14 @@ template class ProtoGalaxyRecursiveTests : public tes builder2.add_public_variable(FF(1)); create_function_circuit(builder2); - auto prover_instance_1 = composer.create_prover_instance(builder1); - auto prover_instance_2 = composer.create_prover_instance(builder2); - auto verifier_instance_1 = composer.create_verifier_instance(prover_instance_1); - auto verifier_instance_2 = composer.create_verifier_instance(prover_instance_2); - 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 }); + auto prover_instance_1 = std::make_shared(builder1); + auto verification_key_1 = std::make_shared(prover_instance_1->proving_key); + auto verifier_instance_1 = std::make_shared(verification_key_1); + auto prover_instance_2 = std::make_shared(builder2); + auto verification_key_2 = std::make_shared(prover_instance_2->proving_key); + auto verifier_instance_2 = std::make_shared(verification_key_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); @@ -169,13 +180,14 @@ template class ProtoGalaxyRecursiveTests : public tes builder2.add_public_variable(FF(1)); create_function_circuit(builder2); - Composer composer = Composer(); - auto prover_instance_1 = composer.create_prover_instance(builder1); - auto verifier_instance_1 = composer.create_verifier_instance(prover_instance_1); - auto prover_instance_2 = composer.create_prover_instance(builder2); - auto verifier_instance_2 = composer.create_verifier_instance(prover_instance_2); + auto prover_instance_1 = std::make_shared(builder1); + auto verification_key_1 = std::make_shared(prover_instance_1->proving_key); + auto verifier_instance_1 = std::make_shared(verification_key_1); + auto prover_instance_2 = std::make_shared(builder2); + auto verification_key_2 = std::make_shared(prover_instance_2->proving_key); + auto verifier_instance_2 = std::make_shared(verification_key_2); // 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 @@ -188,7 +200,7 @@ template 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 @@ -203,11 +215,10 @@ template class ProtoGalaxyRecursiveTests : public tes // Check for a failure flag in the recursive verifier circuit { - auto composer = Composer(); - auto instance = composer.create_prover_instance(folding_circuit); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(folding_circuit); + Prover prover(instance); auto verification_key = std::make_shared(instance->proving_key); - auto verifier = composer.create_verifier(verification_key); + Verifier verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); @@ -232,13 +243,14 @@ template class ProtoGalaxyRecursiveTests : public tes create_function_circuit(builder2); - Composer composer = Composer(); - auto prover_instance_1 = composer.create_prover_instance(builder1); - auto verifier_instance_1 = composer.create_verifier_instance(prover_instance_1); - auto prover_instance_2 = composer.create_prover_instance(builder2); - auto verifier_instance_2 = composer.create_verifier_instance(prover_instance_2); + auto prover_instance_1 = std::make_shared(builder1); + auto verification_key_1 = std::make_shared(prover_instance_1->proving_key); + auto verifier_instance_1 = std::make_shared(verification_key_1); + auto prover_instance_2 = std::make_shared(builder2); + auto verification_key_2 = std::make_shared(prover_instance_2->proving_key); + auto verifier_instance_2 = std::make_shared(verification_key_2); // 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 @@ -254,7 +266,7 @@ template 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 @@ -266,7 +278,7 @@ template class ProtoGalaxyRecursiveTests : public tes EXPECT_EQ(recursive_folding_manifest[i], native_folding_manifest[i]); } - auto decider_prover = composer.create_decider_prover(folding_proof.accumulator); + DeciderProver decider_prover(folding_proof.accumulator); auto decider_proof = decider_prover.construct_proof(); Builder decider_circuit; @@ -276,9 +288,9 @@ template class ProtoGalaxyRecursiveTests : public tes // Check for a failure flag in the recursive verifier circuit EXPECT_EQ(decider_circuit.failed(), false) << decider_circuit.err(); - // Perform native verification then perform the pairing on the outputs of the recursive - // decider verifier and check that the result agrees. - DeciderVerifier native_decider_verifier = composer.create_decider_verifier(verifier_accumulator); + // Perform native verification then perform the pairing on the outputs of the recursive decider verifier and + // check that the result agrees. + NativeDeciderVerifier native_decider_verifier(verifier_accumulator); auto native_result = native_decider_verifier.verify_proof(decider_proof); auto recursive_result = native_decider_verifier.accumulator->pcs_verification_key->pairing_check( pairing_points[0].get_value(), pairing_points[1].get_value()); @@ -294,11 +306,10 @@ template class ProtoGalaxyRecursiveTests : public tes // Construct and verify a proof of the recursive decider verifier circuit { - auto composer = Composer(); - auto instance = composer.create_prover_instance(decider_circuit); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(decider_circuit); + Prover prover(instance); auto verification_key = std::make_shared(instance->proving_key); - auto verifier = composer.create_verifier(verification_key); + Verifier verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); @@ -309,14 +320,13 @@ template class ProtoGalaxyRecursiveTests : public tes static void test_tampered_decider_proof() { // Natively fold two circuits - auto composer = Composer(); - auto [prover_accumulator, verifier_accumulator] = fold_and_verify_native(composer); + auto [prover_accumulator, verifier_accumulator] = fold_and_verify_native(); // Tamper with the accumulator by changing the target sum verifier_accumulator->target_sum = FF::random_element(); // Create a decider proof for the relaxed instance obtained through folding - auto decider_prover = composer.create_decider_prover(prover_accumulator); + DeciderProver decider_prover(prover_accumulator); auto decider_proof = decider_prover.construct_proof(); // Create a decider verifier circuit for recursively verifying the decider proof @@ -332,20 +342,20 @@ template class ProtoGalaxyRecursiveTests : public tes static void test_tampered_accumulator() { // Fold two circuits natively - auto composer = Composer(); - auto [prover_accumulator, verifier_accumulator] = fold_and_verify_native(composer); + auto [prover_accumulator, verifier_accumulator] = fold_and_verify_native(); // Create another circuit to do a second round of folding Builder builder; create_function_circuit(builder); - auto prover_inst = composer.create_prover_instance(builder); - auto verifier_inst = composer.create_verifier_instance(prover_inst); + auto prover_inst = std::make_shared(builder); + auto verification_key = std::make_shared(prover_inst->proving_key); + auto verifier_inst = std::make_shared(verification_key); prover_accumulator->prover_polynomials.w_l[1] = FF::random_element(); // 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 diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp index fd1eddeebe1..44f79b69401 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/verifier.test.cpp @@ -4,7 +4,8 @@ #include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" + +#include "barretenberg/ultra_honk/ultra_prover.hpp" #include "barretenberg/ultra_honk/ultra_verifier.hpp" namespace bb::stdlib::recursion::honk { @@ -16,33 +17,28 @@ namespace bb::stdlib::recursion::honk { * * @tparam Builder */ -template class RecursiveVerifierTest : public testing::Test { +template class HonkRecursiveVerifierTest : public testing::Test { // Define types relevant for testing - using UltraComposer = UltraComposer_; - using GoblinUltraComposer = UltraComposer_; using InnerFlavor = UltraFlavor; - using InnerComposer = UltraComposer; - using InnerBuilder = typename InnerComposer::CircuitBuilder; + using InnerProverInstance = ProverInstance_; + using InnerProver = UltraProver; + using InnerVerifier = UltraVerifier; + using InnerBuilder = typename InnerFlavor::CircuitBuilder; using InnerCurve = bn254; using Commitment = InnerFlavor::Commitment; using FF = InnerFlavor::FF; // Types for recursive verifier circuit - using RecursiveFlavor = UltraRecursiveFlavor_; + using OuterBuilder = typename OuterFlavor::CircuitBuilder; + using RecursiveFlavor = UltraRecursiveFlavor_; using RecursiveVerifier = UltraRecursiveVerifier_; - using OuterBuilder = BuilderType; + using OuterProver = UltraProver_; + using OuterVerifier = UltraVerifier_; + using OuterProverInstance = ProverInstance_; - // Helper for getting composer for prover/verifier of recursive (outer) circuit - template static auto get_outer_composer() - { - if constexpr (IsGoblinBuilder) { - return GoblinUltraComposer(); - } else { - return UltraComposer(); - } - } + using VerificationKey = typename RecursiveVerifier::VerificationKey; /** * @brief Create a non-trivial arbitrary inner circuit, the proof of which will be recursively verified @@ -130,8 +126,8 @@ template class RecursiveVerifierTest : public testing::Te create_inner_circuit(inner_circuit); // Compute native verification key - InnerComposer inner_composer; - auto instance = inner_composer.create_prover_instance(inner_circuit); + auto instance = std::make_shared(inner_circuit); + InnerProver prover(instance); // A prerequisite for computing VK auto verification_key = std::make_shared(instance->proving_key); // Instantiate the recursive verifier using the native verification key RecursiveVerifier verifier{ &outer_circuit, verification_key }; @@ -157,9 +153,8 @@ template class RecursiveVerifierTest : public testing::Te create_inner_circuit(inner_circuit); // Generate a proof over the inner circuit - InnerComposer inner_composer; - auto instance = inner_composer.create_prover_instance(inner_circuit); - auto inner_prover = inner_composer.create_prover(instance); + auto instance = std::make_shared(inner_circuit); + InnerProver inner_prover(instance); auto inner_proof = inner_prover.construct_proof(); auto verification_key = std::make_shared(instance->proving_key); @@ -175,7 +170,7 @@ template class RecursiveVerifierTest : public testing::Te // Check 1: Perform native verification then perform the pairing on the outputs of the recursive // verifier and check that the result agrees. - auto native_verifier = inner_composer.create_verifier(verification_key); + InnerVerifier native_verifier(verification_key); auto native_result = native_verifier.verify_proof(inner_proof); auto recursive_result = native_verifier.key->pcs_verification_key->pairing_check(pairing_points[0].get_value(), pairing_points[1].get_value()); @@ -191,11 +186,10 @@ template class RecursiveVerifierTest : public testing::Te // Check 3: Construct and verify a proof of the recursive verifier circuit { - auto composer = get_outer_composer(); - auto instance = composer.create_prover_instance(outer_circuit); - auto prover = composer.create_prover(instance); - auto verifier_instance = composer.create_verifier_instance(instance); - auto verifier = composer.create_verifier(verifier_instance->verification_key); + auto instance = std::make_shared(outer_circuit); + OuterProver prover(instance); + auto verification_key = std::make_shared(instance->proving_key); + OuterVerifier verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); @@ -216,9 +210,8 @@ template class RecursiveVerifierTest : public testing::Te create_inner_circuit(inner_circuit); // Generate a proof over the inner circuit - InnerComposer inner_composer; - auto instance = inner_composer.create_prover_instance(inner_circuit); - auto inner_prover = inner_composer.create_prover(instance); + auto instance = std::make_shared(inner_circuit); + InnerProver inner_prover(instance); auto inner_proof = inner_prover.construct_proof(); // Arbitrarily tamper with the proof to be verified @@ -240,26 +233,26 @@ template class RecursiveVerifierTest : public testing::Te }; // Run the recursive verifier tests with conventional Ultra builder and Goblin builder -using BuilderTypes = testing::Types; +using Flavors = testing::Types; -TYPED_TEST_SUITE(RecursiveVerifierTest, BuilderTypes); +TYPED_TEST_SUITE(HonkRecursiveVerifierTest, Flavors); -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(); }; diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp index 842152c3a14..008cbd01570 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp @@ -8,7 +8,6 @@ #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/transcript/transcript.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/databus_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/databus_composer.test.cpp index a073c1f1aba..089a6e14572 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/databus_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/databus_composer.test.cpp @@ -7,7 +7,7 @@ #include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "barretenberg/proof_system/instance_inspector.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" + #include "barretenberg/ultra_honk/ultra_prover.hpp" using namespace bb; @@ -81,14 +81,12 @@ TEST_F(DataBusComposerTests, CallDataRead) builder.calldata_read_counts[read_index]++; } - auto composer = GoblinUltraComposer(); - // Construct and verify Honk proof - auto instance = composer.create_prover_instance(builder); + auto instance = std::make_shared>(builder); // For debugging, use "instance_inspector::print_databus_info(instance)" - auto prover = composer.create_prover(instance); + GoblinUltraProver prover(instance); auto verification_key = std::make_shared(instance->proving_key); - auto verifier = composer.create_verifier(verification_key); + GoblinUltraVerifier verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); EXPECT_TRUE(verified); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp index 7ac3a91b378..72ffc358c0e 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp @@ -7,8 +7,8 @@ #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #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" +#include "barretenberg/ultra_honk/ultra_verifier.hpp" using namespace bb; @@ -60,12 +60,12 @@ class GoblinUltraHonkComposerTests : public ::testing::Test { * @brief Construct and a verify a Honk proof * */ - bool construct_and_verify_honk_proof(auto& composer, auto& builder) + bool construct_and_verify_honk_proof(auto& builder) { - auto instance = composer.create_prover_instance(builder); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared>(builder); + GoblinUltraProver prover(instance); auto verification_key = std::make_shared(instance->proving_key); - auto verifier = composer.create_verifier(verification_key); + GoblinUltraVerifier verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); @@ -106,10 +106,8 @@ TEST_F(GoblinUltraHonkComposerTests, SingleCircuit) generate_test_circuit(builder); - auto composer = GoblinUltraComposer(); - // Construct and verify Honk proof - auto honk_verified = construct_and_verify_honk_proof(composer, builder); + bool honk_verified = construct_and_verify_honk_proof(builder); EXPECT_TRUE(honk_verified); // Construct and verify Goblin ECC op queue Merge proof @@ -163,10 +161,8 @@ TEST_F(GoblinUltraHonkComposerTests, MultipleCircuitsHonkOnly) generate_test_circuit(builder); - auto composer = GoblinUltraComposer(); - // Construct and verify Honk proof - auto honk_verified = construct_and_verify_honk_proof(composer, builder); + bool honk_verified = construct_and_verify_honk_proof(builder); EXPECT_TRUE(honk_verified); } } @@ -191,10 +187,8 @@ TEST_F(GoblinUltraHonkComposerTests, MultipleCircuitsHonkAndMerge) generate_test_circuit(builder); - auto composer = GoblinUltraComposer(); - // Construct and verify Honk proof - auto honk_verified = construct_and_verify_honk_proof(composer, builder); + bool honk_verified = construct_and_verify_honk_proof(builder); EXPECT_TRUE(honk_verified); // Construct and verify Goblin ECC op queue Merge proof diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp index 91c5afbb36a..d3a5d4f4424 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp @@ -2,8 +2,11 @@ #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" #include "barretenberg/polynomials/univariate.hpp" +#include "barretenberg/sumcheck/instance/prover_instance.hpp" #include "barretenberg/transcript/transcript.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" +#include "barretenberg/ultra_honk/ultra_prover.hpp" +#include "barretenberg/ultra_honk/ultra_verifier.hpp" + #include using namespace bb; @@ -13,6 +16,7 @@ class GoblinUltraTranscriptTests : public ::testing::Test { static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } using Flavor = GoblinUltraFlavor; + using ProverInstance = ProverInstance_; using FF = Flavor::FF; using VerificationKey = Flavor::VerificationKey; @@ -145,9 +149,8 @@ TEST_F(GoblinUltraTranscriptTests, ProverManifestConsistency) generate_test_circuit(builder); // Automatically generate a transcript manifest by constructing a proof - auto composer = GoblinUltraComposer(); - auto instance = composer.create_prover_instance(builder); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(builder); + GoblinUltraProver prover(instance); auto proof = prover.construct_proof(); // Check that the prover generated manifest agrees with the manifest hard coded in this suite @@ -172,14 +175,13 @@ TEST_F(GoblinUltraTranscriptTests, VerifierManifestConsistency) generate_test_circuit(builder); // Automatically generate a transcript manifest in the prover by constructing a proof - auto composer = GoblinUltraComposer(); - auto instance = composer.create_prover_instance(builder); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(builder); + GoblinUltraProver prover(instance); auto proof = prover.construct_proof(); // Automatically generate a transcript manifest in the verifier by verifying a proof auto verification_key = std::make_shared(instance->proving_key); - auto verifier = composer.create_verifier(verification_key); + GoblinUltraVerifier verifier(verification_key); verifier.verify_proof(proof); // Check consistency between the manifests generated by the prover and verifier @@ -220,16 +222,15 @@ TEST_F(GoblinUltraTranscriptTests, ChallengeGenerationTest) TEST_F(GoblinUltraTranscriptTests, StructureTest) { // Construct a simple circuit of size n = 8 (i.e. the minimum circuit size) - auto builder = typename Flavor::CircuitBuilder(); + Flavor::CircuitBuilder builder; generate_test_circuit(builder); // Automatically generate a transcript manifest by constructing a proof - auto composer = GoblinUltraComposer(); - auto instance = composer.create_prover_instance(builder); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(builder); + GoblinUltraProver prover(instance); auto proof = prover.construct_proof(); auto verification_key = std::make_shared(instance->proving_key); - auto verifier = composer.create_verifier(verification_key); + GoblinUltraVerifier verifier(verification_key); EXPECT_TRUE(verifier.verify_proof(proof)); // try deserializing and serializing with no changes and check proof is still valid diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp index 3c4370edd94..4ae0c8e4a3a 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp @@ -1,7 +1,10 @@ #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/polynomials/pow.hpp" +#include "barretenberg/protogalaxy/decider_prover.hpp" +#include "barretenberg/protogalaxy/decider_verifier.hpp" #include "barretenberg/protogalaxy/protogalaxy_prover.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" +#include "barretenberg/protogalaxy/protogalaxy_verifier.hpp" + #include using namespace bb; @@ -12,7 +15,6 @@ auto& engine = numeric::get_debug_randomness(); template class ProtoGalaxyTests : public testing::Test { public: - using Composer = UltraComposer_; using VerificationKey = typename Flavor::VerificationKey; using ProverInstance = ProverInstance_; using ProverInstances = ProverInstances_; @@ -29,6 +31,10 @@ template class ProtoGalaxyTests : public testing::Test { using WitnessCommitments = typename Flavor::WitnessCommitments; using CommitmentKey = typename Flavor::CommitmentKey; using PowPolynomial = bb::PowPolynomial; + using DeciderProver = DeciderProver_; + using DeciderVerifier = DeciderVerifier_; + using FoldingProver = ProtoGalaxyProver_; + using FoldingVerifier = ProtoGalaxyVerifier_; static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } @@ -63,11 +69,10 @@ template class ProtoGalaxyTests : public testing::Test { static std::tuple, std::shared_ptr> fold_and_verify( const std::vector>& prover_instances, - const std::vector>& verifier_instances, - Composer& composer) + const std::vector>& verifier_instances) { - 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); @@ -93,13 +98,12 @@ template class ProtoGalaxyTests : public testing::Test { static void decide_and_verify(std::shared_ptr& prover_accumulator, std::shared_ptr& verifier_accumulator, - Composer& composer, bool expected_result) { - auto decider_prover = composer.create_decider_prover(prover_accumulator); - auto decider_verifier = composer.create_decider_verifier(verifier_accumulator); - auto decider_proof = decider_prover.construct_proof(); - auto verified = decider_verifier.verify_proof(decider_proof); + DeciderProver decider_prover(prover_accumulator); + DeciderVerifier decider_verifier(verifier_accumulator); + HonkProof decider_proof = decider_prover.construct_proof(); + bool verified = decider_verifier.verify_proof(decider_proof); EXPECT_EQ(verified, expected_result); } @@ -114,8 +118,7 @@ template class ProtoGalaxyTests : public testing::Test { auto builder = typename Flavor::CircuitBuilder(); construct_circuit(builder); - auto composer = Composer(); - auto instance = composer.create_prover_instance(builder); + auto instance = std::make_shared(builder); instance->initialize_prover_polynomials(); auto eta = FF::random_element(); @@ -295,33 +298,35 @@ template class ProtoGalaxyTests : public testing::Test { */ static void test_full_protogalaxy() { - auto composer = Composer(); auto builder_1 = typename Flavor::CircuitBuilder(); construct_circuit(builder_1); - auto prover_instance_1 = composer.create_prover_instance(builder_1); - auto verifier_instance_1 = composer.create_verifier_instance(prover_instance_1); + auto prover_instance_1 = std::make_shared(builder_1); + auto verification_key_1 = std::make_shared(prover_instance_1->proving_key); + auto verifier_instance_1 = std::make_shared(verification_key_1); auto builder_2 = typename Flavor::CircuitBuilder(); construct_circuit(builder_2); - auto prover_instance_2 = composer.create_prover_instance(builder_2); - auto verifier_instance_2 = composer.create_verifier_instance(prover_instance_2); - auto [prover_accumulator, verifier_accumulator] = fold_and_verify( - { prover_instance_1, prover_instance_2 }, { verifier_instance_1, verifier_instance_2 }, composer); + auto prover_instance_2 = std::make_shared(builder_2); + auto verification_key_2 = std::make_shared(prover_instance_2->proving_key); + auto verifier_instance_2 = std::make_shared(verification_key_2); + auto [prover_accumulator, verifier_accumulator] = + fold_and_verify({ prover_instance_1, prover_instance_2 }, { verifier_instance_1, verifier_instance_2 }); check_accumulator_target_sum_manual(prover_accumulator, true); auto builder_3 = typename Flavor::CircuitBuilder(); construct_circuit(builder_3); - auto prover_instance_3 = composer.create_prover_instance(builder_3); - auto verifier_instance_3 = composer.create_verifier_instance(prover_instance_3); + auto prover_instance_3 = std::make_shared(builder_3); + auto verification_key_3 = std::make_shared(prover_instance_3->proving_key); + auto verifier_instance_3 = std::make_shared(verification_key_3); - auto [prover_accumulator_2, verifier_accumulator_2] = fold_and_verify( - { prover_accumulator, prover_instance_3 }, { verifier_accumulator, verifier_instance_3 }, composer); + auto [prover_accumulator_2, verifier_accumulator_2] = + fold_and_verify({ prover_accumulator, prover_instance_3 }, { verifier_accumulator, verifier_instance_3 }); check_accumulator_target_sum_manual(prover_accumulator_2, true); - decide_and_verify(prover_accumulator_2, verifier_accumulator_2, composer, true); + decide_and_verify(prover_accumulator_2, verifier_accumulator_2, true); } /** @@ -330,33 +335,35 @@ template class ProtoGalaxyTests : public testing::Test { */ static void test_tampered_commitment() { - auto composer = Composer(); auto builder_1 = typename Flavor::CircuitBuilder(); construct_circuit(builder_1); - auto prover_instance_1 = composer.create_prover_instance(builder_1); - auto verifier_instance_1 = composer.create_verifier_instance(prover_instance_1); + auto prover_instance_1 = std::make_shared(builder_1); + auto verification_key_1 = std::make_shared(prover_instance_1->proving_key); + auto verifier_instance_1 = std::make_shared(verification_key_1); auto builder_2 = typename Flavor::CircuitBuilder(); construct_circuit(builder_2); - auto prover_instance_2 = composer.create_prover_instance(builder_2); - auto verifier_instance_2 = composer.create_verifier_instance(prover_instance_2); - auto [prover_accumulator, verifier_accumulator] = fold_and_verify( - { prover_instance_1, prover_instance_2 }, { verifier_instance_1, verifier_instance_2 }, composer); + auto prover_instance_2 = std::make_shared(builder_2); + auto verification_key_2 = std::make_shared(prover_instance_2->proving_key); + auto verifier_instance_2 = std::make_shared(verification_key_2); + auto [prover_accumulator, verifier_accumulator] = + fold_and_verify({ prover_instance_1, prover_instance_2 }, { verifier_instance_1, verifier_instance_2 }); check_accumulator_target_sum_manual(prover_accumulator, true); verifier_accumulator->witness_commitments.w_l = Projective(Affine::random_element()); auto builder_3 = typename Flavor::CircuitBuilder(); construct_circuit(builder_3); - auto prover_instance_3 = composer.create_prover_instance(builder_3); - auto verifier_instance_3 = composer.create_verifier_instance(prover_instance_3); + auto prover_instance_3 = std::make_shared(builder_3); + auto verification_key_3 = std::make_shared(prover_instance_3->proving_key); + auto verifier_instance_3 = std::make_shared(verification_key_3); - auto [prover_accumulator_2, verifier_accumulator_2] = fold_and_verify( - { prover_accumulator, prover_instance_3 }, { verifier_accumulator, verifier_instance_3 }, composer); + auto [prover_accumulator_2, verifier_accumulator_2] = + fold_and_verify({ prover_accumulator, prover_instance_3 }, { verifier_accumulator, verifier_instance_3 }); check_accumulator_target_sum_manual(prover_accumulator_2, true); - decide_and_verify(prover_accumulator_2, verifier_accumulator_2, composer, false); + decide_and_verify(prover_accumulator_2, verifier_accumulator_2, false); } /** @@ -366,32 +373,34 @@ template class ProtoGalaxyTests : public testing::Test { */ static void test_tampered_accumulator_polynomial() { - auto composer = Composer(); auto builder_1 = typename Flavor::CircuitBuilder(); construct_circuit(builder_1); - auto prover_instance_1 = composer.create_prover_instance(builder_1); - auto verifier_instance_1 = composer.create_verifier_instance(prover_instance_1); + auto prover_instance_1 = std::make_shared(builder_1); + auto verification_key_1 = std::make_shared(prover_instance_1->proving_key); + auto verifier_instance_1 = std::make_shared(verification_key_1); auto builder_2 = typename Flavor::CircuitBuilder(); construct_circuit(builder_2); - auto prover_instance_2 = composer.create_prover_instance(builder_2); - auto verifier_instance_2 = composer.create_verifier_instance(prover_instance_2); - auto [prover_accumulator, verifier_accumulator] = fold_and_verify( - { prover_instance_1, prover_instance_2 }, { verifier_instance_1, verifier_instance_2 }, composer); + auto prover_instance_2 = std::make_shared(builder_2); + auto verification_key_2 = std::make_shared(prover_instance_2->proving_key); + auto verifier_instance_2 = std::make_shared(verification_key_2); + auto [prover_accumulator, verifier_accumulator] = + fold_and_verify({ prover_instance_1, prover_instance_2 }, { verifier_instance_1, verifier_instance_2 }); check_accumulator_target_sum_manual(prover_accumulator, true); auto builder_3 = typename Flavor::CircuitBuilder(); construct_circuit(builder_3); - auto prover_instance_3 = composer.create_prover_instance(builder_3); - auto verifier_instance_3 = composer.create_verifier_instance(prover_instance_3); + auto prover_instance_3 = std::make_shared(builder_3); + auto verification_key_3 = std::make_shared(prover_instance_3->proving_key); + auto verifier_instance_3 = std::make_shared(verification_key_3); prover_accumulator->prover_polynomials.w_l[1] = FF::random_element(); - auto [prover_accumulator_2, verifier_accumulator_2] = fold_and_verify( - { prover_accumulator, prover_instance_3 }, { verifier_accumulator, verifier_instance_3 }, composer); + auto [prover_accumulator_2, verifier_accumulator_2] = + fold_and_verify({ prover_accumulator, prover_instance_3 }, { verifier_accumulator, verifier_instance_3 }); EXPECT_EQ(prover_accumulator_2->target_sum == verifier_accumulator_2->target_sum, false); - decide_and_verify(prover_accumulator_2, verifier_accumulator_2, composer, false); + decide_and_verify(prover_accumulator_2, verifier_accumulator_2, false); } }; } // namespace diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp index e4e9cfee007..848d5144c0e 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp @@ -1,4 +1,6 @@ #include "barretenberg/flavor/goblin_translator.hpp" +#include "barretenberg/flavor/goblin_ultra.hpp" +#include "barretenberg/flavor/ultra.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/proof_system/library/grand_product_library.hpp" #include "barretenberg/relations/auxiliary_relation.hpp" @@ -9,7 +11,8 @@ #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/relations/ultra_arithmetic_relation.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" +#include "barretenberg/sumcheck/instance/prover_instance.hpp" + #include using namespace bb; @@ -259,8 +262,7 @@ TEST_F(RelationCorrectnessTests, UltraRelationCorrectness) create_some_RAM_gates(builder); // Create a prover (it will compute proving key and witness) - auto composer = UltraComposer(); - auto instance = composer.create_prover_instance(builder); + auto instance = std::make_shared>(builder); auto proving_key = instance->proving_key; auto circuit_size = proving_key->circuit_size; @@ -312,8 +314,7 @@ TEST_F(RelationCorrectnessTests, GoblinUltraRelationCorrectness) create_some_ecc_op_queue_gates(builder); // Goblin! // Create a prover (it will compute proving key and witness) - auto composer = GoblinUltraComposer(); - auto instance = composer.create_prover_instance(builder); + auto instance = std::make_shared>(builder); auto proving_key = instance->proving_key; auto circuit_size = proving_key->circuit_size; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp index 34515508931..69b3285d9d6 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp @@ -10,7 +10,6 @@ #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/transcript/transcript.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" #include @@ -148,8 +147,7 @@ TEST_F(SumcheckTestsRealCircuit, Ultra) false); // Create a prover (it will compute proving key and witness) - auto composer = UltraComposer(); - auto instance = composer.create_prover_instance(builder); + auto instance = std::make_shared>(builder); // Generate eta, beta and gamma FF eta = FF::random_element(); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp deleted file mode 100644 index 506c0d02b81..00000000000 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "barretenberg/ultra_honk/ultra_composer.hpp" -#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" -#include "barretenberg/proof_system/composer/composer_lib.hpp" -#include "barretenberg/proof_system/composer/permutation_lib.hpp" -#include "barretenberg/proof_system/library/grand_product_library.hpp" - -namespace bb { - -template -std::shared_ptr> UltraComposer_::create_prover_instance(CircuitBuilder& circuit) -{ - return std::make_shared(circuit); -} - -template -std::shared_ptr> UltraComposer_::create_verifier_instance( - std::shared_ptr>& prover_instance) -{ - auto verification_key = std::make_shared(prover_instance->proving_key); - auto instance = std::make_shared(verification_key); - return instance; -} - -template -UltraProver_ UltraComposer_::create_prover(const std::shared_ptr& instance, - const std::shared_ptr& transcript) -{ - UltraProver_ output_state(instance, transcript); - - return output_state; -} - -template -UltraVerifier_ UltraComposer_::create_verifier(const std::shared_ptr& verification_key, - const std::shared_ptr& transcript) -{ - return UltraVerifier_(transcript, verification_key); -} - -template -DeciderProver_ UltraComposer_::create_decider_prover(const std::shared_ptr& accumulator, - const std::shared_ptr& transcript) -{ - return DeciderProver_(accumulator, transcript); -} - -template -DeciderVerifier_ UltraComposer_::create_decider_verifier( - const std::shared_ptr& accumulator, const std::shared_ptr& transcript) -{ - return DeciderVerifier_(transcript, accumulator); -} - -template class UltraComposer_; -template class UltraComposer_; -} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp deleted file mode 100644 index b8635ed9ae9..00000000000 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once -#include "barretenberg/flavor/flavor.hpp" -#include "barretenberg/proof_system/composer/composer_lib.hpp" -#include "barretenberg/protogalaxy/decider_prover.hpp" -#include "barretenberg/protogalaxy/decider_verifier.hpp" -#include "barretenberg/protogalaxy/protogalaxy_prover.hpp" -#include "barretenberg/protogalaxy/protogalaxy_verifier.hpp" -#include "barretenberg/srs/global_crs.hpp" -#include "barretenberg/sumcheck/instance/prover_instance.hpp" -#include "barretenberg/ultra_honk/ultra_prover.hpp" -#include "barretenberg/ultra_honk/ultra_verifier.hpp" - -namespace bb { -template class UltraComposer_ { - public: - using Flavor = Flavor_; - using CircuitBuilder = typename Flavor::CircuitBuilder; - using ProvingKey = typename Flavor::ProvingKey; - using VerificationKey = typename Flavor::VerificationKey; - using CommitmentKey = typename Flavor::CommitmentKey; - using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey; - using ProverInstance = ProverInstance_; - using VerifierInstance = VerifierInstance_; - using Transcript = typename Flavor::Transcript; - using ProverInstances = ProverInstances_; - using VerifierInstances = VerifierInstances_; - - std::shared_ptr create_prover_instance(CircuitBuilder&); - - /** - * @brief Create a verifier instance object. - * - * @details Currently use prover instance - */ - std::shared_ptr create_verifier_instance(std::shared_ptr&); - - UltraProver_ create_prover(const std::shared_ptr&, - const std::shared_ptr& transcript = std::make_shared()); - - UltraVerifier_ create_verifier( - const std::shared_ptr&, - const std::shared_ptr& transcript = std::make_shared()); - - DeciderProver_ create_decider_prover( - const std::shared_ptr&, - const std::shared_ptr& transcript = std::make_shared()); - - DeciderVerifier_ create_decider_verifier( - const std::shared_ptr&, - const std::shared_ptr& transcript = std::make_shared()); - - UltraVerifier_ create_ultra_with_keccak_verifier(CircuitBuilder& circuit); - - ProtoGalaxyProver_ create_folding_prover( - const std::vector>& instances) - { - ProtoGalaxyProver_ output_state(instances); - - return output_state; - }; - - ProtoGalaxyVerifier_ create_folding_verifier( - const std::vector>& instances) - { - ProtoGalaxyVerifier_ output_state(instances); - - return output_state; - }; -}; - -// TODO(#532): this pattern is weird; is this not instantiating the templates? -using UltraComposer = UltraComposer_; -using GoblinUltraComposer = UltraComposer_; -} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp index 43fda667d0a..43d1ad26498 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp @@ -1,4 +1,3 @@ -#include "barretenberg/ultra_honk/ultra_composer.hpp" #include "barretenberg/common/serialize.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" @@ -10,11 +9,9 @@ #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/sumcheck/sumcheck_round.hpp" #include "barretenberg/ultra_honk/ultra_prover.hpp" -#include -#include +#include "barretenberg/ultra_honk/ultra_verifier.hpp" + #include -#include -#include using namespace bb; @@ -22,6 +19,7 @@ namespace { auto& engine = numeric::get_debug_randomness(); } +using ProverInstance = ProverInstance_; using VerificationKey = UltraFlavor::VerificationKey; std::vector add_variables(auto& circuit_builder, std::vector variables) @@ -33,12 +31,12 @@ std::vector add_variables(auto& circuit_builder, std::vector v return res; } -void prove_and_verify(auto& circuit_builder, auto& composer, bool expected_result) +void prove_and_verify(auto& circuit_builder, bool expected_result) { - auto instance = composer.create_prover_instance(circuit_builder); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(circuit_builder); + UltraProver prover(instance); auto verification_key = std::make_shared(instance->proving_key); - auto verifier = composer.create_verifier(verification_key); + UltraVerifier verifier(verification_key); auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); EXPECT_EQ(verified, expected_result); @@ -69,9 +67,8 @@ TEST_F(UltraHonkComposerTests, ANonZeroPolynomialIsAGoodPolynomial) { auto circuit_builder = UltraCircuitBuilder(); - auto composer = UltraComposer(); - auto instance = composer.create_prover_instance(circuit_builder); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(circuit_builder); + UltraProver prover(instance); auto proof = prover.construct_proof(); auto proving_key = instance->proving_key; @@ -112,8 +109,7 @@ TEST_F(UltraHonkComposerTests, PublicInputs) builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx, fr(1), fr(1), fr(1), fr(-1), fr(0) }); } - auto composer = UltraComposer(); - prove_and_verify(builder, composer, /*expected_result=*/true); + prove_and_verify(builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, XorConstraint) @@ -140,8 +136,7 @@ TEST_F(UltraHonkComposerTests, XorConstraint) circuit_builder.create_gates_from_plookup_accumulators( plookup::MultiTableId::UINT32_XOR, lookup_accumulators, left_witness_index, right_witness_index); - UltraComposer composer; - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, create_gates_from_plookup_accumulators) @@ -200,11 +195,10 @@ TEST_F(UltraHonkComposerTests, create_gates_from_plookup_accumulators) expected_scalar >>= table_bits; } } - auto composer = UltraComposer(); - auto instance = composer.create_prover_instance(circuit_builder); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(circuit_builder); + UltraProver prover(instance); auto verification_key = std::make_shared(instance->proving_key); - auto verifier = composer.create_verifier(verification_key); + UltraVerifier verifier(verification_key); auto proof = prover.construct_proof(); bool result = verifier.verify_proof(proof); @@ -231,8 +225,7 @@ TEST_F(UltraHonkComposerTests, test_no_lookup_proof) } } - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, test_elliptic_gate) @@ -265,8 +258,7 @@ TEST_F(UltraHonkComposerTests, test_elliptic_gate) y3 = circuit_builder.add_variable(p3.y); circuit_builder.create_ecc_add_gate({ x1, y1, x2, y2, x3, y3, -1 }); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, non_trivial_tag_permutation) @@ -293,8 +285,7 @@ TEST_F(UltraHonkComposerTests, non_trivial_tag_permutation) circuit_builder.assign_tag(c_idx, 2); circuit_builder.assign_tag(d_idx, 2); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, non_trivial_tag_permutation_and_cycles) @@ -331,8 +322,7 @@ TEST_F(UltraHonkComposerTests, non_trivial_tag_permutation_and_cycles) circuit_builder.create_add_gate( { e_idx, f_idx, circuit_builder.zero_idx, fr::one(), -fr::one(), fr::zero(), fr::zero() }); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, bad_tag_permutation) @@ -358,8 +348,7 @@ TEST_F(UltraHonkComposerTests, bad_tag_permutation) circuit_builder.assign_tag(c_idx, 2); circuit_builder.assign_tag(d_idx, 2); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/false); + prove_and_verify(circuit_builder, /*expected_result=*/false); } // Same as above but without tag creation to check reason of failure is really tag mismatch { @@ -375,9 +364,7 @@ TEST_F(UltraHonkComposerTests, bad_tag_permutation) circuit_builder.create_add_gate({ a_idx, b_idx, circuit_builder.zero_idx, 1, 1, 0, 0 }); circuit_builder.create_add_gate({ c_idx, d_idx, circuit_builder.zero_idx, 1, 1, 0, -1 }); - auto composer = UltraComposer(); - - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } } @@ -395,8 +382,7 @@ TEST_F(UltraHonkComposerTests, sort_widget) auto d_idx = circuit_builder.add_variable(d); circuit_builder.create_sort_constraint({ a_idx, b_idx, c_idx, d_idx }); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, sort_with_edges_gate) @@ -423,8 +409,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) circuit_builder.create_sort_constraint_with_edges( { a_idx, b_idx, c_idx, d_idx, e_idx, f_idx, g_idx, h_idx }, a, h); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } { @@ -440,8 +425,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) circuit_builder.create_sort_constraint_with_edges( { a_idx, b_idx, c_idx, d_idx, e_idx, f_idx, g_idx, h_idx }, a, g); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/false); + prove_and_verify(circuit_builder, /*expected_result=*/false); } { auto circuit_builder = UltraCircuitBuilder(); @@ -456,8 +440,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) circuit_builder.create_sort_constraint_with_edges( { a_idx, b_idx, c_idx, d_idx, e_idx, f_idx, g_idx, h_idx }, b, h); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/false); + prove_and_verify(circuit_builder, /*expected_result=*/false); } { auto circuit_builder = UltraCircuitBuilder(); @@ -472,8 +455,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) circuit_builder.create_sort_constraint_with_edges( { a_idx, b2_idx, c_idx, d_idx, e_idx, f_idx, g_idx, h_idx }, b, h); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/false); + prove_and_verify(circuit_builder, /*expected_result=*/false); } { auto circuit_builder = UltraCircuitBuilder(); @@ -481,8 +463,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) 26, 29, 29, 32, 32, 33, 35, 38, 39, 39, 42, 42, 43, 45 }); circuit_builder.create_sort_constraint_with_edges(idx, 1, 45); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } { auto circuit_builder = UltraCircuitBuilder(); @@ -490,8 +471,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) 26, 29, 29, 32, 32, 33, 35, 38, 39, 39, 42, 42, 43, 45 }); circuit_builder.create_sort_constraint_with_edges(idx, 1, 29); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/false); + prove_and_verify(circuit_builder, /*expected_result=*/false); } } @@ -506,8 +486,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) // auto ind = {a_idx,b_idx,c_idx,d_idx,e_idx,f_idx,g_idx,h_idx}; circuit_builder.create_sort_constraint(indices); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } { auto circuit_builder = UltraCircuitBuilder(); @@ -518,8 +497,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) // auto ind = {a_idx,b_idx,c_idx,d_idx,e_idx,f_idx,g_idx,h_idx}; circuit_builder.create_dummy_constraints(indices); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } { auto circuit_builder = UltraCircuitBuilder(); @@ -529,8 +507,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) } circuit_builder.create_sort_constraint(indices); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/false); + prove_and_verify(circuit_builder, /*expected_result=*/false); } { auto circuit_builder = UltraCircuitBuilder(); @@ -541,8 +518,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) } circuit_builder.create_dummy_constraints(indices); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } { auto circuit_builder = UltraCircuitBuilder(); @@ -553,8 +529,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) } circuit_builder.create_dummy_constraints(indices); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/false); + prove_and_verify(circuit_builder, /*expected_result=*/false); } { auto circuit_builder = UltraCircuitBuilder(); @@ -565,8 +540,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) } circuit_builder.create_dummy_constraints(indices); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/false); + prove_and_verify(circuit_builder, /*expected_result=*/false); } } @@ -585,8 +559,7 @@ TEST_F(UltraHonkComposerTests, range_with_gates) circuit_builder.create_add_gate( { idx[6], idx[7], circuit_builder.zero_idx, fr::one(), fr::one(), fr::zero(), -15 }); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, range_with_gates_where_range_is_not_a_power_of_two) @@ -604,8 +577,7 @@ TEST_F(UltraHonkComposerTests, range_with_gates_where_range_is_not_a_power_of_tw circuit_builder.create_add_gate( { idx[6], idx[7], circuit_builder.zero_idx, fr::one(), fr::one(), fr::zero(), -15 }); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, sort_widget_complex) @@ -619,8 +591,7 @@ TEST_F(UltraHonkComposerTests, sort_widget_complex) ind.emplace_back(circuit_builder.add_variable(a[i])); circuit_builder.create_sort_constraint(ind); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } { @@ -631,8 +602,7 @@ TEST_F(UltraHonkComposerTests, sort_widget_complex) ind.emplace_back(circuit_builder.add_variable(a[i])); circuit_builder.create_sort_constraint(ind); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/false); + prove_and_verify(circuit_builder, /*expected_result=*/false); } } @@ -650,8 +620,7 @@ TEST_F(UltraHonkComposerTests, sort_widget_neg) auto d_idx = circuit_builder.add_variable(d); circuit_builder.create_sort_constraint({ a_idx, b_idx, c_idx, d_idx }); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/false); + prove_and_verify(circuit_builder, /*expected_result=*/false); } TEST_F(UltraHonkComposerTests, composed_range_constraint) @@ -664,8 +633,7 @@ TEST_F(UltraHonkComposerTests, composed_range_constraint) circuit_builder.create_add_gate({ a_idx, circuit_builder.zero_idx, circuit_builder.zero_idx, 1, 0, 0, -fr(e) }); circuit_builder.decompose_into_default_range(a_idx, 134); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, non_native_field_multiplication) @@ -721,8 +689,7 @@ TEST_F(UltraHonkComposerTests, non_native_field_multiplication) const auto [lo_1_idx, hi_1_idx] = circuit_builder.evaluate_non_native_field_multiplication(inputs); circuit_builder.range_constrain_two_limbs(lo_1_idx, hi_1_idx, 70, 70); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, rom) @@ -763,8 +730,7 @@ TEST_F(UltraHonkComposerTests, rom) 0, }); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, ram) @@ -827,8 +793,7 @@ TEST_F(UltraHonkComposerTests, ram) }, false); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } TEST_F(UltraHonkComposerTests, range_checks_on_duplicates) @@ -863,8 +828,7 @@ TEST_F(UltraHonkComposerTests, range_checks_on_duplicates) }, false); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); + prove_and_verify(circuit_builder, /*expected_result=*/true); } // Ensure copy constraints added on variables smaller than 2^14, which have been previously @@ -887,6 +851,5 @@ TEST_F(UltraHonkComposerTests, range_constraint_small_variable) circuit_builder.create_range_constraint(c_idx, 8, "bad range"); circuit_builder.assert_equal(a_idx, c_idx); - auto composer = UltraComposer(); - prove_and_verify(circuit_builder, composer, /*expected_result=*/true); -} \ No newline at end of file + prove_and_verify(circuit_builder, /*expected_result=*/true); +} diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp index c4f62204066..7d4325054ee 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp @@ -19,6 +19,22 @@ UltraProver_::UltraProver_(const std::shared_ptr& inst, const instance->initialize_prover_polynomials(); } +/** + * Create UltraProver_ from a circuit. + * + * @param instance Circuit with witnesses whose validity we'd like to prove. + * + * @tparam a type of UltraFlavor + * */ +template +UltraProver_::UltraProver_(Builder& circuit) + : instance(std::make_shared(circuit)) + , transcript(std::make_shared()) + , commitment_key(instance->proving_key->commitment_key) +{ + instance->initialize_prover_polynomials(); +} + /** * @brief Add circuit size, public input size, and public inputs to transcript * diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp index 356f163983b..dd822986f11 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp @@ -10,22 +10,27 @@ namespace bb { -template class UltraProver_ { +template class UltraProver_ { + public: + using Flavor = Flavor_; using FF = typename Flavor::FF; + using Builder = typename Flavor::CircuitBuilder; using Commitment = typename Flavor::Commitment; using CommitmentKey = typename Flavor::CommitmentKey; using Polynomial = typename Flavor::Polynomial; using ProverPolynomials = typename Flavor::ProverPolynomials; using CommitmentLabels = typename Flavor::CommitmentLabels; using Curve = typename Flavor::Curve; - using Instance = ProverInstance_; + using ProverInstance = ProverInstance_; + using Instance = ProverInstance; using Transcript = typename Flavor::Transcript; using RelationSeparator = typename Flavor::RelationSeparator; - public: explicit UltraProver_(const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); + explicit UltraProver_(Builder&); + BB_PROFILE void execute_preamble_round(); BB_PROFILE void execute_wire_commitments_round(); BB_PROFILE void execute_sorted_list_accumulator_round(); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp index 14afc28f05b..723cbeaf30b 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp @@ -1,9 +1,13 @@ #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/flavor/flavor.hpp" +#include "barretenberg/flavor/ultra.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" #include "barretenberg/polynomials/univariate.hpp" +#include "barretenberg/sumcheck/instance/prover_instance.hpp" #include "barretenberg/transcript/transcript.hpp" -#include "barretenberg/ultra_honk/ultra_composer.hpp" +#include "barretenberg/ultra_honk/ultra_prover.hpp" +#include "barretenberg/ultra_honk/ultra_verifier.hpp" + #include using namespace bb; @@ -15,6 +19,7 @@ class UltraTranscriptTests : public ::testing::Test { using Flavor = UltraFlavor; using VerificationKey = Flavor::VerificationKey; using FF = Flavor::FF; + using ProverInstance = ProverInstance_; /** * @brief Construct a manifest for a Ultra Honk proof @@ -131,9 +136,8 @@ TEST_F(UltraTranscriptTests, ProverManifestConsistency) generate_test_circuit(builder); // Automatically generate a transcript manifest by constructing a proof - auto composer = UltraComposer(); - auto instance = composer.create_prover_instance(builder); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(builder); + UltraProver prover(instance); auto proof = prover.construct_proof(); // Check that the prover generated manifest agrees with the manifest hard coded in this suite @@ -158,14 +162,13 @@ TEST_F(UltraTranscriptTests, VerifierManifestConsistency) generate_test_circuit(builder); // Automatically generate a transcript manifest in the prover by constructing a proof - auto composer = UltraComposer(); - auto instance = composer.create_prover_instance(builder); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(builder); + UltraProver prover(instance); auto proof = prover.construct_proof(); // Automatically generate a transcript manifest in the verifier by verifying a proof auto verification_key = std::make_shared(instance->proving_key); - auto verifier = composer.create_verifier(verification_key); + UltraVerifier verifier(verification_key); verifier.verify_proof(proof); // Check consistency between the manifests generated by the prover and verifier @@ -210,12 +213,11 @@ TEST_F(UltraTranscriptTests, StructureTest) generate_test_circuit(builder); // Automatically generate a transcript manifest by constructing a proof - auto composer = UltraComposer(); - auto instance = composer.create_prover_instance(builder); - auto prover = composer.create_prover(instance); + auto instance = std::make_shared(builder); + UltraProver prover(instance); auto proof = prover.construct_proof(); auto verification_key = std::make_shared(instance->proving_key); - auto verifier = composer.create_verifier(verification_key); + UltraVerifier verifier(verification_key); EXPECT_TRUE(verifier.verify_proof(proof)); // try deserializing and serializing with no changes and check proof is still valid