Skip to content

Commit

Permalink
Ultra Honk (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
ledwards2225 authored May 11, 2023
1 parent e59eb2c commit 9074ab3
Show file tree
Hide file tree
Showing 24 changed files with 2,879 additions and 1,097 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace {
// Parameters for generator table construction
struct GeneratorParameters {
size_t num_default_generators; // Number of unique base points with default main index with precomputed ladders
size_t num_hash_indices; // Number of unique hash indices
size_t num_hash_indices; // Number of unique hash indices
size_t num_generators_per_hash_index; // Number of generators per hash index
size_t hash_indices_generator_offset; // Offset for hash index generators
};
Expand All @@ -16,13 +16,13 @@ struct GeneratorParameters {
// This hack is to avoid breakage due to generators in aztec circuits while maintaining compatibility
// with the barretenberg master.
#ifdef BARRETENBERG_CRYPTO_GENERATOR_PARAMETERS_HACK
constexpr GeneratorParameters GEN_PARAMS = {BARRETENBERG_CRYPTO_GENERATOR_PARAMETERS_HACK};
constexpr GeneratorParameters GEN_PARAMS = { BARRETENBERG_CRYPTO_GENERATOR_PARAMETERS_HACK };
#else
#ifdef __wasm__
constexpr GeneratorParameters GEN_PARAMS = {32, 16, 8, 2048};
constexpr GeneratorParameters GEN_PARAMS = { 32, 16, 8, 2048 };
// TODO need to resolve memory out of bounds when these are too high
#else
constexpr GeneratorParameters GEN_PARAMS = {2048, 16, 8, 2048};
constexpr GeneratorParameters GEN_PARAMS = { 2048, 16, 8, 2048 };
#endif
#endif

Expand Down Expand Up @@ -277,8 +277,8 @@ generator_data const& get_generator_data(generator_index_t index)
}
ASSERT(index.index <= GEN_PARAMS.num_hash_indices);
ASSERT(index.sub_index < GEN_PARAMS.num_generators_per_hash_index);
return *global_generator_data[GEN_PARAMS.hash_indices_generator_offset + ((index.index - 1) * GEN_PARAMS.num_generators_per_hash_index) +
index.sub_index];
return *global_generator_data[GEN_PARAMS.hash_indices_generator_offset +
((index.index - 1) * GEN_PARAMS.num_generators_per_hash_index) + index.sub_index];
}

const fixed_base_ladder* generator_data::get_ladder(size_t num_bits) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,25 @@ UltraProver UltraHonkComposerHelper::create_prover(CircuitConstructor& circuit_c
return output_state;
}

// /**
// * Create verifier: compute verification key,
// * initialize verifier with it and an initial manifest and initialize commitment_scheme.
// *
// * @return The verifier.
// * */
// plonk::UltraVerifier UltraHonkComposerHelper::create_verifier(
// const CircuitConstructor& circuit_constructor)
// {
// auto verification_key = compute_verification_key(circuit_constructor);
/**
* Create verifier: compute verification key,
* initialize verifier with it and an initial manifest and initialize commitment_scheme.
*
* @return The verifier.
* */
UltraVerifier UltraHonkComposerHelper::create_verifier(const CircuitConstructor& circuit_constructor)
{
auto verification_key = compute_verification_key(circuit_constructor);

// plonk::UltraVerifier output_state(verification_key,
// create_manifest(circuit_constructor.public_inputs.size()));
UltraVerifier output_state(verification_key);

// std::unique_ptr<plonk::KateCommitmentScheme<plonk::ultra_settings>> kate_commitment_scheme =
// std::make_unique<plonk::KateCommitmentScheme<plonk::ultra_settings>>();
// TODO(Cody): This should be more generic
auto kate_verification_key = std::make_unique<pcs::kzg::VerificationKey>("../srs_db/ignition");

// output_state.commitment_scheme = std::move(kate_commitment_scheme);
output_state.kate_verification_key = std::move(kate_verification_key);

// return output_state;
// }
return output_state;
}

std::shared_ptr<UltraHonkComposerHelper::Flavor::ProvingKey> UltraHonkComposerHelper::compute_proving_key(
const CircuitConstructor& circuit_constructor)
Expand Down Expand Up @@ -296,50 +294,65 @@ std::shared_ptr<UltraHonkComposerHelper::Flavor::ProvingKey> UltraHonkComposerHe
return proving_key;
}

// /**
// * Compute verification key consisting of selector precommitments.
// *
// * @return Pointer to created circuit verification key.
// * */
// std::shared_ptr<VerificationKey> UltraHonkComposerHelper::compute_verification_key(
// const CircuitConstructor& circuit_constructor)
// {
// if (verification_key) {
// return verification_key;
// }

// if (!proving_key) {
// compute_proving_key(circuit_constructor);
// }
// verification_key = compute_verification_key_common(proving_key,
// crs_factory_->get_verifier_crs());

// verification_key->composer_type = type; // Invariably plookup for this class.

// // See `add_recusrive_proof()` for how this recursive data is assigned.
// verification_key->recursive_proof_public_input_indices =
// std::vector<uint32_t>(recursive_proof_public_input_indices.begin(),
// recursive_proof_public_input_indices.end());

// verification_key->contains_recursive_proof = contains_recursive_proof;

// return verification_key;
// }

// void UltraHonkComposerHelper::add_table_column_selector_poly_to_proving_key(
// polynomial& selector_poly_lagrange_form, const std::string& tag)
// {
// polynomial selector_poly_lagrange_form_copy(selector_poly_lagrange_form, proving_key->small_domain.size);

// selector_poly_lagrange_form.ifft(proving_key->small_domain);
// auto& selector_poly_coeff_form = selector_poly_lagrange_form;

// polynomial selector_poly_coset_form(selector_poly_coeff_form, proving_key->circuit_size * 4);
// selector_poly_coset_form.coset_fft(proving_key->large_domain);

// proving_key->polynomial_store.put(tag, std::move(selector_poly_coeff_form));
// proving_key->polynomial_store.put(tag + "_lagrange", std::move(selector_poly_lagrange_form_copy));
// proving_key->polynomial_store.put(tag + "_fft", std::move(selector_poly_coset_form));
// }
/**
* Compute verification key consisting of selector precommitments.
*
* @return Pointer to created circuit verification key.
* */
std::shared_ptr<UltraHonkComposerHelper::VerificationKey> UltraHonkComposerHelper::compute_verification_key(
const CircuitConstructor& circuit_constructor)
{
if (verification_key) {
return verification_key;
}

if (!proving_key) {
compute_proving_key(circuit_constructor);
}

verification_key = std::make_shared<UltraHonkComposerHelper::VerificationKey>(proving_key->circuit_size,
proving_key->num_public_inputs,
crs_factory_->get_verifier_crs(),
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
verification_key->q_m = commitment_key.commit(proving_key->q_m);
verification_key->q_l = commitment_key.commit(proving_key->q_l);
verification_key->q_r = commitment_key.commit(proving_key->q_r);
verification_key->q_o = commitment_key.commit(proving_key->q_o);
verification_key->q_4 = commitment_key.commit(proving_key->q_4);
verification_key->q_c = commitment_key.commit(proving_key->q_c);
verification_key->q_arith = commitment_key.commit(proving_key->q_arith);
verification_key->q_sort = commitment_key.commit(proving_key->q_sort);
verification_key->q_elliptic = commitment_key.commit(proving_key->q_elliptic);
verification_key->q_aux = commitment_key.commit(proving_key->q_aux);
verification_key->q_lookup = commitment_key.commit(proving_key->q_lookup);
verification_key->sigma_1 = commitment_key.commit(proving_key->sigma_1);
verification_key->sigma_2 = commitment_key.commit(proving_key->sigma_2);
verification_key->sigma_3 = commitment_key.commit(proving_key->sigma_3);
verification_key->sigma_4 = commitment_key.commit(proving_key->sigma_4);
verification_key->id_1 = commitment_key.commit(proving_key->id_1);
verification_key->id_2 = commitment_key.commit(proving_key->id_2);
verification_key->id_3 = commitment_key.commit(proving_key->id_3);
verification_key->id_4 = commitment_key.commit(proving_key->id_4);
verification_key->table_1 = commitment_key.commit(proving_key->table_1);
verification_key->table_2 = commitment_key.commit(proving_key->table_2);
verification_key->table_3 = commitment_key.commit(proving_key->table_3);
verification_key->table_4 = commitment_key.commit(proving_key->table_4);
verification_key->lagrange_first = commitment_key.commit(proving_key->lagrange_first);
verification_key->lagrange_last = commitment_key.commit(proving_key->lagrange_last);

// // See `add_recusrive_proof()` for how this recursive data is assigned.
// verification_key->recursive_proof_public_input_indices =
// std::vector<uint32_t>(recursive_proof_public_input_indices.begin(),
// recursive_proof_public_input_indices.end());

// verification_key->contains_recursive_proof = contains_recursive_proof;

return verification_key;
}

} // namespace proof_system::honk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "barretenberg/srs/reference_string/file_reference_string.hpp"
#include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp"
#include "barretenberg/honk/proof_system/ultra_prover.hpp"
// #include "barretenberg/plonk/proof_system/verifier/verifier.hpp"
#include "barretenberg/honk/proof_system/ultra_verifier.hpp"

#include <cstddef>
#include <memory>
Expand Down Expand Up @@ -61,12 +61,12 @@ class UltraHonkComposerHelper {
void finalize_circuit(CircuitConstructor& circuit_constructor) { circuit_constructor.finalize_circuit(); };

std::shared_ptr<ProvingKey> compute_proving_key(const CircuitConstructor& circuit_constructor);
// std::shared_ptr<VerificationKey> compute_verification_key(const CircuitConstructor& circuit_constructor);
std::shared_ptr<VerificationKey> compute_verification_key(const CircuitConstructor& circuit_constructor);

void compute_witness(CircuitConstructor& circuit_constructor);

UltraProver create_prover(CircuitConstructor& circuit_constructor);
// UltraVerifier create_verifier(const CircuitConstructor& circuit_constructor);
UltraVerifier create_verifier(const CircuitConstructor& circuit_constructor);

void add_table_column_selector_poly_to_proving_key(polynomial& small, const std::string& tag);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp"
#include "barretenberg/honk/proof_system/ultra_prover.hpp"
#include "barretenberg/honk/proof_system/ultra_verifier.hpp"
#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp"
#include "barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp"
#include "barretenberg/honk/flavor/ultra.hpp"
Expand Down Expand Up @@ -51,7 +52,12 @@ class UltraHonkComposer {
void finalize_circuit() { circuit_constructor.finalize_circuit(); };

UltraProver create_prover() { return composer_helper.create_prover(circuit_constructor); };
// UltraVerifier create_verifier() { return composer_helper.create_verifier(circuit_constructor); };
UltraVerifier create_verifier() { return composer_helper.create_verifier(circuit_constructor); };

void add_gates_to_ensure_all_polys_are_non_zero()
{
circuit_constructor.add_gates_to_ensure_all_polys_are_non_zero();
}

void create_add_gate(const add_triple& in) { circuit_constructor.create_add_gate(in); }

Expand Down Expand Up @@ -118,7 +124,10 @@ class UltraHonkComposer {
// accumulator_triple create_and_constraint(const uint32_t a, const uint32_t b, const size_t num_bits);
// accumulator_triple create_xor_constraint(const uint32_t a, const uint32_t b, const size_t num_bits);

// uint32_t put_constant_variable(const barretenberg::fr& variable);
uint32_t put_constant_variable(const barretenberg::fr& variable)
{
return circuit_constructor.put_constant_variable(variable);
};

// size_t get_num_constant_gates() const override { return 0; }

Expand Down
Loading

0 comments on commit 9074ab3

Please sign in to comment.