Skip to content

Commit

Permalink
Get rid of compute_verification_key
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Apr 4, 2024
1 parent 55be40d commit 54f8e15
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
26 changes: 2 additions & 24 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ template <IsECCVMFlavor Flavor>
ECCVMVerifier_<Flavor> ECCVMComposer_<Flavor>::create_verifier(CircuitConstructor& circuit_constructor,
const std::shared_ptr<Transcript>& transcript)
{
auto verification_key = compute_verification_key(circuit_constructor);
proving_key = std::make_shared<typename Flavor::ProvingKey>(circuit_constructor);
auto verification_key = std::make_shared<typename Flavor::VerificationKey>(proving_key);

ECCVMVerifier_<Flavor> output_state(verification_key);

Expand All @@ -26,29 +27,6 @@ ECCVMVerifier_<Flavor> ECCVMComposer_<Flavor>::create_verifier(CircuitConstructo
return output_state;
}

/**
* Compute verification key consisting of selector precommitments.
*
* @return Pointer to created circuit verification key.
* */
template <IsECCVMFlavor Flavor>
std::shared_ptr<typename Flavor::VerificationKey> ECCVMComposer_<Flavor>::compute_verification_key(
CircuitConstructor& circuit_constructor)
{
if (verification_key) {
return verification_key;
}

proving_key = std::make_shared<typename Flavor::ProvingKey>(circuit_constructor);
commitment_key = std::make_shared<typename Flavor::CommitmentKey>(proving_key->circuit_size);
verification_key =
std::make_shared<typename Flavor::VerificationKey>(proving_key->circuit_size, proving_key->num_public_inputs);

verification_key->lagrange_first = commitment_key->commit(proving_key->lagrange_first);
verification_key->lagrange_second = commitment_key->commit(proving_key->lagrange_second);
verification_key->lagrange_last = commitment_key->commit(proving_key->lagrange_last);
return verification_key;
}
template class ECCVMComposer_<ECCVMFlavor>;

} // namespace bb
3 changes: 0 additions & 3 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ template <IsECCVMFlavor Flavor> class ECCVMComposer_ {
ECCVMComposer_& operator=(ECCVMComposer_ const& other) noexcept = default;
~ECCVMComposer_() = default;

std::shared_ptr<ProvingKey> compute_proving_key(CircuitConstructor& circuit_constructor);
std::shared_ptr<VerificationKey> compute_verification_key(CircuitConstructor& circuit_constructor);

ECCVMVerifier_<Flavor> create_verifier(
CircuitConstructor& circuit_constructor,
const std::shared_ptr<Transcript>& transcript = std::make_shared<Transcript>());
Expand Down
24 changes: 23 additions & 1 deletion barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,29 @@ class ECCVMFlavor {
* resolve that, and split out separate PrecomputedPolynomials/Commitments data for clarity but also for
* portability of our circuits.
*/
using VerificationKey = VerificationKey_<PrecomputedEntities<Commitment>, VerifierCommitmentKey>;
class VerificationKey : public VerificationKey_<PrecomputedEntities<Commitment>, VerifierCommitmentKey> {
public:
std::vector<FF> public_inputs;

VerificationKey(const size_t circuit_size, const size_t num_public_inputs)
: VerificationKey_(circuit_size, num_public_inputs)
{}

VerificationKey(const std::shared_ptr<ProvingKey>& proving_key)
: public_inputs(proving_key->public_inputs)
{
// this->pcs_verification_key = std::make_shared<VerifierCommitmentKey>(); // WORKTODO
this->circuit_size = proving_key->circuit_size;
this->log_circuit_size = numeric::get_msb(this->circuit_size);
this->num_public_inputs = proving_key->num_public_inputs;
this->pub_inputs_offset = proving_key->pub_inputs_offset;

for (auto [polynomial, commitment] :
zip_view(proving_key->get_precomputed_polynomials(), this->get_all())) {
commitment = proving_key->commitment_key->commit(polynomial);
}
}
};

/**
* @brief A container for polynomials produced after the first round of sumcheck.
Expand Down
4 changes: 4 additions & 0 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_verifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ template <typename Flavor> class ECCVMVerifier_ {
using FF = typename Flavor::FF;
using Commitment = typename Flavor::Commitment;
using VerificationKey = typename Flavor::VerificationKey;
using ProvingKey = typename Flavor::ProvingKey;
using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey;
using Transcript = typename Flavor::Transcript;

public:
explicit ECCVMVerifier_(const std::shared_ptr<VerificationKey>& verifier_key = nullptr);

explicit ECCVMVerifier_(const std::shared_ptr<ECCVMVerifier_::ProvingKey>& proving_key)
: ECCVMVerifier_(std::make_shared<ECCVMFlavor::VerificationKey>(proving_key)){};

bool verify_proof(const HonkProof& proof);

std::shared_ptr<VerificationKey> key;
Expand Down

0 comments on commit 54f8e15

Please sign in to comment.