Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Feb 20, 2024
1 parent ffaddfc commit f69db72
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,26 @@ class IvcBench : public benchmark::Fixture {
*/
static void perform_ivc_accumulation_rounds(State& state, ClientIVC& ivc)
{
// Initialize IVC with function circuit
// Initialize IVC with a function circuit
Builder initial_function_circuit{ ivc.goblin.op_queue };
GoblinMockCircuits::construct_mock_function_circuit(initial_function_circuit);
ivc.initialize(initial_function_circuit);
auto kernel_verifeir_accumulator = std::make_shared<ClientIVC::VerifierInstance>();
kernel_verifeir_accumulator->verification_key = ivc.vks[0];

// Accumulate another function circuit
Builder function_circuit{ ivc.goblin.op_queue };
GoblinMockCircuits::construct_mock_function_circuit(function_circuit);
auto function_fold_proof = ivc.accumulate(function_circuit);
FoldOutput function_fold_output = { function_fold_proof, ivc.vks[1] };

// Create and accumulate the first folding kernel which only verifies the accumulation of a function circuit
Builder kernel_circuit{ ivc.goblin.op_queue };
kernel_verifeir_accumulator = GoblinMockCircuits::construct_mock_folding_kernel(
kernel_circuit, function_fold_output, {}, kernel_verifeir_accumulator);
auto kernel_fold_proof = ivc.accumulate(kernel_circuit);
FoldOutput kernel_fold_output = { kernel_fold_proof, ivc.vks[2] };

auto NUM_CIRCUITS = static_cast<size_t>(state.range(0));
// Subtract one to account for the "initialization" round above
NUM_CIRCUITS -= 1;
Expand All @@ -71,7 +74,8 @@ class IvcBench : public benchmark::Fixture {
auto function_fold_proof = ivc.accumulate(function_circuit);
function_fold_output = { function_fold_proof, ivc.vks[1] };

// Accumulate kernel circuit
// Create kernel circuit containing the recursive folding verification of a function circuit and a kernel
// circuit and accumulate it
Builder kernel_circuit{ ivc.goblin.op_queue };
kernel_verifeir_accumulator = GoblinMockCircuits::construct_mock_folding_kernel(
kernel_circuit, function_fold_output, kernel_fold_output, kernel_verifeir_accumulator);
Expand Down
8 changes: 3 additions & 5 deletions barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class ClientIVC {
using FoldProof = std::vector<FF>;
using ProverAccumulator = std::shared_ptr<ProverInstance_<Flavor>>;
using VerifierAccumulator = std::shared_ptr<VerifierInstance_<Flavor>>;
using VerifierInstance = VerifierInstance_<GoblinUltraFlavor>;
using ProverInstance = ProverInstance_<GoblinUltraFlavor>;
using ClientCircuit = GoblinUltraCircuitBuilder; // can only be GoblinUltra

Expand All @@ -35,16 +34,15 @@ class ClientIVC {
private:
using ProverFoldOutput = FoldingResult<GoblinUltraFlavor>;
using Composer = GoblinUltraComposer;
// 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
std::shared_ptr<ProverInstance> prover_instance;

public:
Goblin goblin;
ProverFoldOutput prover_fold_output;
ProverAccumulator prover_accumulator;

// 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
std::shared_ptr<ProverInstance> prover_instance;

std::array<std::shared_ptr<VerificationKey>, 4> vks;

ClientIVC();
Expand Down
6 changes: 5 additions & 1 deletion barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class GoblinMockCircuits {
using VerificationKey = Flavor::VerificationKey;
static constexpr size_t NUM_OP_QUEUE_COLUMNS = Flavor::NUM_WIRES;

/**
* @brief
*
*/
struct FoldOutput {
std::vector<FF> fold_proof;
std::shared_ptr<VerificationKey> inst_vk;
Expand Down Expand Up @@ -242,7 +246,7 @@ class GoblinMockCircuits {
stdlib::generate_ecdsa_verification_test_circuit(builder, NUM_ECDSA_VERIFICATIONS);
stdlib::generate_sha256_test_circuit(builder, NUM_SHA_HASHES);

// Init
// Initial kernel iteration does not have a previous kernel to fold
if (kernel.fold_proof.empty()) {
FoldingRecursiveVerifier verifier_1{ &builder, prev_kernel_accum, { func.inst_vk } };
auto fctn_verifier_accum = verifier_1.verify_folding_proof(func.fold_proof);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ template <class ProverInstances> void ProtoGalaxyProver_<ProverInstances>::pertu
FF delta = transcript->template get_challenge<FF>("delta");
state.deltas = compute_round_challenge_pows(state.accumulator->log_instance_size, delta);
state.perturbator = compute_perturbator(state.accumulator, state.deltas);

// Prover doesn't send the constant coefficient of F because this is supposed to be equal to the target sum of the
// accumulator which the folding verifier has from the previous iteration.
for (size_t idx = 1; idx <= state.accumulator->log_instance_size; idx++) {
transcript->send_to_verifier("perturbator_" + std::to_string(idx), state.perturbator[idx]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ template <class ProverInstances_> class ProtoGalaxyProver_ {

ProverInstances instances;
std::shared_ptr<Transcript> transcript = std::make_shared<Transcript>();
ProtogalaxyProofConstructionState<ProverInstances> state;
std::shared_ptr<CommitmentKey> commitment_key;
ProtogalaxyProofConstructionState<ProverInstances> state;

ProtoGalaxyProver_() = default;
ProtoGalaxyProver_(const std::vector<std::shared_ptr<Instance>>& insts,
Expand Down Expand Up @@ -457,9 +457,28 @@ template <class ProverInstances_> class ProtoGalaxyProver_ {
FF& challenge,
const FF& compressed_perturbator);

/**
* @brief
*
*/
void preparation_round();

/**
* @brief
*
*/
void perturbator_round();

/**
* @brief
*
*/
void combiner_quotient_round();

/**
* @brief
*
*/
void accumulator_update_round();
};
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ std::array<typename Flavor::GroupElement, 2> DeciderRecursiveVerifier_<Flavor>::
return pairing_points;
}

// template class DeciderRecursiveVerifier_<bb::UltraRecursiveFlavor_<GoblinUltraCircuitBuilder>>;
template class DeciderRecursiveVerifier_<bb::UltraRecursiveFlavor_<UltraCircuitBuilder>>;
template class DeciderRecursiveVerifier_<bb::GoblinUltraRecursiveFlavor_<GoblinUltraCircuitBuilder>>;
} // namespace bb::stdlib::recursion::honk
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ std::shared_ptr<typename VerifierInstances::Instance> ProtoGalaxyRecursiveVerifi
return next_accumulator;
}

// template class ProtoGalaxyRecursiveVerifier_<VerifierInstances_<UltraRecursiveFlavor_<GoblinUltraCircuitBuilder>,
// 2>>;
template class ProtoGalaxyRecursiveVerifier_<
RecursiveVerifierInstances_<UltraRecursiveFlavor_<UltraCircuitBuilder>, 2>>;
template class ProtoGalaxyRecursiveVerifier_<
RecursiveVerifierInstances_<GoblinUltraRecursiveFlavor_<GoblinUltraCircuitBuilder>, 2>>;
} // namespace bb::stdlib::recursion::honk
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
static void test_new_evaluate()
{
Builder builder;
using fr_ct = bn254<Builder>::ScalarField;
using fr = bn254<Builder>::ScalarFieldNative;
using fr_ct = typename bn254<Builder>::ScalarField;
using fr = typename bn254<Builder>::ScalarFieldNative;

std::vector<fr> coeffs;
std::vector<fr_ct> coeffs_ct;
Expand Down Expand Up @@ -349,7 +349,8 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
};
};

using FlavorTypes = testing::Types<GoblinUltraRecursiveFlavor_<GoblinUltraCircuitBuilder>>;
using FlavorTypes =
testing::Types<GoblinUltraRecursiveFlavor_<GoblinUltraCircuitBuilder>, UltraRecursiveFlavor_<UltraCircuitBuilder>>;
TYPED_TEST_SUITE(ProtoGalaxyRecursiveTests, FlavorTypes);

TYPED_TEST(ProtoGalaxyRecursiveTests, InnerCircuit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "barretenberg/sumcheck/instance/verifier_instance.hpp"

namespace bb::stdlib::recursion::honk {

/**
* @brief The stdlib counterpart of VerifierInstance, used in recursive folding verification
*/
template <IsRecursiveFlavor Flavor> class RecursiveVerifierInstance_ {
public:
using FF = typename Flavor::FF;
Expand Down Expand Up @@ -92,6 +96,13 @@ template <IsRecursiveFlavor Flavor> class RecursiveVerifierInstance_ {
FF::from_witness(builder, instance->relation_parameters.lookup_grand_product_delta);
}

/**
* @brief Return the underlying native VerifierInstance.
*
* @details In the context of client IVC, we will have several iterations of recursive folding verification. The
* RecursiveVerifierInstance is tied to the builder in whose context it was created so in order to preserve the
* accumulator values between several iterations we need to retrieve the native VerifierInstance values.
*/
VerifierInstance get_value()
{
VerifierInstance inst;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace bb {
* required by an Ultra Goblin Honk prover to create a proof. A ProverInstance is also the result of running the
* Protogalaxy prover, in which case it becomes a relaxed counterpart with the folding parameters (target sum and gate
* challenges set to non-zero values).
*
* @details This is the equivalent of ω in the paper.
*/

template <class Flavor> class ProverInstance_ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace bb {
/**
* @brief
* @brief The VerifierInstance encapsulates all the necessary information for a Goblin Ultra Honk Verifier to verify a
* proof (sumcheck + Zeromorph). In the context of folding, this is returned by the Protogalaxy verifier with non-zero
* target sum and gate challenges.
*
* @tparam Flavor
* @details This is ϕ in the paper.
*/
template <class Flavor> class VerifierInstance_ {
public:
Expand Down

0 comments on commit f69db72

Please sign in to comment.