barretenberg
Loading...
Searching...
No Matches
composer_lib.hpp
1#pragma once
2#include "barretenberg/ecc/curves/bn254/bn254.hpp"
3#include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp"
4#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
5
6namespace proof_system::plonk {
8 std::string name;
9 // TODO: does the prover need the raw lagrange-base selector values?
10 bool requires_lagrange_base_polynomial = false;
11};
12
24std::shared_ptr<plonk::proving_key> initialize_proving_key(
25 const auto& circuit_constructor,
27 const size_t minimum_circuit_size,
28 const size_t num_randomized_gates,
29 CircuitType circuit_type)
30{
31 const size_t num_gates = circuit_constructor.num_gates;
32
33 const size_t num_public_inputs = circuit_constructor.public_inputs.size();
34 const size_t num_constraints = num_gates + num_public_inputs;
35 const size_t total_num_constraints = std::max(minimum_circuit_size, num_constraints);
36 const size_t subgroup_size =
37 circuit_constructor.get_circuit_subgroup_size(total_num_constraints + num_randomized_gates); // next power of 2
38
39 auto crs = crs_factory->get_prover_crs(subgroup_size + 1);
40
41 // Differentiate between Honk and Plonk here since Plonk pkey requires crs whereas Honk pkey does not
42 auto proving_key = std::make_shared<plonk::proving_key>(subgroup_size, num_public_inputs, crs, circuit_type);
43
44 return proving_key;
45}
46
54void enforce_nonzero_selector_polynomials(const auto& circuit_constructor, auto* proving_key)
55{
56 for (size_t idx = 0; idx < circuit_constructor.num_selectors; ++idx) {
57 auto current_selector =
58 proving_key->polynomial_store.get(circuit_constructor.selector_names[idx] + "_lagrange");
59 current_selector[current_selector.size() - 1] = idx + 1;
60 proving_key->polynomial_store.put(circuit_constructor.selector_names[idx] + "_lagrange",
61 std::move(current_selector));
62 }
63}
64
73 std::vector<SelectorProperties> selector_properties);
74
80std::shared_ptr<plonk::verification_key> compute_verification_key_common(
81 std::shared_ptr<plonk::proving_key> const& proving_key,
82 // silencing for now but need to figure out where to extract type of VerifierCrs from :-/
84
85} // namespace proof_system::plonk
Definition: crs_factory.hpp:72
Definition: crs_factory.hpp:30
Definition: widget.bench.cpp:13
void enforce_nonzero_selector_polynomials(const auto &circuit_constructor, auto *proving_key)
Fill the last index of each selector polynomial in lagrange form with a non-zero value.
Definition: composer_lib.hpp:54
std::shared_ptr< plonk::verification_key > compute_verification_key_common(std::shared_ptr< plonk::proving_key > const &proving_key, std::shared_ptr< barretenberg::srs::factories::VerifierCrs< curve::BN254 > > const &vrs)
Computes the verification key by computing the: (1) commitments to the selector, permutation,...
Definition: composer_lib.cpp:45
void compute_monomial_and_coset_selector_forms(plonk::proving_key *circuit_proving_key, std::vector< SelectorProperties > selector_properties)
Retrieve lagrange forms of selector polynomials and compute monomial and coset-monomial forms and put...
Definition: composer_lib.cpp:18
std::shared_ptr< plonk::proving_key > initialize_proving_key(const auto &circuit_constructor, barretenberg::srs::factories::CrsFactory< curve::BN254 > *crs_factory, const size_t minimum_circuit_size, const size_t num_randomized_gates, CircuitType circuit_type)
Initilalize proving key and load the crs.
Definition: composer_lib.hpp:24
Definition: composer_lib.hpp:7
Definition: proving_key.hpp:38