Skip to content

Commit

Permalink
Get rid of system composer.
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Apr 14, 2023
1 parent 4bfda8f commit 611c479
Show file tree
Hide file tree
Showing 71 changed files with 499 additions and 548 deletions.
2 changes: 0 additions & 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
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 @@ -9,7 +9,7 @@
#include "merkle_membership_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 All @@ -36,23 +36,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
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
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
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 All @@ -14,8 +14,7 @@ struct MerkleMembershipConstraint {
friend bool operator==(MerkleMembershipConstraint const& lhs, MerkleMembershipConstraint const& rhs) = default;
};

void create_merkle_check_membership_constraint(plonk::stdlib::types::Composer& composer,
const MerkleMembershipConstraint& input);
void create_merkle_check_membership_constraint(Composer& composer, const MerkleMembershipConstraint& input);

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

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

namespace acir_format {

using namespace proof_system::plonk;

void create_pedersen_constraint(Composer& composer, const PedersenConstraint& input)
{
std::vector<field_ct> scalars;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/barretenberg/dsl/acir_format/pedersen.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 All @@ -13,7 +13,7 @@ struct PedersenConstraint {
friend bool operator==(PedersenConstraint const& lhs, PedersenConstraint const& rhs) = default;
};

void create_pedersen_constraint(plonk::stdlib::types::Composer& composer, const PedersenConstraint& input);
void create_pedersen_constraint(Composer& composer, const PedersenConstraint& input);

template <typename B> inline void read(B& buf, PedersenConstraint& constraint)
{
Expand Down
9 changes: 5 additions & 4 deletions cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "schnorr_verify.hpp"
#include "barretenberg/stdlib/encryption/schnorr/schnorr.hpp"
#include "barretenberg/crypto/schnorr/schnorr.hpp"

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

namespace acir_format {

using namespace proof_system::plonk::stdlib;

crypto::schnorr::signature convert_signature(Composer& composer, std::vector<uint32_t> signature)
{

Expand Down Expand Up @@ -82,9 +83,9 @@ void create_schnorr_verify_constraints(Composer& composer, const SchnorrConstrai

point_ct pub_key{ witness_ct(&composer, pubkey_value_x), witness_ct(&composer, pubkey_value_y) };

schnorr::signature_bits sig = stdlib::schnorr::convert_signature(&composer, new_sig);
schnorr_signature_bits_ct sig = schnorr::convert_signature(&composer, new_sig);

bool_ct signature_result = stdlib::schnorr::signature_verification_result(message, pub_key, sig);
bool_ct signature_result = schnorr::signature_verification_result(message, pub_key, sig);

bool_ct signature_result_normalized = signature_result.normalize();

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/barretenberg/dsl/acir_format/schnorr_verify.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 All @@ -25,7 +25,7 @@ struct SchnorrConstraint {
friend bool operator==(SchnorrConstraint const& lhs, SchnorrConstraint const& rhs) = default;
};

void create_schnorr_verify_constraints(plonk::stdlib::types::Composer& composer, const SchnorrConstraint& input);
void create_schnorr_verify_constraints(Composer& composer, const SchnorrConstraint& input);

template <typename B> inline void read(B& buf, SchnorrConstraint& constraint)
{
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "sha256_constraint.hpp"
#include "round.hpp"
#include "barretenberg/stdlib/hash/sha256/sha256.hpp"

using namespace proof_system::plonk::stdlib::types;
#include "barretenberg/dsl/types.hpp"

namespace acir_format {

// using namespace ;

// This function does not work (properly) because the stdlib:sha256 function is not working correctly for 512 bits
// pair<witness_index, bits>
void create_sha256_constraints(Composer& composer, const Sha256Constraint& constraint)
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/barretenberg/dsl/acir_format/sha256_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 @@ -21,7 +21,7 @@ struct Sha256Constraint {

// This function does not work (properly) because the stdlib:sha256 function is not working correctly for 512 bits
// pair<witness_index, bits>
void create_sha256_constraints(plonk::stdlib::types::Composer& composer, const Sha256Constraint& constraint);
void create_sha256_constraints(Composer& composer, const Sha256Constraint& constraint);

template <typename B> inline void read(B& buf, Sha256Input& constraint)
{
Expand Down
Loading

0 comments on commit 611c479

Please sign in to comment.