diff --git a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.cpp b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.cpp index a0414baa0f7a..d18d18131e74 100644 --- a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.cpp @@ -60,7 +60,13 @@ void AztecIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr(circuit)); // Construct the prover instance for circuit - auto prover_instance = std::make_shared(circuit, trace_structure); + std::shared_ptr prover_instance; + if (!initialized) { + prover_instance = std::make_shared(circuit, trace_structure); + } else { + prover_instance = std::make_shared( + circuit, trace_structure, fold_output.accumulator->proving_key.commitment_key); + } // Set the instance verification key from precomputed if available, else compute it instance_vk = precomputed_vk ? precomputed_vk : std::make_shared(prover_instance->proving_key); diff --git a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp index 6387ad2c99b1..237d8b6b7e77 100644 --- a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp @@ -132,6 +132,24 @@ TEST_F(AztecIVCTests, Basic) EXPECT_TRUE(ivc.prove_and_verify()); }; +/** + * @brief A simple test demonstrating IVC for four mock circuits, which is slightly more than minimal. + * @details When accumulating only four circuits, we execute all the functionality of a full AztecIVC run. + * + */ +TEST_F(AztecIVCTests, BasicFour) +{ + AztecIVC ivc; + + MockCircuitProducer circuit_producer; + for (size_t idx = 0; idx < 4; ++idx) { + Builder circuit = circuit_producer.create_next_circuit(ivc); + ivc.accumulate(circuit); + } + + EXPECT_TRUE(ivc.prove_and_verify()); +}; + /** * @brief Check that the IVC fails to verify if an intermediate fold proof is invalid * @details When accumulating 4 circuits, there are 3 fold proofs to verify (the first two are recursively verfied and diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 3ad94098b4dc..6d93871660b4 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -37,7 +37,13 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr(circuit)); // Construct the prover instance for circuit - auto prover_instance = std::make_shared(circuit, trace_structure); + std::shared_ptr prover_instance; + if (!initialized) { + prover_instance = std::make_shared(circuit, trace_structure); + } else { + prover_instance = std::make_shared( + circuit, trace_structure, fold_output.accumulator->proving_key.commitment_key); + } // Track the maximum size of each block for all circuits porcessed (for debugging purposes only) max_block_size_tracker.update(circuit); diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp index 53b9c372805c..3051b1bf4338 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp @@ -66,7 +66,6 @@ class ClientIVC { public: GoblinProver goblin; ProverFoldOutput fold_output; - std::shared_ptr prover_accumulator; std::shared_ptr verifier_accumulator; std::shared_ptr instance_vk; 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 6444e2630d28..57cf69978372 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -90,7 +90,7 @@ TEST_F(ClientIVCTests, Basic) }; /** - * @brief A simple-as-possible test demonstrating IVC for three mock circuits + * @brief A simple test demonstrating IVC for three mock circuits which does more logic than just two circuits. * */ TEST_F(ClientIVCTests, BasicThree) diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index a0e6b43e6c41..69a3a9dabb46 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -124,11 +124,16 @@ template class ProvingKey_ { std::vector public_inputs; ProvingKey_() = default; - ProvingKey_(const size_t circuit_size, const size_t num_public_inputs) + ProvingKey_(const size_t circuit_size, + const size_t num_public_inputs, + std::shared_ptr commitment_key = nullptr) { - { + if (commitment_key == nullptr) { ZoneScopedN("init commitment key"); this->commitment_key = std::make_shared(circuit_size + 1); + } else { + // Don't create another commitment key if we already have one + this->commitment_key = commitment_key; } this->evaluation_domain = bb::EvaluationDomain(circuit_size, circuit_size); this->circuit_size = circuit_size; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 4e2e48fe9834..071bd50c6758 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -412,12 +412,13 @@ class MegaFlavor { */ class ProvingKey : public ProvingKey_ { public: - // Expose constructors on the base class using Base = ProvingKey_; - using Base::Base; - ProvingKey(const size_t circuit_size, const size_t num_public_inputs) - : Base(circuit_size, num_public_inputs) + ProvingKey() = default; + ProvingKey(const size_t circuit_size, + const size_t num_public_inputs, + std::shared_ptr commitment_key = nullptr) + : Base(circuit_size, num_public_inputs, commitment_key) , polynomials(circuit_size){}; std::vector memory_read_records; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index b2a4afa86b04..1acd95d33194 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -331,12 +331,13 @@ class UltraFlavor { */ class ProvingKey : public ProvingKey_ { public: - // Expose constructors on the base class using Base = ProvingKey_; - using Base::Base; - ProvingKey(const size_t circuit_size, const size_t num_public_inputs) - : Base(circuit_size, num_public_inputs) + ProvingKey() = default; + ProvingKey(const size_t circuit_size, + const size_t num_public_inputs, + std::shared_ptr commitment_key = nullptr) + : Base(circuit_size, num_public_inputs, std::move(commitment_key)) , polynomials(circuit_size){}; std::vector memory_read_records; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp index b9bbfa35c2f3..91f9017893cd 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp @@ -278,12 +278,13 @@ class UltraKeccakFlavor { */ class ProvingKey : public ProvingKey_ { public: - // Expose constructors on the base class using Base = ProvingKey_; - using Base::Base; - ProvingKey(const size_t circuit_size, const size_t num_public_inputs) - : Base(circuit_size, num_public_inputs) + ProvingKey() = default; + ProvingKey(const size_t circuit_size, + const size_t num_public_inputs, + std::shared_ptr commitment_key = nullptr) + : Base(circuit_size, num_public_inputs, commitment_key) , polynomials(circuit_size){}; std::vector memory_read_records; diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index 269dabe3bbfa..5aa275facb78 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -44,11 +44,14 @@ template class ProverInstance_ { std::vector gate_challenges; FF target_sum; - ProverInstance_(Circuit& circuit, TraceStructure trace_structure = TraceStructure::NONE) + ProverInstance_(Circuit& circuit, + TraceStructure trace_structure = TraceStructure::NONE, + std::shared_ptr commitment_key = nullptr) { BB_OP_COUNT_TIME_NAME("ProverInstance(Circuit&)"); circuit.add_gates_to_ensure_all_polys_are_non_zero(); circuit.finalize_circuit(); + info("finalized gate count: ", circuit.num_gates); // Set flag indicating whether the polynomials will be constructed with fixed block sizes for each gate type const bool is_structured = (trace_structure != TraceStructure::NONE); @@ -70,7 +73,7 @@ template class ProverInstance_ { } { ZoneScopedN("constructing proving key"); - proving_key = ProvingKey(dyadic_circuit_size, circuit.public_inputs.size()); + proving_key = ProvingKey(dyadic_circuit_size, circuit.public_inputs.size(), commitment_key); } // Construct and add to proving key the wire, selector and copy constraint polynomials