Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Introducing the flavor classes (mainly honk, splash of plonk)
---------

Co-authored-by: ledwards2225 <[email protected]>
  • Loading branch information
codygunton and ledwards2225 authored May 4, 2023
1 parent 63104aa commit 2b35104
Show file tree
Hide file tree
Showing 80 changed files with 3,436 additions and 2,524 deletions.
24 changes: 11 additions & 13 deletions circuits/cpp/barretenberg/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
name: "Build"
command: cond_spot_run_build barretenberg-x86_64-linux-clang-assert 64

barretenberg-tests:
stdlib-tests:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
Expand All @@ -157,10 +157,10 @@ jobs:
- *setup_env
- run:
name: "Test"
command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 1 bb-tests
command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 1 stdlib-tests
- *save_logs

honk-tests:
barretenberg-tests:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
Expand All @@ -169,11 +169,10 @@ jobs:
- *setup_env
- run:
name: "Test"
command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 1 honk_tests
command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 1 bb-tests
- *save_logs


stdlib-primitives-tests:
honk-tests:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
Expand All @@ -182,10 +181,10 @@ jobs:
- *setup_env
- run:
name: "Test"
command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 1 stdlib_primitives_tests --gtest_filter=-stdlib_biggroup*
command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 1 honk_tests
- *save_logs

stdlib-biggroup-tests:
proof-system-tests:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
Expand All @@ -194,7 +193,7 @@ jobs:
- *setup_env
- run:
name: "Test"
command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 1 stdlib_primitives_tests --gtest_filter=stdlib_biggroup*
command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 1 proof_system_tests
- *save_logs

stdlib-recursion-turbo-tests:
Expand Down Expand Up @@ -323,18 +322,17 @@ workflows:
- x86_64-linux-clang: *defaults
- x86_64-linux-clang-assert: *defaults
- wasm-linux-clang: *defaults
- proof-system-tests: *bb_test
- honk-tests: *bb_test
- barretenberg-tests: *bb_test
- stdlib-primitives-tests: *bb_test
- stdlib-biggroup-tests: *bb_test
- stdlib-tests: *bb_test
- stdlib-recursion-turbo-tests: *bb_test
- stdlib-recursion-ultra-tests: *bb_test
- join-split-tests: *bb_test
- benchmark-aggregator:
requires:
- barretenberg-tests
- stdlib-primitives-tests
- stdlib-biggroup-tests
- stdlib-tests
- stdlib-recursion-turbo-tests
- stdlib-recursion-ultra-tests
- join-split-tests
Expand Down
4 changes: 4 additions & 0 deletions circuits/cpp/barretenberg/barretenberg.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
// to the default value "clangd".
//
"clangd.path": "clangd-15",
// We should disable automatic inclusion of headers unless we decide to follow "WhyIWYU".
"clangd.arguments": [
"-header-insertion=never"
]
//
// CMake
//
Expand Down
11 changes: 8 additions & 3 deletions circuits/cpp/barretenberg/cpp/.clangd
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ CompileFlags: # Tweak the parse settings
If:
PathMatch: [src/.*\.hpp, src/.*\.cpp, src/.*\.tcc]
Diagnostics:
# Checks whether we are including unused header files
# Value Strict checks whether we are including unused header files
# Note that some headers may be _implicitly_ used and still
# need to be included, so be careful before removing them.
UnusedIncludes: Strict
# need to be included. This is very noisy, and is probably best used
# by occasionally toggling it on.
UnusedIncludes: None

# Static analysis configuration
ClangTidy:
Expand Down Expand Up @@ -56,6 +57,10 @@ Diagnostics:
- cert-err58-cpp
# Triggers on some tests that are not complex
- readability-function-cognitive-complexity
# It is often nicer to not be explicit
- google-explicit-constructor
CheckOptions:
- cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: True

--- # this divider is necessary
# Disable some checks for Google Test/Bench
Expand Down
11 changes: 1 addition & 10 deletions circuits/cpp/barretenberg/cpp/scripts/bb-tests
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@ ecc_tests
numeric_tests
plonk_tests
polynomials_tests
proof_system_tests
join_split_example_proofs_inner_proof_data_tests
join_split_example_proofs_notes_tests
srs_tests
stdlib_aes128_tests
stdlib_blake2s_tests
stdlib_blake3s_tests
stdlib_ecdsa_tests
stdlib_merkle_tree_tests
stdlib_pedersen_commitment_tests
stdlib_schnorr_tests
stdlib_sha256_tests
transcript_tests
transcript_tests
9 changes: 9 additions & 0 deletions circuits/cpp/barretenberg/cpp/scripts/stdlib-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
stdlib_primitives_tests
stdlib_aes128_tests
stdlib_blake2s_tests
stdlib_blake3s_tests
stdlib_ecdsa_tests
stdlib_merkle_tree_tests
stdlib_pedersen_commitment_tests
stdlib_schnorr_tests
stdlib_sha256_tests
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "standard_honk_composer_helper.hpp"
#include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/honk/flavor/flavor.hpp"
#include "barretenberg/honk/pcs/commitment_key.hpp"
#include "barretenberg/numeric/bitop/get_msb.hpp"
#include "barretenberg/srs/reference_string/reference_string.hpp"

#include <cstddef>
#include <cstdint>
Expand All @@ -14,26 +15,25 @@ namespace proof_system::honk {
* Compute proving key base.
*
* 1. Load crs.
* 2. Initialize this.circuit_proving_key.
* 2. Initialize this->proving_key.
* 3. Create constraint selector polynomials from each of this composer's `selectors` vectors and add them to the
* proving key.
*
* @param minimum_circuit_size Used as the total number of gates when larger than n + count of public inputs.
* @param num_reserved_gates The number of reserved gates.
* @return Pointer to the initialized proving key updated with selector polynomials.
* */
template <typename CircuitConstructor>
std::shared_ptr<plonk::proving_key> StandardHonkComposerHelper<CircuitConstructor>::compute_proving_key_base(
std::shared_ptr<StandardHonkComposerHelper::ProvingKey> StandardHonkComposerHelper::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(
// Initialize proving_key
// TODO(#392)(Kesha): replace composer types.
proving_key = initialize_proving_key<Flavor>(
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());
construct_selector_polynomials<Flavor>(constructor, proving_key.get());

return circuit_proving_key;
return proving_key;
}

/**
Expand All @@ -42,29 +42,29 @@ std::shared_ptr<plonk::proving_key> StandardHonkComposerHelper<CircuitConstructo
* (2) sets the polynomial manifest using the data from proving key.
*/

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<VerifierReferenceString> const& vrs)
std::shared_ptr<StandardHonkComposerHelper::VerificationKey> StandardHonkComposerHelper::compute_verification_key_base(
std::shared_ptr<StandardHonkComposerHelper::ProvingKey> const& proving_key,
std::shared_ptr<VerifierReferenceString> const& vrs)
{
auto key = std::make_shared<plonk::verification_key>(
auto key = std::make_shared<VerificationKey>(
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");

// Compute and store commitments to all precomputed polynomials
key->commitments["Q_M"] = commitment_key.commit(proving_key->polynomial_store.get("q_m_lagrange"));
key->commitments["Q_1"] = commitment_key.commit(proving_key->polynomial_store.get("q_1_lagrange"));
key->commitments["Q_2"] = commitment_key.commit(proving_key->polynomial_store.get("q_2_lagrange"));
key->commitments["Q_3"] = commitment_key.commit(proving_key->polynomial_store.get("q_3_lagrange"));
key->commitments["Q_C"] = commitment_key.commit(proving_key->polynomial_store.get("q_c_lagrange"));
key->commitments["SIGMA_1"] = commitment_key.commit(proving_key->polynomial_store.get("sigma_1_lagrange"));
key->commitments["SIGMA_2"] = commitment_key.commit(proving_key->polynomial_store.get("sigma_2_lagrange"));
key->commitments["SIGMA_3"] = commitment_key.commit(proving_key->polynomial_store.get("sigma_3_lagrange"));
key->commitments["ID_1"] = commitment_key.commit(proving_key->polynomial_store.get("id_1_lagrange"));
key->commitments["ID_2"] = commitment_key.commit(proving_key->polynomial_store.get("id_2_lagrange"));
key->commitments["ID_3"] = commitment_key.commit(proving_key->polynomial_store.get("id_3_lagrange"));
key->commitments["LAGRANGE_FIRST"] = commitment_key.commit(proving_key->polynomial_store.get("L_first_lagrange"));
key->commitments["LAGRANGE_LAST"] = commitment_key.commit(proving_key->polynomial_store.get("L_last_lagrange"));
key->q_m = commitment_key.commit(proving_key->q_m);
key->q_l = commitment_key.commit(proving_key->q_l);
key->q_r = commitment_key.commit(proving_key->q_r);
key->q_o = commitment_key.commit(proving_key->q_o);
key->q_c = commitment_key.commit(proving_key->q_c);
key->sigma_1 = commitment_key.commit(proving_key->sigma_1);
key->sigma_2 = commitment_key.commit(proving_key->sigma_2);
key->sigma_3 = commitment_key.commit(proving_key->sigma_3);
key->id_1 = commitment_key.commit(proving_key->id_1);
key->id_2 = commitment_key.commit(proving_key->id_2);
key->id_3 = commitment_key.commit(proving_key->id_3);
key->lagrange_first = commitment_key.commit(proving_key->lagrange_first);
key->lagrange_last = commitment_key.commit(proving_key->lagrange_last);

return key;
}
Expand All @@ -78,14 +78,18 @@ std::shared_ptr<plonk::verification_key> StandardHonkComposerHelper<CircuitConst
*
* @tparam Program settings needed to establish if w_4 is being used.
* */
template <typename CircuitConstructor>
void StandardHonkComposerHelper<CircuitConstructor>::compute_witness(const CircuitConstructor& circuit_constructor,
const size_t minimum_circuit_size)
void StandardHonkComposerHelper::compute_witness(const CircuitConstructor& circuit_constructor,
const size_t minimum_circuit_size)
{
if (computed_witness) {
return;
}
wire_polynomials = compute_witness_base(circuit_constructor, minimum_circuit_size, NUM_RANDOMIZED_GATES);
auto wire_polynomials =
construct_wire_polynomials_base<Flavor>(circuit_constructor, minimum_circuit_size, NUM_RANDOMIZED_GATES);

proving_key->w_l = wire_polynomials[0];
proving_key->w_r = wire_polynomials[1];
proving_key->w_o = wire_polynomials[2];

computed_witness = true;
}
Expand All @@ -97,55 +101,51 @@ void StandardHonkComposerHelper<CircuitConstructor>::compute_witness(const Circu
* @return Proving key with saved computed polynomials.
* */

template <typename CircuitConstructor>
std::shared_ptr<plonk::proving_key> StandardHonkComposerHelper<CircuitConstructor>::compute_proving_key(
std::shared_ptr<StandardHonkComposerHelper::ProvingKey> StandardHonkComposerHelper::compute_proving_key(
const CircuitConstructor& circuit_constructor)
{
if (circuit_proving_key) {
return circuit_proving_key;
if (proving_key) {
return proving_key;
}
// Compute q_l, q_r, q_o, etc polynomials
StandardHonkComposerHelper::compute_proving_key_base(circuit_constructor, ComposerType::STANDARD_HONK);
StandardHonkComposerHelper::compute_proving_key_base(
circuit_constructor, /*minimum_circuit_size=*/0, NUM_RANDOMIZED_GATES);

// Compute sigma polynomials (we should update that late)
compute_standard_honk_sigma_permutations<CircuitConstructor::num_wires>(circuit_constructor,
circuit_proving_key.get());
compute_standard_honk_id_polynomials<CircuitConstructor::num_wires>(circuit_proving_key.get());
compute_standard_honk_sigma_permutations<Flavor>(circuit_constructor, proving_key.get());
compute_standard_honk_id_polynomials<Flavor>(proving_key.get());

compute_first_and_last_lagrange_polynomials(circuit_proving_key.get());
compute_first_and_last_lagrange_polynomials<Flavor>(proving_key.get());

return circuit_proving_key;
return proving_key;
}

/**
* Compute verification key consisting of selector precommitments.
*
* @return Pointer to created circuit verification key.
* */
template <typename CircuitConstructor>
std::shared_ptr<plonk::verification_key> StandardHonkComposerHelper<CircuitConstructor>::compute_verification_key(
std::shared_ptr<StandardHonkComposerHelper::VerificationKey> StandardHonkComposerHelper::compute_verification_key(
const CircuitConstructor& circuit_constructor)
{
if (circuit_verification_key) {
return circuit_verification_key;
if (verification_key) {
return verification_key;
}
if (!circuit_proving_key) {
if (!proving_key) {
compute_proving_key(circuit_constructor);
}

circuit_verification_key = StandardHonkComposerHelper::compute_verification_key_base(
circuit_proving_key, crs_factory_->get_verifier_crs());
circuit_verification_key->composer_type = circuit_proving_key->composer_type;
verification_key =
StandardHonkComposerHelper::compute_verification_key_base(proving_key, crs_factory_->get_verifier_crs());
verification_key->composer_type = proving_key->composer_type;

return circuit_verification_key;
return verification_key;
}

template <typename CircuitConstructor>
StandardVerifier StandardHonkComposerHelper<CircuitConstructor>::create_verifier(
const CircuitConstructor& circuit_constructor)
StandardVerifier StandardHonkComposerHelper::create_verifier(const CircuitConstructor& circuit_constructor)
{
compute_verification_key(circuit_constructor);
StandardVerifier output_state(circuit_verification_key);
StandardVerifier output_state(verification_key);

// TODO(Cody): This should be more generic
auto kate_verification_key = std::make_unique<pcs::kzg::VerificationKey>("../srs_db/ignition");
Expand All @@ -155,23 +155,13 @@ StandardVerifier StandardHonkComposerHelper<CircuitConstructor>::create_verifier
return output_state;
}

template <typename CircuitConstructor>
template <typename Flavor>
// TODO(Cody): this file should be generic with regard to flavor/arithmetization/whatever.
StandardProver StandardHonkComposerHelper<CircuitConstructor>::create_prover(
const CircuitConstructor& circuit_constructor)
StandardProver StandardHonkComposerHelper::create_prover(const CircuitConstructor& circuit_constructor)
{
compute_proving_key(circuit_constructor);
compute_witness(circuit_constructor);

size_t num_sumcheck_rounds(circuit_proving_key->log_circuit_size);
// TODO(luke): what is this manifest? Remove?
auto manifest = Flavor::create_manifest(circuit_constructor.public_inputs.size(), num_sumcheck_rounds);
StandardProver output_state(std::move(wire_polynomials), circuit_proving_key);
StandardProver output_state(proving_key);

return output_state;
}
template class StandardHonkComposerHelper<StandardCircuitConstructor>;
template StandardProver StandardHonkComposerHelper<StandardCircuitConstructor>::create_prover<StandardHonk>(
const StandardCircuitConstructor& circuit_constructor);
} // namespace proof_system::honk
Loading

0 comments on commit 2b35104

Please sign in to comment.