Skip to content

Commit

Permalink
construct recursive ver directly from native vkey
Browse files Browse the repository at this point in the history
  • Loading branch information
ledwards2225 committed Nov 30, 2023
1 parent b3382a6 commit b2c0922
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ template <typename BuilderType> class GoblinUltraRecursive_ {
using Commitment = typename Curve::Element;
using CommitmentHandle = typename Curve::Element;
using FF = typename Curve::ScalarField;
using NativeVerificationKey = flavor::GoblinUltra::VerificationKey;

// Note(luke): Eventually this may not be needed at all
using VerifierCommitmentKey = pcs::VerifierCommitmentKey<Curve>;
Expand Down Expand Up @@ -324,7 +325,7 @@ template <typename BuilderType> class GoblinUltraRecursive_ {
* @param builder
* @param native_key Native verification key from which to extract the precomputed commitments
*/
VerificationKey(CircuitBuilder* builder, auto native_key)
VerificationKey(CircuitBuilder* builder, std::shared_ptr<NativeVerificationKey> native_key)
: VerificationKey_<PrecomputedEntities<Commitment>>(native_key->circuit_size, native_key->num_public_inputs)
{
this->q_m = Commitment::from_witness(builder, native_key->q_m);
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/barretenberg/flavor/ultra_recursive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ template <typename BuilderType> class UltraRecursive_ {
using Commitment = typename Curve::Element;
using CommitmentHandle = typename Curve::Element;
using FF = typename Curve::ScalarField;
using NativeVerificationKey = flavor::Ultra::VerificationKey;

// Note(luke): Eventually this may not be needed at all
using VerifierCommitmentKey = pcs::VerifierCommitmentKey<Curve>;
Expand Down Expand Up @@ -256,7 +257,7 @@ template <typename BuilderType> class UltraRecursive_ {
* @param builder
* @param native_key Native verification key from which to extract the precomputed commitments
*/
VerificationKey(CircuitBuilder* builder, auto native_key)
VerificationKey(CircuitBuilder* builder, std::shared_ptr<NativeVerificationKey> native_key)
: VerificationKey_<PrecomputedEntities<Commitment>>(native_key->circuit_size, native_key->num_public_inputs)
{
this->q_m = Commitment::from_witness(builder, native_key->q_m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,26 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi
{
// Create an arbitrary inner circuit
auto inner_circuit = create_inner_circuit();
OuterBuilder outer_circuit;

// Compute native verification key
InnerComposer inner_composer;
auto instance = inner_composer.create_instance(inner_circuit);
auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK
const auto native_verification_key = instance->compute_verification_key();

// Instantiate the recursive verification key from the native verification key
OuterBuilder outer_circuit;
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, native_verification_key);
// Instantiate the recursive verifier using the native verification key
RecursiveVerifier verifier{ &outer_circuit, native_verification_key };

// Spot check some values in the recursive VK to ensure it was constructed correctly
EXPECT_EQ(verification_key->circuit_size, native_verification_key->circuit_size);
EXPECT_EQ(verification_key->log_circuit_size, native_verification_key->log_circuit_size);
EXPECT_EQ(verification_key->num_public_inputs, native_verification_key->num_public_inputs);
EXPECT_EQ(verification_key->q_m.get_value(), native_verification_key->q_m);
EXPECT_EQ(verification_key->q_r.get_value(), native_verification_key->q_r);
EXPECT_EQ(verification_key->sigma_1.get_value(), native_verification_key->sigma_1);
EXPECT_EQ(verification_key->id_3.get_value(), native_verification_key->id_3);
EXPECT_EQ(verification_key->lagrange_ecc_op.get_value(), native_verification_key->lagrange_ecc_op);
EXPECT_EQ(verifier.key->circuit_size, native_verification_key->circuit_size);
EXPECT_EQ(verifier.key->log_circuit_size, native_verification_key->log_circuit_size);
EXPECT_EQ(verifier.key->num_public_inputs, native_verification_key->num_public_inputs);
EXPECT_EQ(verifier.key->q_m.get_value(), native_verification_key->q_m);
EXPECT_EQ(verifier.key->q_r.get_value(), native_verification_key->q_r);
EXPECT_EQ(verifier.key->sigma_1.get_value(), native_verification_key->sigma_1);
EXPECT_EQ(verifier.key->id_3.get_value(), native_verification_key->id_3);
EXPECT_EQ(verifier.key->lagrange_ecc_op.get_value(), native_verification_key->lagrange_ecc_op);
}

/**
Expand All @@ -186,8 +186,7 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi

// Create a recursive verification circuit for the proof of the inner circuit
OuterBuilder outer_circuit;
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, native_verification_key);
RecursiveVerifier verifier(&outer_circuit, verification_key);
RecursiveVerifier verifier{ &outer_circuit, native_verification_key };
auto pairing_points = verifier.verify_proof(inner_proof);

// Check for a failure flag in the recursive verifier circuit
Expand Down Expand Up @@ -248,8 +247,7 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi

// Create a recursive verification circuit for the proof of the inner circuit
OuterBuilder outer_circuit;
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, native_verification_key);
RecursiveVerifier verifier(&outer_circuit, verification_key);
RecursiveVerifier verifier{ &outer_circuit, native_verification_key };
verifier.verify_proof(inner_proof);

// We expect the circuit check to fail due to the bad proof
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace proof_system::plonk::stdlib::recursion::honk {

template <typename Flavor>
UltraRecursiveVerifier_<Flavor>::UltraRecursiveVerifier_(Builder* builder,
std::shared_ptr<VerificationKey> verifier_key)
: key(verifier_key)
std::shared_ptr<NativeVerificationKey> native_verifier_key)
: key(std::make_shared<VerificationKey>(builder, native_verifier_key))
, builder(builder)
{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ template <typename Flavor> class UltraRecursiveVerifier_ {
using Commitment = typename Flavor::Commitment;
using GroupElement = typename Flavor::GroupElement;
using VerificationKey = typename Flavor::VerificationKey;
using NativeVerificationKey = typename Flavor::NativeVerificationKey;
using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey;
using Builder = typename Flavor::CircuitBuilder;
using PairingPoints = std::array<GroupElement, 2>;

explicit UltraRecursiveVerifier_(Builder* builder, std::shared_ptr<VerificationKey> verifier_key = nullptr);
explicit UltraRecursiveVerifier_(Builder* builder, std::shared_ptr<NativeVerificationKey> native_verifier_key);
UltraRecursiveVerifier_(UltraRecursiveVerifier_&& other) = delete;
UltraRecursiveVerifier_(const UltraRecursiveVerifier_& other) = delete;
UltraRecursiveVerifier_& operator=(const UltraRecursiveVerifier_& other) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te
auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK
const auto native_verification_key = instance->compute_verification_key();

// Instantiate the recursive verification key from the native verification key
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, native_verification_key);
// Instantiate the recursive verifier using the native verification key
RecursiveVerifier verifier{ &outer_circuit, native_verification_key };

// Spot check some values in the recursive VK to ensure it was constructed correctly
EXPECT_EQ(verification_key->circuit_size, native_verification_key->circuit_size);
EXPECT_EQ(verification_key->log_circuit_size, native_verification_key->log_circuit_size);
EXPECT_EQ(verification_key->num_public_inputs, native_verification_key->num_public_inputs);
EXPECT_EQ(verification_key->q_m.get_value(), native_verification_key->q_m);
EXPECT_EQ(verification_key->q_r.get_value(), native_verification_key->q_r);
EXPECT_EQ(verification_key->sigma_1.get_value(), native_verification_key->sigma_1);
EXPECT_EQ(verification_key->id_3.get_value(), native_verification_key->id_3);
EXPECT_EQ(verifier.key->circuit_size, native_verification_key->circuit_size);
EXPECT_EQ(verifier.key->log_circuit_size, native_verification_key->log_circuit_size);
EXPECT_EQ(verifier.key->num_public_inputs, native_verification_key->num_public_inputs);
EXPECT_EQ(verifier.key->q_m.get_value(), native_verification_key->q_m);
EXPECT_EQ(verifier.key->q_r.get_value(), native_verification_key->q_r);
EXPECT_EQ(verifier.key->sigma_1.get_value(), native_verification_key->sigma_1);
EXPECT_EQ(verifier.key->id_3.get_value(), native_verification_key->id_3);
}

/**
Expand All @@ -170,8 +170,7 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te

// Create a recursive verification circuit for the proof of the inner circuit
OuterBuilder outer_circuit;
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, native_verification_key);
RecursiveVerifier verifier(&outer_circuit, verification_key);
RecursiveVerifier verifier{ &outer_circuit, native_verification_key };
auto pairing_points = verifier.verify_proof(inner_proof);

// Check for a failure flag in the recursive verifier circuit
Expand Down Expand Up @@ -233,8 +232,7 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te

// Create a recursive verification circuit for the proof of the inner circuit
OuterBuilder outer_circuit;
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, native_verification_key);
RecursiveVerifier verifier(&outer_circuit, verification_key);
RecursiveVerifier verifier{ &outer_circuit, native_verification_key };
verifier.verify_proof(inner_proof);

// We expect the circuit check to fail due to the bad proof
Expand Down

0 comments on commit b2c0922

Please sign in to comment.