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

Ultraplonk check_circuit #366

Merged
merged 11 commits into from
Apr 27, 2023
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ endif()
if(ENABLE_ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
set(DISABLE_ASM ON)
endif()

if(SERIALIZE_CANARY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void UltraHonkComposerHelper<CircuitConstructor>::compute_witness(CircuitConstru
const size_t filled_gates = circuit_constructor.num_gates + circuit_constructor.public_inputs.size();
const size_t total_num_gates = std::max(filled_gates, tables_size + lookups_size);

const size_t subgroup_size = circuit_constructor.get_circuit_subgroup_size(total_num_gates + NUM_RESERVED_GATES);
const size_t subgroup_size = circuit_constructor.get_circuit_subgroup_size(total_num_gates + NUM_RANDOMIZED_GATES);

// Pad the wires (pointers to `witness_indices` of the `variables` vector).
// Note: the remaining NUM_RESERVED_GATES indices are padded with zeros within `compute_witness_base` (called
Expand Down
16 changes: 9 additions & 7 deletions cpp/src/barretenberg/honk/composer/ultra_honk_composer.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "barretenberg/plonk/composer/plookup_tables/plookup_tables.hpp"
#include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp"
#include "barretenberg/honk/proof_system/ultra_prover.hpp"
#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp"
#include "barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp"
Expand Down Expand Up @@ -289,7 +289,7 @@ class UltraHonkComposer {
std::vector<uint32_t> decompose_into_default_range(
const uint32_t variable_index,
const uint64_t num_bits,
const uint64_t target_range_bitnum = DEFAULT_PLOOKUP_RANGE_BITNUM,
const uint64_t target_range_bitnum = UltraCircuitConstructor::DEFAULT_PLOOKUP_RANGE_BITNUM,
std::string const& msg = "decompose_into_default_range")
{
return circuit_constructor.decompose_into_default_range(variable_index, num_bits, target_range_bitnum, msg);
Expand Down Expand Up @@ -348,17 +348,19 @@ class UltraHonkComposer {
// /**
// * Non Native Field Arithmetic
// **/
void range_constrain_two_limbs(const uint32_t lo_idx,
const uint32_t hi_idx,
const size_t lo_limb_bits = DEFAULT_NON_NATIVE_FIELD_LIMB_BITS,
const size_t hi_limb_bits = DEFAULT_NON_NATIVE_FIELD_LIMB_BITS)
void range_constrain_two_limbs(
const uint32_t lo_idx,
const uint32_t hi_idx,
const size_t lo_limb_bits = UltraCircuitConstructor::DEFAULT_NON_NATIVE_FIELD_LIMB_BITS,
const size_t hi_limb_bits = UltraCircuitConstructor::DEFAULT_NON_NATIVE_FIELD_LIMB_BITS)
{
circuit_constructor.range_constrain_two_limbs(lo_idx, hi_idx, lo_limb_bits, hi_limb_bits);
};
// std::array<uint32_t, 2> decompose_non_native_field_double_width_limb(
// const uint32_t limb_idx, const size_t num_limb_bits = (2 * DEFAULT_NON_NATIVE_FIELD_LIMB_BITS));
std::array<uint32_t, 2> queue_non_native_field_multiplication(
const non_native_field_witnesses& input, const bool range_constrain_quotient_and_remainder = true)
const UltraCircuitConstructor::non_native_field_witnesses& input,
const bool range_constrain_quotient_and_remainder = true)
{
return circuit_constructor.queue_non_native_field_multiplication(input, range_constrain_quotient_and_remainder);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ TEST(UltraHonkComposer, non_native_field_multiplication)
const auto q_indices = get_limb_witness_indices(split_into_limbs(uint256_t(q)));
const auto r_indices = get_limb_witness_indices(split_into_limbs(uint256_t(r)));

proof_system::non_native_field_witnesses inputs{
proof_system::UltraCircuitConstructor::non_native_field_witnesses inputs{
a_indices, b_indices, q_indices, r_indices, modulus_limbs, fr(uint256_t(modulus)),
};
const auto [lo_1_idx, hi_1_idx] = honk_composer.queue_non_native_field_multiplication(inputs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void UltraPlonkComposerHelper<CircuitConstructor>::compute_witness(CircuitConstr

// TODO(luke): subgroup size was already computed above but compute_witness_base computes it again. If we pass in
// NUM_RANDOMIZED_GATES (as in the other split composers) the resulting sizes can differ. Reconcile this.
auto wire_polynomial_evaluations = compute_witness_base(circuit_constructor, total_num_gates, NUM_RANDOMIZED_GATES);
auto wire_polynomial_evaluations = compute_witness_base(circuit_constructor, total_num_gates, NUM_RESERVED_GATES);
Copy link
Collaborator

@codygunton codygunton Apr 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corresponding change in the definition of compute_witness_base? If it's really should be called NUM_RESERVED_GATES then we should change the name of the function argument, no? Your goal is just uniformity of naming, right, there's no difference?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But below we have num_randomized_gates = NUM_RESERVED_GATES. Are we just using the fact that presently we have NUM_RESERVED_GATES==NUM_RANDOMIZED_GATES? Both of these could be specified statically in the flavor, so it's probably best to keep the roles distinct.


for (size_t j = 0; j < program_width; ++j) {
std::string index = std::to_string(j + 1);
Expand Down Expand Up @@ -225,7 +225,7 @@ std::shared_ptr<proving_key> UltraPlonkComposerHelper<CircuitConstructor>::compu
}

const size_t minimum_circuit_size = tables_size + lookups_size;
const size_t num_randomized_gates = NUM_RANDOMIZED_GATES;
const size_t num_randomized_gates = NUM_RESERVED_GATES;
// Initialize circuit_proving_key
// TODO(#229)(Kesha): replace composer types.
circuit_proving_key = initialize_proving_key(
Expand Down Expand Up @@ -359,7 +359,7 @@ std::shared_ptr<plonk::verification_key> UltraPlonkComposerHelper<CircuitConstru
}
circuit_verification_key = compute_verification_key_common(circuit_proving_key, crs_factory_->get_verifier_crs());

circuit_verification_key->composer_type = type; // Invariably plookup for this class.
circuit_verification_key->composer_type = ComposerType::PLOOKUP; // Invariably plookup for this class.

// See `add_recusrive_proof()` for how this recursive data is assigned.
circuit_verification_key->recursive_proof_public_input_indices =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ template <typename CircuitConstructor> class UltraPlonkComposerHelper {
// NUM_RESERVED_GATES). Therefore for consistency within this composer itself, and consistency with the original
// Ultra Composer, this value must match that of NUM_RESERVED_GATES. This issue needs to be reconciled
// simultaneously here and in the other split composers.
static constexpr size_t NUM_RANDOMIZED_GATES = 4; // equal to the number of multilinear evaluations leaked
static constexpr size_t NUM_RESERVED_GATES = 4; // equal to the number of multilinear evaluations leaked
static constexpr size_t program_width = CircuitConstructor::program_width;
std::shared_ptr<plonk::proving_key> circuit_proving_key;
std::shared_ptr<plonk::verification_key> circuit_verification_key;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "barretenberg/plonk/composer/composer_base.hpp"
#include "barretenberg/plonk/composer/plookup_tables/plookup_tables.hpp"
#include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp"
#include "barretenberg/plonk/proof_system/prover/prover.hpp"
#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp"
#include "barretenberg/proof_system/types/merkle_hash_type.hpp"
Expand Down Expand Up @@ -311,7 +311,7 @@ class UltraPlonkComposer {
std::vector<uint32_t> decompose_into_default_range(
const uint32_t variable_index,
const uint64_t num_bits,
const uint64_t target_range_bitnum = DEFAULT_PLOOKUP_RANGE_BITNUM,
const uint64_t target_range_bitnum = UltraCircuitConstructor::DEFAULT_PLOOKUP_RANGE_BITNUM,
std::string const& msg = "decompose_into_default_range")
{
return circuit_constructor.decompose_into_default_range(variable_index, num_bits, target_range_bitnum, msg);
Expand Down Expand Up @@ -370,17 +370,19 @@ class UltraPlonkComposer {
// /**
// * Non Native Field Arithmetic
// **/
void range_constrain_two_limbs(const uint32_t lo_idx,
const uint32_t hi_idx,
const size_t lo_limb_bits = DEFAULT_NON_NATIVE_FIELD_LIMB_BITS,
const size_t hi_limb_bits = DEFAULT_NON_NATIVE_FIELD_LIMB_BITS)
void range_constrain_two_limbs(
const uint32_t lo_idx,
const uint32_t hi_idx,
const size_t lo_limb_bits = UltraCircuitConstructor::DEFAULT_NON_NATIVE_FIELD_LIMB_BITS,
const size_t hi_limb_bits = UltraCircuitConstructor::DEFAULT_NON_NATIVE_FIELD_LIMB_BITS)
{
circuit_constructor.range_constrain_two_limbs(lo_idx, hi_idx, lo_limb_bits, hi_limb_bits);
};
// std::array<uint32_t, 2> decompose_non_native_field_double_width_limb(
// const uint32_t limb_idx, const size_t num_limb_bits = (2 * DEFAULT_NON_NATIVE_FIELD_LIMB_BITS));
std::array<uint32_t, 2> queue_non_native_field_multiplication(
const non_native_field_witnesses& input, const bool range_constrain_quotient_and_remainder = true)
const UltraCircuitConstructor::non_native_field_witnesses& input,
const bool range_constrain_quotient_and_remainder = true)
{
return circuit_constructor.queue_non_native_field_multiplication(input, range_constrain_quotient_and_remainder);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ TEST(ultra_plonk_composer_splitting_tmp, non_native_field_multiplication)
const auto q_indices = get_limb_witness_indices(split_into_limbs(uint256_t(q)));
const auto r_indices = get_limb_witness_indices(split_into_limbs(uint256_t(r)));

non_native_field_witnesses inputs{
UltraCircuitConstructor::non_native_field_witnesses inputs{
a_indices, b_indices, q_indices, r_indices, modulus_limbs, fr(uint256_t(modulus)),
};
const auto [lo_1_idx, hi_1_idx] = composer.queue_non_native_field_multiplication(inputs);
Expand Down
9 changes: 5 additions & 4 deletions cpp/src/barretenberg/plonk/composer/ultra_composer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#include "barretenberg/plonk/proof_system/commitment_scheme/kate_commitment_scheme.hpp"
#include "barretenberg/srs/reference_string/file_reference_string.hpp"

#include "plookup_tables/types.hpp"
#include "plookup_tables/plookup_tables.hpp"
#include "plookup_tables/aes128.hpp"
#include "plookup_tables/sha256.hpp"
#include "barretenberg/proof_system/plookup_tables/types.hpp"
#include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp"
#include "barretenberg/proof_system/plookup_tables/aes128.hpp"
#include "barretenberg/proof_system/plookup_tables/sha256.hpp"

#ifndef NO_TBB
#include <tbb/atomic.h>
Expand Down Expand Up @@ -1845,6 +1845,7 @@ std::array<uint32_t, 2> UltraComposer::decompose_non_native_field_double_width_l
const uint256_t value = get_variable(limb_idx);
const uint256_t low = value & LIMB_MASK;
const uint256_t hi = value >> DEFAULT_NON_NATIVE_FIELD_LIMB_BITS;
// WTF(kesha): What is this supposed to do? Unless uint256_t has failed, this should always work
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, harder to find this if it doesn't contain the word TODO somewhere...

ASSERT(low + (hi << DEFAULT_NON_NATIVE_FIELD_LIMB_BITS) == value);

const uint32_t low_idx = add_variable(low);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/plonk/composer/ultra_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "composer_base.hpp"
#include "barretenberg/proof_system/types/merkle_hash_type.hpp"
#include "barretenberg/proof_system/types/pedersen_commitment_type.hpp"
#include "plookup_tables/plookup_tables.hpp"
#include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp"
#include <optional>

namespace proof_system::plonk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "barretenberg/numeric/bitop/get_msb.hpp"
#include "barretenberg/numeric/uintx/uintx.hpp"
#include "../proof_system/widgets/random_widgets/plookup_widget.hpp"
#include "./plookup_tables/sha256.hpp"
#include "barretenberg/proof_system/plookup_tables/sha256.hpp"

using namespace barretenberg;
using namespace proof_system;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/proof_system/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(proof_system polynomials crypto_generators)
barretenberg_module(proof_system polynomials crypto_generators crypto_pedersen_hash)
Loading