Skip to content

Commit

Permalink
recursive verifier test updates; dead code deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
ledwards2225 committed Nov 28, 2023
1 parent 4152ba6 commit 595ccf7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,43 @@
namespace proof_system::plonk::stdlib::recursion::honk {

/**
* @brief Test suite for recursive verification of conventional Ultra Honk proofs
* @brief Test suite for recursive verification of Goblin Ultra Honk proofs
* @details The recursive verification circuit is arithmetized in two different ways: 1) using the conventional Ultra
* arithmetization (UltraCircuitBuilder), or 2) a Goblin-style Ultra arithmetization (GoblinUltraCircuitBuilder).
*
* @tparam Builder Circuit builder for the recursive verifier circuit
*/
template <typename BuilderType> class GoblinRecursiveVerifierTest : public testing::Test {

// Define types relevant for inner circuit
using Flavor = ::proof_system::honk::flavor::GoblinUltra;
using InnerComposer = ::proof_system::honk::UltraComposer_<Flavor>;
// Define types relevant for testing
using UltraFlavor = ::proof_system::honk::flavor::Ultra;
using GoblinUltraFlavor = ::proof_system::honk::flavor::GoblinUltra;
using UltraComposer = ::proof_system::honk::UltraComposer_<UltraFlavor>;
using GoblinUltraComposer = ::proof_system::honk::UltraComposer_<GoblinUltraFlavor>;

using InnerFlavor = GoblinUltraFlavor;
using InnerComposer = GoblinUltraComposer;
using InnerBuilder = typename InnerComposer::CircuitBuilder;
using NativeVerifier = ::proof_system::honk::UltraVerifier_<::proof_system::honk::flavor::Ultra>;
using InnerCurve = bn254<InnerBuilder>;
using Commitment = InnerFlavor::Commitment;
using FF = InnerFlavor::FF;

// Types for recursive verifier circuit
using RecursiveFlavor = ::proof_system::honk::flavor::GoblinUltraRecursive_<BuilderType>;
using RecursiveVerifier = UltraRecursiveVerifier_<RecursiveFlavor>;
using OuterBuilder = BuilderType;
using VerificationKey = typename RecursiveVerifier::VerificationKey;

// Helper for getting composer for prover/verifier of recursive (outer) circuit
template <typename BuilderT> static auto get_composer()
{
if constexpr (IsGoblinBuilder<BuilderT>) {
return GoblinUltraComposer();
} else {
return UltraComposer();
}
}

/**
* @brief Create a non-trivial arbitrary inner circuit, the proof of which will be recursively verified
*
Expand Down Expand Up @@ -178,8 +194,18 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi
EXPECT_EQ(outer_circuit.failed(), false) << outer_circuit.err();
EXPECT_TRUE(outer_circuit.check_circuit());

// Additional check 1: Perform native verification then perform the pairing on the outputs of the recursive
// verifier and check that the result agrees.
// { // Construct and verify a proof of the recursive verifier circuit
// auto composer = get_composer<OuterBuilder>();
// auto instance = composer.create_instance(outer_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);
// }

// Additional 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(instance);
auto native_result = native_verifier.verify_proof(inner_proof);
auto recursive_result = native_verifier.pcs_verification_key->pairing_check(pairing_points[0].get_value(),
Expand Down Expand Up @@ -217,7 +243,7 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi

// Arbitrarily tamper with the proof to be verified
inner_prover.transcript.deserialize_full_transcript();
inner_prover.transcript.sorted_accum_comm = Flavor::Commitment::one() * Flavor::FF::random_element();
inner_prover.transcript.sorted_accum_comm = Commitment::one() * FF::random_element();
inner_prover.transcript.serialize_full_transcript();
inner_proof = inner_prover.export_proof();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,35 @@ namespace proof_system::plonk::stdlib::recursion::honk {
*/
template <typename BuilderType> class RecursiveVerifierTest : public testing::Test {

// Define types relevant for inner circuit
using Flavor = ::proof_system::honk::flavor::Ultra;
using InnerComposer = ::proof_system::honk::UltraComposer_<Flavor>;
// Define types relevant for testing
using UltraFlavor = ::proof_system::honk::flavor::Ultra;
using GoblinUltraFlavor = ::proof_system::honk::flavor::GoblinUltra;
using UltraComposer = ::proof_system::honk::UltraComposer_<UltraFlavor>;
using GoblinUltraComposer = ::proof_system::honk::UltraComposer_<GoblinUltraFlavor>;

using InnerFlavor = UltraFlavor;
using InnerComposer = UltraComposer;
using InnerBuilder = typename InnerComposer::CircuitBuilder;
using NativeVerifier = ::proof_system::honk::UltraVerifier_<::proof_system::honk::flavor::Ultra>;
using InnerCurve = bn254<InnerBuilder>;
using Commitment = InnerFlavor::Commitment;
using FF = InnerFlavor::FF;

// Types for recursive verifier circuit
using RecursiveFlavor = ::proof_system::honk::flavor::UltraRecursive_<BuilderType>;
using RecursiveVerifier = UltraRecursiveVerifier_<RecursiveFlavor>;
using OuterBuilder = BuilderType;
using VerificationKey = typename RecursiveVerifier::VerificationKey;

// Helper for getting composer for prover/verifier of recursive (outer) circuit
template <typename BuilderT> static auto get_composer()
{
if constexpr (IsGoblinBuilder<BuilderT>) {
return GoblinUltraComposer();
} else {
return UltraComposer();
}
}

/**
* @brief Create a non-trivial arbitrary inner circuit, the proof of which will be recursively verified
*
Expand Down Expand Up @@ -162,6 +178,16 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te
EXPECT_EQ(outer_circuit.failed(), false) << outer_circuit.err();
EXPECT_TRUE(outer_circuit.check_circuit());

// { // Construct and verify a proof of the recursive verifier circuit
// auto composer = get_composer<OuterBuilder>();
// auto instance = composer.create_instance(outer_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);
// }

// Additional 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(instance);
Expand Down Expand Up @@ -202,7 +228,7 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te

// Arbitrarily tamper with the proof to be verified
inner_prover.transcript.deserialize_full_transcript();
inner_prover.transcript.sorted_accum_comm = Flavor::Commitment::one() * Flavor::FF::random_element();
inner_prover.transcript.sorted_accum_comm = Commitment::one() * FF::random_element();
inner_prover.transcript.serialize_full_transcript();
inner_proof = inner_prover.export_proof();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ template <UltraFlavor Flavor> class UltraComposer_ {
static constexpr size_t num_zero_rows = Flavor::has_zero_row ? 1 : 0;
static constexpr std::string_view NAME_STRING = "UltraHonk";
static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES;
std::shared_ptr<ProvingKey> proving_key;
std::shared_ptr<VerificationKey> verification_key;

// The crs_factory holds the path to the srs and exposes methods to extract the srs elements
std::shared_ptr<srs::factories::CrsFactory<typename Flavor::Curve>> crs_factory_;
Expand All @@ -43,11 +41,6 @@ template <UltraFlavor Flavor> class UltraComposer_ {
: crs_factory_(std::move(crs_factory))
{}

UltraComposer_(std::shared_ptr<ProvingKey> p_key, std::shared_ptr<VerificationKey> v_key)
: proving_key(std::move(p_key))
, verification_key(std::move(v_key))
{}

UltraComposer_(UltraComposer_&& other) noexcept = default;
UltraComposer_(UltraComposer_ const& other) noexcept = default;
UltraComposer_& operator=(UltraComposer_&& other) noexcept = default;
Expand Down
3 changes: 0 additions & 3 deletions barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ template <UltraFlavor Flavor> class UltraProver_ {

Transcript transcript;

std::vector<FF> public_inputs;
size_t pub_inputs_offset;

proof_system::RelationParameters<FF> relation_parameters;

CommitmentLabels commitment_labels;
Expand Down

0 comments on commit 595ccf7

Please sign in to comment.