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

Mv/move to ultra #249

Closed
wants to merge 13 commits into from
Closed
6 changes: 3 additions & 3 deletions cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ if(WASM)
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
$<TARGET_OBJECTS:acir_format_objects>
$<TARGET_OBJECTS:turbo_proofs_objects>
$<TARGET_OBJECTS:acir_proofs_objects>
)

# With binaryen installed, it seems its wasm backend optimiser gets invoked automatically.
Expand Down Expand Up @@ -151,7 +151,7 @@ if(WASM)
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
$<TARGET_OBJECTS:acir_format_objects>
$<TARGET_OBJECTS:turbo_proofs_objects>
$<TARGET_OBJECTS:acir_proofs_objects>
)
else()
# For use when compiling dependent cpp projects
Expand Down Expand Up @@ -183,7 +183,7 @@ else()
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
$<TARGET_OBJECTS:acir_format_objects>
$<TARGET_OBJECTS:turbo_proofs_objects>
$<TARGET_OBJECTS:acir_proofs_objects>
$<TARGET_OBJECTS:env_objects>
)

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/dsl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_subdirectory(acir_format)
add_subdirectory(turbo_proofs)
add_subdirectory(acir_proofs)
34 changes: 17 additions & 17 deletions cpp/src/barretenberg/dsl/acir_format/acir_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace acir_format {

void read_witness(TurboComposer& composer, std::vector<barretenberg::fr> witness)
void read_witness(Composer& composer, std::vector<barretenberg::fr> witness)
{
composer.variables[0] = 0;
for (size_t i = 0; i < witness.size(); ++i) {
composer.variables[i + 1] = witness[i];
}
}

void create_circuit(TurboComposer& composer, const acir_format& constraint_system)
void create_circuit(Composer& composer, const acir_format& constraint_system)
{
if (constraint_system.public_inputs.size() > constraint_system.varnum) {
std::cout << "too many public inputs!" << std::endl;
Expand Down Expand Up @@ -41,7 +41,7 @@ void create_circuit(TurboComposer& composer, const acir_format& constraint_syste

// Add range constraint
for (const auto& constraint : constraint_system.range_constraints) {
composer.decompose_into_base4_accumulators(constraint.witness, constraint.num_bits, "");
composer.create_range_constraint(constraint.witness, constraint.num_bits, "");
}

// Add sha256 constraints
Expand Down Expand Up @@ -85,14 +85,14 @@ void create_circuit(TurboComposer& composer, const acir_format& constraint_syste
}
}

TurboComposer create_circuit(const acir_format& constraint_system,
std::unique_ptr<bonk::ReferenceStringFactory>&& crs_factory)
Composer create_circuit(const acir_format& constraint_system,
std::unique_ptr<bonk::ReferenceStringFactory>&& crs_factory)
{
if (constraint_system.public_inputs.size() > constraint_system.varnum) {
std::cout << "too many public inputs!" << std::endl;
}

TurboComposer composer(std::move(crs_factory));
Composer composer(std::move(crs_factory));

for (size_t i = 1; i < constraint_system.varnum; ++i) {
// If the index is in the public inputs vector, then we add it as a public input
Expand All @@ -119,7 +119,7 @@ TurboComposer create_circuit(const acir_format& constraint_system,

// Add range constraint
for (const auto& constraint : constraint_system.range_constraints) {
composer.decompose_into_base4_accumulators(constraint.witness, constraint.num_bits, "");
composer.create_range_constraint(constraint.witness, constraint.num_bits, "");
}

// Add sha256 constraints
Expand Down Expand Up @@ -165,15 +165,15 @@ TurboComposer create_circuit(const acir_format& constraint_system,
return composer;
}

TurboComposer 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)
{
if (constraint_system.public_inputs.size() > constraint_system.varnum) {
std::cout << "too many public inputs!" << std::endl;
}

TurboComposer composer(std::move(crs_factory));
Composer composer(std::move(crs_factory));

for (size_t i = 1; i < constraint_system.varnum; ++i) {
// If the index is in the public inputs vector, then we add it as a public input
Expand Down Expand Up @@ -203,7 +203,7 @@ TurboComposer create_circuit_with_witness(const acir_format& constraint_system,

// Add range constraint
for (const auto& constraint : constraint_system.range_constraints) {
composer.decompose_into_base4_accumulators(constraint.witness, constraint.num_bits, "");
composer.create_range_constraint(constraint.witness, constraint.num_bits, "");
}

// Add sha256 constraints
Expand Down Expand Up @@ -248,13 +248,13 @@ TurboComposer create_circuit_with_witness(const acir_format& constraint_system,

return composer;
}
TurboComposer 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)
{
if (constraint_system.public_inputs.size() > constraint_system.varnum) {
std::cout << "too many public inputs!" << std::endl;
}

auto composer = TurboComposer();
auto composer = Composer();

for (size_t i = 1; i < constraint_system.varnum; ++i) {
// If the index is in the public inputs vector, then we add it as a public input
Expand Down Expand Up @@ -284,7 +284,7 @@ TurboComposer create_circuit_with_witness(const acir_format& constraint_system,

// Add range constraint
for (const auto& constraint : constraint_system.range_constraints) {
composer.decompose_into_base4_accumulators(constraint.witness, constraint.num_bits, "");
composer.create_range_constraint(constraint.witness, constraint.num_bits, "");
}

// Add sha256 constraints
Expand Down Expand Up @@ -329,7 +329,7 @@ TurboComposer create_circuit_with_witness(const acir_format& constraint_system,

return composer;
}
void create_circuit_with_witness(TurboComposer& 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)
{
if (constraint_system.public_inputs.size() > constraint_system.varnum) {
std::cout << "too many public inputs!" << std::endl;
Expand Down Expand Up @@ -363,7 +363,7 @@ void create_circuit_with_witness(TurboComposer& composer, const acir_format& con

// Add range constraint
for (const auto& constraint : constraint_system.range_constraints) {
composer.decompose_into_base4_accumulators(constraint.witness, constraint.num_bits, "");
composer.create_range_constraint(constraint.witness, constraint.num_bits, "");
}

// Add sha256 constraints
Expand Down
23 changes: 12 additions & 11 deletions cpp/src/barretenberg/dsl/acir_format/acir_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "merkle_membership_constraint.hpp"
#include "pedersen.hpp"
#include "hash_to_field.hpp"
#include "barretenberg/stdlib/types/types.hpp"

using namespace plonk::stdlib::types;

namespace acir_format {

Expand All @@ -35,22 +38,20 @@ struct acir_format {
friend bool operator==(acir_format const& lhs, acir_format const& rhs) = default;
};

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

void create_circuit(TurboComposer& composer, const acir_format& constraint_system);
void create_circuit(Composer& composer, const acir_format& constraint_system);

TurboComposer create_circuit(const acir_format& constraint_system,
std::unique_ptr<bonk::ReferenceStringFactory>&& crs_factory);
Composer create_circuit(const acir_format& constraint_system,
std::unique_ptr<bonk::ReferenceStringFactory>&& crs_factory);

TurboComposer 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);

TurboComposer 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(TurboComposer& 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
7 changes: 2 additions & 5 deletions cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#include "blake2s_constraint.hpp"
#include "round.hpp"
#include "barretenberg/stdlib/types/types.hpp"

using namespace plonk::stdlib::types;

namespace acir_format {

void create_blake2s_constraints(plonk::TurboComposer& composer, const Blake2sConstraint& constraint)
void create_blake2s_constraints(Composer& composer, const Blake2sConstraint& constraint)
{

// Create byte array struct
Expand All @@ -27,7 +24,7 @@ void create_blake2s_constraints(plonk::TurboComposer& composer, const Blake2sCon
arr.write(element_bytes);
}

byte_array_ct output_bytes = plonk::stdlib::blake2s<plonk::TurboComposer>(arr);
byte_array_ct output_bytes = plonk::stdlib::blake2s<Composer>(arr);

// Convert byte array to vector of field_t
auto bytes = output_bytes.bytes();
Expand Down
6 changes: 4 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,9 @@
#pragma once
#include <cstdint>
#include <vector>
#include "barretenberg/plonk/composer/turbo_composer.hpp"
#include "barretenberg/stdlib/types/types.hpp"

using namespace plonk::stdlib::types;

namespace acir_format {

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

void create_blake2s_constraints(plonk::TurboComposer& 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
19 changes: 8 additions & 11 deletions cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#include "ecdsa_secp256k1.hpp"
#include "barretenberg/crypto/ecdsa/ecdsa.hpp"
#include "barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp"
#include "barretenberg/stdlib/types/types.hpp"

using namespace plonk::stdlib::types;

namespace acir_format {

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

crypto::ecdsa::signature signature_cr;
Expand Down Expand Up @@ -42,7 +39,7 @@ crypto::ecdsa::signature ecdsa_convert_signature(plonk::TurboComposer& composer,
return signature_cr;
}

secp256k1_ct::g1_ct ecdsa_convert_inputs(plonk::TurboComposer* ctx, const secp256k1::g1::affine_element& input)
secp256k1_ct::g1_ct ecdsa_convert_inputs(Composer* ctx, const secp256k1::g1::affine_element& input)
{
uint256_t x_u256(input.x);
uint256_t y_u256(input.y);
Expand All @@ -61,7 +58,7 @@ secp256k1_ct::g1_ct ecdsa_convert_inputs(plonk::TurboComposer* ctx, const secp25
// vector of bytes here, assumes that the witness indices point to a field element which can be represented
// with just a byte.
// notice that this function truncates each field_element to a byte
byte_array_ct ecdsa_vector_of_bytes_to_byte_array(plonk::TurboComposer& composer, std::vector<uint32_t> vector_of_bytes)
byte_array_ct ecdsa_vector_of_bytes_to_byte_array(Composer& composer, std::vector<uint32_t> vector_of_bytes)
{
byte_array_ct arr(&composer);

Expand All @@ -77,13 +74,13 @@ byte_array_ct ecdsa_vector_of_bytes_to_byte_array(plonk::TurboComposer& composer
}
return arr;
}
witness_ct ecdsa_index_to_witness(plonk::TurboComposer& composer, uint32_t index)
witness_ct ecdsa_index_to_witness(Composer& composer, uint32_t index)
{
fr value = composer.get_variable(index);
return { &composer, value };
}

void create_ecdsa_verify_constraints(plonk::TurboComposer& composer, const EcdsaSecp256k1Constraint& input)
void create_ecdsa_verify_constraints(Composer& composer, const EcdsaSecp256k1Constraint& input)
{

auto new_sig = ecdsa_convert_signature(composer, input.signature);
Expand All @@ -98,15 +95,15 @@ void create_ecdsa_verify_constraints(plonk::TurboComposer& composer, const Ecdsa
std::vector<uint8_t> rr(new_sig.r.begin(), new_sig.r.end());
std::vector<uint8_t> ss(new_sig.s.begin(), new_sig.s.end());

stdlib::ecdsa::signature<plonk::TurboComposer> sig{ stdlib::byte_array<plonk::TurboComposer>(&composer, rr),
stdlib::byte_array<plonk::TurboComposer>(&composer, ss) };
stdlib::ecdsa::signature<Composer> sig{ stdlib::byte_array<Composer>(&composer, rr),
stdlib::byte_array<Composer>(&composer, ss) };

pub_key_x_fq.assert_is_in_field();
pub_key_y_fq.assert_is_in_field();

secp256k1_ct::g1_bigfr_ct public_key = secp256k1_ct::g1_bigfr_ct(pub_key_x_fq, pub_key_y_fq);

bool_ct signature_result = stdlib::ecdsa::verify_signature<plonk::TurboComposer,
bool_ct signature_result = stdlib::ecdsa::verify_signature<Composer,
secp256k1_ct,
secp256k1_ct::fq_ct,
secp256k1_ct::bigfr_ct,
Expand Down
6 changes: 4 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,8 @@
#pragma once
#include <vector>
#include "barretenberg/plonk/composer/turbo_composer.hpp"
#include "barretenberg/stdlib/types/types.hpp"

using namespace plonk::stdlib::types;

namespace acir_format {

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

void create_ecdsa_verify_constraints(plonk::TurboComposer& 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
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#include "fixed_base_scalar_mul.hpp"
#include "barretenberg/stdlib/types/types.hpp"

using namespace plonk::stdlib::types;

namespace acir_format {

void create_fixed_base_constraint(plonk::TurboComposer& composer, const FixedBaseScalarMul& input)
void create_fixed_base_constraint(Composer& composer, const FixedBaseScalarMul& input)
{

field_ct scalar_as_field = field_ct::from_witness_index(&composer, input.scalar);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include <cstdint>
#include "barretenberg/plonk/composer/turbo_composer.hpp"
#include "barretenberg/stdlib/types/types.hpp"

using namespace plonk::stdlib::types;

namespace acir_format {

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

void create_fixed_base_constraint(plonk::TurboComposer& 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
7 changes: 2 additions & 5 deletions cpp/src/barretenberg/dsl/acir_format/hash_to_field.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#include "hash_to_field.hpp"
#include "round.hpp"
#include "barretenberg/stdlib/types/types.hpp"

using namespace plonk::stdlib::types;

namespace acir_format {

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

// Create byte array struct
Expand All @@ -31,7 +28,7 @@ void create_hash_to_field_constraints(plonk::TurboComposer& composer, const Hash
// Hash To Field using blake2s.
// Note: It does not need to be blake2s in the future

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

field_ct out(out_bytes);
field_ct normalised_out = out.normalize();
Expand Down
Loading