Skip to content

Commit

Permalink
proof_system independent of plonk.
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Apr 5, 2023
1 parent b97db86 commit 796490a
Show file tree
Hide file tree
Showing 114 changed files with 457 additions and 685 deletions.
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_format/acir_format.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "acir_format.hpp"

using namespace plonk::stdlib::types;
using namespace proof_system::plonk::stdlib::types;

namespace acir_format {

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_format/logic_constraint.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "logic_constraint.hpp"
#include "barretenberg/stdlib/primitives/logic/logic.hpp"

using namespace plonk::stdlib::types;
using namespace proof_system::plonk::stdlib::types;

namespace acir_format {

Expand Down
12 changes: 6 additions & 6 deletions cpp/src/barretenberg/dsl/acir_proofs/acir_proofs.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#include "acir_proofs.hpp"
#include "barretenberg/proof_system/proving_key/serialize.hpp"
#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp"
#include "barretenberg/dsl/acir_format/acir_format.hpp"
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/srs/reference_string/pippenger_reference_string.hpp"
#include "barretenberg/proof_system/verification_key/sol_gen.hpp"
#include "barretenberg/plonk/proof_system/verification_key/sol_gen.hpp"

using namespace proof_system::plonk::stdlib::types;

Expand All @@ -13,9 +13,9 @@ namespace acir_proofs {
size_t get_solidity_verifier(uint8_t const* g2x, uint8_t const* vk_buf, uint8_t** output_buf)
{
auto crs = std::make_shared<VerifierMemReferenceString>(g2x);
bonk::verification_key_data vk_data;
proof_system::plonk::verification_key_data vk_data;
read(vk_buf, vk_data);
auto verification_key = std::make_shared<bonk::verification_key>(std::move(vk_data), crs);
auto verification_key = std::make_shared<proof_system::plonk::verification_key>(std::move(vk_data), crs);

std::ostringstream stream;
// TODO(blaine): Should we just use "VerificationKey" generically?
Expand All @@ -42,7 +42,7 @@ uint32_t get_exact_circuit_size(uint8_t const* constraint_system_buf)
uint32_t get_total_circuit_size(uint8_t const* constraint_system_buf)
{
auto constraint_system = from_buffer<acir_format::acir_format>(constraint_system_buf);
auto crs_factory = std::make_unique<bonk::ReferenceStringFactory>();
auto crs_factory = std::make_unique<proof_system::ReferenceStringFactory>();
auto composer = create_circuit(constraint_system, std::move(crs_factory));

return static_cast<uint32_t>(composer.get_total_circuit_size());
Expand Down Expand Up @@ -138,7 +138,7 @@ bool verify_proof(
auto crs = std::make_shared<VerifierMemReferenceString>(g2x);
plonk::verification_key_data vk_data;
read(vk_buf, vk_data);
auto verification_key = std::make_shared<plonk::verification_key>(std::move(vk_data), crs);
auto verification_key = std::make_shared<proof_system::plonk::verification_key>(std::move(vk_data), crs);

Composer composer(nullptr, verification_key);
create_circuit(composer, constraint_system);
Expand Down
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
Loading

0 comments on commit 796490a

Please sign in to comment.