Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Goblin acir composer #4112

Merged
merged 25 commits into from
Jan 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a485b04
split honk acir composer from original
ledwards2225 Jan 17, 2024
44259ee
use accumulate framework for basic GUH
ledwards2225 Jan 17, 2024
735fd29
use accumulate nomenclature
ledwards2225 Jan 17, 2024
ebbc8f7
update to use accumulate nomenclature everywhere
ledwards2225 Jan 18, 2024
f95a12a
update docker files to use accumulate
ledwards2225 Jan 18, 2024
22bfac8
debug prints
ledwards2225 Jan 18, 2024
934e38a
full goblin verifies
ledwards2225 Jan 18, 2024
1402ef7
cleanup and commenting
ledwards2225 Jan 18, 2024
851d430
Add goblin flow to docker
ledwards2225 Jan 18, 2024
f370400
name change honk to goblin
ledwards2225 Jan 18, 2024
8c7ef97
Merge branch 'master' into lde/honk_acir_composer
ledwards2225 Jan 18, 2024
8fc65a4
fix wasm: create goblin acir composer
ledwards2225 Jan 18, 2024
d9f5b67
fix index ts formatting
ledwards2225 Jan 18, 2024
a05e3b4
removed grumpkin from the wrong flow
ledwards2225 Jan 18, 2024
d415de2
js flow for full goblin prove and verify
ledwards2225 Jan 19, 2024
4a14cdc
debug
ledwards2225 Jan 19, 2024
8b71f47
test faking it with accum methods
ledwards2225 Jan 19, 2024
a49026b
Merge branch 'master' into lde/honk_acir_composer
ledwards2225 Jan 19, 2024
52c52a2
WiP debug
ledwards2225 Jan 19, 2024
3c91cdc
Merge branch 'master' into lde/honk_acir_composer
ledwards2225 Jan 19, 2024
28c085c
bring it all together
ledwards2225 Jan 19, 2024
cad7ac7
Merge branch 'master' into lde/honk_acir_composer
ledwards2225 Jan 22, 2024
91fc81e
fix bberg and acir
ledwards2225 Jan 22, 2024
57af750
additional comments
ledwards2225 Jan 22, 2024
f8efa12
Merge branch 'master' into lde/honk_acir_composer
ledwards2225 Jan 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
split honk acir composer from original
ledwards2225 committed Jan 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit a485b041b6a32a015cc3453d3bb2b312129dd933
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
#include <barretenberg/common/timer.hpp>
#include <barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp>
#include <barretenberg/dsl/acir_proofs/acir_composer.hpp>
#include <barretenberg/dsl/acir_proofs/honk_acir_composer.hpp>
#include <barretenberg/srs/global_crs.hpp>
#include <iostream>
#include <stdexcept>
@@ -135,7 +136,7 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath,
auto constraint_system = get_constraint_system(bytecodePath);
auto witness = get_witness(witnessPath);

acir_proofs::AcirComposer acir_composer;
acir_proofs::HonkAcirComposer acir_composer;
acir_composer.create_goblin_circuit(constraint_system, witness);

// TODO(https://github.com/AztecProtocol/barretenberg/issues/811): Don't hardcode dyadic circuit size. Currently set
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
#include "barretenberg/common/throw_or_abort.hpp"
#include "barretenberg/dsl/acir_format/acir_format.hpp"
#include "barretenberg/dsl/types.hpp"
#include "barretenberg/goblin/mock_circuits.hpp"
#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp"
#include "barretenberg/plonk/proof_system/verification_key/sol_gen.hpp"
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
@@ -61,27 +60,6 @@ std::vector<uint8_t> AcirComposer::create_proof(bool is_recursive)
return proof;
}

void AcirComposer::create_goblin_circuit(acir_format::acir_format& constraint_system,
acir_format::WitnessVector& witness)
{
// Construct a builder using the witness and public input data from acir
goblin_builder_ = acir_format::GoblinBuilder{
goblin.op_queue, witness, constraint_system.public_inputs, constraint_system.varnum
};

// Populate constraints in the builder via the data in constraint_system
acir_format::build_constraints(goblin_builder_, constraint_system, true);

// TODO(https://github.com/AztecProtocol/barretenberg/issues/817): Add some arbitrary op gates to ensure the
// associated polynomials are non-zero and to give ECCVM and Translator some ECC ops to process.
GoblinMockCircuits::construct_goblin_ecc_op_circuit(goblin_builder_);
}

std::vector<uint8_t> AcirComposer::create_goblin_proof()
{
return goblin.construct_proof(goblin_builder_);
}

std::shared_ptr<proof_system::plonk::verification_key> AcirComposer::init_verification_key()
{
if (!proving_key_) {
@@ -132,11 +110,6 @@ bool AcirComposer::verify_proof(std::vector<uint8_t> const& proof, bool is_recur
}
}

bool AcirComposer::verify_goblin_proof(std::vector<uint8_t> const& proof)
{
return goblin.verify_proof({ proof });
}

std::string AcirComposer::get_solidity_verifier()
{
std::ostringstream stream;
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include <barretenberg/dsl/acir_format/acir_format.hpp>
#include <barretenberg/goblin/goblin.hpp>

namespace acir_proofs {

@@ -38,15 +37,8 @@ class AcirComposer {

std::vector<bb::fr> serialize_verification_key_into_fields();

// Goblin specific methods
void create_goblin_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness);
std::vector<uint8_t> create_goblin_proof();
bool verify_goblin_proof(std::vector<uint8_t> const& proof);

private:
acir_format::Builder builder_;
acir_format::GoblinBuilder goblin_builder_;
Goblin goblin;
size_t size_hint_;
std::shared_ptr<proof_system::plonk::proving_key> proving_key_;
std::shared_ptr<proof_system::plonk::verification_key> verification_key_;
5 changes: 3 additions & 2 deletions barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
#include "barretenberg/common/serialize.hpp"
#include "barretenberg/common/slab_allocator.hpp"
#include "barretenberg/dsl/acir_format/acir_format.hpp"
#include "barretenberg/dsl/acir_proofs/honk_acir_composer.hpp"
#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp"
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
#include "barretenberg/srs/global_crs.hpp"
@@ -62,7 +63,7 @@ WASM_EXPORT void acir_create_goblin_proof(in_ptr acir_composer_ptr,
uint8_t const* witness_vec,
uint8_t** out)
{
auto acir_composer = reinterpret_cast<acir_proofs::AcirComposer*>(*acir_composer_ptr);
auto acir_composer = reinterpret_cast<acir_proofs::HonkAcirComposer*>(*acir_composer_ptr);
auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec));
auto witness = acir_format::witness_buf_to_witness_data(from_buffer<std::vector<uint8_t>>(witness_vec));

@@ -104,7 +105,7 @@ WASM_EXPORT void acir_get_proving_key(in_ptr acir_composer_ptr, uint8_t const* a

WASM_EXPORT void acir_verify_goblin_proof(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result)
{
auto acir_composer = reinterpret_cast<acir_proofs::AcirComposer*>(*acir_composer_ptr);
auto acir_composer = reinterpret_cast<acir_proofs::HonkAcirComposer*>(*acir_composer_ptr);
auto proof = from_buffer<std::vector<uint8_t>>(proof_buf);
*result = acir_composer->verify_goblin_proof(proof);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "honk_acir_composer.hpp"
#include "barretenberg/common/throw_or_abort.hpp"
#include "barretenberg/dsl/acir_format/acir_format.hpp"
#include "barretenberg/dsl/types.hpp"
#include "barretenberg/goblin/mock_circuits.hpp"

namespace acir_proofs {

HonkAcirComposer::HonkAcirComposer(size_t size_hint, bool verbose)
: size_hint_(size_hint)
, verbose_(verbose)
{}

void HonkAcirComposer::create_goblin_circuit(acir_format::acir_format& constraint_system,
acir_format::WitnessVector& witness)
{
// Construct a builder using the witness and public input data from acir
goblin_builder_ = acir_format::GoblinBuilder{
goblin.op_queue, witness, constraint_system.public_inputs, constraint_system.varnum
};

// Populate constraints in the builder via the data in constraint_system
acir_format::build_constraints(goblin_builder_, constraint_system, true);

// TODO(https://github.com/AztecProtocol/barretenberg/issues/817): Add some arbitrary op gates to ensure the
// associated polynomials are non-zero and to give ECCVM and Translator some ECC ops to process.
GoblinMockCircuits::construct_goblin_ecc_op_circuit(goblin_builder_);
}

std::vector<uint8_t> HonkAcirComposer::create_goblin_proof()
{
return goblin.construct_proof(goblin_builder_);
}

bool HonkAcirComposer::verify_goblin_proof(std::vector<uint8_t> const& proof)
{
return goblin.verify_proof({ proof });
}

} // namespace acir_proofs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once
#include <barretenberg/dsl/acir_format/acir_format.hpp>
#include <barretenberg/goblin/goblin.hpp>

namespace acir_proofs {

/**
* @brief A class responsible for marshalling construction of keys and prover and verifier instances used to prove
* satisfiability of circuits written in ACIR.
* @todo: This reflects the design of Plonk. Perhaps we should author new classes to better reflect the
* structure of the newer code since there's much more of that code now?
*/
class HonkAcirComposer {

using WitnessVector = std::vector<fr, ContainerSlabAllocator<fr>>;

public:
HonkAcirComposer(size_t size_hint = 0, bool verbose = true);

// Goblin specific methods
void create_goblin_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness);
std::vector<uint8_t> create_goblin_proof();
bool verify_goblin_proof(std::vector<uint8_t> const& proof);

private:
acir_format::GoblinBuilder goblin_builder_;
Goblin goblin;
size_t size_hint_;
bool verbose_ = true;

template <typename... Args> inline void vinfo(Args... args)
{
if (verbose_) {
info(args...);
}
}
};

} // namespace acir_proofs