Skip to content

Commit

Permalink
Fixes after rebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Apr 5, 2023
1 parent 892edd5 commit 41daf32
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 63 deletions.
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_format/acir_format.cpp
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
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/acir_format/logic_constraint.cpp
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
12 changes: 6 additions & 6 deletions cpp/src/barretenberg/dsl/acir_proofs/acir_proofs.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

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

Expand All @@ -13,9 +13,9 @@ 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 @@ -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 Down Expand Up @@ -138,7 +138,7 @@ bool verify_proof(
auto crs = std::make_shared<VerifierMemReferenceString>(g2x);
plonk::verification_key_data vk_data;
read(vk_buf, vk_data);
auto verification_key = std::make_shared<plonk::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
Expand Up @@ -10,7 +10,7 @@
#include <cstdint>
#include <string>

namespace plonk {
namespace proof_system::plonk {

/**
* @brief Computes `this.witness`, which is basiclly a set of polynomials mapped-to by strings.
Expand Down Expand Up @@ -228,20 +228,17 @@ std::shared_ptr<proving_key> UltraPlonkComposerHelper<CircuitConstructor>::compu
const size_t num_randomized_gates = NUM_RANDOMIZED_GATES;
// Initialize circuit_proving_key
// TODO(#229)(Kesha): replace composer types.
circuit_proving_key = initialize_proving_key(circuit_constructor,
crs_factory_.get(),
minimum_circuit_size,
num_randomized_gates,
plonk::ComposerType::PLOOKUP);
circuit_proving_key = initialize_proving_key(
circuit_constructor, crs_factory_.get(), minimum_circuit_size, num_randomized_gates, ComposerType::PLOOKUP);

construct_lagrange_selector_forms(circuit_constructor, circuit_proving_key.get());

enforce_nonzero_polynomial_selectors(circuit_constructor, circuit_proving_key.get());

compute_monomial_and_coset_selector_forms(circuit_proving_key.get(), ultra_selector_properties());

bonk::compute_plonk_generalized_sigma_permutations<CircuitConstructor::program_width>(circuit_constructor,
circuit_proving_key.get());
compute_plonk_generalized_sigma_permutations<CircuitConstructor::program_width>(circuit_constructor,
circuit_proving_key.get());

const size_t subgroup_size = circuit_proving_key->circuit_size;

Expand Down Expand Up @@ -350,7 +347,7 @@ std::shared_ptr<proving_key> UltraPlonkComposerHelper<CircuitConstructor>::compu
* @return Pointer to created circuit verification key.
* */
template <typename CircuitConstructor>
std::shared_ptr<bonk::verification_key> UltraPlonkComposerHelper<CircuitConstructor>::compute_verification_key(
std::shared_ptr<plonk::verification_key> UltraPlonkComposerHelper<CircuitConstructor>::compute_verification_key(
const CircuitConstructor& circuit_constructor)
{
if (circuit_verification_key) {
Expand Down Expand Up @@ -391,4 +388,4 @@ void UltraPlonkComposerHelper<CircuitConstructor>::add_table_column_selector_pol
}

template class UltraPlonkComposerHelper<UltraCircuitConstructor>;
} // namespace plonk
} // namespace proof_system::plonk
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once

#include "barretenberg/proof_system/composer/composer_helper_lib.hpp"
#include "barretenberg/plonk/composer/splitting_tmp/composer_helper/composer_helper_lib.hpp"
#include "barretenberg/srs/reference_string/file_reference_string.hpp"
#include "barretenberg/proof_system/proving_key/proving_key.hpp"
#include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp"
#include "barretenberg/plonk/proof_system/prover/prover.hpp"
#include "barretenberg/plonk/proof_system/verifier/verifier.hpp"

#include <cstddef>
#include <utility>

namespace plonk {
namespace proof_system::plonk {
// TODO(Kesha): change initializations to specify this parameter
// Cody: What does this mean?
template <typename CircuitConstructor> class UltraPlonkComposerHelper {
Expand All @@ -21,11 +22,11 @@ template <typename CircuitConstructor> class UltraPlonkComposerHelper {
// 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 program_width = CircuitConstructor::program_width;
std::shared_ptr<bonk::proving_key> circuit_proving_key;
std::shared_ptr<bonk::verification_key> circuit_verification_key;
std::shared_ptr<plonk::proving_key> circuit_proving_key;
std::shared_ptr<plonk::verification_key> circuit_verification_key;
// TODO(#218)(kesha): we need to put this into the commitment key, so that the composer doesn't have to handle srs
// at all
std::shared_ptr<bonk::ReferenceStringFactory> crs_factory_;
std::shared_ptr<ReferenceStringFactory> crs_factory_;

std::vector<uint32_t> recursive_proof_public_input_indices;
bool contains_recursive_proof = false;
Expand All @@ -52,7 +53,7 @@ template <typename CircuitConstructor> class UltraPlonkComposerHelper {
UltraPlonkComposerHelper& operator=(UltraPlonkComposerHelper const& other) noexcept = default;
~UltraPlonkComposerHelper() = default;

std::vector<bonk::SelectorProperties> ultra_selector_properties()
std::vector<SelectorProperties> ultra_selector_properties()
{
// When reading and writing the proving key from a buffer we must precompute the Lagrange form of certain
// selector polynomials. In order to avoid a new selector type and definitions in the polynomial manifest, we
Expand All @@ -63,7 +64,7 @@ template <typename CircuitConstructor> class UltraPlonkComposerHelper {
// { "q_m", true }, { "q_c", true }, { "q_1", true }, { "q_2", true },
// { "q_3", true }, { "q_4", false }, { "q_arith", false }, { "q_sort", false },
// { "q_elliptic", false }, { "q_aux", false }, { "table_type", true },
std::vector<bonk::SelectorProperties> result{
std::vector<SelectorProperties> result{
{ "q_m", true }, { "q_c", true }, { "q_1", true }, { "q_2", true },
{ "q_3", true }, { "q_4", true }, { "q_arith", true }, { "q_sort", true },
{ "q_elliptic", true }, { "q_aux", true }, { "table_type", true },
Expand All @@ -75,8 +76,8 @@ template <typename CircuitConstructor> class UltraPlonkComposerHelper {

void finalize_circuit(CircuitConstructor& circuit_constructor) { circuit_constructor.finalize_circuit(); };

std::shared_ptr<bonk::proving_key> compute_proving_key(const CircuitConstructor& circuit_constructor);
std::shared_ptr<bonk::verification_key> compute_verification_key(const CircuitConstructor& circuit_constructor);
std::shared_ptr<plonk::proving_key> compute_proving_key(const CircuitConstructor& circuit_constructor);
std::shared_ptr<plonk::verification_key> compute_verification_key(const CircuitConstructor& circuit_constructor);

void compute_witness(CircuitConstructor& circuit_constructor);

Expand Down Expand Up @@ -208,4 +209,4 @@ template <typename CircuitConstructor> class UltraPlonkComposerHelper {
}
};

} // namespace plonk
} // namespace proof_system::plonk
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#include "barretenberg/plonk/composer/splitting_tmp/composer_helper/ultra_plonk_composer_helper.hpp"
#include <optional>

using namespace bonk;

namespace plonk {
namespace proof_system::plonk {

class UltraPlonkComposer {

Expand Down Expand Up @@ -364,7 +362,7 @@ class UltraPlonkComposer {
// 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> evaluate_non_native_field_multiplication(
const bonk::non_native_field_witnesses& input, const bool range_constrain_quotient_and_remainder = true)
const non_native_field_witnesses& input, const bool range_constrain_quotient_and_remainder = true)
{
return circuit_constructor.evaluate_non_native_field_multiplication(input,
range_constrain_quotient_and_remainder);
Expand Down Expand Up @@ -473,4 +471,4 @@ class UltraPlonkComposer {
// std::vector<uint32_t> recursive_proof_public_input_indices;
// bool contains_recursive_proof = false;
};
} // namespace plonk
} // namespace proof_system::plonk
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
#include "barretenberg/numeric/uintx/uintx.hpp"

using namespace barretenberg;
using namespace bonk;

namespace plonk {
namespace proof_system::plonk {

namespace {
auto& engine = numeric::random::get_debug_engine();
Expand Down Expand Up @@ -780,7 +779,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)));

bonk::non_native_field_witnesses inputs{
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.evaluate_non_native_field_multiplication(inputs);
Expand Down Expand Up @@ -914,4 +913,4 @@ TEST(ultra_plonk_composer_splitting_tmp, ram)
EXPECT_EQ(result, true);
}

} // namespace plonk
} // namespace proof_system::plonk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace proof_system {
* Uses StandardPlonk
**/
inline void output_vk_sol_standard(std::ostream& os,
std::shared_ptr<verification_key> const& key,
std::shared_ptr<plonk::verification_key> const& key,
std::string const& class_name)
{
const auto print_u256 = [&](const std::string& offset, const barretenberg::fr& element, const std::string& name) {
Expand Down Expand Up @@ -65,7 +65,7 @@ inline void output_vk_sol_standard(std::ostream& os,
* Write a solidity file containing the vk params to the given stream.
* Uses UltraPlonk
**/
inline void output_vk_sol_ultra(std::ostream& os, std::shared_ptr<verification_key> const& key, std::string const& class_name)
inline void output_vk_sol_ultra(std::ostream& os, std::shared_ptr<plonk::verification_key> const& key, std::string const& class_name)
{
const auto print_u256 = [&](const std::string& offset, const barretenberg::fr& element, const std::string& name) {
os << " mstore(add(_vk, " << offset << "), " << element << ") // " << name << std::endl;
Expand Down Expand Up @@ -141,7 +141,7 @@ inline void output_vk_sol_ultra(std::ostream& os, std::shared_ptr<verification_k
* @param key
* @param class_name
*/
inline void output_vk_sol(std::ostream& os, std::shared_ptr<verification_key> const& key, std::string const& class_name)
inline void output_vk_sol(std::ostream& os, std::shared_ptr<plonk::verification_key> const& key, std::string const& class_name)
{
ComposerType composer_type = static_cast<ComposerType>(key->composer_type);
switch (composer_type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using namespace barretenberg;

namespace bonk {
namespace proof_system {

void UltraCircuitConstructor::finalize_circuit()
{
Expand Down Expand Up @@ -2321,4 +2321,4 @@ void UltraCircuitConstructor::process_RAM_arrays(const size_t gate_offset_from_p
}
}

} // namespace bonk
} // namespace proof_system
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "barretenberg/proof_system/arithmetization/arithmetization.hpp"
#include "barretenberg/proof_system/types/polynomial_manifest.hpp"
#include "barretenberg/plonk/proof_system/types/polynomial_manifest.hpp"
#include "circuit_constructor_base.hpp"
#include "barretenberg/plonk/proof_system/constants.hpp"
#include "barretenberg/proof_system/flavor/flavor.hpp"
Expand All @@ -10,9 +10,9 @@
#include "barretenberg/plonk/proof_system/types/prover_settings.hpp"
#include <optional>

namespace bonk {
namespace proof_system {

static constexpr plonk::ComposerType type = plonk::ComposerType::PLOOKUP;
static constexpr ComposerType type = ComposerType::PLOOKUP;
static constexpr plonk::MerkleHashType merkle_hash_type = plonk::MerkleHashType::LOOKUP_PEDERSEN;
static constexpr size_t NUM_RESERVED_GATES = 4; // This must be >= num_roots_cut_out_of_vanishing_polynomial
// See the comment in plonk/proof_system/prover/prover.cpp
Expand Down Expand Up @@ -167,7 +167,7 @@ class UltraCircuitConstructor : public CircuitConstructorBase<arithmetization::U

// TODO(#216)(Kesha): replace this with Honk enums after we have a verifier and no longer depend on plonk
// prover/verifier
static constexpr plonk::ComposerType type = plonk::ComposerType::STANDARD_HONK;
static constexpr ComposerType type = ComposerType::STANDARD_HONK;
static constexpr size_t UINT_LOG2_BASE = 2;

// These are variables that we have used a gate on, to enforce that they are
Expand Down Expand Up @@ -536,4 +536,4 @@ class UltraCircuitConstructor : public CircuitConstructorBase<arithmetization::U
void process_RAM_array(const size_t ram_id, const size_t gate_offset_from_public_inputs);
void process_RAM_arrays(const size_t gate_offset_from_public_inputs);
};
} // namespace bonk
} // namespace proof_system
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
#include <memory>
#include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp"

namespace proof_system {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ inline void compute_first_and_last_lagrange_polynomials(auto key) // proving_key
* @return std::array<std::vector<permutation_subgroup_element>, program_width>
*/
template <size_t program_width, typename CircuitConstructor>
void compute_plonk_generalized_sigma_permutations(const CircuitConstructor& circuit_constructor, bonk::proving_key* key)
void compute_plonk_generalized_sigma_permutations(const CircuitConstructor& circuit_constructor,
plonk::proving_key* key)
{
// Compute wire copy cycles for public and private variables
auto wire_copy_cycles = compute_wire_copy_cycles<program_width>(circuit_constructor);
Expand Down
6 changes: 2 additions & 4 deletions cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include "../composers/composers.hpp"
#include "../plookup/plookup.hpp"

namespace plonk {
namespace stdlib {
namespace proof_system::plonk::stdlib {

/**
* @brief A logical AND or XOR over a variable number of bits.
Expand Down Expand Up @@ -90,5 +89,4 @@ field_t<Composer> logic<Composer>::create_logic_constraint(field_pt& a, field_pt
}
}
INSTANTIATE_STDLIB_TYPE(logic);
} // namespace stdlib
} // namespace plonk
} // namespace proof_system::plonk::stdlib
15 changes: 7 additions & 8 deletions cpp/src/barretenberg/stdlib/primitives/logic/logic.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#pragma once
#include "../composers/composers_fwd.hpp"
#include "../field/field.hpp"
#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp"
#include "barretenberg/stdlib/primitives/field/field.hpp"
#include "barretenberg/stdlib/primitives/witness/witness.hpp"

namespace plonk {
namespace stdlib {
namespace proof_system::plonk::stdlib {

template <typename Composer> class logic {
private:
typedef field_t<Composer> field_pt;
typedef witness_t<Composer> witness_pt;
using field_pt = field_t<Composer>;
using witness_pt = witness_t<Composer>;

public:
static field_pt create_logic_constraint(field_pt& a, field_pt& b, size_t num_bits, bool is_xor_gate);
};

EXTERN_STDLIB_TYPE(logic);

} // namespace stdlib
} // namespace plonk
} // namespace proof_system::plonk::stdlib
4 changes: 1 addition & 3 deletions cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "barretenberg/plonk/composer/turbo_composer.hpp"
#include "barretenberg/numeric/random/engine.hpp"

using namespace bonk;

namespace test_stdlib_logic {

namespace {
Expand All @@ -19,7 +17,7 @@ auto& engine = numeric::random::get_debug_engine();
template <class T> void ignore_unused(T&) {} // use to ignore unused variables in lambdas

using namespace barretenberg;
using namespace plonk;
using namespace proof_system::plonk;

template <typename Composer> class stdlib_logic : public testing::Test {
typedef stdlib::bool_t<Composer> bool_ct;
Expand Down

0 comments on commit 41daf32

Please sign in to comment.