diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 582d728537..4f719a0335 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -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.") diff --git a/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp b/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp index c702ec980a..0f10fb87ed 100644 --- a/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -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 witness) diff --git a/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp b/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp index 55d5ee969e..0b326e922c 100644 --- a/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp @@ -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 { @@ -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 witness); +void read_witness(Composer& composer, std::vector 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&& crs_factory); +Composer create_circuit(const acir_format& constraint_system, + std::unique_ptr&& crs_factory); -plonk::stdlib::types::Composer create_circuit_with_witness(const acir_format& constraint_system, - std::vector witness, - std::unique_ptr&& crs_factory); +Composer create_circuit_with_witness(const acir_format& constraint_system, + std::vector witness, + std::unique_ptr&& crs_factory); -plonk::stdlib::types::Composer create_circuit_with_witness(const acir_format& constraint_system, - std::vector witness); +Composer create_circuit_with_witness(const acir_format& constraint_system, std::vector witness); -void create_circuit_with_witness(plonk::stdlib::types::Composer& composer, - const acir_format& constraint_system, - std::vector witness); +void create_circuit_with_witness(Composer& composer, const acir_format& constraint_system, std::vector witness); // Serialisation template inline void read(B& buf, acir_format& data) diff --git a/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp b/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp index 03deb176f6..8cd00269af 100644 --- a/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp +++ b/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp @@ -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) diff --git a/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp b/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp index 643eb1e39b..f68bf2019a 100644 --- a/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp @@ -1,7 +1,7 @@ #pragma once #include #include -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/dsl/types.hpp" namespace acir_format { @@ -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 inline void read(B& buf, Blake2sInput& constraint) { diff --git a/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp b/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp index d81a670cb0..c18a426e20 100644 --- a/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp +++ b/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp @@ -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 signature) { diff --git a/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp b/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp index 9fee1b035a..55d8f6c16d 100644 --- a/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/dsl/types.hpp" namespace acir_format { @@ -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 inline void read(B& buf, EcdsaSecp256k1Constraint& constraint) { diff --git a/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp b/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp index 81251944e6..453ab56f47 100644 --- a/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp +++ b/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp @@ -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) diff --git a/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp b/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp index 2b61305a5c..80e52e03db 100644 --- a/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/dsl/types.hpp" namespace acir_format { @@ -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 inline void read(B& buf, FixedBaseScalarMul& constraint) { diff --git a/cpp/src/barretenberg/dsl/acir_format/hash_to_field.cpp b/cpp/src/barretenberg/dsl/acir_format/hash_to_field.cpp index 998b414cd4..afc3e2cf9f 100644 --- a/cpp/src/barretenberg/dsl/acir_format/hash_to_field.cpp +++ b/cpp/src/barretenberg/dsl/acir_format/hash_to_field.cpp @@ -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) { @@ -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(arr); + byte_array_ct out_bytes = stdlib::blake2s(arr); field_ct out(out_bytes); field_ct normalised_out = out.normalize(); diff --git a/cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp b/cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp index 275ce3fd0d..504493ce3e 100644 --- a/cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp @@ -1,7 +1,7 @@ #pragma once #include #include -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/dsl/types.hpp" namespace acir_format { @@ -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 inline void read(B& buf, HashToFieldInput& constraint) { diff --git a/cpp/src/barretenberg/dsl/acir_format/logic_constraint.cpp b/cpp/src/barretenberg/dsl/acir_format/logic_constraint.cpp index ca14b7cbc4..09990fe04b 100644 --- a/cpp/src/barretenberg/dsl/acir_format/logic_constraint.cpp +++ b/cpp/src/barretenberg/dsl/acir_format/logic_constraint.cpp @@ -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, diff --git a/cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp b/cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp index 0a194838ad..964f84f5af 100644 --- a/cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/dsl/types.hpp" namespace acir_format { @@ -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 inline void read(B& buf, LogicConstraint& constraint) { diff --git a/cpp/src/barretenberg/dsl/acir_format/merkle_membership_constraint.cpp b/cpp/src/barretenberg/dsl/acir_format/merkle_membership_constraint.cpp index 3f30a61fcb..780373f5be 100644 --- a/cpp/src/barretenberg/dsl/acir_format/merkle_membership_constraint.cpp +++ b/cpp/src/barretenberg/dsl/acir_format/merkle_membership_constraint.cpp @@ -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) @@ -22,7 +19,7 @@ void create_merkle_check_membership_constraint(Composer& composer, const MerkleM // We are given the HashPath as a Vec // 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 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 @@ -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()); } diff --git a/cpp/src/barretenberg/dsl/acir_format/merkle_membership_constraint.hpp b/cpp/src/barretenberg/dsl/acir_format/merkle_membership_constraint.hpp index 1fa1481e88..25bfcd0404 100644 --- a/cpp/src/barretenberg/dsl/acir_format/merkle_membership_constraint.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/merkle_membership_constraint.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/dsl/types.hpp" namespace acir_format { @@ -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 inline void read(B& buf, MerkleMembershipConstraint& constraint) { diff --git a/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp b/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp index 3ac7951ec9..d272a3a8ed 100644 --- a/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp +++ b/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp @@ -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 scalars; @@ -13,12 +13,9 @@ void create_pedersen_constraint(Composer& composer, const PedersenConstraint& in field_ct scalar_as_field = field_ct::from_witness_index(&composer, scalar); scalars.push_back(scalar_as_field); } -#ifdef USE_TURBO - auto point = pedersen_commitment::commit(scalars); -#else + // TODO: Does Noir need additive homomorphic Pedersen hash? If so, using plookup version won't help. auto point = stdlib::pedersen_plookup_commitment::commit(scalars); -#endif composer.assert_equal(point.x.witness_index, input.result_x); composer.assert_equal(point.y.witness_index, input.result_y); diff --git a/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp b/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp index b801d2a8f2..3144359b2f 100644 --- a/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/dsl/types.hpp" namespace acir_format { @@ -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 inline void read(B& buf, PedersenConstraint& constraint) { diff --git a/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp b/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp index f92176bd08..cb717ed99a 100644 --- a/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp +++ b/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp @@ -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 signature) { @@ -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(); diff --git a/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.hpp b/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.hpp index f8e6b9c53f..7b6b984294 100644 --- a/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/dsl/types.hpp" namespace acir_format { @@ -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 inline void read(B& buf, SchnorrConstraint& constraint) { diff --git a/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp b/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp index e54697d4e7..07c8166bd1 100644 --- a/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp +++ b/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp @@ -1,8 +1,7 @@ #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 { diff --git a/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp b/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp index dec3bca40a..eccb1521ab 100644 --- a/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp +++ b/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp @@ -1,7 +1,7 @@ #pragma once #include #include -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/dsl/types.hpp" namespace acir_format { @@ -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 -void create_sha256_constraints(plonk::stdlib::types::Composer& composer, const Sha256Constraint& constraint); +void create_sha256_constraints(Composer& composer, const Sha256Constraint& constraint); template inline void read(B& buf, Sha256Input& constraint) { diff --git a/cpp/src/barretenberg/dsl/acir_proofs/acir_proofs.cpp b/cpp/src/barretenberg/dsl/acir_proofs/acir_proofs.cpp index bbcb24c42c..2010c592fb 100644 --- a/cpp/src/barretenberg/dsl/acir_proofs/acir_proofs.cpp +++ b/cpp/src/barretenberg/dsl/acir_proofs/acir_proofs.cpp @@ -2,12 +2,10 @@ #include "acir_proofs.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/dsl/types.hpp" #include "barretenberg/srs/reference_string/pippenger_reference_string.hpp" #include "barretenberg/plonk/proof_system/verification_key/sol_gen.hpp" -using namespace proof_system::plonk::stdlib::types; - namespace acir_proofs { size_t get_solidity_verifier(uint8_t const* g2x, uint8_t const* vk_buf, uint8_t** output_buf) @@ -77,9 +75,9 @@ size_t init_verification_key(void* pippenger, uint8_t const* g2x, uint8_t const* reinterpret_cast(pippenger), g2x); proving_key->reference_string = crs_factory->get_prover_crs(proving_key->circuit_size); - Composer composer(proving_key, nullptr); + acir_format::Composer composer(proving_key, nullptr); auto verification_key = - plonk::stdlib::types::Composer::compute_verification_key_base(proving_key, crs_factory->get_verifier_crs()); + acir_format::Composer::compute_verification_key_base(proving_key, crs_factory->get_verifier_crs()); // The composer_type has not yet been set. We need to set the composer_type for when we later read in and // construct the verification key so that we have the correct polynomial manifest @@ -113,13 +111,13 @@ size_t new_proof(void* pippenger, reinterpret_cast(pippenger), g2x); proving_key->reference_string = crs_factory->get_prover_crs(proving_key->circuit_size); - Composer composer(proving_key, nullptr); + acir_format::Composer composer(proving_key, nullptr); create_circuit_with_witness(composer, constraint_system, witness); auto prover = composer.create_ultra_with_keccak_prover(); - auto heapProver = new stdlib::types::Prover(std::move(prover)); + auto heapProver = new acir_format::Prover(std::move(prover)); auto& proof_data = heapProver->construct_proof().proof_data; *proof_data_buf = proof_data.data(); @@ -140,7 +138,7 @@ bool verify_proof( read(vk_buf, vk_data); auto verification_key = std::make_shared(std::move(vk_data), crs); - Composer composer(nullptr, verification_key); + acir_format::Composer composer(nullptr, verification_key); create_circuit(composer, constraint_system); plonk::proof pp = { std::vector(proof, proof + length) }; diff --git a/cpp/src/barretenberg/dsl/types.hpp b/cpp/src/barretenberg/dsl/types.hpp new file mode 100644 index 0000000000..edb5905711 --- /dev/null +++ b/cpp/src/barretenberg/dsl/types.hpp @@ -0,0 +1,63 @@ +#pragma once +#include "barretenberg/plonk/composer/ultra_composer.hpp" + +#include "barretenberg/plonk/proof_system/prover/prover.hpp" +#include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" +#include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" +#include "barretenberg/stdlib/primitives/bit_array/bit_array.hpp" +#include "barretenberg/stdlib/primitives/bool/bool.hpp" +#include "barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp" +#include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" +#include "barretenberg/stdlib/primitives/uint/uint.hpp" +#include "barretenberg/stdlib/primitives/witness/witness.hpp" +#include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" +#include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" +#include "barretenberg/stdlib/commitment/pedersen/pedersen.hpp" +#include "barretenberg/stdlib/commitment/pedersen/pedersen_plookup.hpp" +#include "barretenberg/stdlib/merkle_tree/hash_path.hpp" +#include "barretenberg/stdlib/encryption/schnorr/schnorr.hpp" +#include "barretenberg/stdlib/primitives/curves/bn254.hpp" +#include "barretenberg/stdlib/primitives/curves/secp256k1.hpp" +#include "barretenberg/stdlib/primitives/memory/rom_table.hpp" +namespace acir_format { + +using Composer = plonk::UltraComposer; + +using Prover = std::conditional_t< + std::same_as, + plonk::UltraWithKeccakProver, + std::conditional_t, plonk::TurboProver, plonk::Prover>>; + +using Verifier = std::conditional_t< + std::same_as, + plonk::UltraWithKeccakVerifier, + std::conditional_t, plonk::TurboVerifier, plonk::Verifier>>; + +using witness_ct = proof_system::plonk::stdlib::witness_t; +using public_witness_ct = proof_system::plonk::stdlib::public_witness_t; +using bool_ct = proof_system::plonk::stdlib::bool_t; +using byte_array_ct = proof_system::plonk::stdlib::byte_array; +using packed_byte_array_ct = proof_system::plonk::stdlib::packed_byte_array; +using field_ct = proof_system::plonk::stdlib::field_t; +using suint_ct = proof_system::plonk::stdlib::safe_uint_t; +using uint8_ct = proof_system::plonk::stdlib::uint8; +using uint16_ct = proof_system::plonk::stdlib::uint16; +using uint32_ct = proof_system::plonk::stdlib::uint32; +using uint64_ct = proof_system::plonk::stdlib::uint64; +using bit_array_ct = proof_system::plonk::stdlib::bit_array; +using fq_ct = proof_system::plonk::stdlib::bigfield; +using biggroup_ct = proof_system::plonk::stdlib::element; +using point_ct = proof_system::plonk::stdlib::point; +using pedersen_commitment = proof_system::plonk::stdlib::pedersen_commitment; +using group_ct = proof_system::plonk::stdlib::group; +using bn254 = proof_system::plonk::stdlib::bn254; +using secp256k1_ct = proof_system::plonk::stdlib::secp256k1; + +using hash_path_ct = proof_system::plonk::stdlib::merkle_tree::hash_path; + +using schnorr_signature_bits_ct = proof_system::plonk::stdlib::schnorr::signature_bits; + +// Ultra-composer specific typesv +using rom_table_ct = proof_system::plonk::stdlib::rom_table; + +} // namespace acir_format diff --git a/cpp/src/barretenberg/honk/proof_system/verifier.cpp b/cpp/src/barretenberg/honk/proof_system/verifier.cpp index 26e4b7e033..b26f10fa47 100644 --- a/cpp/src/barretenberg/honk/proof_system/verifier.cpp +++ b/cpp/src/barretenberg/honk/proof_system/verifier.cpp @@ -3,7 +3,6 @@ #include #include #include "barretenberg/honk/transcript/transcript.hpp" -#include "barretenberg/plonk/proof_system/constants.hpp" #include "./verifier.hpp" #include "barretenberg/plonk/proof_system/public_inputs/public_inputs.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" diff --git a/cpp/src/barretenberg/honk/proof_system/verifier.test.cpp b/cpp/src/barretenberg/honk/proof_system/verifier.test.cpp index b98d39e893..903ea36adb 100644 --- a/cpp/src/barretenberg/honk/proof_system/verifier.test.cpp +++ b/cpp/src/barretenberg/honk/proof_system/verifier.test.cpp @@ -1,5 +1,4 @@ #include "barretenberg/numeric/bitop/get_msb.hpp" -#include "barretenberg/plonk/proof_system/constants.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/honk/flavor/flavor.hpp" #include "prover.hpp" diff --git a/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp b/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp index b7dfb6f48d..e5371b8bd0 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp @@ -229,20 +229,20 @@ circuit_data get_circuit_data(std::string const& name, Timer timer; if (!mock) { - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); auto proof = prover.construct_proof(); data.padding_proof = proof.proof_data; data.num_gates = composer.get_num_gates(); info(name, ": Circuit size: ", data.num_gates); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); info(name, ": Padding verified: ", verifier.verify_proof(proof)); } else { - auto prover = mock_proof_composer.create_ultra_with_keccak_prover(); + auto prover = mock_proof_composer.create_prover(); auto proof = prover.construct_proof(); data.padding_proof = proof.proof_data; data.num_gates = mock_proof_composer.get_num_gates(); info(name, ": Mock circuit size: ", data.num_gates); - auto verifier = mock_proof_composer.create_ultra_with_keccak_verifier(); + auto verifier = mock_proof_composer.create_verifier(); info(name, ": Padding verified: ", verifier.verify_proof(proof)); } info(name, ": Padding proof computed in ", timer.toString(), "s"); diff --git a/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.cpp b/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.cpp index cb35a19d27..5ee4b90fad 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "c_bind.h" #include "join_split.hpp" #include "compute_signing_data.hpp" @@ -5,14 +8,12 @@ #include "barretenberg/common/streams.hpp" #include "barretenberg/common/mem.hpp" #include "barretenberg/common/container.hpp" -#include #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "barretenberg/srs/reference_string/pippenger_reference_string.hpp" #include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" -#include +#include "barretenberg/join_split_example/types.hpp" using namespace barretenberg; -using namespace proof_system::plonk::stdlib::types; using namespace join_split_example::proofs::join_split; #define WASM_EXPORT __attribute__((visibility("default"))) @@ -42,22 +43,10 @@ WASM_EXPORT void join_split__release_key() WASM_EXPORT uint32_t join_split__get_new_proving_key_data(uint8_t** output) { -// Computing the size of the serialized key is non trivial. We know it's ~331mb. -// Allocate a buffer large enough to hold it, and abort if we overflow. -// This is to keep memory usage down. -#ifdef USE_TURBO - size_t total_buf_len = 350 * 1024 * 1024; - auto raw_buf = (uint8_t*)malloc(total_buf_len); - auto raw_buf_end = raw_buf; - write(raw_buf_end, *get_proving_key()); - *output = raw_buf; - auto len = static_cast(raw_buf_end - raw_buf); - if (len > total_buf_len) { - info("Buffer overflow serializing proving key."); - std::abort(); - } - return len; -#else + // Computing the size of the serialized key is non trivial. We know it's ~331mb. + // Allocate a buffer large enough to hold it, and abort if we overflow. + // This is to keep memory usage down. + auto proving_key = get_proving_key(); auto buffer = to_buffer(*proving_key); auto raw_buf = (uint8_t*)malloc(buffer.size()); @@ -65,7 +54,6 @@ WASM_EXPORT uint32_t join_split__get_new_proving_key_data(uint8_t** output) *output = raw_buf; return static_cast(buffer.size()); -#endif } WASM_EXPORT void join_split__init_verification_key(void* pippenger, uint8_t const* g2x) @@ -103,13 +91,13 @@ WASM_EXPORT void* join_split__new_prover(uint8_t const* join_split_buf, bool moc { auto tx = from_buffer(join_split_buf); auto prover = new_join_split_prover(tx, mock); - auto heapProver = new stdlib::types::Prover(std::move(prover)); + auto heapProver = new join_split_example::Prover(std::move(prover)); return heapProver; } WASM_EXPORT void join_split__delete_prover(void* prover) { - delete reinterpret_cast(prover); + delete reinterpret_cast(prover); } WASM_EXPORT bool join_split__verify_proof(uint8_t* proof, uint32_t length) diff --git a/cpp/src/barretenberg/join_split_example/proofs/join_split/compute_circuit_data.cpp b/cpp/src/barretenberg/join_split_example/proofs/join_split/compute_circuit_data.cpp index 47fc4deec2..037799660b 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/join_split/compute_circuit_data.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/join_split/compute_circuit_data.cpp @@ -3,13 +3,14 @@ #include "sign_join_split_tx.hpp" #include "../notes/native/index.hpp" #include "barretenberg/stdlib/merkle_tree/hash_path.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example { namespace proofs { namespace join_split { using namespace join_split_example::proofs::join_split; -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; using namespace join_split_example::proofs::notes::native; using namespace proof_system::plonk::stdlib::merkle_tree; diff --git a/cpp/src/barretenberg/join_split_example/proofs/join_split/create_proof.hpp b/cpp/src/barretenberg/join_split_example/proofs/join_split/create_proof.hpp index b86ae164a1..8dd542fdf6 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/join_split/create_proof.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/join_split/create_proof.hpp @@ -20,7 +20,7 @@ inline std::vector create_proof(join_split_tx const& tx, info("Join-split circuit logic failed: ", composer.err()); } - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); auto proof = prover.construct_proof(); return proof.proof_data; diff --git a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp index bacb9868c8..95aee064e2 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp @@ -2,6 +2,7 @@ #include "join_split_circuit.hpp" #include "compute_circuit_data.hpp" #include "barretenberg/plonk/proof_system/commitment_scheme/kate_commitment_scheme.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example { namespace proofs { @@ -23,7 +24,7 @@ void init_proving_key(std::shared_ptr cons join_split_tx tx = noop_tx(); if (!mock) { - stdlib::types::Composer composer(crs_factory); + Composer composer(crs_factory); join_split_circuit(composer, tx); proving_key = composer.compute_proving_key(); } else { @@ -55,8 +56,7 @@ void init_verification_key(std::unique_ptr // Patch the 'nothing' reference string fed to init_proving_key. proving_key->reference_string = crs_factory->get_prover_crs(proving_key->circuit_size + 1); - verification_key = - plonk::stdlib::types::Composer::compute_verification_key_base(proving_key, crs_factory->get_verifier_crs()); + verification_key = Composer::compute_verification_key_base(proving_key, crs_factory->get_verifier_crs()); } void init_verification_key(std::shared_ptr const& crs, @@ -65,7 +65,7 @@ void init_verification_key(std::shared_ptr(std::move(vk_data), crs); } -stdlib::types::Prover new_join_split_prover(join_split_tx const& tx, bool mock) +Prover new_join_split_prover(join_split_tx const& tx, bool mock) { Composer composer(proving_key, nullptr); join_split_circuit(composer, tx); @@ -79,27 +79,21 @@ stdlib::types::Prover new_join_split_prover(join_split_tx const& tx, bool mock) if (!mock) { info("composer gates: ", composer.get_num_gates()); - return composer.create_ultra_with_keccak_prover(); + return composer.create_prover(); } else { Composer mock_proof_composer(proving_key, nullptr); join_split_example::proofs::mock::mock_circuit(mock_proof_composer, composer.get_public_inputs()); info("mock composer gates: ", mock_proof_composer.get_num_gates()); - return mock_proof_composer.create_ultra_with_keccak_prover(); + return mock_proof_composer.create_prover(); } } bool verify_proof(plonk::proof const& proof) { - plonk::stdlib::types::Verifier verifier(verification_key, - Composer::create_manifest(verification_key->num_public_inputs)); + Verifier verifier(verification_key, Composer::create_manifest(verification_key->num_public_inputs)); -#ifdef USE_TURBO - std::unique_ptr> kate_commitment_scheme = - std::make_unique>(); -#else std::unique_ptr> kate_commitment_scheme = std::make_unique>(); -#endif verifier.commitment_scheme = std::move(kate_commitment_scheme); return verifier.verify_proof(proof); diff --git a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.hpp b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.hpp index 6c9b4ac5ab..a6c103a4a0 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.hpp @@ -1,14 +1,13 @@ #pragma once #include "join_split_tx.hpp" #include "barretenberg/srs/reference_string/mem_reference_string.hpp" -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example { namespace proofs { namespace join_split { using namespace proof_system::plonk::stdlib::merkle_tree; -using namespace proof_system::plonk::stdlib::types; void init_proving_key(std::shared_ptr const& crs_factory, bool mock); @@ -22,7 +21,7 @@ void init_verification_key(std::unique_ptr void init_verification_key(std::shared_ptr const& crs, plonk::verification_key_data&& vk_data); -stdlib::types::Prover new_join_split_prover(join_split_tx const& tx, bool mock); +Prover new_join_split_prover(join_split_tx const& tx, bool mock); bool verify_proof(plonk::proof const& proof); diff --git a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp index fc3e4a1426..25b802cd62 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp @@ -1,3 +1,5 @@ +#include + #include "../../constants.hpp" #include "../inner_proof_data/inner_proof_data.hpp" #include "index.hpp" @@ -5,9 +7,9 @@ #include "join_split_circuit.hpp" #include "barretenberg/common/streams.hpp" #include "barretenberg/common/test.hpp" -#include #include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" #include "barretenberg/stdlib/merkle_tree/index.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example::proofs::join_split { @@ -98,14 +100,14 @@ TYPED_TEST(join_split, deposit) BenchmarkInfoCollator benchmark_collator; Timer timer; - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); auto build_time = timer.toString(); benchmark_collator.benchmark_info_deferred( GET_COMPOSER_NAME_STRING(Composer::type), "Core", "join split", "Build time", build_time); auto proof = prover.construct_proof(); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); bool verified = verifier.verify_proof(proof); ASSERT_TRUE(verified); @@ -122,7 +124,7 @@ constexpr bool CIRCUIT_CHANGE_EXPECTED = false; #endif using namespace barretenberg; -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; using namespace proof_system::plonk::stdlib::merkle_tree; using namespace join_split_example::proofs::notes::native; using key_pair = join_split_example::fixtures::grumpkin_key_pair; @@ -800,17 +802,12 @@ TEST_F(join_split_tests, test_0_input_notes_and_detect_circuit_change) EXPECT_TRUE(result.valid); -// The below part detects any changes in the join-split circuit -#ifdef USE_TURBO - constexpr uint32_t CIRCUIT_GATE_COUNT = 59175; - constexpr uint32_t GATES_NEXT_POWER_OF_TWO = 65536; - const uint256_t VK_HASH("095cbe8f1b09690713d5161708b5ea77119575884e3cfab14f7364b9f1ba7faa"); -#else + // The below part detects any changes in the join-split circuit + constexpr uint32_t CIRCUIT_GATE_COUNT = 185573; constexpr uint32_t GATES_NEXT_POWER_OF_TWO = 524288; const uint256_t VK_HASH("13eb88883e80efb9bf306af2962cd1a49e9fa1b0bfb2d4b563b95217a17bcc74"); -#endif auto number_of_gates_js = result.number_of_gates; auto vk_hash_js = get_verification_key()->sha256_hash(); @@ -2623,11 +2620,8 @@ TEST_F(join_split_tests, serialized_proving_key_size) { uint8_t* ptr; auto len = join_split__get_new_proving_key_data(&ptr); -#ifdef USE_TURBO - EXPECT_LE(len, 2 * 170 * 1024 * 1024); -#else + EXPECT_LE(len, 2315258552); -#endif } } // namespace join_split_example::proofs::join_split diff --git a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.cpp b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.cpp index a0061cde88..c1ea2af1da 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.cpp @@ -6,6 +6,7 @@ #include "../notes/circuit/claim/claim_note.hpp" #include "verify_signature.hpp" #include "barretenberg/stdlib/merkle_tree/membership.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example { namespace proofs { @@ -22,7 +23,7 @@ using namespace proof_system::plonk::stdlib::merkle_tree; */ field_ct process_input_note(field_ct const& account_private_key, field_ct const& merkle_root, - merkle_tree::hash_path const& hash_path, + hash_path_ct const& hash_path, suint_ct const& index, value::value_note const& note, bool_ct is_propagated, @@ -31,7 +32,7 @@ field_ct process_input_note(field_ct const& account_private_key, const bool_ct valid_value = note.value == 0 || is_note_in_use; valid_value.assert_equal(true, "padding note non zero"); - const bool_ct exists = merkle_tree::check_membership( + const bool_ct exists = proof_system::plonk::stdlib::merkle_tree::check_membership( merkle_root, hash_path, note.commitment, index.value.decompose_into_bits(DATA_TREE_DEPTH)); const bool_ct valid = exists || is_propagated || !is_note_in_use; valid.assert_equal(true, "input note not a member"); @@ -216,10 +217,10 @@ join_split_outputs join_split_circuit_component(join_split_inputs const& inputs) const auto account_alias_hash = inputs.alias_hash; const auto account_note_data = account::account_note(account_alias_hash.value, account_public_key, signer); const bool_ct signing_key_exists = - merkle_tree::check_membership(inputs.merkle_root, - inputs.account_note_path, - account_note_data.commitment, - inputs.account_note_index.value.decompose_into_bits(DATA_TREE_DEPTH)); + stdlib::merkle_tree::check_membership(inputs.merkle_root, + inputs.account_note_path, + account_note_data.commitment, + inputs.account_note_index.value.decompose_into_bits(DATA_TREE_DEPTH)); (signing_key_exists || !inputs.account_required).assert_equal(true, "account check_membership failed"); } @@ -287,8 +288,8 @@ void join_split_circuit(Composer& composer, join_split_tx const& tx) .signing_pub_key = stdlib::create_point_witness(composer, tx.signing_pub_key), .signature = stdlib::schnorr::convert_signature(&composer, tx.signature), .merkle_root = witness_ct(&composer, tx.old_data_root), - .input_path1 = merkle_tree::create_witness_hash_path(composer, tx.input_path[0]), - .input_path2 = merkle_tree::create_witness_hash_path(composer, tx.input_path[1]), + .input_path1 = stdlib::merkle_tree::create_witness_hash_path(composer, tx.input_path[0]), + .input_path2 = stdlib::merkle_tree::create_witness_hash_path(composer, tx.input_path[1]), .account_note_index = suint_ct(witness_ct(&composer, tx.account_note_index), DATA_TREE_DEPTH, "account_note_index"), .account_note_path = merkle_tree::create_witness_hash_path(composer, tx.account_note_path), diff --git a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.hpp b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.hpp index b8821989b4..bde45a710c 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.hpp @@ -3,15 +3,14 @@ #include "../notes/circuit/value/witness_data.hpp" #include "../notes/circuit/claim/witness_data.hpp" #include "barretenberg/crypto/schnorr/schnorr.hpp" -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example { namespace proofs { namespace join_split { -using namespace proof_system::plonk::stdlib::types; - struct join_split_inputs { + field_ct proof_id; suint_ct public_value; field_ct public_owner; @@ -25,12 +24,12 @@ struct join_split_inputs { notes::circuit::value::witness_data output_note2; notes::circuit::claim::partial_claim_note_witness_data partial_claim_note; point_ct signing_pub_key; - stdlib::schnorr::signature_bits signature; + schnorr::signature_bits signature; field_ct merkle_root; - merkle_tree::hash_path input_path1; - merkle_tree::hash_path input_path2; + hash_path_ct input_path1; + hash_path_ct input_path2; suint_ct account_note_index; - merkle_tree::hash_path account_note_path; + hash_path_ct account_note_path; field_ct account_private_key; suint_ct alias_hash; bool_ct account_required; diff --git a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.hpp b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.hpp index 4dae8f30e3..fe309b8dac 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.hpp @@ -3,14 +3,12 @@ #include "../notes/native/value/value_note.hpp" #include "barretenberg/crypto/schnorr/schnorr.hpp" #include "barretenberg/stdlib/merkle_tree/hash_path.hpp" -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example { namespace proofs { namespace join_split { -using namespace proof_system::plonk::stdlib::types; - struct join_split_tx { uint32_t proof_id; uint256_t public_value; @@ -19,7 +17,7 @@ struct join_split_tx { uint32_t num_input_notes; std::array input_index; barretenberg::fr old_data_root; - std::array input_path; + std::array input_path; std::array input_note; std::array output_note; @@ -29,7 +27,7 @@ struct join_split_tx { barretenberg::fr alias_hash; bool account_required; uint32_t account_note_index; - merkle_tree::fr_hash_path account_note_path; + proof_system::plonk::stdlib::merkle_tree::fr_hash_path account_note_path; grumpkin::g1::affine_element signing_pub_key; barretenberg::fr backward_link; // 0: no link, otherwise: any commitment. diff --git a/cpp/src/barretenberg/join_split_example/proofs/mock/mock_circuit.test.cpp b/cpp/src/barretenberg/join_split_example/proofs/mock/mock_circuit.test.cpp index 2188725010..6960962095 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/mock/mock_circuit.test.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/mock/mock_circuit.test.cpp @@ -1,9 +1,9 @@ #include "mock_circuit.hpp" #include "../join_split/join_split_tx.hpp" #include "barretenberg/common/test.hpp" -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; namespace rollup { namespace proofs { @@ -20,14 +20,14 @@ TEST(mock_circuit_tests, test_simple_circuit) Composer composer = Composer("../srs_db/ignition"); mock_circuit(composer, public_inputs); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); plonk::proof proof = prover.construct_proof(); std::cout << "gates: " << composer.get_num_gates() << std::endl; std::cout << "proof size: " << proof.proof_data.size() << std::endl; std::cout << "public inputs size: " << composer.public_inputs.size() << std::endl; - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); bool result = verifier.verify_proof(proof); EXPECT_TRUE(result); diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/account/account_note.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/account/account_note.hpp index 334b2edfc3..30390eb103 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/account/account_note.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/account/account_note.hpp @@ -1,6 +1,7 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" #include "commit.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example { namespace proofs { @@ -8,8 +9,6 @@ namespace notes { namespace circuit { namespace account { -using namespace proof_system::plonk::stdlib::types; - struct account_note { field_ct account_alias_hash; point_ct account_public_key; diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/account/commit.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/account/commit.hpp index 497644a951..dbe568197a 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/account/commit.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/account/commit.hpp @@ -1,6 +1,8 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/stdlib/commitment/pedersen/pedersen.hpp" +#include "barretenberg/stdlib/primitives/point/point.hpp" #include "../../constants.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example { namespace proofs { @@ -8,7 +10,7 @@ namespace notes { namespace circuit { namespace account { -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; inline auto commit(field_ct const& account_alias_hash, point_ct const& account_public_key, diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/asset_id.cpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/asset_id.cpp index 5163231bc5..6a7a559b70 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/asset_id.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/asset_id.cpp @@ -1,9 +1,9 @@ -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" #include "../constants.hpp" namespace join_split_example::proofs::notes::circuit { -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; std::pair deflag_asset_id(suint_ct const& asset_id) { diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/asset_id.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/asset_id.hpp index 3c67f16695..89e244f39b 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/asset_id.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/asset_id.hpp @@ -1,9 +1,9 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example::proofs::notes::circuit { -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; std::pair deflag_asset_id(suint_ct const& asset_id); diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/bridge_call_data.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/bridge_call_data.hpp index f5b1bbd319..f8ea941167 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/bridge_call_data.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/bridge_call_data.hpp @@ -1,5 +1,5 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" #include "../native/bridge_call_data.hpp" #include "./asset_id.hpp" #include "../constants.hpp" @@ -9,7 +9,7 @@ namespace proofs { namespace notes { namespace circuit { -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; constexpr uint32_t input_asset_id_a_shift = DEFI_BRIDGE_ADDRESS_ID_LEN; constexpr uint32_t input_asset_id_b_shift = input_asset_id_a_shift + DEFI_BRIDGE_INPUT_A_ASSET_ID_LEN; diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/claim_note.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/claim_note.hpp index 8021265a43..8a23ff9f93 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/claim_note.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/claim_note.hpp @@ -1,5 +1,6 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" + #include "../bridge_call_data.hpp" #include "witness_data.hpp" #include "../value/create_partial_commitment.hpp" @@ -12,7 +13,7 @@ namespace notes { namespace circuit { namespace claim { -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; struct partial_claim_note { suint_ct deposit_value; diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/complete_partial_commitment.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/complete_partial_commitment.hpp index 9b1010ab58..fb20d7fef9 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/complete_partial_commitment.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/complete_partial_commitment.hpp @@ -1,6 +1,7 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" #include "../../constants.hpp" +#include "barretenberg/stdlib/commitment/pedersen/pedersen.hpp" namespace join_split_example { namespace proofs { @@ -8,7 +9,7 @@ namespace notes { namespace circuit { namespace claim { -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; inline auto complete_partial_commitment(field_ct const& partial_commitment, field_ct const& interaction_nonce, diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/compute_nullifier.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/compute_nullifier.hpp index 304f9f6205..2ffb181bb2 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/compute_nullifier.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/compute_nullifier.hpp @@ -1,5 +1,6 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" + +#include "barretenberg/join_split_example/types.hpp" #include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" #include "../../constants.hpp" @@ -9,8 +10,6 @@ namespace notes { namespace circuit { namespace claim { -using namespace proof_system::plonk::stdlib::types; - inline field_ct compute_nullifier(field_ct const& note_commitment) { return pedersen_commitment::compress(std::vector{ note_commitment }, diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/create_partial_commitment.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/create_partial_commitment.hpp index 30eb7adb7a..36c37a8e78 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/create_partial_commitment.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/create_partial_commitment.hpp @@ -1,5 +1,5 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" #include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" #include "../../constants.hpp" @@ -9,7 +9,7 @@ namespace notes { namespace circuit { namespace claim { -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; inline auto create_partial_commitment(field_ct const& deposit_value, field_ct const& bridge_call_data, diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/witness_data.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/witness_data.hpp index b49bddd3bb..e5fc35fb39 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/witness_data.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/witness_data.hpp @@ -1,5 +1,6 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" + +#include "barretenberg/join_split_example/types.hpp" #include "../../native/claim/claim_note.hpp" #include "../../native/claim/claim_note_tx_data.hpp" #include "../../constants.hpp" @@ -11,7 +12,7 @@ namespace notes { namespace circuit { namespace claim { -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; /** * Convert native claim note data into circuit witness data. diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/complete_partial_commitment.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/complete_partial_commitment.hpp index e5bc84b994..1ec344d17a 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/complete_partial_commitment.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/complete_partial_commitment.hpp @@ -1,15 +1,15 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" + +#include "barretenberg/join_split_example/types.hpp" #include "barretenberg/stdlib/commitment/pedersen/pedersen.hpp" #include "../../constants.hpp" - namespace join_split_example { namespace proofs { namespace notes { namespace circuit { namespace value { -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; inline auto complete_partial_commitment(field_ct const& value_note_partial_commitment, suint_ct const& value, diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.cpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.cpp index 30dafca6b6..6f73dd418f 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.cpp @@ -1,6 +1,6 @@ #include "compute_nullifier.hpp" #include "../../constants.hpp" -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example { namespace proofs { @@ -8,7 +8,7 @@ namespace notes { namespace circuit { using namespace barretenberg; -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; field_ct compute_nullifier(field_ct const& note_commitment, field_ct const& account_private_key, diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.hpp index 3271035abb..85a14dd416 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.hpp @@ -1,14 +1,11 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example { namespace proofs { namespace notes { namespace circuit { -using namespace barretenberg; -using namespace proof_system::plonk::stdlib::types; - field_ct compute_nullifier(field_ct const& note_commitment, field_ct const& account_private_key, bool_ct const& is_note_in_use); diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.test.cpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.test.cpp index 063ef93edd..88198aa7c5 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.test.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.test.cpp @@ -4,10 +4,10 @@ #include "./value_note.hpp" #include "../../native/value/compute_nullifier.hpp" #include "../../native/value/value_note.hpp" -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" +namespace join_split_example { using namespace join_split_example::proofs::notes; -using namespace proof_system::plonk::stdlib::types; TEST(compute_nullifier_circuit, native_consistency) { @@ -18,7 +18,6 @@ TEST(compute_nullifier_circuit, native_consistency) native::value::value_note{ 100, 0, 0, user.owner.public_key, user.note_secret, 0, fr::random_element() }; auto native_commitment = native_input_note.commit(); auto native_nullifier = native::compute_nullifier(native_commitment, priv_key, true); - Composer composer; auto circuit_witness_data = circuit::value::witness_data(composer, native_input_note); auto circuit_input_note = circuit::value::value_note(circuit_witness_data); @@ -27,3 +26,4 @@ TEST(compute_nullifier_circuit, native_consistency) EXPECT_EQ(circuit_nullifier.get_value(), native_nullifier); } +} // namespace join_split_example \ No newline at end of file diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/create_partial_commitment.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/create_partial_commitment.hpp index f01324ee34..ac6104c65a 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/create_partial_commitment.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/create_partial_commitment.hpp @@ -1,6 +1,6 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" -#include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" +#include "barretenberg/stdlib/commitment/pedersen/pedersen.hpp" +#include "barretenberg/join_split_example/types.hpp" #include "../../constants.hpp" namespace join_split_example { @@ -9,8 +9,6 @@ namespace notes { namespace circuit { namespace value { -using namespace proof_system::plonk::stdlib::types; - inline auto create_partial_commitment(field_ct const& secret, point_ct const& owner, bool_ct const& account_required, diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.hpp index a4f8cc04c8..9f2d47a6c6 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.hpp @@ -1,5 +1,5 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/join_split_example/types.hpp" #include "witness_data.hpp" #include "commit.hpp" @@ -9,7 +9,7 @@ namespace notes { namespace circuit { namespace value { -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; struct value_note { point_ct owner; diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp index f3410308bd..55b65c9949 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp @@ -2,13 +2,14 @@ #include "../../../../fixtures/user_context.hpp" #include "../../native/value/value_note.hpp" #include "../../constants.hpp" +#include "barretenberg/join_split_example/types.hpp" #include +namespace join_split_example { using namespace barretenberg; -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; using namespace join_split_example::proofs::notes; using namespace join_split_example::proofs::notes::circuit::value; - TEST(value_note, commits) { auto user = join_split_example::fixtures::create_user_context(); @@ -30,11 +31,11 @@ TEST(value_note, commits) auto result = circuit_note.commitment; result.assert_equal(expected); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); EXPECT_FALSE(composer.failed()); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -64,11 +65,11 @@ TEST(value_note, commits_with_0_value) auto result = circuit_note.commitment; result.assert_equal(expected); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); EXPECT_FALSE(composer.failed()); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -96,14 +97,15 @@ TEST(value_note, commit_with_oversized_asset_id_fails) auto result = circuit_note.commitment; result.assert_equal(expected); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); EXPECT_TRUE(composer.failed()); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); bool proof_result = verifier.verify_proof(proof); EXPECT_EQ(proof_result, false); -} \ No newline at end of file +} +} // namespace join_split_example \ No newline at end of file diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/witness_data.hpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/witness_data.hpp index ff0cbc0cc2..367f0e704e 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/witness_data.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/witness_data.hpp @@ -1,7 +1,6 @@ #pragma once -#include "barretenberg/stdlib/types/types.hpp" #include "../../native/value/value_note.hpp" -#include "../../constants.hpp" +#include "barretenberg/join_split_example/types.hpp" namespace join_split_example { namespace proofs { @@ -9,7 +8,7 @@ namespace notes { namespace circuit { namespace value { -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; struct witness_data { point_ct owner; diff --git a/cpp/src/barretenberg/join_split_example/proofs/verify.hpp b/cpp/src/barretenberg/join_split_example/proofs/verify.hpp index 9daf7e4795..e87a3e0bee 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/verify.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/verify.hpp @@ -90,12 +90,12 @@ auto verify_internal(Composer& composer, Tx& tx, CircuitData const& cd, char con auto proof = prover.construct_proof(); result.proof_data = proof.proof_data; } else { - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); auto proof = prover.construct_proof(); result.proof_data = proof.proof_data; } } else { - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); auto proof = prover.construct_proof(); result.proof_data = proof.proof_data; } @@ -108,12 +108,12 @@ auto verify_internal(Composer& composer, Tx& tx, CircuitData const& cd, char con auto proof = prover.construct_proof(); result.proof_data = proof.proof_data; } else { - auto prover = mock_proof_composer.create_ultra_with_keccak_prover(); + auto prover = mock_proof_composer.create_prover(); auto proof = prover.construct_proof(); result.proof_data = proof.proof_data; } } else { - auto prover = mock_proof_composer.create_ultra_with_keccak_prover(); + auto prover = mock_proof_composer.create_prover(); auto proof = prover.construct_proof(); result.proof_data = proof.proof_data; } @@ -126,11 +126,11 @@ auto verify_internal(Composer& composer, Tx& tx, CircuitData const& cd, char con auto verifier = composer.create_ultra_to_standard_verifier(); result.verified = verifier.verify_proof({ result.proof_data }); } else { - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); result.verified = verifier.verify_proof({ result.proof_data }); } } else { - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); result.verified = verifier.verify_proof({ result.proof_data }); } diff --git a/cpp/src/barretenberg/join_split_example/types.hpp b/cpp/src/barretenberg/join_split_example/types.hpp new file mode 100644 index 0000000000..65b6cca423 --- /dev/null +++ b/cpp/src/barretenberg/join_split_example/types.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include "barretenberg/plonk/composer/standard_composer.hpp" +#include "barretenberg/plonk/composer/turbo_composer.hpp" +#include "barretenberg/plonk/composer/ultra_composer.hpp" + +#include "barretenberg/plonk/proof_system/prover/prover.hpp" +#include "barretenberg/stdlib/primitives/bool/bool.hpp" +#include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" +#include "barretenberg/stdlib/primitives/uint/uint.hpp" +#include "barretenberg/stdlib/primitives/witness/witness.hpp" +#include "barretenberg/stdlib/commitment/pedersen/pedersen.hpp" +#include "barretenberg/stdlib/commitment/pedersen/pedersen_plookup.hpp" +#include "barretenberg/stdlib/merkle_tree/hash_path.hpp" +#include "barretenberg/stdlib/encryption/schnorr/schnorr.hpp" +#include "barretenberg/stdlib/primitives/curves/bn254.hpp" + +namespace join_split_example { + +using Composer = plonk::UltraComposer; + +using Prover = std::conditional_t< + std::same_as, + plonk::UltraProver, + std::conditional_t, plonk::TurboProver, plonk::Prover>>; + +using Verifier = std::conditional_t< + std::same_as, + plonk::UltraVerifier, + std::conditional_t, plonk::TurboVerifier, plonk::Verifier>>; + +using witness_ct = proof_system::plonk::stdlib::witness_t; +using public_witness_ct = proof_system::plonk::stdlib::public_witness_t; +using bool_ct = proof_system::plonk::stdlib::bool_t; +using byte_array_ct = proof_system::plonk::stdlib::byte_array; +using field_ct = proof_system::plonk::stdlib::field_t; +using suint_ct = proof_system::plonk::stdlib::safe_uint_t; +using uint32_ct = proof_system::plonk::stdlib::uint32; +using point_ct = proof_system::plonk::stdlib::point; +using pedersen_commitment = proof_system::plonk::stdlib::pedersen_commitment; +using group_ct = proof_system::plonk::stdlib::group; +using bn254 = proof_system::plonk::stdlib::bn254; + +using hash_path_ct = proof_system::plonk::stdlib::merkle_tree::hash_path; + +namespace schnorr { +using signature_bits = proof_system::plonk::stdlib::schnorr::signature_bits; +} // namespace schnorr + +} // namespace join_split_example \ No newline at end of file diff --git a/cpp/src/barretenberg/plonk/proof_system/constants.hpp b/cpp/src/barretenberg/plonk/proof_system/constants.hpp index b5de8c110a..ac2ee70fec 100644 --- a/cpp/src/barretenberg/plonk/proof_system/constants.hpp +++ b/cpp/src/barretenberg/plonk/proof_system/constants.hpp @@ -1,20 +1,10 @@ #pragma once #include -#include "barretenberg/proof_system/types/composer_type.hpp" -namespace proof_system::plonk { -// This variable sets the composer (TURBO or ULTRA) of the entire stdlib and rollup modules. -// To switch to using a new composer, only changing this variable should activate the new composer -// throughout the stdlib and circuits. -#ifdef USE_TURBO -static constexpr uint32_t SYSTEM_COMPOSER = ComposerType::TURBO; -#else -static constexpr uint32_t SYSTEM_COMPOSER = ComposerType::PLOOKUP; -#endif +namespace proof_system::plonk { // limb size when simulating a non-native field using bigfield class // (needs to be a universal constant to be used by native verifier) static constexpr uint64_t NUM_LIMB_BITS_IN_FIELD_SIMULATION = 68; - static constexpr uint32_t NUM_QUOTIENT_PARTS = 4; } // namespace proof_system::plonk diff --git a/cpp/src/barretenberg/plonk/proof_system/prover/c_bind.cpp b/cpp/src/barretenberg/plonk/proof_system/prover/c_bind.cpp index 6cd4d4c7af..ef1d1c1392 100644 --- a/cpp/src/barretenberg/plonk/proof_system/prover/c_bind.cpp +++ b/cpp/src/barretenberg/plonk/proof_system/prover/c_bind.cpp @@ -1,7 +1,6 @@ #include "prover.hpp" #include "barretenberg/env/data_store.hpp" #include "barretenberg/env/crs.hpp" -#include "barretenberg/proof_system/types/composer_type.hpp" #define WASM_EXPORT __attribute__((visibility("default"))) @@ -48,8 +47,8 @@ WASM_EXPORT void* test_env_load_prover_crs(size_t num_points) { return env_load_prover_crs(num_points); } -typedef std::conditional_t - WasmProver; + +using WasmProver = plonk::UltraProver; WASM_EXPORT void prover_process_queue(WasmProver* prover) { diff --git a/cpp/src/barretenberg/plonk/proof_system/prover/c_bind_unrolled.cpp b/cpp/src/barretenberg/plonk/proof_system/prover/c_bind_unrolled.cpp deleted file mode 100644 index 66cfdc7496..0000000000 --- a/cpp/src/barretenberg/plonk/proof_system/prover/c_bind_unrolled.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include "prover.hpp" -#include "barretenberg/proof_system/types/composer_type.hpp" - -#define WASM_EXPORT __attribute__((visibility("default"))) - -using namespace barretenberg; - -extern "C" { - -// TODO(Cody): Removed "unrolled" here when the time comes, if it does. -typedef std::conditional_t - WasmUnrolledProver; - -WASM_EXPORT void unrolled_prover_process_queue(WasmUnrolledProver* prover) -{ - prover->queue.process_queue(); -} - -WASM_EXPORT size_t unrolled_prover_get_circuit_size(WasmUnrolledProver* prover) -{ - return prover->get_circuit_size(); -} - -WASM_EXPORT void unrolled_prover_get_work_queue_item_info(WasmUnrolledProver* prover, uint8_t* result) -{ - auto info = prover->get_queued_work_item_info(); - memcpy(result, &info, sizeof(info)); -} - -WASM_EXPORT fr* unrolled_prover_get_scalar_multiplication_data(WasmUnrolledProver* prover, size_t work_item_number) -{ - return prover->get_scalar_multiplication_data(work_item_number); -} - -WASM_EXPORT size_t unrolled_prover_get_scalar_multiplication_size(WasmUnrolledProver* prover, size_t work_item_number) -{ - return prover->get_scalar_multiplication_size(work_item_number); -} - -WASM_EXPORT void unrolled_prover_put_scalar_multiplication_data(WasmUnrolledProver* prover, - g1::element* result, - const size_t work_item_number) -{ - prover->put_scalar_multiplication_data(*result, work_item_number); -} - -WASM_EXPORT fr* unrolled_prover_get_fft_data(WasmUnrolledProver* prover, fr* shift_factor, size_t work_item_number) -{ - auto data = prover->get_fft_data(work_item_number); - *shift_factor = data.shift_factor; - return data.data; -} - -WASM_EXPORT void unrolled_prover_put_fft_data(WasmUnrolledProver* prover, fr* result, size_t work_item_number) -{ - prover->put_fft_data(result, work_item_number); -} - -WASM_EXPORT fr* unrolled_prover_get_ifft_data(WasmUnrolledProver* prover, size_t work_item_number) -{ - return prover->get_ifft_data(work_item_number); -} - -WASM_EXPORT void unrolled_prover_put_ifft_data(WasmUnrolledProver* prover, fr* result, size_t work_item_number) -{ - prover->put_ifft_data(result, work_item_number); -} - -WASM_EXPORT void unrolled_prover_execute_preamble_round(WasmUnrolledProver* prover) -{ - prover->execute_preamble_round(); -} - -WASM_EXPORT void unrolled_prover_execute_first_round(WasmUnrolledProver* prover) -{ - prover->execute_first_round(); -} - -WASM_EXPORT void unrolled_prover_execute_second_round(WasmUnrolledProver* prover) -{ - prover->execute_second_round(); -} - -WASM_EXPORT void unrolled_prover_execute_third_round(WasmUnrolledProver* prover) -{ - prover->execute_third_round(); -} - -WASM_EXPORT void unrolled_prover_execute_fourth_round(WasmUnrolledProver* prover) -{ - prover->execute_fourth_round(); -} - -WASM_EXPORT void unrolled_prover_execute_fifth_round(WasmUnrolledProver* prover) -{ - prover->execute_fifth_round(); -} - -WASM_EXPORT void unrolled_prover_execute_sixth_round(WasmUnrolledProver* prover) -{ - prover->execute_sixth_round(); -} - -WASM_EXPORT size_t unrolled_prover_export_proof(WasmUnrolledProver* prover, uint8_t** proof_data_buf) -{ - auto& proof_data = prover->export_proof().proof_data; - *proof_data_buf = proof_data.data(); - return proof_data.size(); -} -} diff --git a/cpp/src/barretenberg/plonk/proof_system/types/polynomial_manifest.hpp b/cpp/src/barretenberg/plonk/proof_system/types/polynomial_manifest.hpp index aefd348ff9..8a56d34168 100644 --- a/cpp/src/barretenberg/plonk/proof_system/types/polynomial_manifest.hpp +++ b/cpp/src/barretenberg/plonk/proof_system/types/polynomial_manifest.hpp @@ -3,7 +3,7 @@ #include #include #include -#include "barretenberg/plonk/proof_system/constants.hpp" +#include "barretenberg/proof_system/types/composer_type.hpp" namespace proof_system::plonk { diff --git a/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp b/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp index 53062b79fe..4a2ab39e8a 100644 --- a/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp +++ b/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp @@ -1,15 +1,28 @@ #include "schnorr.hpp" #include "barretenberg/crypto/pedersen_commitment/pedersen.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" +#include "barretenberg/plonk/composer/ultra_composer.hpp" +#include "barretenberg/stdlib/primitives/field/field.hpp" +#include "barretenberg/stdlib/primitives/bool/bool.hpp" +#include "barretenberg/stdlib/primitives/witness/witness.hpp" +#include "barretenberg/stdlib/primitives/point/point.hpp" #include -#include "barretenberg/stdlib/types/types.hpp" -namespace test_stdlib_schnorr { +namespace proof_system::test_stdlib_schnorr { using namespace barretenberg; -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; using namespace proof_system::plonk::stdlib::schnorr; +using Composer = plonk::UltraComposer; +using Prover = plonk::UltraProver; +using Verifier = plonk::UltraVerifier; +using bool_ct = bool_t; +using byte_array_ct = byte_array; +using field_ct = field_t; +using point_ct = point; +using witness_ct = witness_t; + auto run_scalar_mul_test = [](grumpkin::fr scalar_mont, bool expect_verify) { Composer composer = Composer(); @@ -33,10 +46,10 @@ auto run_scalar_mul_test = [](grumpkin::fr scalar_mont, bool expect_verify) { EXPECT_EQ(output.y.get_value(), expected.y); }; - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); info("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -152,10 +165,10 @@ TEST(stdlib_schnorr, convert_field_into_wnaf) field_ct input(&composer, scalar); convert_field_into_wnaf(&composer, input); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); info("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -204,13 +217,13 @@ TEST(stdlib_schnorr, verify_signature) EXPECT_EQ(first_result, true); point_ct pub_key{ witness_ct(&composer, account.public_key.x), witness_ct(&composer, account.public_key.y) }; - stdlib::schnorr::signature_bits sig = stdlib::schnorr::convert_signature(&composer, signature); + signature_bits sig = convert_signature(&composer, signature); byte_array_ct message(&composer, message_string); - stdlib::schnorr::verify_signature(message, pub_key, sig); + verify_signature(message, pub_key, sig); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); info("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); bool result = verifier.verify_proof(proof); EXPECT_EQ(result, true); @@ -248,14 +261,14 @@ TEST(stdlib_schnorr, verify_signature_failure) // check stdlib verification with account 2 public key fails point_ct pub_key2_ct{ witness_ct(&composer, account2.public_key.x), witness_ct(&composer, account2.public_key.y) }; - stdlib::schnorr::signature_bits sig = stdlib::schnorr::convert_signature(&composer, signature); + signature_bits sig = convert_signature(&composer, signature); byte_array_ct message(&composer, message_string); - stdlib::schnorr::verify_signature(message, pub_key2_ct, sig); + verify_signature(message, pub_key2_ct, sig); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); info("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -286,14 +299,14 @@ TEST(stdlib_schnorr, signature_verification_result) EXPECT_EQ(first_result, true); point_ct pub_key{ witness_ct(&composer, account.public_key.x), witness_ct(&composer, account.public_key.y) }; - stdlib::schnorr::signature_bits sig = stdlib::schnorr::convert_signature(&composer, signature); + signature_bits sig = convert_signature(&composer, signature); byte_array_ct message(&composer, longer_string); - bool_ct signature_result = stdlib::schnorr::signature_verification_result(message, pub_key, sig); + bool_ct signature_result = signature_verification_result(message, pub_key, sig); EXPECT_EQ(signature_result.witness_bool, true); - plonk::stdlib::types::Prover prover = composer.create_ultra_with_keccak_prover(); + Prover prover = composer.create_prover(); info("composer gates = %zu\n", composer.get_num_gates()); - plonk::stdlib::types::Verifier verifier = composer.create_ultra_with_keccak_verifier(); + Verifier verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); bool result = verifier.verify_proof(proof); EXPECT_EQ(result, true); @@ -330,17 +343,17 @@ TEST(stdlib_schnorr, signature_verification_result_failure) // check stdlib verification with account 2 public key fails point_ct pub_key2_ct{ witness_ct(&composer, account2.public_key.x), witness_ct(&composer, account2.public_key.y) }; - stdlib::schnorr::signature_bits sig = stdlib::schnorr::convert_signature(&composer, signature); + signature_bits sig = convert_signature(&composer, signature); byte_array_ct message(&composer, message_string); - bool_ct signature_result = stdlib::schnorr::signature_verification_result(message, pub_key2_ct, sig); + bool_ct signature_result = signature_verification_result(message, pub_key2_ct, sig); EXPECT_EQ(signature_result.witness_bool, false); - plonk::stdlib::types::Prover prover = composer.create_ultra_with_keccak_prover(); + Prover prover = composer.create_prover(); info("composer gates = %zu\n", composer.get_num_gates()); - plonk::stdlib::types::Verifier verifier = composer.create_ultra_with_keccak_verifier(); + Verifier verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); bool verification_result = verifier.verify_proof(proof); EXPECT_EQ(verification_result, true); } -} // namespace test_stdlib_schnorr +} // namespace proof_system::test_stdlib_schnorr diff --git a/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp b/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp index 4b5fc2910d..61e7ccc293 100644 --- a/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp +++ b/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp @@ -1,21 +1,27 @@ #include "blake2s.hpp" #include "blake2s_plookup.hpp" -#include "barretenberg/crypto/blake2s/blake2s.hpp" #include -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/crypto/blake2s/blake2s.hpp" using namespace barretenberg; using namespace proof_system::plonk; -using namespace proof_system::plonk::stdlib::types; -typedef stdlib::byte_array byte_array; -typedef stdlib::byte_array byte_array_plookup; -typedef stdlib::public_witness_t public_witness_t; -typedef stdlib::public_witness_t public_witness_t_plookup; +using namespace plonk::stdlib; + +using Composer = plonk::UltraComposer; +using Prover = plonk::UltraProver; +using Verifier = plonk::UltraVerifier; + +using field_ct = field_t; +using witness_ct = witness_t; +using byte_array_ct = stdlib::byte_array; +using byte_array_plookup = stdlib::byte_array; +using public_witness_t = stdlib::public_witness_t; +using public_witness_t_plookup = stdlib::public_witness_t; TEST(stdlib_blake2s, test_single_block) { - Composer composer = Composer(); + auto composer = Composer(); std::string input = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01"; std::vector input_v(input.begin(), input.end()); @@ -26,10 +32,10 @@ TEST(stdlib_blake2s, test_single_block) EXPECT_EQ(output.get_value(), expected); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); - printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + info("composer gates = %zu\n", composer.get_num_gates()); + auto verifier = composer.create_verifier(); auto proof = prover.construct_proof(); @@ -50,10 +56,10 @@ TEST(stdlib_blake2s, test_single_block_plookup) EXPECT_EQ(output.get_value(), expected); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); std::cout << "prover gates = " << prover.circuit_size << std::endl; - printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + info("composer gates = %zu\n", composer.get_num_gates()); + auto verifier = composer.create_verifier(); auto proof = prover.construct_proof(); @@ -63,7 +69,7 @@ TEST(stdlib_blake2s, test_single_block_plookup) TEST(stdlib_blake2s, test_double_block) { - Composer composer = Composer(); + auto composer = Composer(); std::string input = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"; std::vector input_v(input.begin(), input.end()); @@ -74,10 +80,10 @@ TEST(stdlib_blake2s, test_double_block) EXPECT_EQ(output.get_value(), expected); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); - printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + info("composer gates = %zu\n", composer.get_num_gates()); + auto verifier = composer.create_verifier(); auto proof = prover.construct_proof(); @@ -98,10 +104,10 @@ TEST(stdlib_blake2s, test_double_block_plookup) EXPECT_EQ(output.get_value(), expected); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); std::cout << "prover gates = " << prover.circuit_size << std::endl; - printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + info("composer gates = %zu\n", composer.get_num_gates()); + auto verifier = composer.create_verifier(); auto proof = prover.construct_proof(); diff --git a/cpp/src/barretenberg/stdlib/hash/sha256/sha256.bench.cpp b/cpp/src/barretenberg/stdlib/hash/sha256/sha256.bench.cpp index 4e79f1fb43..d912505c44 100644 --- a/cpp/src/barretenberg/stdlib/hash/sha256/sha256.bench.cpp +++ b/cpp/src/barretenberg/stdlib/hash/sha256/sha256.bench.cpp @@ -2,10 +2,14 @@ #include #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" -#include "barretenberg/stdlib/types/types.hpp" +#include "barretenberg/plonk/proof_system/prover/prover.hpp" +#include "barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp" using namespace benchmark; -using namespace proof_system::plonk::stdlib::types; + +using Composer = proof_system::plonk::UltraComposer; +using Prover = proof_system::plonk::UltraProver; +using Verifier = proof_system::plonk::UltraVerifier; constexpr size_t NUM_HASHES = 8; constexpr size_t BYTES_PER_CHUNK = 512; @@ -24,13 +28,13 @@ void generate_test_plonk_circuit(Composer& composer, size_t num_bytes) for (size_t i = 0; i < num_bytes; ++i) { in[i] = get_random_char(); } - packed_byte_array_ct input(&composer, in); - plonk::stdlib::sha256(input); + proof_system::plonk::stdlib::packed_byte_array input(&composer, in); + proof_system::plonk::stdlib::sha256(input); } -stdlib::types::Composer composers[NUM_HASHES]; -stdlib::types::Prover provers[NUM_HASHES]; -stdlib::types::Verifier verifiers[NUM_HASHES]; +Composer composers[NUM_HASHES]; +Prover provers[NUM_HASHES]; +Verifier verifiers[NUM_HASHES]; plonk::proof proofs[NUM_HASHES]; void construct_witnesses_bench(State& state) noexcept @@ -47,7 +51,7 @@ void preprocess_witnesses_bench(State& state) noexcept { for (auto _ : state) { size_t idx = (static_cast((state.range(0))) - START_BYTES) / BYTES_PER_CHUNK; - provers[idx] = composers[idx].create_ultra_with_keccak_prover(); + provers[idx] = composers[idx].create_prover(); std::cout << "prover subgroup size = " << provers[idx].key->small_domain.size << std::endl; // printf("num bytes = %" PRIx64 ", num gates = %zu\n", state.range(0), composers[idx].get_num_gates()); } @@ -58,7 +62,7 @@ void construct_instances_bench(State& state) noexcept { for (auto _ : state) { size_t idx = (static_cast((state.range(0))) - START_BYTES) / BYTES_PER_CHUNK; - verifiers[idx] = composers[idx].create_ultra_with_keccak_verifier(); + verifiers[idx] = composers[idx].create_verifier(); } } BENCHMARK(construct_instances_bench)->DenseRange(START_BYTES, MAX_BYTES, BYTES_PER_CHUNK); diff --git a/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp b/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp index 4ac0307275..8f9952da34 100644 --- a/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp +++ b/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp @@ -2,8 +2,9 @@ #include "barretenberg/common/test.hpp" #include "barretenberg/crypto/sha256/sha256.hpp" #include "barretenberg/plonk/composer/standard_composer.hpp" +#include "barretenberg/plonk/composer/turbo_composer.hpp" +#include "barretenberg/plonk/composer/ultra_composer.hpp" #include "barretenberg/plonk/composer/plookup_tables/plookup_tables.hpp" -#include "barretenberg/stdlib/types/types.hpp" #include "barretenberg/numeric/random/engine.hpp" #include "barretenberg/numeric/bitop/rotate.hpp" @@ -13,11 +14,18 @@ namespace { auto& engine = numeric::random::get_debug_engine(); } -namespace test_stdlib_sha256 { +namespace proof_system::test_stdlib_sha256 { using namespace barretenberg; -using namespace proof_system::plonk; -using namespace proof_system::plonk::stdlib::types; +using namespace proof_system::plonk::stdlib; + +using Composer = plonk::UltraComposer; +using Prover = plonk::UltraProver; +using Verifier = plonk::UltraVerifier; + +using byte_array_ct = byte_array; +using packed_byte_array_ct = packed_byte_array; +using field_ct = field_t; constexpr uint64_t ror(uint64_t val, uint64_t shift) { @@ -112,8 +120,9 @@ std::array inner_block(std::array& w) TEST(stdlib_sha256, test_duplicate_proving_key) { - plonk::StandardComposer first_composer = StandardComposer(); - stdlib::packed_byte_array input(&first_composer, "An 8 character password? Snow White and the 7 Dwarves.."); + auto first_composer = plonk::StandardComposer(); + plonk::stdlib::packed_byte_array input( + &first_composer, "An 8 character password? Snow White and the 7 Dwarves.."); plonk::stdlib::sha256(input); auto prover = first_composer.create_prover(); auto verifier = first_composer.create_verifier(); @@ -125,8 +134,9 @@ TEST(stdlib_sha256, test_duplicate_proving_key) auto circuit_size = prover.circuit_size; // Test a second time with same keys and different input. - plonk::StandardComposer second_composer = StandardComposer(proving_key, verification_key, circuit_size); - stdlib::packed_byte_array input2(&second_composer, "An 8 character password? Snow White and the 9 Dwarves.."); + auto second_composer = plonk::StandardComposer(proving_key, verification_key, circuit_size); + plonk::stdlib::packed_byte_array input2( + &second_composer, "An 8 character password? Snow White and the 9 Dwarves.."); plonk::stdlib::sha256(input2); auto second_prover = second_composer.create_prover(); auto second_verifier = second_composer.create_verifier(); @@ -138,14 +148,14 @@ TEST(stdlib_sha256, test_duplicate_proving_key) // TEST(stdlib_sha256_plookup, test_round) // { -// plonk::UltraComposer composer = UltraComposer(); +// auto composer = UltraComposer(); // std::array w_inputs; // std::array, 64> w_elements; // for (size_t i = 0; i < 64; ++i) { // w_inputs[i] = engine.get_random_uint32(); -// w_elements[i] = stdlib::witness_t(&composer, +// w_elements[i] = plonk::stdlib::witness_t(&composer, // barretenberg::fr(w_inputs[i])); // } @@ -169,15 +179,15 @@ TEST(stdlib_sha256, test_duplicate_proving_key) TEST(stdlib_sha256, test_plookup_55_bytes) { - typedef stdlib::field_t field_pt; - typedef stdlib::packed_byte_array packed_byte_array_pt; + typedef plonk::stdlib::field_t field_pt; + typedef plonk::stdlib::packed_byte_array packed_byte_array_pt; // 55 bytes is the largest number of bytes that can be hashed in a single block, // accounting for the single padding bit, and the 64 size bits required by the SHA-256 standard. - plonk::UltraComposer composer = UltraComposer(); + auto composer = plonk::UltraComposer(); packed_byte_array_pt input(&composer, "An 8 character password? Snow White and the 7 Dwarves.."); - packed_byte_array_pt output_bits = stdlib::sha256(input); + packed_byte_array_pt output_bits = plonk::stdlib::sha256(input); std::vector output = output_bits.to_unverified_byte_slices(4); @@ -205,10 +215,10 @@ TEST(stdlib_sha256, test_55_bytes) { // 55 bytes is the largest number of bytes that can be hashed in a single block, // accounting for the single padding bit, and the 64 size bits required by the SHA-256 standard. - Composer composer = Composer(); + auto composer = Composer(); packed_byte_array_ct input(&composer, "An 8 character password? Snow White and the 7 Dwarves.."); - packed_byte_array_ct output_bits = stdlib::sha256(input); + packed_byte_array_ct output_bits = plonk::stdlib::sha256(input); std::vector output = output_bits.to_unverified_byte_slices(4); @@ -222,9 +232,9 @@ TEST(stdlib_sha256, test_55_bytes) EXPECT_EQ(output[7].get_value(), fr(0x93791fc7ULL)); printf("composer gates = %zu\n", composer.get_num_gates()); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); printf("constructing proof \n"); plonk::proof proof = prover.construct_proof(); printf("constructed proof \n"); @@ -234,13 +244,13 @@ TEST(stdlib_sha256, test_55_bytes) TEST(stdlib_sha256, test_NIST_vector_one_packed_byte_array) { - typedef stdlib::field_t field_pt; - typedef stdlib::packed_byte_array packed_byte_array_pt; + typedef plonk::stdlib::field_t field_pt; + typedef plonk::stdlib::packed_byte_array packed_byte_array_pt; - plonk::UltraComposer composer = UltraComposer(); + auto composer = plonk::UltraComposer(); packed_byte_array_pt input(&composer, "abc"); - packed_byte_array_pt output_bytes = stdlib::sha256(input); + packed_byte_array_pt output_bytes = plonk::stdlib::sha256(input); std::vector output = output_bytes.to_unverified_byte_slices(4); EXPECT_EQ(uint256_t(output[0].get_value()).data[0], (uint64_t)0xBA7816BFU); EXPECT_EQ(uint256_t(output[1].get_value()).data[0], (uint64_t)0x8F01CFEAU); @@ -252,9 +262,9 @@ TEST(stdlib_sha256, test_NIST_vector_one_packed_byte_array) EXPECT_EQ(uint256_t(output[7].get_value()).data[0], (uint64_t)0xF20015ADU); printf("composer gates = %zu\n", composer.get_num_gates()); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); printf("constructing proof \n"); plonk::proof proof = prover.construct_proof(); printf("constructed proof \n"); @@ -265,14 +275,14 @@ TEST(stdlib_sha256, test_NIST_vector_one_packed_byte_array) TEST(stdlib_sha256, test_NIST_vector_one) { - typedef stdlib::field_t field_pt; - typedef stdlib::packed_byte_array packed_byte_array_pt; + typedef plonk::stdlib::field_t field_pt; + typedef plonk::stdlib::packed_byte_array packed_byte_array_pt; - plonk::UltraComposer composer = UltraComposer(); + auto composer = plonk::UltraComposer(); packed_byte_array_pt input(&composer, "abc"); - packed_byte_array_pt output_bits = stdlib::sha256(input); + packed_byte_array_pt output_bits = plonk::stdlib::sha256(input); std::vector output = output_bits.to_unverified_byte_slices(4); @@ -299,11 +309,11 @@ TEST(stdlib_sha256, test_NIST_vector_one) TEST(stdlib_sha256, test_NIST_vector_two) { - Composer composer = Composer(); + auto composer = Composer(); byte_array_ct input(&composer, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"); - byte_array_ct output_bits = stdlib::sha256(input); + byte_array_ct output_bits = plonk::stdlib::sha256(input); std::vector output = packed_byte_array_ct(output_bits).to_unverified_byte_slices(4); @@ -317,9 +327,9 @@ TEST(stdlib_sha256, test_NIST_vector_two) EXPECT_EQ(output[7].get_value(), 0x19DB06C1ULL); printf("composer gates = %zu\n", composer.get_num_gates()); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); printf("constructing proof \n"); plonk::proof proof = prover.construct_proof(); printf("constructed proof \n"); @@ -330,12 +340,12 @@ TEST(stdlib_sha256, test_NIST_vector_two) TEST(stdlib_sha256, test_NIST_vector_three) { - Composer composer = Composer(); + auto composer = Composer(); // one byte, 0xbd byte_array_ct input(&composer, std::vector{ 0xbd }); - byte_array_ct output_bits = stdlib::sha256(input); + byte_array_ct output_bits = plonk::stdlib::sha256(input); std::vector output = packed_byte_array_ct(output_bits).to_unverified_byte_slices(4); @@ -349,9 +359,9 @@ TEST(stdlib_sha256, test_NIST_vector_three) EXPECT_EQ(output[7].get_value(), 0x8ffe732bULL); printf("composer gates = %zu\n", composer.get_num_gates()); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -361,12 +371,12 @@ TEST(stdlib_sha256, test_NIST_vector_three) TEST(stdlib_sha256, test_NIST_vector_four) { - Composer composer = Composer(); + auto composer = Composer(); // 4 bytes, 0xc98c8e55 byte_array_ct input(&composer, std::vector{ 0xc9, 0x8c, 0x8e, 0x55 }); - byte_array_ct output_bits = stdlib::sha256(input); + byte_array_ct output_bits = plonk::stdlib::sha256(input); std::vector output = packed_byte_array_ct(output_bits).to_unverified_byte_slices(4); @@ -379,10 +389,10 @@ TEST(stdlib_sha256, test_NIST_vector_four) EXPECT_EQ(output[6].get_value(), 0xbd56c61cULL); EXPECT_EQ(output[7].get_value(), 0xcccd9504ULL); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -392,10 +402,10 @@ TEST(stdlib_sha256, test_NIST_vector_four) HEAVY_TEST(stdlib_sha256, test_NIST_vector_five) { - typedef stdlib::field_t field_pt; - typedef stdlib::packed_byte_array packed_byte_array_pt; + typedef plonk::stdlib::field_t field_pt; + typedef plonk::stdlib::packed_byte_array packed_byte_array_pt; - plonk::UltraComposer composer = UltraComposer(); + auto composer = plonk::UltraComposer(); packed_byte_array_pt input( &composer, @@ -410,7 +420,7 @@ HEAVY_TEST(stdlib_sha256, test_NIST_vector_five) "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAA"); - packed_byte_array_pt output_bits = stdlib::sha256(input); + packed_byte_array_pt output_bits = plonk::stdlib::sha256(input); std::vector output = output_bits.to_unverified_byte_slices(4); @@ -436,7 +446,7 @@ HEAVY_TEST(stdlib_sha256, test_NIST_vector_five) TEST(stdlib_sha256, test_input_len_multiple) { - Composer composer = Composer(); + auto composer = Composer(); std::vector input_sizes = { 1, 7, 15, 16, 30, 32, 55, 64, 90, 128, 512, 700 }; @@ -444,7 +454,7 @@ TEST(stdlib_sha256, test_input_len_multiple) auto input_buf = std::vector(inp, 1); byte_array_ct input(&composer, input_buf); - byte_array_ct output_bits = stdlib::sha256(input); + byte_array_ct output_bits = plonk::stdlib::sha256(input); auto circuit_output = output_bits.get_value(); @@ -456,7 +466,7 @@ TEST(stdlib_sha256, test_input_len_multiple) TEST(stdlib_sha256, test_input_str_len_multiple) { - Composer composer = Composer(); + auto composer = Composer(); std::vector input_strings = { "y", // 1 @@ -488,7 +498,7 @@ TEST(stdlib_sha256, test_input_str_len_multiple) auto input_buf = std::vector(input_str.begin(), input_str.end()); byte_array_ct input(&composer, input_buf); - byte_array_ct output_bits = stdlib::sha256(input); + byte_array_ct output_bits = plonk::stdlib::sha256(input); auto circuit_output = output_bits.get_value(); @@ -498,4 +508,4 @@ TEST(stdlib_sha256, test_input_str_len_multiple) } } -} // namespace test_stdlib_sha256 +} // namespace proof_system::test_stdlib_sha256 diff --git a/cpp/src/barretenberg/stdlib/merkle_tree/hash.hpp b/cpp/src/barretenberg/stdlib/merkle_tree/hash.hpp index 32e6fb2d8d..63b647d7eb 100644 --- a/cpp/src/barretenberg/stdlib/merkle_tree/hash.hpp +++ b/cpp/src/barretenberg/stdlib/merkle_tree/hash.hpp @@ -15,20 +15,12 @@ namespace merkle_tree { inline barretenberg::fr hash_pair_native(barretenberg::fr const& lhs, barretenberg::fr const& rhs) { - if (plonk::SYSTEM_COMPOSER == ComposerType::PLOOKUP) { - return crypto::pedersen_hash::lookup::hash_multiple({ lhs, rhs }); // uses lookup tables - } else { - return crypto::pedersen_hash::hash_multiple({ lhs, rhs }); // uses fixed-base multiplication gate - } + return crypto::pedersen_hash::lookup::hash_multiple({ lhs, rhs }); // uses lookup tables } inline barretenberg::fr hash_multiple_native(std::vector const& inputs) { - if (plonk::SYSTEM_COMPOSER == ComposerType::PLOOKUP) { - return crypto::pedersen_hash::lookup::hash_multiple(inputs); // uses lookup tables - } else { - return crypto::pedersen_hash::hash_multiple(inputs); // uses fixed-base multiplication gate - } + return crypto::pedersen_hash::lookup::hash_multiple(inputs); // uses lookup tables } /** @@ -46,11 +38,7 @@ inline barretenberg::fr compute_tree_root_native(std::vector c while (layer.size() > 1) { std::vector next_layer(layer.size() / 2); for (size_t i = 0; i < next_layer.size(); ++i) { - if (plonk::SYSTEM_COMPOSER == ComposerType::PLOOKUP) { - next_layer[i] = crypto::pedersen_hash::lookup::hash_multiple({ layer[i * 2], layer[i * 2 + 1] }); - } else { - next_layer[i] = crypto::pedersen_hash::hash_multiple({ layer[i * 2], layer[i * 2 + 1] }); - } + next_layer[i] = crypto::pedersen_hash::lookup::hash_multiple({ layer[i * 2], layer[i * 2 + 1] }); } layer = std::move(next_layer); } @@ -69,11 +57,7 @@ inline std::vector compute_tree_native(std::vector 1) { std::vector next_layer(layer.size() / 2); for (size_t i = 0; i < next_layer.size(); ++i) { - if (plonk::SYSTEM_COMPOSER == ComposerType::PLOOKUP) { - next_layer[i] = crypto::pedersen_hash::lookup::hash_multiple({ layer[i * 2], layer[i * 2 + 1] }); - } else { - next_layer[i] = crypto::pedersen_hash::hash_multiple({ layer[i * 2], layer[i * 2 + 1] }); - } + next_layer[i] = crypto::pedersen_hash::lookup::hash_multiple({ layer[i * 2], layer[i * 2 + 1] }); tree.push_back(next_layer[i]); } layer = std::move(next_layer); diff --git a/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp b/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp index da60dfa799..5273c89677 100644 --- a/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp +++ b/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp @@ -1,20 +1,31 @@ #include "hash.hpp" #include "memory_tree.hpp" #include -#include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" + +#include "barretenberg/plonk/composer/ultra_composer.hpp" +#include "barretenberg/stdlib/primitives/field/field.hpp" +#include "barretenberg/stdlib/primitives/witness/witness.hpp" #include "barretenberg/stdlib/merkle_tree/membership.hpp" -#include "barretenberg/stdlib/types/types.hpp" + +namespace proof_system::stdlib_merkle_tree_hash_test { using namespace barretenberg; -using namespace proof_system::plonk::stdlib::types; +using namespace plonk::stdlib; + +using Composer = plonk::UltraComposer; +using Prover = plonk::UltraProver; +using Verifier = plonk::UltraVerifier; + +using field_ct = field_t; +using witness_ct = witness_t; TEST(stdlib_merkle_tree_hash, compress_native_vs_circuit) { fr x = uint256_t(0x5ec473eb273a8011, 0x50160109385471ca, 0x2f3095267e02607d, 0x02586f4a39e69b86); Composer composer = Composer(); witness_ct y = witness_ct(&composer, x); - field_ct z = plonk::stdlib::pedersen_hash::hash_multiple({ y, y }); - auto zz = stdlib::merkle_tree::hash_pair_native(x, x); + field_ct z = pedersen_hash::hash_multiple({ y, y }); + auto zz = merkle_tree::hash_pair_native(x, x); EXPECT_EQ(z.get_value(), zz); } @@ -31,8 +42,8 @@ TEST(stdlib_merkle_tree_hash, compute_tree_root_native_vs_circuit) inputs_ct.push_back(input_ct); } - field_ct z = plonk::stdlib::merkle_tree::compute_tree_root(inputs_ct); - auto zz = plonk::stdlib::merkle_tree::compute_tree_root_native(inputs); + field_ct z = merkle_tree::compute_tree_root(inputs_ct); + auto zz = merkle_tree::compute_tree_root_native(inputs); EXPECT_EQ(z.get_value(), zz); } @@ -40,7 +51,7 @@ TEST(stdlib_merkle_tree_hash, compute_tree_root_native_vs_circuit) TEST(stdlib_merkle_tree_hash, compute_tree_native) { constexpr size_t depth = 2; - stdlib::merkle_tree::MemoryTree mem_tree(depth); + merkle_tree::MemoryTree mem_tree(depth); std::vector leaves; for (size_t i = 0; i < (size_t(1) << depth); i++) { @@ -49,7 +60,7 @@ TEST(stdlib_merkle_tree_hash, compute_tree_native) mem_tree.update_element(i, input); } - std::vector tree_vector = plonk::stdlib::merkle_tree::compute_tree_native(leaves); + std::vector tree_vector = merkle_tree::compute_tree_native(leaves); // Check if the tree vector matches the memory tree hashes for (size_t i = 0; i < tree_vector.size() - 1; i++) { @@ -57,3 +68,4 @@ TEST(stdlib_merkle_tree_hash, compute_tree_native) } EXPECT_EQ(tree_vector.back(), mem_tree.root()); } +} // namespace proof_system::stdlib_merkle_tree_hash_test \ No newline at end of file diff --git a/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp b/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp index 477e1406cf..506a363ba2 100644 --- a/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp +++ b/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp @@ -1,23 +1,38 @@ +#include + #include "merkle_tree.hpp" #include "membership.hpp" #include "memory_store.hpp" #include "memory_tree.hpp" -#include -#include "barretenberg/stdlib/types/types.hpp" -using namespace barretenberg; -using namespace proof_system::plonk::stdlib::types; -using namespace proof_system::plonk::stdlib::merkle_tree; +#include "barretenberg/plonk/composer/ultra_composer.hpp" +#include "barretenberg/stdlib/primitives/bool/bool.hpp" +#include "barretenberg/stdlib/primitives/field/field.hpp" +#include "barretenberg/stdlib/primitives/witness/witness.hpp" namespace { auto& engine = numeric::random::get_debug_engine(); } +namespace proof_system::stdlib_merkle_test { + +using namespace barretenberg; +using namespace proof_system::plonk::stdlib::merkle_tree; +using namespace plonk::stdlib; + +using Composer = plonk::UltraComposer; +using Prover = plonk::UltraProver; +using Verifier = plonk::UltraVerifier; + +using bool_ct = bool_t; +using field_ct = field_t; +using witness_ct = witness_t; + TEST(stdlib_merkle_tree, test_check_membership) { MemoryStore store; auto db = MerkleTree(store, 3); - Composer composer = Composer(); + auto composer = Composer(); // Check membership at index 0. auto zero = field_ct(witness_ct(&composer, fr::zero())).decompose_into_bits(); @@ -32,10 +47,10 @@ TEST(stdlib_merkle_tree, test_check_membership) bool_ct is_member_ = check_membership(root, create_witness_hash_path(composer, db.get_hash_path(1)), field_ct(1), seven); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -49,7 +64,7 @@ TEST(stdlib_merkle_tree, test_batch_update_membership) { MemoryStore store; MerkleTree db(store, 4); - Composer composer = Composer(); + auto composer = Composer(); // Fill in an arbitrary value at i = 2. db.update_element(2, fr::random_element()); // Define old state. @@ -66,9 +81,9 @@ TEST(stdlib_merkle_tree, test_batch_update_membership) field_ct start_idx = field_ct(witness_ct(&composer, fr(4))); batch_update_membership(new_root, old_root, old_hash_path_1, values, start_idx); batch_update_membership(new_root, old_root, old_hash_path_2, values, start_idx); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); bool result = verifier.verify_proof(proof); EXPECT_EQ(result, true); @@ -78,17 +93,17 @@ TEST(stdlib_merkle_tree, test_assert_check_membership) { MemoryStore store; auto db = MerkleTree(store, 3); - Composer composer = Composer(); + auto composer = Composer(); auto zero = field_ct(witness_ct(&composer, fr::zero())).decompose_into_bits(); field_ct root = witness_ct(&composer, db.root()); assert_check_membership(root, create_witness_hash_path(composer, db.get_hash_path(0)), field_ct(0), zero); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -101,17 +116,17 @@ TEST(stdlib_merkle_tree, test_assert_check_membership_fail) MemoryStore store; auto db = MerkleTree(store, 3); - Composer composer = Composer(); + auto composer = Composer(); auto zero = field_ct(witness_ct(&composer, fr::zero())).decompose_into_bits(); field_ct root = witness_ct(&composer, db.root()); assert_check_membership(root, create_witness_hash_path(composer, db.get_hash_path(0)), field_ct(1), zero); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -125,7 +140,7 @@ TEST(stdlib_merkle_tree, test_update_members) MemoryStore store; auto db = MerkleTree(store, 3); - Composer composer = Composer(); + auto composer = Composer(); auto zero = field_ct(witness_ct(&composer, fr::zero())).decompose_into_bits(); @@ -140,10 +155,10 @@ TEST(stdlib_merkle_tree, test_update_members) update_membership(new_root, new_value, old_root, old_path, old_value, zero); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -154,7 +169,7 @@ TEST(stdlib_merkle_tree, test_update_members) MemoryStore store; auto db = MerkleTree(store, 3); - Composer composer = Composer(); + auto composer = Composer(); auto zero = field_ct(witness_ct(&composer, fr::zero())).decompose_into_bits(); @@ -169,10 +184,10 @@ TEST(stdlib_merkle_tree, test_update_members) update_membership(new_root, new_value, old_root, new_path, old_value, zero); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -189,7 +204,7 @@ TEST(stdlib_merkle_tree, test_tree) MerkleTree db(store, depth); MemoryTree mem_tree(depth); - Composer composer = Composer(); + auto composer = Composer(); auto zero_field = field_ct(witness_ct(&composer, fr::zero())); auto values = std::vector(num, zero_field); @@ -197,10 +212,10 @@ TEST(stdlib_merkle_tree, test_tree) assert_check_tree(root, values); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); @@ -214,7 +229,7 @@ TEST(stdlib_merkle_tree, test_update_memberships) MemoryStore store; MerkleTree tree(store, depth); - Composer composer = Composer(); + auto composer = Composer(); constexpr size_t filled = (1UL << depth) / 2; std::vector filled_values; @@ -266,10 +281,11 @@ TEST(stdlib_merkle_tree, test_update_memberships) update_memberships(old_root_ct, new_roots_ct, new_values_ct, old_values_ct, old_hash_paths_ct, old_indices_ct); - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_verifier(); plonk::proof proof = prover.construct_proof(); bool result = verifier.verify_proof(proof); EXPECT_EQ(result, true); } +} // namespace proof_system::stdlib_merkle_test \ No newline at end of file diff --git a/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.test.cpp b/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.test.cpp index a4b3607be9..ed42634b57 100644 --- a/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.test.cpp +++ b/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.test.cpp @@ -4,11 +4,18 @@ #include "barretenberg/common/streams.hpp" #include "barretenberg/common/test.hpp" #include "barretenberg/numeric/random/engine.hpp" -#include "barretenberg/stdlib/types/types.hpp" -using namespace barretenberg; +namespace proof_system::test_stdlib_merkle_tree { + +using namespace plonk::stdlib; using namespace proof_system::plonk::stdlib::merkle_tree; +using Composer = plonk::UltraComposer; +using Prover = plonk::UltraProver; +using Verifier = plonk::UltraVerifier; + +using field_ct = field_t; +using witness_ct = witness_t; namespace { auto& engine = numeric::random::get_debug_engine(); auto& random_engine = numeric::random::get_engine(); @@ -128,3 +135,4 @@ TEST(stdlib_merkle_tree, test_get_hash_path_layers) EXPECT_NE(before[2], after[2]); } } +} // namespace proof_system::test_stdlib_merkle_tree \ No newline at end of file diff --git a/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp b/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp index 32eb7d5b80..e3b6576e9f 100644 --- a/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp +++ b/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp @@ -19,7 +19,6 @@ namespace { auto& engine = numeric::random::get_debug_engine(); } -// using namespace barretenberg; using namespace proof_system::plonk; // One can only define a TYPED_TEST with a single template paramter. diff --git a/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp b/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp index 81fcd8139a..3e8d1b2430 100644 --- a/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp +++ b/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp @@ -1,7 +1,8 @@ #include "byte_array.hpp" #include -#include "../../types/types.hpp" #include "barretenberg/plonk/composer/standard_composer.hpp" +#include "barretenberg/plonk/composer/turbo_composer.hpp" +#include "barretenberg/plonk/composer/ultra_composer.hpp" #include "barretenberg/honk/composer/standard_honk_composer.hpp" #include "barretenberg/stdlib/primitives/bool/bool.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" diff --git a/cpp/src/barretenberg/stdlib/primitives/group/group.test.cpp b/cpp/src/barretenberg/stdlib/primitives/group/group.test.cpp index 1a71438a2e..07df473361 100644 --- a/cpp/src/barretenberg/stdlib/primitives/group/group.test.cpp +++ b/cpp/src/barretenberg/stdlib/primitives/group/group.test.cpp @@ -1,8 +1,13 @@ -#include "../../types/types.hpp" #include +#include "barretenberg/plonk/composer/standard_composer.hpp" +#include "barretenberg/plonk/composer/turbo_composer.hpp" +#include "barretenberg/plonk/composer/ultra_composer.hpp" #include "barretenberg/honk/composer/standard_honk_composer.hpp" #include "barretenberg/stdlib/primitives/witness/witness.hpp" +#include "barretenberg/stdlib/primitives/field/field.hpp" +#include "barretenberg/stdlib/primitives/group/group.hpp" #include "barretenberg/numeric/random/engine.hpp" + #define STDLIB_TYPE_ALIASES \ using Composer = TypeParam; \ using witness_ct = stdlib::witness_t; \ diff --git a/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp b/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp index 340d02a543..c194d0fead 100644 --- a/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp +++ b/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp @@ -1,8 +1,13 @@ -#include "packed_byte_array.hpp" -#include "../../types/types.hpp" -#include "../byte_array/byte_array.hpp" #include + +#include "packed_byte_array.hpp" +#include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" #include "barretenberg/numeric/random/engine.hpp" +#include "barretenberg/plonk/composer/standard_composer.hpp" +#include "barretenberg/plonk/composer/turbo_composer.hpp" +#include "barretenberg/plonk/composer/ultra_composer.hpp" +#include "barretenberg/honk/composer/standard_honk_composer.hpp" + #pragma GCC diagnostic ignored "-Wunused-local-typedefs" namespace test_stdlib_packed_byte_array { diff --git a/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.test.cpp b/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.test.cpp index 45657fb45f..3a315b1bd7 100644 --- a/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.test.cpp +++ b/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.test.cpp @@ -6,8 +6,10 @@ #include "safe_uint.hpp" #include "barretenberg/numeric/random/engine.hpp" #include "../byte_array/byte_array.hpp" +#include "barretenberg/plonk/composer/standard_composer.hpp" +#include "barretenberg/plonk/composer/turbo_composer.hpp" +#include "barretenberg/plonk/composer/ultra_composer.hpp" #include "barretenberg/honk/composer/standard_honk_composer.hpp" -#include "barretenberg/stdlib/types/types.hpp" #pragma GCC diagnostic ignored "-Wunused-local-typedefs" diff --git a/cpp/src/barretenberg/stdlib/types/types.hpp b/cpp/src/barretenberg/stdlib/types/types.hpp deleted file mode 100644 index 6a1db12f6e..0000000000 --- a/cpp/src/barretenberg/stdlib/types/types.hpp +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once -#include "barretenberg/plonk/proof_system/constants.hpp" -#include "barretenberg/plonk/composer/standard_composer.hpp" -#include "barretenberg/plonk/composer/turbo_composer.hpp" -#include "barretenberg/plonk/composer/ultra_composer.hpp" -#include "barretenberg/plonk/proof_system/prover/prover.hpp" -#include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" -#include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" -#include "barretenberg/stdlib/primitives/bit_array/bit_array.hpp" -#include "barretenberg/stdlib/primitives/bool/bool.hpp" -#include "barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp" -#include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" -#include "barretenberg/stdlib/primitives/uint/uint.hpp" -#include "barretenberg/stdlib/primitives/witness/witness.hpp" -#include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" -#include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" -#include "barretenberg/stdlib/commitment/pedersen/pedersen.hpp" -#include "barretenberg/stdlib/commitment/pedersen/pedersen_plookup.hpp" -#include "barretenberg/stdlib/merkle_tree/hash_path.hpp" -#include "barretenberg/stdlib/encryption/schnorr/schnorr.hpp" -#include "barretenberg/stdlib/primitives/curves/bn254.hpp" -#include "barretenberg/stdlib/primitives/curves/secp256k1.hpp" -#include "barretenberg/stdlib/primitives/memory/rom_table.hpp" -#include "barretenberg/stdlib/recursion/verifier/program_settings.hpp" -#include "barretenberg/stdlib/primitives/memory/ram_table.hpp" -#include "barretenberg/stdlib/primitives/memory/rom_table.hpp" -#include "barretenberg/stdlib/primitives/memory/dynamic_array.hpp" - -namespace proof_system::plonk::stdlib::types { - -using namespace proof_system::plonk; -static constexpr size_t SYSTEM_COMPOSER = proof_system::plonk::SYSTEM_COMPOSER; - -typedef std::conditional_t< - SYSTEM_COMPOSER == proof_system::STANDARD, - plonk::StandardComposer, - std::conditional_t> - Composer; - -typedef std::conditional_t< - SYSTEM_COMPOSER == proof_system::STANDARD, - plonk::Prover, - std::conditional_t> - Prover; - -typedef std::conditional_t< - SYSTEM_COMPOSER == proof_system::STANDARD, - plonk::Verifier, - std::conditional_t> - Verifier; - -typedef stdlib::witness_t witness_ct; -typedef stdlib::public_witness_t public_witness_ct; -typedef stdlib::bool_t bool_ct; -typedef stdlib::byte_array byte_array_ct; -typedef stdlib::packed_byte_array packed_byte_array_ct; -typedef stdlib::field_t field_ct; -typedef stdlib::safe_uint_t suint_ct; -typedef stdlib::uint8 uint8_ct; -typedef stdlib::uint16 uint16_ct; -typedef stdlib::uint32 uint32_ct; -typedef stdlib::uint64 uint64_ct; -typedef stdlib::bit_array bit_array_ct; -typedef stdlib::bigfield fq_ct; -typedef stdlib::element biggroup_ct; -typedef stdlib::point point_ct; -typedef stdlib::pedersen_commitment pedersen_commitment; -typedef stdlib::group group_ct; -typedef stdlib::bn254 bn254; -typedef stdlib::secp256k1 secp256k1_ct; - -namespace merkle_tree { -using namespace stdlib::merkle_tree; -typedef stdlib::merkle_tree::hash_path hash_path; -} // namespace merkle_tree - -namespace schnorr { -typedef stdlib::schnorr::signature_bits signature_bits; -} // namespace schnorr - -// Ultra-composer specific types -typedef stdlib::rom_table rom_table_ct; - -typedef std::conditional_t, - recursion::recursive_ultra_verifier_settings> - recursive_inner_verifier_settings; - -} // namespace proof_system::plonk::stdlib::types