Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 1 addition & 7 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ option(SERIALIZE_CANARY "Build with serialize canary" OFF)
option(ENABLE_ASAN "Address sanitizer for debugging tricky memory corruption" OFF)
option(ENABLE_HEAVY_TESTS "Enable heavy tests when collecting coverage" OFF)
option(INSTALL_BARRETENBERG "Enable installation of barretenberg. (Projects embedding barretenberg may want to turn this OFF.)" ON)
option(USE_TURBO "Enable the use of TurboPlonk in barretenberg." OFF)

if(USE_TURBO)
message(STATUS "Building barretenberg for TurboPlonk Composer.")
add_definitions(-DUSE_TURBO)
else()
message(STATUS "Building barretenberg for UltraPlonk Composer.")
endif()
message(STATUS "Building barretenberg for UltraPlonk Composer.")

if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
message(STATUS "Compiling for ARM.")
Expand Down
10 changes: 3 additions & 7 deletions cpp/src/barretenberg/crypto/generators/generator_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ namespace {

// The number of unique base points with default main index with precomputed ladders
#ifdef __wasm__
constexpr size_t num_default_generators = 64;
constexpr size_t num_generators_per_hash_index = 16;
constexpr size_t num_hash_indices = 32;
// TODO need to resolve memory out of bounds when these are too high
constexpr size_t num_default_generators = 32;
#else
constexpr size_t num_default_generators = 2048;
constexpr size_t num_hash_indices = 32;
constexpr size_t num_generators_per_hash_index = 128;
#endif

constexpr size_t hash_indices_generator_offset = 2048;

constexpr size_t num_hash_indices = 16;
constexpr size_t num_generators_per_hash_index = 8;
constexpr size_t num_indexed_generators = num_hash_indices * num_generators_per_hash_index;
constexpr size_t size_of_generator_data_array = hash_indices_generator_offset + num_indexed_generators;
constexpr size_t num_generator_types = 3;
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/barretenberg/dsl/acir_format/acir_format.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "acir_format.hpp"
#include "barretenberg/common/log.hpp"

using namespace proof_system::plonk::stdlib::types;

namespace acir_format {

void read_witness(Composer& composer, std::vector<barretenberg::fr> witness)
Expand Down Expand Up @@ -114,6 +112,7 @@ Composer create_circuit(const acir_format& constraint_system,
composer.add_variable(0);
}
}

// Add arithmetic gates
for (const auto& constraint : constraint_system.constraints) {
composer.create_poly_gate(constraint);
Expand Down
23 changes: 10 additions & 13 deletions cpp/src/barretenberg/dsl/acir_format/acir_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "recursion_constraint.hpp"
#include "pedersen.hpp"
#include "hash_to_field.hpp"
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand Down Expand Up @@ -39,23 +39,20 @@ struct acir_format {
friend bool operator==(acir_format const& lhs, acir_format const& rhs) = default;
};

void read_witness(plonk::stdlib::types::Composer& composer, std::vector<barretenberg::fr> witness);
void read_witness(Composer& composer, std::vector<barretenberg::fr> witness);

void create_circuit(plonk::stdlib::types::Composer& composer, const acir_format& constraint_system);
void create_circuit(Composer& composer, const acir_format& constraint_system);

plonk::stdlib::types::Composer create_circuit(const acir_format& constraint_system,
std::unique_ptr<proof_system::ReferenceStringFactory>&& crs_factory);
Composer create_circuit(const acir_format& constraint_system,
std::unique_ptr<proof_system::ReferenceStringFactory>&& crs_factory);

plonk::stdlib::types::Composer create_circuit_with_witness(const acir_format& constraint_system,
std::vector<fr> witness,
std::unique_ptr<ReferenceStringFactory>&& crs_factory);
Composer create_circuit_with_witness(const acir_format& constraint_system,
std::vector<fr> witness,
std::unique_ptr<ReferenceStringFactory>&& crs_factory);

plonk::stdlib::types::Composer create_circuit_with_witness(const acir_format& constraint_system,
std::vector<fr> witness);
Composer create_circuit_with_witness(const acir_format& constraint_system, std::vector<fr> witness);

void create_circuit_with_witness(plonk::stdlib::types::Composer& composer,
const acir_format& constraint_system,
std::vector<fr> witness);
void create_circuit_with_witness(Composer& composer, const acir_format& constraint_system, std::vector<fr> witness);

// Serialisation
template <typename B> inline void read(B& buf, acir_format& data)
Expand Down
52 changes: 46 additions & 6 deletions cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,46 @@
#include <vector>
#include "barretenberg/common/streams.hpp"

TEST(acir_format, test_a_single_constraint_no_pub_inputs)
{

poly_triple constraint{
.a = 1,
.b = 2,
.c = 3,
.q_m = 0,
.q_l = 1,
.q_r = 1,
.q_o = -1,
.q_c = 0,
};

acir_format::acir_format constraint_system{
.varnum = 4,
.public_inputs = {},
.fixed_base_scalar_mul_constraints = {},
.logic_constraints = {},
.range_constraints = {},
.schnorr_constraints = {},
.ecdsa_constraints = {},
.sha256_constraints = {},
.blake2s_constraints = {},
.hash_to_field_constraints = {},
.pedersen_constraints = {},
.merkle_membership_constraints = {},
.constraints = { constraint },
};

auto composer = acir_format::create_circuit_with_witness(constraint_system, { 0, 0, 1 });

auto prover = composer.create_ultra_with_keccak_prover();
auto proof = prover.construct_proof();

auto verifier = composer.create_ultra_with_keccak_verifier();

EXPECT_EQ(verifier.verify_proof(proof), false);
}

TEST(acir_format, test_logic_gate_from_noir_circuit)
{
/**
Expand Down Expand Up @@ -105,10 +145,10 @@ TEST(acir_format, test_logic_gate_from_noir_circuit)

std::cout << "made composer" << std::endl;

auto prover = composer.create_prover();
auto prover = composer.create_ultra_with_keccak_prover();
auto proof = prover.construct_proof();

auto verifier = composer.create_verifier();
auto verifier = composer.create_ultra_with_keccak_verifier();

EXPECT_EQ(verifier.verify_proof(proof), true);
}
Expand Down Expand Up @@ -174,10 +214,10 @@ TEST(acir_format, test_schnorr_verify_pass)
67, 16, 37, 128, 85, 76, 19, 253, 30, 77, 192, 53, 138, 205, 69, 33, 236, 163, 83, 194,
84, 137, 184, 221, 176, 121, 179, 27, 63, 70, 54, 16, 176, 250, 39, 239, 1, 0, 0, 0 });

auto prover = composer.create_prover();
auto prover = composer.create_ultra_with_keccak_prover();
auto proof = prover.construct_proof();

auto verifier = composer.create_verifier();
auto verifier = composer.create_ultra_with_keccak_verifier();

EXPECT_EQ(verifier.verify_proof(proof), true);
}
Expand Down Expand Up @@ -243,10 +283,10 @@ TEST(acir_format, test_schnorr_verify_small_range)
67, 16, 37, 128, 85, 76, 19, 253, 30, 77, 192, 53, 138, 205, 69, 33, 236, 163, 83, 194,
84, 137, 184, 221, 176, 121, 179, 27, 63, 70, 54, 16, 176, 250, 39, 239, 1, 0, 0, 0 });

auto prover = composer.create_prover();
auto prover = composer.create_ultra_with_keccak_prover();
auto proof = prover.construct_proof();

auto verifier = composer.create_verifier();
auto verifier = composer.create_ultra_with_keccak_verifier();

EXPECT_EQ(verifier.verify_proof(proof), true);
}
2 changes: 0 additions & 2 deletions cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "blake2s_constraint.hpp"
#include "round.hpp"

using namespace proof_system::plonk::stdlib::types;

namespace acir_format {

void create_blake2s_constraints(Composer& composer, const Blake2sConstraint& constraint)
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <cstdint>
#include <vector>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand All @@ -19,7 +19,7 @@ struct Blake2sConstraint {
friend bool operator==(Blake2sConstraint const& lhs, Blake2sConstraint const& rhs) = default;
};

void create_blake2s_constraints(plonk::stdlib::types::Composer& composer, const Blake2sConstraint& constraint);
void create_blake2s_constraints(Composer& composer, const Blake2sConstraint& constraint);

template <typename B> inline void read(B& buf, Blake2sInput& constraint)
{
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#include "barretenberg/crypto/ecdsa/ecdsa.hpp"
#include "barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp"

using namespace proof_system::plonk::stdlib::types;

namespace acir_format {

using namespace proof_system::plonk;

crypto::ecdsa::signature ecdsa_convert_signature(Composer& composer, std::vector<uint32_t> signature)
{

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <vector>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand Down Expand Up @@ -28,7 +28,7 @@ struct EcdsaSecp256k1Constraint {
friend bool operator==(EcdsaSecp256k1Constraint const& lhs, EcdsaSecp256k1Constraint const& rhs) = default;
};

void create_ecdsa_verify_constraints(plonk::stdlib::types::Composer& composer, const EcdsaSecp256k1Constraint& input);
void create_ecdsa_verify_constraints(Composer& composer, const EcdsaSecp256k1Constraint& input);

template <typename B> inline void read(B& buf, EcdsaSecp256k1Constraint& constraint)
{
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <gtest/gtest.h>
#include <vector>

using namespace proof_system::plonk::stdlib::types;
using curve = stdlib::secp256k1<Composer>;
using namespace proof_system::plonk;
using curve = stdlib::secp256k1<acir_format::Composer>;

size_t generate_ecdsa_constraint(acir_format::EcdsaSecp256k1Constraint& ecdsa_constraint,
std::vector<fr>& witness_values)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "fixed_base_scalar_mul.hpp"

using namespace proof_system::plonk::stdlib::types;

namespace acir_format {

void create_fixed_base_constraint(Composer& composer, const FixedBaseScalarMul& input)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <cstdint>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand All @@ -12,7 +12,7 @@ struct FixedBaseScalarMul {
friend bool operator==(FixedBaseScalarMul const& lhs, FixedBaseScalarMul const& rhs) = default;
};

void create_fixed_base_constraint(plonk::stdlib::types::Composer& composer, const FixedBaseScalarMul& input);
void create_fixed_base_constraint(Composer& composer, const FixedBaseScalarMul& input);

template <typename B> inline void read(B& buf, FixedBaseScalarMul& constraint)
{
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/barretenberg/dsl/acir_format/hash_to_field.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "hash_to_field.hpp"
#include "round.hpp"

using namespace proof_system::plonk::stdlib::types;

namespace acir_format {

using namespace proof_system::plonk;

void create_hash_to_field_constraints(Composer& composer, const HashToFieldConstraint constraint)
{

Expand All @@ -30,7 +30,7 @@ void create_hash_to_field_constraints(Composer& composer, const HashToFieldConst
// Hash To Field using blake2s.
// Note: It does not need to be blake2s in the future

byte_array_ct out_bytes = proof_system::plonk::stdlib::blake2s<Composer>(arr);
byte_array_ct out_bytes = stdlib::blake2s<Composer>(arr);

field_ct out(out_bytes);
field_ct normalised_out = out.normalize();
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <cstdint>
#include <vector>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand All @@ -19,7 +19,7 @@ struct HashToFieldConstraint {
friend bool operator==(HashToFieldConstraint const& lhs, HashToFieldConstraint const& rhs) = default;
};

void create_hash_to_field_constraints(plonk::stdlib::types::Composer& composer, HashToFieldConstraint constraint);
void create_hash_to_field_constraints(Composer& composer, HashToFieldConstraint constraint);

template <typename B> inline void read(B& buf, HashToFieldInput& constraint)
{
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/barretenberg/dsl/acir_format/logic_constraint.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "logic_constraint.hpp"
#include "barretenberg/stdlib/primitives/logic/logic.hpp"

using namespace proof_system::plonk::stdlib::types;

namespace acir_format {

using namespace proof_system::plonk;

void create_logic_gate(Composer& composer,
const uint32_t a,
const uint32_t b,
Expand Down
13 changes: 4 additions & 9 deletions cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <cstdint>
#include "barretenberg/stdlib/types/types.hpp"
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

Expand All @@ -14,16 +14,11 @@ struct LogicConstraint {
friend bool operator==(LogicConstraint const& lhs, LogicConstraint const& rhs) = default;
};

void create_logic_gate(plonk::stdlib::types::Composer& composer,
uint32_t a,
uint32_t b,
uint32_t result,
size_t num_bits,
bool is_xor_gate);
void create_logic_gate(Composer& composer, uint32_t a, uint32_t b, uint32_t result, size_t num_bits, bool is_xor_gate);

void xor_gate(plonk::stdlib::types::Composer& composer, uint32_t a, uint32_t b, uint32_t result);
void xor_gate(Composer& composer, uint32_t a, uint32_t b, uint32_t result);

void and_gate(plonk::stdlib::types::Composer& composer, uint32_t a, uint32_t b, uint32_t result);
void and_gate(Composer& composer, uint32_t a, uint32_t b, uint32_t result);

template <typename B> inline void read(B& buf, LogicConstraint& constraint)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "merkle_membership_constraint.hpp"
#include "barretenberg/stdlib/merkle_tree/membership.hpp"

using namespace proof_system::plonk::stdlib::types;
using namespace proof_system::plonk::stdlib::merkle_tree;

namespace acir_format {

void create_merkle_check_membership_constraint(Composer& composer, const MerkleMembershipConstraint& input)
Expand All @@ -22,7 +19,7 @@ void create_merkle_check_membership_constraint(Composer& composer, const MerkleM
// We are given the HashPath as a Vec<fr>
// We want to first convert it into a Vec<(fr, fr)> then cast this to hash_path
// struct which requires the method create_witness_hashpath
hash_path<Composer> hash_path;
hash_path_ct hash_path;

// In Noir we accept a hash path that only contains one hash per tree level
// It is ok to reuse the leaf as it will be overridden in check_subtree_membership when computing the current root
Expand All @@ -39,7 +36,7 @@ void create_merkle_check_membership_constraint(Composer& composer, const MerkleM
}
}

auto exists = check_subtree_membership(root, hash_path, leaf, index_bits, 0);
auto exists = plonk::stdlib::merkle_tree::check_subtree_membership(root, hash_path, leaf, index_bits, 0);
composer.assert_equal_constant(exists.witness_index, fr::one());
}

Expand Down
Loading