Skip to content

Commit

Permalink
proof_system independent of plonk.
Browse files Browse the repository at this point in the history
Don't qualify ComposerType

Revert settings change.

Reduce namespace verbosity

Update some comments.
  • Loading branch information
codygunton committed Apr 5, 2023
1 parent 2da9588 commit 892edd5
Show file tree
Hide file tree
Showing 101 changed files with 402 additions and 623 deletions.
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/honk/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
barretenberg_module(honk numeric ecc srs proof_system transcript)
barretenberg_module(honk numeric ecc srs proof_system transcript plonk)

if(TESTING)
# TODO: Re-enable all these warnings once PoC is finished
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ std::shared_ptr<plonk::proving_key> StandardHonkComposerHelper<CircuitConstructo
{
// Initialize circuit_proving_key
// TODO(#229)(Kesha): replace composer types.
circuit_proving_key = initialize_proving_key(constructor,
crs_factory_.get(),
minimum_circuit_size,
num_randomized_gates,
proof_system::ComposerType::STANDARD_HONK);
circuit_proving_key = initialize_proving_key(
constructor, crs_factory_.get(), minimum_circuit_size, num_randomized_gates, ComposerType::STANDARD_HONK);
// Compute lagrange selectors
construct_lagrange_selector_forms(constructor, circuit_proving_key.get());

Expand All @@ -47,8 +44,7 @@ std::shared_ptr<plonk::proving_key> StandardHonkComposerHelper<CircuitConstructo

template <typename CircuitConstructor>
std::shared_ptr<plonk::verification_key> StandardHonkComposerHelper<CircuitConstructor>::compute_verification_key_base(
std::shared_ptr<plonk::proving_key> const& proving_key,
std::shared_ptr<proof_system::VerifierReferenceString> const& vrs)
std::shared_ptr<plonk::proving_key> const& proving_key, std::shared_ptr<VerifierReferenceString> const& vrs)
{
auto key = std::make_shared<plonk::verification_key>(
proving_key->circuit_size, proving_key->num_public_inputs, vrs, proving_key->composer_type);
Expand Down Expand Up @@ -109,8 +105,7 @@ std::shared_ptr<plonk::proving_key> StandardHonkComposerHelper<CircuitConstructo
return circuit_proving_key;
}
// Compute q_l, q_r, q_o, etc polynomials
StandardHonkComposerHelper::compute_proving_key_base(circuit_constructor,
proof_system::ComposerType::STANDARD_HONK);
StandardHonkComposerHelper::compute_proving_key_base(circuit_constructor, ComposerType::STANDARD_HONK);

// Compute sigma polynomials (we should update that late)
compute_standard_honk_sigma_permutations<CircuitConstructor::num_wires>(circuit_constructor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ template <typename CircuitConstructor> class StandardHonkComposerHelper {
std::shared_ptr<plonk::verification_key> circuit_verification_key;
// TODO(#218)(kesha): we need to put this into the commitment key, so that the composer doesn't have to handle srs
// at all
std::shared_ptr<proof_system::ReferenceStringFactory> crs_factory_;
std::shared_ptr<ReferenceStringFactory> crs_factory_;
bool computed_witness = false;
StandardHonkComposerHelper()
: StandardHonkComposerHelper(std::shared_ptr<proof_system::ReferenceStringFactory>(
: StandardHonkComposerHelper(std::shared_ptr<ReferenceStringFactory>(
new proof_system::FileReferenceStringFactory("../srs_db/ignition")))
{}
StandardHonkComposerHelper(std::shared_ptr<proof_system::ReferenceStringFactory> crs_factory)
StandardHonkComposerHelper(std::shared_ptr<ReferenceStringFactory> crs_factory)
: crs_factory_(std::move(crs_factory))
{}

StandardHonkComposerHelper(std::unique_ptr<proof_system::ReferenceStringFactory>&& crs_factory)
StandardHonkComposerHelper(std::unique_ptr<ReferenceStringFactory>&& crs_factory)
: crs_factory_(std::move(crs_factory))
{}
StandardHonkComposerHelper(std::shared_ptr<plonk::proving_key> p_key,
Expand Down Expand Up @@ -67,8 +67,7 @@ template <typename CircuitConstructor> class StandardHonkComposerHelper {
// This needs to be static as it may be used only to compute the selector commitments.

static std::shared_ptr<plonk::verification_key> compute_verification_key_base(
std::shared_ptr<plonk::proving_key> const& proving_key,
std::shared_ptr<proof_system::VerifierReferenceString> const& vrs);
std::shared_ptr<plonk::proving_key> const& proving_key, std::shared_ptr<VerifierReferenceString> const& vrs);

void compute_witness(const CircuitConstructor& circuit_constructor, const size_t minimum_circuit_size = 0);
};
Expand Down
14 changes: 6 additions & 8 deletions cpp/src/barretenberg/honk/composer/standard_honk_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace proof_system::honk {
*/
class StandardHonkComposer {
public:
static constexpr proof_system::ComposerType type = proof_system::ComposerType::STANDARD_HONK;
static constexpr ComposerType type = ComposerType::STANDARD_HONK;

static constexpr size_t UINT_LOG2_BASE = 2;
// An instantiation of the circuit constructor that only depends on arithmetization, not on the proof system
Expand All @@ -38,20 +38,18 @@ class StandardHonkComposer {
, variables(circuit_constructor.variables){};

StandardHonkComposer(std::string const& crs_path, const size_t size_hint = 0)
: StandardHonkComposer(std::unique_ptr<proof_system::ReferenceStringFactory>(
new proof_system::FileReferenceStringFactory(crs_path)),
size_hint){};
: StandardHonkComposer(
std::unique_ptr<ReferenceStringFactory>(new proof_system::FileReferenceStringFactory(crs_path)),
size_hint){};

StandardHonkComposer(std::shared_ptr<proof_system::ReferenceStringFactory> const& crs_factory,
const size_t size_hint = 0)
StandardHonkComposer(std::shared_ptr<ReferenceStringFactory> const& crs_factory, const size_t size_hint = 0)
: circuit_constructor(size_hint)
, composer_helper(crs_factory)
, num_gates(circuit_constructor.num_gates)
, variables(circuit_constructor.variables)

{}
StandardHonkComposer(std::unique_ptr<proof_system::ReferenceStringFactory>&& crs_factory,
const size_t size_hint = 0)
StandardHonkComposer(std::unique_ptr<ReferenceStringFactory>&& crs_factory, const size_t size_hint = 0)
: circuit_constructor(size_hint)
, composer_helper(std::move(crs_factory))
, num_gates(circuit_constructor.num_gates)
Expand Down
15 changes: 6 additions & 9 deletions cpp/src/barretenberg/honk/proof_system/prover_library.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ template <class FF> class ProverLibraryTests : public testing::Test {
// Define some mock inputs for proving key constructor
static const size_t num_gates = 8;
static const size_t num_public_inputs = 0;
auto reference_string =
std::make_shared<proof_system::FileReferenceString>(num_gates + 1, "../srs_db/ignition");
auto reference_string = std::make_shared<FileReferenceString>(num_gates + 1, "../srs_db/ignition");

// Instatiate a proving_key and make a pointer to it. This will be used to instantiate a Prover.
auto proving_key = std::make_shared<plonk::proving_key>(
num_gates, num_public_inputs, reference_string, proof_system::ComposerType::STANDARD_HONK);
num_gates, num_public_inputs, reference_string, ComposerType::STANDARD_HONK);

// static const size_t program_width = StandardProver::settings_::program_width;

Expand Down Expand Up @@ -157,12 +156,11 @@ template <class FF> class ProverLibraryTests : public testing::Test {
// Define some mock inputs for proving key constructor
static const size_t circuit_size = 8;
static const size_t num_public_inputs = 0;
auto reference_string =
std::make_shared<proof_system::FileReferenceString>(circuit_size + 1, "../srs_db/ignition");
auto reference_string = std::make_shared<FileReferenceString>(circuit_size + 1, "../srs_db/ignition");

// Instatiate a proving_key and make a pointer to it. This will be used to instantiate a Prover.
auto proving_key = std::make_shared<plonk::proving_key>(
circuit_size, num_public_inputs, reference_string, proof_system::ComposerType::STANDARD_HONK);
circuit_size, num_public_inputs, reference_string, ComposerType::STANDARD_HONK);

// Construct mock wire and permutation polynomials.
// Note: for the purpose of checking the consistency between two methods of computing z_perm, these polynomials
Expand Down Expand Up @@ -287,10 +285,9 @@ template <class FF> class ProverLibraryTests : public testing::Test {
// Construct a proving_key
static const size_t circuit_size = 8;
static const size_t num_public_inputs = 0;
auto reference_string =
std::make_shared<proof_system::FileReferenceString>(circuit_size + 1, "../srs_db/ignition");
auto reference_string = std::make_shared<FileReferenceString>(circuit_size + 1, "../srs_db/ignition");
auto proving_key = std::make_shared<plonk::proving_key>(
circuit_size, num_public_inputs, reference_string, proof_system::ComposerType::STANDARD_HONK);
circuit_size, num_public_inputs, reference_string, ComposerType::STANDARD_HONK);

// Get random challenge eta
auto eta = FF::random_element();
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/barretenberg/honk/proof_system/verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ template <typename program_settings> bool Verifier<program_settings>::verify_pro
using Gemini = pcs::gemini::MultilinearReductionScheme<pcs::kzg::Params>;
using Shplonk = pcs::shplonk::SingleBatchOpeningScheme<pcs::kzg::Params>;
using KZG = pcs::kzg::UnivariateOpeningScheme<pcs::kzg::Params>;
const size_t NUM_POLYNOMIALS = proof_system::honk::StandardArithmetization::NUM_POLYNOMIALS;
const size_t NUM_UNSHIFTED = proof_system::honk::StandardArithmetization::NUM_UNSHIFTED_POLYNOMIALS;
const size_t NUM_PRECOMPUTED = proof_system::honk::StandardArithmetization::NUM_PRECOMPUTED_POLYNOMIALS;
const size_t NUM_POLYNOMIALS = honk::StandardArithmetization::NUM_POLYNOMIALS;
const size_t NUM_UNSHIFTED = honk::StandardArithmetization::NUM_UNSHIFTED_POLYNOMIALS;
const size_t NUM_PRECOMPUTED = honk::StandardArithmetization::NUM_PRECOMPUTED_POLYNOMIALS;

constexpr auto num_wires = program_settings::num_wires;

Expand Down
10 changes: 5 additions & 5 deletions cpp/src/barretenberg/honk/proof_system/verifier.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ template <class FF> class VerifierTests : public testing::Test {
prover));
}

auto crs = std::make_shared<proof_system::VerifierFileReferenceString>("../srs_db/ignition");
auto crs = std::make_shared<VerifierFileReferenceString>("../srs_db/ignition");
auto circuit_verification_key =
std::make_shared<plonk::verification_key>(circuit_proving_key->circuit_size,
circuit_proving_key->num_public_inputs,
Expand Down Expand Up @@ -82,9 +82,9 @@ template <class FF> class VerifierTests : public testing::Test {
// Create some constraints that satisfy our arithmetic circuit relation
// even indices = mul gates, odd incides = add gates

auto crs = std::make_shared<proof_system::FileReferenceString>(n + 1, "../srs_db/ignition");
auto crs = std::make_shared<FileReferenceString>(n + 1, "../srs_db/ignition");
std::shared_ptr<plonk::proving_key> proving_key =
std::make_shared<plonk::proving_key>(n, 0, crs, proof_system::ComposerType::STANDARD_HONK);
std::make_shared<plonk::proving_key>(n, 0, crs, ComposerType::STANDARD_HONK);

polynomial w_l(n);
polynomial w_r(n);
Expand Down Expand Up @@ -178,8 +178,8 @@ template <class FF> class VerifierTests : public testing::Test {
proving_key->polynomial_store.put("sigma_2_lagrange", std::move(sigma_2_lagrange_base));
proving_key->polynomial_store.put("sigma_3_lagrange", std::move(sigma_3_lagrange_base));

proof_system::compute_standard_honk_id_polynomials<3>(proving_key);
proof_system::compute_first_and_last_lagrange_polynomials(proving_key);
compute_standard_honk_id_polynomials<3>(proving_key);
compute_first_and_last_lagrange_polynomials(proving_key);

proving_key->polynomial_store.put("w_1_lagrange", std::move(w_l));
proving_key->polynomial_store.put("w_2_lagrange", std::move(w_r));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TYPED_TEST(MultivariatesTests, FoldTwoRoundsSpecial)
std::array<FF, 4> f0 = { v00, v10, v01, v11 };

auto full_polynomials = std::array<std::span<FF>, 1>({ f0 });
auto transcript = proof_system::honk::ProverTranscript<FF>::init_empty();
auto transcript = honk::ProverTranscript<FF>::init_empty();
auto sumcheck = Sumcheck<FF, Transcript, ArithmeticRelation>(multivariate_n, transcript);

FF round_challenge_0 = { 0x6c7301b49d85a46c, 0x44311531e39c64f6, 0xb13d66d8d6c1a24c, 0x04410c360230a295 };
Expand Down Expand Up @@ -94,7 +94,7 @@ TYPED_TEST(MultivariatesTests, FoldTwoRoundsGeneric)
std::array<FF, 4> f0 = { v00, v10, v01, v11 };

auto full_polynomials = std::array<std::span<FF>, 1>({ f0 });
auto transcript = proof_system::honk::ProverTranscript<FF>::init_empty();
auto transcript = honk::ProverTranscript<FF>::init_empty();
auto sumcheck = Sumcheck<FF, Transcript, ArithmeticRelation>(multivariate_n, transcript);

FF round_challenge_0 = FF::random_element();
Expand Down Expand Up @@ -153,7 +153,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsSpecial)
std::array<FF, 8> f0 = { v000, v100, v010, v110, v001, v101, v011, v111 };

auto full_polynomials = std::array<std::span<FF>, 1>({ f0 });
auto transcript = proof_system::honk::ProverTranscript<FF>::init_empty();
auto transcript = honk::ProverTranscript<FF>::init_empty();
auto sumcheck = Sumcheck<FF, Transcript, ArithmeticRelation>(multivariate_n, transcript);

FF round_challenge_0 = 1;
Expand Down Expand Up @@ -202,7 +202,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsGeneric)
std::array<FF, 8> f0 = { v000, v100, v010, v110, v001, v101, v011, v111 };

auto full_polynomials = std::array<std::span<FF>, 1>({ f0 });
auto transcript = proof_system::honk::ProverTranscript<FF>::init_empty();
auto transcript = honk::ProverTranscript<FF>::init_empty();
auto sumcheck = Sumcheck<FF, Transcript, ArithmeticRelation>(multivariate_n, transcript);

FF round_challenge_0 = FF::random_element();
Expand Down Expand Up @@ -261,7 +261,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsGenericMultiplePolys)
std::array<FF, 8> f2 = { v000[2], v100[2], v010[2], v110[2], v001[2], v101[2], v011[2], v111[2] };

auto full_polynomials = std::array<std::span<FF>, 3>{ f0, f1, f2 };
auto transcript = proof_system::honk::ProverTranscript<FF>::init_empty();
auto transcript = honk::ProverTranscript<FF>::init_empty();
auto sumcheck = Sumcheck<FF, Transcript, ArithmeticRelation>(multivariate_n, transcript);

std::array<FF, 3> expected_q1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ TYPED_TEST_SUITE(SumcheckRelation, FieldTypes);
TYPED_TEST(SumcheckRelation, ArithmeticRelation)
{
SUMCHECK_RELATION_TYPE_ALIASES
using MULTIVARIATE = proof_system::honk::StandardArithmetization::POLYNOMIAL;
using MULTIVARIATE = honk::StandardArithmetization::POLYNOMIAL;
const auto relation_parameters = TestFixture::compute_mock_relation_parameters();
auto run_test = [&relation_parameters](bool is_random_input) {
std::array<Univariate<FF, FULL_RELATION_LENGTH>, NUM_POLYNOMIALS> extended_edges;
Expand Down Expand Up @@ -216,7 +216,7 @@ TYPED_TEST(SumcheckRelation, ArithmeticRelation)
TYPED_TEST(SumcheckRelation, GrandProductComputationRelation)
{
SUMCHECK_RELATION_TYPE_ALIASES
using MULTIVARIATE = proof_system::honk::StandardArithmetization::POLYNOMIAL;
using MULTIVARIATE = honk::StandardArithmetization::POLYNOMIAL;
const auto relation_parameters = TestFixture::compute_mock_relation_parameters();
auto run_test = [&relation_parameters](bool is_random_input) {
std::array<Univariate<FF, FULL_RELATION_LENGTH>, NUM_POLYNOMIALS> extended_edges;
Expand Down Expand Up @@ -278,7 +278,7 @@ TYPED_TEST(SumcheckRelation, GrandProductComputationRelation)
TYPED_TEST(SumcheckRelation, GrandProductInitializationRelation)
{
SUMCHECK_RELATION_TYPE_ALIASES
using MULTIVARIATE = proof_system::honk::StandardArithmetization::POLYNOMIAL;
using MULTIVARIATE = honk::StandardArithmetization::POLYNOMIAL;
const auto relation_parameters = TestFixture::compute_mock_relation_parameters();
auto run_test = [&relation_parameters](bool is_random_input) {
std::array<Univariate<FF, FULL_RELATION_LENGTH>, NUM_POLYNOMIALS> extended_edges;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/join_split_example/proofs/verify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ template <typename Composer> struct verify_result {

template <typename Composer>
inline bool pairing_check(plonk::stdlib::recursion::recursion_output<plonk::stdlib::bn254<Composer>> recursion_output,
std::shared_ptr<proof_system::VerifierReferenceString> const& srs)
std::shared_ptr<VerifierReferenceString> const& srs)
{
g1::affine_element P[2];
P[0].x = barretenberg::fq(recursion_output.P0.x.get_value().lo);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/plonk/composer/composer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ template <size_t program_width, bool with_tags> void ComposerBase::compute_sigma
* @param num_reserved_gates The number of reserved gates.
* @return Pointer to the initialized proving key updated with selector polynomials.
* */
std::shared_ptr<proving_key> ComposerBase::compute_proving_key_base(const proof_system::ComposerType composer_type,
std::shared_ptr<proving_key> ComposerBase::compute_proving_key_base(const ComposerType composer_type,
const size_t minimum_circuit_size,
const size_t num_reserved_gates)
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/plonk/composer/composer_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ComposerBase {
virtual size_t get_total_circuit_size() const = 0;
virtual void print_num_gates() const { std::cout << num_gates << std::endl; }
virtual size_t get_num_variables() const { return variables.size(); }
virtual std::shared_ptr<proving_key> compute_proving_key_base(const proof_system::ComposerType type = STANDARD,
virtual std::shared_ptr<proving_key> compute_proving_key_base(const ComposerType type = STANDARD,
const size_t minimum_ciricut_size = 0,
const size_t num_reserved_gates = NUM_RESERVED_GATES);
// This needs to be static as it may be used only to compute the selector commitments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ void compute_monomial_and_coset_selector_forms(plonk::proving_key* circuit_provi
* (2) sets the polynomial manifest using the data from proving key.
*/
std::shared_ptr<plonk::verification_key> compute_verification_key_common(
std::shared_ptr<plonk::proving_key> const& proving_key,
std::shared_ptr<proof_system::VerifierReferenceString> const& vrs)
std::shared_ptr<plonk::proving_key> const& proving_key, std::shared_ptr<VerifierReferenceString> const& vrs)
{
auto circuit_verification_key = std::make_shared<plonk::verification_key>(
proving_key->circuit_size, proving_key->num_public_inputs, vrs, proving_key->composer_type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ void compute_monomial_and_coset_selector_forms(plonk::proving_key* key,
* (2) sets the polynomial manifest using the data from proving key.
*/
std::shared_ptr<plonk::verification_key> compute_verification_key_common(
std::shared_ptr<plonk::proving_key> const& proving_key,
std::shared_ptr<proof_system::VerifierReferenceString> const& vrs);
std::shared_ptr<plonk::proving_key> const& proving_key, std::shared_ptr<VerifierReferenceString> const& vrs);

} // namespace proof_system::plonk
Loading

0 comments on commit 892edd5

Please sign in to comment.