Skip to content

Commit

Permalink
typos + make gcc pass
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Feb 20, 2024
1 parent 5a75ea3 commit 28c79aa
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace {
class IvcBench : public benchmark::Fixture {
public:
using Builder = GoblinUltraCircuitBuilder;
using FoldOutput = GoblinMockCircuits::FoldOutput;
using VerifierFoldData = GoblinMockCircuits::VerifierFoldData;

// Number of function circuits to accumulate(based on Zacs target numbers)
static constexpr size_t NUM_ITERATIONS_MEDIUM_COMPLEXITY = 6;
Expand All @@ -48,21 +48,21 @@ class IvcBench : public benchmark::Fixture {
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.first_func_vk;
auto kernel_verifier_accumulator = std::make_shared<ClientIVC::VerifierInstance>();
kernel_verifier_accumulator->verification_key = ivc.vks.first_func_vk;

// 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.func_vk };
VerifierFoldData function_fold_output = { function_fold_proof, ivc.vks.func_vk };

// 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);
kernel_verifier_accumulator = GoblinMockCircuits::construct_mock_folding_kernel(
kernel_circuit, function_fold_output, {}, kernel_verifier_accumulator);
auto kernel_fold_proof = ivc.accumulate(kernel_circuit);
FoldOutput kernel_fold_output = { kernel_fold_proof, ivc.vks.first_kernel_vk };
VerifierFoldData kernel_fold_output = { kernel_fold_proof, ivc.vks.first_kernel_vk };

auto NUM_CIRCUITS = static_cast<size_t>(state.range(0));
// Subtract one to account for the "initialization" round above
Expand All @@ -77,8 +77,8 @@ class IvcBench : public benchmark::Fixture {
// 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);
kernel_verifier_accumulator = GoblinMockCircuits::construct_mock_folding_kernel(
kernel_circuit, function_fold_output, kernel_fold_output, kernel_verifier_accumulator);

kernel_fold_proof = ivc.accumulate(kernel_circuit);
kernel_fold_output = { kernel_fold_proof, ivc.vks.kernel_vk };
Expand Down
15 changes: 8 additions & 7 deletions barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ClientIVCTests : public ::testing::Test {
using VerifierAccumulator = ClientIVC::VerifierAccumulator;
using VerifierInstance = ClientIVC::VerifierInstance;
using FoldProof = ClientIVC::FoldProof;
using FoldOutput = GoblinMockCircuits::FoldOutput;
using VerifierFoldData = GoblinMockCircuits::VerifierFoldData;
using GURecursiveFlavor = GoblinUltraRecursiveFlavor_<Builder>;
using RecursiveVerifierInstance = ::bb::stdlib::recursion::honk::RecursiveVerifierInstance_<GURecursiveFlavor>;
using RecursiveVerifierAccumulator = std::shared_ptr<RecursiveVerifierInstance>;
Expand Down Expand Up @@ -55,8 +55,8 @@ class ClientIVCTests : public ::testing::Test {
* @param kernel_fold_proof
*/
static VerifierAccumulator construct_mock_folding_kernel(Builder& builder,
FoldOutput& func_accum,
FoldOutput& kernel_accum,
VerifierFoldData& func_accum,
VerifierFoldData& kernel_accum,
VerifierAccumulator& prev_kernel_accum)
{

Expand Down Expand Up @@ -90,25 +90,26 @@ TEST_F(ClientIVCTests, Full)
FoldProof kernel_fold_proof = ivc.accumulate(kernel_circuit);
auto function_vk_2 = composer.compute_verification_key(ivc.prover_instance);
auto kernel_vk = function_vk_2;
FoldOutput kernel_fold_output = { kernel_fold_proof, function_vk_2 };
VerifierFoldData kernel_fold_output = { kernel_fold_proof, function_vk_2 };
size_t NUM_CIRCUITS = 1;
for (size_t circuit_idx = 0; circuit_idx < NUM_CIRCUITS; ++circuit_idx) {
// Accumulate function circuit
Builder function_circuit = create_mock_circuit(ivc);
FoldProof function_fold_proof = ivc.accumulate(function_circuit);
FoldOutput function_fold_output = { function_fold_proof, function_vk_2 };
VerifierFoldData function_fold_output = { function_fold_proof, function_vk_2 };
// Accumulate kernel circuit
Builder kernel_circuit{ ivc.goblin.op_queue };
kernel_acc =
construct_mock_folding_kernel(kernel_circuit, kernel_fold_output, function_fold_output, kernel_acc);
FoldProof kernel_fold_proof = ivc.accumulate(kernel_circuit);
kernel_vk = composer.compute_verification_key(ivc.prover_instance);
FoldOutput kernel_fold_output = { kernel_fold_proof, kernel_vk };
VerifierFoldData kernel_fold_output = { kernel_fold_proof, kernel_vk };
}

// Constuct four proofs: merge, eccvm, translator, decider
auto proof = ivc.prove();
auto inst = std::make_shared<VerifierInstance>(kernel_vk);
auto inst = std::make_shared<VerifierInstance>();
inst->verification_key = kernel_vk;
// Verify all four proofs
EXPECT_TRUE(ivc.verify(proof, { kernel_acc, inst }));
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,37 @@ class MockKernelTest : public ::testing::Test {

TEST_F(MockKernelTest, PinFoldingKernelSizes)
{
using FoldOutput = GoblinMockCircuits::FoldOutput;
ClientIVC ivc;
ivc.precompute_folding_verification_keys();
// Accumulate three circuits to generate two folding proofs for input to foldng kernel
// Accumulate three circuits to generate two folding proofs for input to folding kernel
GoblinUltraCircuitBuilder circuit_1{ ivc.goblin.op_queue };
GoblinMockCircuits::construct_mock_function_circuit(circuit_1);
ivc.initialize(circuit_1);
auto verifier_acc = std::make_shared<ClientIVC::VerifierInstance>();
verifier_acc->verification_key = ivc.vks.first_func_vk;
auto initial_acc = std::make_shared<ClientIVC::VerifierInstance>();
initial_acc->verification_key = ivc.vks.first_func_vk;

GoblinUltraCircuitBuilder circuit_2{ ivc.goblin.op_queue };
GoblinMockCircuits::construct_mock_function_circuit(circuit_2);
auto fold_proof_1 = ivc.accumulate(circuit_2);
auto func_fold_proof = ivc.accumulate(circuit_2);

FoldOutput kernel_accum;
// Construct kernel circuit
GoblinUltraCircuitBuilder kernel_circuit{ ivc.goblin.op_queue };
auto new_acc = GoblinMockCircuits::construct_mock_folding_kernel(
kernel_circuit, { fold_proof_1, ivc.vks.func_vk }, {}, verifier_acc);
auto kernel_acc = GoblinMockCircuits::construct_mock_folding_kernel(
kernel_circuit, { func_fold_proof, ivc.vks.func_vk }, {}, initial_acc);

auto fold_proof_3 = ivc.accumulate(kernel_circuit);
auto kernel_fold_proof = ivc.accumulate(kernel_circuit);
EXPECT_EQ(ivc.prover_instance->log_instance_size, 17);

GoblinUltraCircuitBuilder circuit_4{ ivc.goblin.op_queue };
GoblinMockCircuits::construct_mock_function_circuit(circuit_4);
auto fold_proof_4 = ivc.accumulate(circuit_4);
func_fold_proof = ivc.accumulate(circuit_4);

GoblinUltraCircuitBuilder new_kernel_circuit = GoblinUltraCircuitBuilder{ ivc.goblin.op_queue };
new_acc = GoblinMockCircuits::construct_mock_folding_kernel(
new_kernel_circuit, { fold_proof_3, ivc.vks.first_kernel_vk }, { fold_proof_4, ivc.vks.func_vk }, new_acc);
kernel_circuit = GoblinUltraCircuitBuilder{ ivc.goblin.op_queue };
kernel_acc = GoblinMockCircuits::construct_mock_folding_kernel(kernel_circuit,
{ 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(new_kernel_circuit);
auto instance = composer.create_prover_instance(kernel_circuit);
EXPECT_EQ(instance->proving_key->log_circuit_size, 17);
}
14 changes: 7 additions & 7 deletions barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class GoblinMockCircuits {
static constexpr size_t NUM_OP_QUEUE_COLUMNS = Flavor::NUM_WIRES;

/**
* @brief
*
* @brief Information required by the verifier to verify a folding round besides the previous accumulator.
*/
struct FoldOutput {
std::vector<FF> fold_proof;
std::shared_ptr<VerificationKey> inst_vk;
struct VerifierFoldData {
std::vector<FF> fold_proof; // folding proof
std::shared_ptr<VerificationKey>
inst_vk; // Verification key of the instance to be folded (note: this would be a vector if k > 1 )
};

/**
Expand Down Expand Up @@ -227,8 +227,8 @@ class GoblinMockCircuits {
*/
static std::shared_ptr<VerifierInstance> construct_mock_folding_kernel(
GoblinUltraBuilder& builder,
const FoldOutput& func,
const FoldOutput& kernel,
const VerifierFoldData& func,
const VerifierFoldData& kernel,
std::shared_ptr<VerifierInstance>& prev_kernel_accum)
{
using GURecursiveFlavor = GoblinUltraRecursiveFlavor_<GoblinUltraBuilder>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ std::shared_ptr<typename VerifierInstances::Instance> ProtoGalaxyVerifier_<Verif
next_accumulator->instance_size = accumulator->instance_size;
next_accumulator->log_instance_size = accumulator->log_instance_size;
next_accumulator->is_accumulator = true;
// Compute next folding parameters and verify against the ones received from the prover
// Compute next folding parameters
next_accumulator->target_sum =
perturbator_at_challenge * lagranges[0] + vanishing_polynomial_at_challenge * combiner_quotient_at_challenge;
next_accumulator->gate_challenges =
update_gate_challenges(perturbator_challenge, accumulator->gate_challenges, deltas);

// Compute ϕ and verify against the data received from the prover
// Compute ϕ
auto& acc_witness_commitments = next_accumulator->witness_commitments;
auto witness_labels = commitment_labels.get_witness();
size_t comm_idx = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ template <class VerifierInstances> class ProtoGalaxyVerifier_ {
*/
void prepare_for_folding(const std::vector<FF>&);

/**
* @brief Instantiatied the accumulator (i.e. the relaxed instance) from the transcript.
*
*/
// void receive_accumulator(const std::shared_ptr<Instance>&, const std::string&);

/**
* @brief Process the public data ϕ for the Instances to be folded.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,13 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
Builder folding_circuit;
auto verifier =
FoldingRecursiveVerifier(&folding_circuit, verifier_instance_1, { verifier_instance_2->verification_key });
auto recursive_verifier_accumulator = verifier.verify_folding_proof(folding_proof.folding_data);
auto acc = std::make_shared<VerifierInstance>(recursive_verifier_accumulator->get_value());
verifier.verify_folding_proof(folding_proof.folding_data);
info("Folding Recursive Verifier: num gates = ", folding_circuit.num_gates);

// 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 });
auto verifier_accumulator = native_folding_verifier.verify_folding_proof(folding_proof.folding_data);
native_folding_verifier.verify_folding_proof(folding_proof.folding_data);

// Ensure that the underlying native and recursive folding verification algorithms agree by ensuring the
// manifestsproduced by each agree.
Expand Down Expand Up @@ -240,7 +239,7 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
auto verifier =
FoldingRecursiveVerifier(&folding_circuit, verifier_instance_1, { verifier_instance_2->verification_key });
auto recursive_verifier_accumulator = verifier.verify_folding_proof(folding_proof.folding_data);
auto acc = std::make_shared<VerifierInstance>(recursive_verifier_accumulator->get_value());
auto native_verifier_acc = std::make_shared<VerifierInstance>(recursive_verifier_accumulator->get_value());
info("Folding Recursive Verifier: num gates = ", folding_circuit.num_gates);

// Perform native folding verification and ensure it returns the same result (either true or false) as
Expand All @@ -261,7 +260,7 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
auto decider_proof = decider_prover.construct_proof();

Builder decider_circuit;
DeciderRecursiveVerifier decider_verifier{ &decider_circuit, acc };
DeciderRecursiveVerifier decider_verifier{ &decider_circuit, native_verifier_acc };
auto pairing_points = decider_verifier.verify_proof(decider_proof);
info("Decider Recursive Verifier: num gates = ", decider_circuit.num_gates);
// Check for a failure flag in the recursive verifier circuit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ std::shared_ptr<typename Flavor::VerificationKey> UltraComposer_<Flavor>::comput
verification_key->q_poseidon2_internal = commitment_key->commit(proving_key->q_poseidon2_internal);
}

return std::move(verification_key);
return verification_key;
}

template <IsUltraFlavor Flavor>
Expand Down

0 comments on commit 28c79aa

Please sign in to comment.