Skip to content

Commit

Permalink
Prep: move composer type, proving key and verification key. (AztecPro…
Browse files Browse the repository at this point in the history
…tocol/barretenberg#303)

* Move composer type from plonk to bonk.
* Move pk & vk into plonk.
* bonk ~>  proof_system; nest plonk and honk in it.
* proof_system independent of plonk.
  • Loading branch information
codygunton authored Apr 5, 2023
1 parent 34e1dfa commit e5aaece
Show file tree
Hide file tree
Showing 331 changed files with 1,571 additions and 1,642 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void create_prover_bench(State& state) noexcept
for (auto _ : state) {
state.PauseTiming();
auto num_gates = 1 << (size_t)state.range(0);
auto composer = honk::StandardHonkComposer(static_cast<size_t>(num_gates));
auto composer = proof_system::honk::StandardHonkComposer(static_cast<size_t>(num_gates));
generate_test_plonk_circuit(composer, static_cast<size_t>(num_gates));
state.ResumeTiming();

Expand All @@ -51,7 +51,7 @@ void create_verifier_bench(State& state) noexcept
for (auto _ : state) {
state.PauseTiming();
auto num_gates = 1 << (size_t)state.range(0);
auto composer = honk::StandardHonkComposer(static_cast<size_t>(num_gates));
auto composer = proof_system::honk::StandardHonkComposer(static_cast<size_t>(num_gates));
generate_test_plonk_circuit(composer, static_cast<size_t>(num_gates));
state.ResumeTiming();

Expand All @@ -68,7 +68,7 @@ void construct_proof_bench(State& state) noexcept
auto num_gates = 1 << (size_t)state.range(0);
for (auto _ : state) {
state.PauseTiming();
auto composer = honk::StandardHonkComposer(static_cast<size_t>(num_gates));
auto composer = proof_system::honk::StandardHonkComposer(static_cast<size_t>(num_gates));
generate_test_plonk_circuit(composer, static_cast<size_t>(num_gates));
auto ext_prover = composer.create_prover();
state.ResumeTiming();
Expand All @@ -90,7 +90,7 @@ void verify_proof_bench(State& state) noexcept
for (auto _ : state) {
state.PauseTiming();
auto num_gates = (size_t)state.range(0);
auto composer = honk::StandardHonkComposer(static_cast<size_t>(num_gates));
auto composer = proof_system::honk::StandardHonkComposer(static_cast<size_t>(num_gates));
generate_test_plonk_circuit(composer, static_cast<size_t>(num_gates));
auto prover = composer.create_prover();
auto proof = prover.construct_proof();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ constexpr size_t NUM_POINTS = 1 << 16;
std::vector<fr> scalars;
static barretenberg::evaluation_domain small_domain;
static barretenberg::evaluation_domain large_domain;
auto reference_string = std::make_shared<bonk::FileReferenceString>(NUM_POINTS, "../srs_db/ignition");
auto reference_string = std::make_shared<proof_system::FileReferenceString>(NUM_POINTS, "../srs_db/ignition");

const auto init = []() {
small_domain = barretenberg::evaluation_domain(NUM_POINTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void construct_witnesses_bench(State& state) noexcept
{
for (auto _ : state) {
state.PauseTiming();
plonk::StandardComposer composer = plonk::StandardComposer(static_cast<size_t>(state.range(0)));
plonk::StandardComposer composer = proof_system::plonk::StandardComposer(static_cast<size_t>(state.range(0)));
generate_test_plonk_circuit(composer, static_cast<size_t>(state.range(0)));
composer.compute_proving_key();
state.ResumeTiming();
Expand All @@ -49,7 +49,7 @@ BENCHMARK(construct_witnesses_bench)->RangeMultiplier(2)->Range(START, MAX_GATES
void construct_proving_keys_bench(State& state) noexcept
{
for (auto _ : state) {
plonk::StandardComposer composer = plonk::StandardComposer(static_cast<size_t>(state.range(0)));
plonk::StandardComposer composer = proof_system::plonk::StandardComposer(static_cast<size_t>(state.range(0)));
generate_test_plonk_circuit(composer, static_cast<size_t>(state.range(0)));
size_t idx = static_cast<size_t>(numeric::get_msb((uint64_t)state.range(0))) -
static_cast<size_t>(numeric::get_msb(START));
Expand All @@ -65,7 +65,7 @@ void construct_instances_bench(State& state) noexcept
{
for (auto _ : state) {
state.PauseTiming();
plonk::StandardComposer composer = plonk::StandardComposer(static_cast<size_t>(state.range(0)));
plonk::StandardComposer composer = proof_system::plonk::StandardComposer(static_cast<size_t>(state.range(0)));
generate_test_plonk_circuit(composer, static_cast<size_t>(state.range(0)));
size_t idx = static_cast<size_t>(numeric::get_msb((uint64_t)state.range(0))) -
static_cast<size_t>(numeric::get_msb(START));
Expand Down
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 Expand Up @@ -88,7 +88,7 @@ void create_circuit(Composer& composer, const acir_format& constraint_system)
}

Composer create_circuit(const acir_format& constraint_system,
std::unique_ptr<bonk::ReferenceStringFactory>&& crs_factory)
std::unique_ptr<proof_system::ReferenceStringFactory>&& crs_factory)
{
if (constraint_system.public_inputs.size() > constraint_system.varnum) {
std::cout << "too many public inputs!" << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void read_witness(plonk::stdlib::types::Composer& composer, std::vector<barreten
void create_circuit(plonk::stdlib::types::Composer& composer, const acir_format& constraint_system);

plonk::stdlib::types::Composer create_circuit(const acir_format& constraint_system,
std::unique_ptr<bonk::ReferenceStringFactory>&& crs_factory);
std::unique_ptr<proof_system::ReferenceStringFactory>&& crs_factory);

plonk::stdlib::types::Composer create_circuit_with_witness(const acir_format& constraint_system,
std::vector<fr> witness,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "blake2s_constraint.hpp"
#include "round.hpp"

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

namespace acir_format {

Expand All @@ -26,7 +26,7 @@ void create_blake2s_constraints(Composer& composer, const Blake2sConstraint& con
arr.write(element_bytes);
}

byte_array_ct output_bytes = plonk::stdlib::blake2s<Composer>(arr);
byte_array_ct output_bytes = proof_system::plonk::stdlib::blake2s<Composer>(arr);

// Convert byte array to vector of field_t
auto bytes = output_bytes.bytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "barretenberg/crypto/ecdsa/ecdsa.hpp"
#include "barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp"

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

namespace acir_format {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "fixed_base_scalar_mul.hpp"

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

namespace acir_format {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "hash_to_field.hpp"
#include "round.hpp"

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

namespace acir_format {

Expand Down Expand Up @@ -30,7 +30,7 @@ void create_hash_to_field_constraints(Composer& composer, const HashToFieldConst
// Hash To Field using blake2s.
// Note: It does not need to be blake2s in the future

byte_array_ct out_bytes = plonk::stdlib::blake2s<Composer>(arr);
byte_array_ct out_bytes = proof_system::plonk::stdlib::blake2s<Composer>(arr);

field_ct out(out_bytes);
field_ct normalised_out = out.normalize();
Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "merkle_membership_constraint.hpp"
#include "barretenberg/stdlib/merkle_tree/membership.hpp"

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

namespace acir_format {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "pedersen.hpp"

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

namespace acir_format {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "schnorr_verify.hpp"
#include "barretenberg/crypto/schnorr/schnorr.hpp"

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

namespace acir_format {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "round.hpp"
#include "barretenberg/stdlib/hash/sha256/sha256.hpp"

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

namespace acir_format {

Expand Down Expand Up @@ -30,7 +30,7 @@ void create_sha256_constraints(Composer& composer, const Sha256Constraint& const
}

// Compute sha256
byte_array_ct output_bytes = plonk::stdlib::sha256<Composer>(arr);
byte_array_ct output_bytes = proof_system::plonk::stdlib::sha256<Composer>(arr);

// Convert byte array to vector of field_t
auto bytes = output_bytes.bytes();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@

#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 plonk::stdlib::types;
using namespace proof_system::plonk::stdlib::types;

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 @@ -32,7 +32,7 @@ size_t get_solidity_verifier(uint8_t const* g2x, uint8_t const* vk_buf, uint8_t*
uint32_t get_exact_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));

auto num_gates = composer.get_num_gates();
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 All @@ -69,9 +69,9 @@ size_t init_proving_key(uint8_t const* constraint_system_buf, uint8_t const** pk
size_t init_verification_key(void* pippenger, uint8_t const* g2x, uint8_t const* pk_buf, uint8_t const** vk_buf)
{
std::shared_ptr<ProverReferenceString> crs;
bonk::proving_key_data pk_data;
plonk::proving_key_data pk_data;
read(pk_buf, pk_data);
auto proving_key = std::make_shared<bonk::proving_key>(std::move(pk_data), crs);
auto proving_key = std::make_shared<plonk::proving_key>(std::move(pk_data), crs);

auto crs_factory = std::make_unique<PippengerReferenceStringFactory>(
reinterpret_cast<scalar_multiplication::Pippenger*>(pippenger), g2x);
Expand All @@ -83,7 +83,7 @@ size_t init_verification_key(void* pippenger, uint8_t const* g2x, uint8_t const*

// The composer_type has not yet been set. We need to set the composer_type for when we later read in and
// construct the verification key so that we have the correct polynomial manifest
verification_key->composer_type = ComposerType::PLOOKUP;
verification_key->composer_type = proof_system::ComposerType::PLOOKUP;

auto buffer = to_buffer(*verification_key);
auto raw_buf = (uint8_t*)malloc(buffer.size());
Expand All @@ -103,9 +103,9 @@ size_t new_proof(void* pippenger,
auto constraint_system = from_buffer<acir_format::acir_format>(constraint_system_buf);

std::shared_ptr<ProverReferenceString> crs;
bonk::proving_key_data pk_data;
plonk::proving_key_data pk_data;
read(pk_buf, pk_data);
auto proving_key = std::make_shared<bonk::proving_key>(std::move(pk_data), crs);
auto proving_key = std::make_shared<plonk::proving_key>(std::move(pk_data), crs);

auto witness = from_buffer<std::vector<fr>>(witness_buf);

Expand Down Expand Up @@ -136,9 +136,9 @@ bool verify_proof(
#endif
auto constraint_system = from_buffer<acir_format::acir_format>(constraint_system_buf);
auto crs = std::make_shared<VerifierMemReferenceString>(g2x);
bonk::verification_key_data vk_data;
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);

Composer composer(nullptr, verification_key);
create_circuit(composer, constraint_system);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

namespace bonk {
namespace proof_system {
enum CurveType { BN254, SECP256K1, SECP256R1, GRUMPKIN };
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
barretenberg_module(honk numeric ecc srs proof_system transcript)
# TODO(Cody): Remove plonk dependency
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 @@ -8,7 +8,7 @@
#include <cstdint>
#include <string>

namespace honk {
namespace proof_system::honk {

/**
* Compute proving key base.
Expand All @@ -23,16 +23,13 @@ namespace honk {
* @return Pointer to the initialized proving key updated with selector polynomials.
* */
template <typename CircuitConstructor>
std::shared_ptr<bonk::proving_key> StandardHonkComposerHelper<CircuitConstructor>::compute_proving_key_base(
std::shared_ptr<plonk::proving_key> StandardHonkComposerHelper<CircuitConstructor>::compute_proving_key_base(
const CircuitConstructor& constructor, const size_t minimum_circuit_size, const size_t num_randomized_gates)
{
// 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,
plonk::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 @@ -46,10 +43,10 @@ std::shared_ptr<bonk::proving_key> StandardHonkComposerHelper<CircuitConstructor
*/

template <typename CircuitConstructor>
std::shared_ptr<bonk::verification_key> StandardHonkComposerHelper<CircuitConstructor>::compute_verification_key_base(
std::shared_ptr<bonk::proving_key> const& proving_key, std::shared_ptr<bonk::VerifierReferenceString> const& vrs)
std::shared_ptr<plonk::verification_key> StandardHonkComposerHelper<CircuitConstructor>::compute_verification_key_base(
std::shared_ptr<plonk::proving_key> const& proving_key, std::shared_ptr<VerifierReferenceString> const& vrs)
{
auto key = std::make_shared<bonk::verification_key>(
auto key = std::make_shared<plonk::verification_key>(
proving_key->circuit_size, proving_key->num_public_inputs, vrs, proving_key->composer_type);
// TODO(kesha): Dirty hack for now. Need to actually make commitment-agnositc
auto commitment_key = pcs::kzg::CommitmentKey(proving_key->circuit_size, "../srs_db/ignition");
Expand Down Expand Up @@ -101,14 +98,14 @@ void StandardHonkComposerHelper<CircuitConstructor>::compute_witness(const Circu
* */

template <typename CircuitConstructor>
std::shared_ptr<bonk::proving_key> StandardHonkComposerHelper<CircuitConstructor>::compute_proving_key(
std::shared_ptr<plonk::proving_key> StandardHonkComposerHelper<CircuitConstructor>::compute_proving_key(
const CircuitConstructor& circuit_constructor)
{
if (circuit_proving_key) {
return circuit_proving_key;
}
// Compute q_l, q_r, q_o, etc polynomials
StandardHonkComposerHelper::compute_proving_key_base(circuit_constructor, plonk::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 All @@ -126,7 +123,7 @@ std::shared_ptr<bonk::proving_key> StandardHonkComposerHelper<CircuitConstructor
* @return Pointer to created circuit verification key.
* */
template <typename CircuitConstructor>
std::shared_ptr<bonk::verification_key> StandardHonkComposerHelper<CircuitConstructor>::compute_verification_key(
std::shared_ptr<plonk::verification_key> StandardHonkComposerHelper<CircuitConstructor>::compute_verification_key(
const CircuitConstructor& circuit_constructor)
{
if (circuit_verification_key) {
Expand Down Expand Up @@ -182,4 +179,4 @@ StandardProver StandardHonkComposerHelper<CircuitConstructor>::create_prover(
template class StandardHonkComposerHelper<StandardCircuitConstructor>;
template StandardProver StandardHonkComposerHelper<StandardCircuitConstructor>::create_prover<StandardHonk>(
const StandardCircuitConstructor& circuit_constructor);
} // namespace honk
} // namespace proof_system::honk
Loading

0 comments on commit e5aaece

Please sign in to comment.