Skip to content

Commit

Permalink
more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Feb 2, 2024
1 parent 2d39bbc commit 539fa3a
Showing 1 changed file with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,21 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
}
};

static std::shared_ptr<Instance> fold_and_verify(const std::vector<std::shared_ptr<Instance>>& instances,
InnerComposer& inner_composer)
static std::shared_ptr<Instance> fold_and_verify_native(const std::vector<std::shared_ptr<Instance>>& instances,
InnerComposer& composer)
{
auto folding_prover = composer.create_folding_prover(instances);
auto folding_verifier = composer.create_folding_verifier();

auto proof = folding_prover.fold_instances();
auto next_accumulator = proof.accumulator;
auto res = folding_verifier.verify_folding_proof(proof.folding_data);
EXPECT_EQ(res, true);
return next_accumulator;
}

static std::shared_ptr<Instance> fold_and_verify_recursive(const std::vector<std::shared_ptr<Instance>>& instances,
InnerComposer& inner_composer)
{
// Generate a folding proof
auto inner_folding_prover = inner_composer.create_folding_prover(instances);
Expand All @@ -130,10 +143,10 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
// check_circuit on the recursive folding verifier
auto native_folding_verifier = inner_composer.create_folding_verifier();
auto native_folding_result = native_folding_verifier.verify_folding_proof(inner_folding_proof.folding_data);
EXPECT_EQ(native_folding_result, outer_folding_circuit.check_circuit());
EXPECT_EQ(native_folding_result, !outer_folding_circuit.failed());

// Ensure that the underlying native and recursive folding verification algorithms agree by ensuring
// the manifests produced by each agree.
// Ensure that the underlying native and recursive folding verification algorithms agree by ensuring the
// manifestsproduced by each agree.
auto recursive_folding_manifest = verifier.transcript->get_manifest();
auto native_folding_manifest = native_folding_verifier.transcript->get_manifest();

Expand All @@ -144,6 +157,17 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
// Check for a failure flag in the recursive verifier circuit
EXPECT_EQ(outer_folding_circuit.failed(), false) << outer_folding_circuit.err();

{
auto composer = OuterComposer();
auto instance = composer.create_instance(outer_folding_circuit);
auto prover = composer.create_prover(instance);
auto verifier = composer.create_verifier(instance);
auto proof = prover.construct_proof();
bool verified = verifier.verify_proof(proof);

ASSERT(verified);
}

return inner_folding_proof.accumulator;
}

Expand Down Expand Up @@ -206,14 +230,16 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
auto instance2 = inner_composer.create_instance(builder2);
auto instances = std::vector<std::shared_ptr<Instance>>{ instance1, instance2 };

fold_and_verify(instances, inner_composer);
fold_and_verify_recursive(instances, inner_composer);
};

/**
* @brief Recursively verify two rounds of folding valid circuits and then recursive verify the final decider proof,
* @brief Perform two rounds of folding valid circuits and then recursive verify the final decider proof,
* make sure the verifer circuits pass check_circuit(). Ensure that the algorithm of the recursive and native
* verifiers are identical by checking the manifests
*/
// TODO(https://github.com/AztecProtocol/barretenberg/issues/844): Fold the recursive folding verifier in tests once
// we can fold instances of different sizes.
static void test_full_protogalaxy_recursive()
{
// Create two arbitrary circuits for the first round of folding
Expand All @@ -229,15 +255,15 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
auto instance2 = inner_composer.create_instance(builder2);
auto instances = std::vector<std::shared_ptr<Instance>>{ instance1, instance2 };

auto accumulator = fold_and_verify(instances, inner_composer);
auto accumulator = fold_and_verify_native(instances, inner_composer);

// Create another circuit to do a second round of folding
InnerBuilder builder3;
create_inner_circuit(builder3);
auto instance3 = inner_composer.create_instance(builder3);
instances = std::vector<std::shared_ptr<Instance>>{ accumulator, instance3 };

accumulator = fold_and_verify(instances, inner_composer);
accumulator = fold_and_verify_native(instances, inner_composer);

// Create a decider proof for the relaxed instance obtained through folding
auto inner_decider_prover = inner_composer.create_decider_prover(accumulator);
Expand Down Expand Up @@ -295,7 +321,7 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
auto instance2 = inner_composer.create_instance(builder2);
auto instances = std::vector<std::shared_ptr<Instance>>{ instance1, instance2 };

auto accumulator = fold_and_verify(instances, inner_composer);
auto accumulator = fold_and_verify_native(instances, inner_composer);

// Tamper with the accumulator by changing the target sum
accumulator->target_sum = FF::random_element();
Expand Down Expand Up @@ -329,7 +355,7 @@ template <typename RecursiveFlavor> class ProtoGalaxyRecursiveTests : public tes
auto instance2 = inner_composer.create_instance(builder2);
auto instances = std::vector<std::shared_ptr<Instance>>{ instance1, instance2 };

auto accumulator = fold_and_verify(instances, inner_composer);
auto accumulator = fold_and_verify_native(instances, inner_composer);

// Create another circuit to do a second round of folding
InnerBuilder builder3;
Expand Down

0 comments on commit 539fa3a

Please sign in to comment.