diff --git a/barretenberg/cpp/src/barretenberg/benchmark/decrypt_bench/main.cpp b/barretenberg/cpp/src/barretenberg/benchmark/decrypt_bench/main.cpp index 265e2e2d7bd..ecef366a1da 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/decrypt_bench/main.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/decrypt_bench/main.cpp @@ -1,6 +1,8 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include +using namespace bb; + int main(int, char**) { diff --git a/barretenberg/cpp/src/barretenberg/benchmark/poseidon2_bench/poseidon2.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/poseidon2_bench/poseidon2.bench.cpp index 4118e492560..69bc05fc051 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/poseidon2_bench/poseidon2.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/poseidon2_bench/poseidon2.bench.cpp @@ -3,6 +3,7 @@ #include using namespace benchmark; +using namespace bb; grumpkin::fq poseidon_function(const size_t count) { diff --git a/barretenberg/cpp/src/barretenberg/common/parallel_for_atomic_pool.cpp b/barretenberg/cpp/src/barretenberg/common/parallel_for_atomic_pool.cpp index 08da4e27a92..29c45e34896 100644 --- a/barretenberg/cpp/src/barretenberg/common/parallel_for_atomic_pool.cpp +++ b/barretenberg/cpp/src/barretenberg/common/parallel_for_atomic_pool.cpp @@ -100,6 +100,7 @@ void ThreadPool::worker_loop(size_t /*unused*/) } } // namespace +namespace bb { /** * A thread pooled strategy that uses atomics to prevent needing constantly lock on a queue. * The main thread acts as a worker also, and when it completes, it spins until thread workers are done. @@ -112,3 +113,4 @@ void parallel_for_atomic_pool(size_t num_iterations, const std::function #include +namespace { class ThreadPool { public: ThreadPool(size_t num_threads) @@ -85,7 +86,9 @@ class ThreadPool { } } }; +} // namespace +namespace bb { /** * A Thread pooled strategy that uses a popular lock-free multiple-producer multiple-consume queue library by * "moodycamel" as the underlying mechanism to distribute work and join on completion. @@ -97,3 +100,4 @@ void parallel_for_moody(size_t num_iterations, const std::function pool.start_tasks(func, num_iterations); } +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/common/parallel_for_mutex_pool.cpp b/barretenberg/cpp/src/barretenberg/common/parallel_for_mutex_pool.cpp index 7c85c03927c..24479dec9c1 100644 --- a/barretenberg/cpp/src/barretenberg/common/parallel_for_mutex_pool.cpp +++ b/barretenberg/cpp/src/barretenberg/common/parallel_for_mutex_pool.cpp @@ -115,6 +115,7 @@ void ThreadPool::worker_loop(size_t /*unused*/) } } // namespace +namespace bb { /** * A thread pooled strategy that uses std::mutex for protection. Each worker increments the "iteration" and processes. * The main thread acts as a worker also, and when it completes, it spins until thread workers are done. @@ -127,3 +128,4 @@ void parallel_for_mutex_pool(size_t num_iterations, const std::function #include +namespace bb { void parallel_for_omp(size_t num_iterations, const std::function& func) { #ifndef NO_OMP_MULTITHREADING @@ -10,3 +11,4 @@ void parallel_for_omp(size_t num_iterations, const std::function& func(i); } } +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/common/parallel_for_queued.cpp b/barretenberg/cpp/src/barretenberg/common/parallel_for_queued.cpp index caac4022d59..33dc7af9c29 100644 --- a/barretenberg/cpp/src/barretenberg/common/parallel_for_queued.cpp +++ b/barretenberg/cpp/src/barretenberg/common/parallel_for_queued.cpp @@ -8,6 +8,7 @@ #include #include +namespace { class ThreadPool { public: ThreadPool(size_t num_threads); @@ -100,7 +101,9 @@ void ThreadPool::worker_loop(size_t /*unused*/) } // info("worker exit ", worker_num); } +} // namespace +namespace bb { /** * A thread pooled strategey that assumed that thread pools would be more efficient than spawning threads. * Every iteration becomes a task in a queue. That's probably not very efficient. @@ -120,3 +123,4 @@ void parallel_for_queued(size_t num_iterations, const std::function&, size_t, size_t, size_t, size_t, size_t, size_t, size_t); template void run_loop_in_parallel_if_effective_internal( - size_t, const std::function&, size_t, size_t, size_t, size_t, size_t, size_t, size_t); \ No newline at end of file + size_t, const std::function&, size_t, size_t, size_t, size_t, size_t, size_t, size_t); + +/** + * @brief calculates number of threads to create based on minimum iterations per thread + * @details Finds the number of cpus with get_num_cpus(), and calculates `desired_num_threads` + * Returns the min of `desired_num_threads` and `max_num_threads`. + * Note that it will not calculate a power of 2 necessarily, use `calculate_num_threads_pow2` instead + * + * @param num_iterations + * @param min_iterations_per_thread + * @return size_t + */ +size_t calculate_num_threads(size_t num_iterations, size_t min_iterations_per_thread) +{ + size_t max_num_threads = get_num_cpus(); // number of available threads + size_t desired_num_threads = num_iterations / min_iterations_per_thread; + size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified + num_threads = num_threads > 0 ? num_threads : 1; // ensure num_threads is at least 1 + return num_threads; +} + +/** + * @brief calculates number of threads to create based on minimum iterations per thread, guaranteed power of 2 + * @details Same functionality as `calculate_num_threads` but guaranteed power of 2 + * @param num_iterations + * @param min_iterations_per_thread + * @return size_t + */ +size_t calculate_num_threads_pow2(size_t num_iterations, size_t min_iterations_per_thread) +{ + size_t max_num_threads = get_num_cpus_pow2(); // number of available threads (power of 2) + size_t desired_num_threads = num_iterations / min_iterations_per_thread; + desired_num_threads = static_cast(1ULL << numeric::get_msb(desired_num_threads)); + size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified + num_threads = num_threads > 0 ? num_threads : 1; // ensure num_threads is at least 1 + return num_threads; +} +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/common/thread.hpp b/barretenberg/cpp/src/barretenberg/common/thread.hpp index c2d3ec76744..723d2834fa5 100644 --- a/barretenberg/cpp/src/barretenberg/common/thread.hpp +++ b/barretenberg/cpp/src/barretenberg/common/thread.hpp @@ -7,6 +7,8 @@ #include #include +namespace bb { + inline size_t get_num_cpus() { #ifdef NO_MULTITHREADING @@ -19,7 +21,7 @@ inline size_t get_num_cpus() // For algorithms that need to be divided amongst power of 2 threads. inline size_t get_num_cpus_pow2() { - return static_cast(1ULL << bb::numeric::get_msb(get_num_cpus())); + return static_cast(1ULL << numeric::get_msb(get_num_cpus())); } void parallel_for(size_t num_iterations, const std::function& func); @@ -89,4 +91,30 @@ inline void run_loop_in_parallel_if_effective_with_index(size_t num_points, group_element_doublings_per_iteration, scalar_multiplications_per_iteration, sequential_copy_ops_per_iteration); -} \ No newline at end of file +} + +const size_t DEFAULT_MIN_ITERS_PER_THREAD = 1 << 4; + +/** + * @brief calculates number of threads to create based on minimum iterations per thread + * @details Finds the number of cpus with get_num_cpus(), and calculates `desired_num_threads` + * Returns the min of `desired_num_threads` and `max_num_theads`. + * Note that it will not calculate a power of 2 necessarily, use `calculate_num_threads_pow2` instead + * + * @param num_iterations + * @param min_iterations_per_thread + * @return size_t + */ +size_t calculate_num_threads(size_t num_iterations, size_t min_iterations_per_thread = DEFAULT_MIN_ITERS_PER_THREAD); + +/** + * @brief calculates number of threads to create based on minimum iterations per thread, guaranteed power of 2 + * @details Same functionality as `calculate_num_threads` but guaranteed power of 2 + * @param num_iterations + * @param min_iterations_per_thread + * @return size_t + */ +size_t calculate_num_threads_pow2(size_t num_iterations, + size_t min_iterations_per_thread = DEFAULT_MIN_ITERS_PER_THREAD); + +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/common/thread_utils.cpp b/barretenberg/cpp/src/barretenberg/common/thread_utils.cpp deleted file mode 100644 index de9181f3ecc..00000000000 --- a/barretenberg/cpp/src/barretenberg/common/thread_utils.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "thread_utils.hpp" - -namespace bb::thread_utils { -/** - * @brief calculates number of threads to create based on minimum iterations per thread - * @details Finds the number of cpus with get_num_cpus(), and calculates `desired_num_threads` - * Returns the min of `desired_num_threads` and `max_num_threads`. - * Note that it will not calculate a power of 2 necessarily, use `calculate_num_threads_pow2` instead - * - * @param num_iterations - * @param min_iterations_per_thread - * @return size_t - */ -size_t calculate_num_threads(size_t num_iterations, size_t min_iterations_per_thread) -{ - size_t max_num_threads = get_num_cpus(); // number of available threads - size_t desired_num_threads = num_iterations / min_iterations_per_thread; - size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified - num_threads = num_threads > 0 ? num_threads : 1; // ensure num_threads is at least 1 - return num_threads; -} - -/** - * @brief calculates number of threads to create based on minimum iterations per thread, guaranteed power of 2 - * @details Same functionality as `calculate_num_threads` but guaranteed power of 2 - * @param num_iterations - * @param min_iterations_per_thread - * @return size_t - */ -size_t calculate_num_threads_pow2(size_t num_iterations, size_t min_iterations_per_thread) -{ - size_t max_num_threads = get_num_cpus_pow2(); // number of available threads (power of 2) - size_t desired_num_threads = num_iterations / min_iterations_per_thread; - desired_num_threads = static_cast(1ULL << numeric::get_msb(desired_num_threads)); - size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified - num_threads = num_threads > 0 ? num_threads : 1; // ensure num_threads is at least 1 - return num_threads; -} - -} // namespace bb::thread_utils \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/common/thread_utils.hpp b/barretenberg/cpp/src/barretenberg/common/thread_utils.hpp deleted file mode 100644 index 2e3dbf81c9f..00000000000 --- a/barretenberg/cpp/src/barretenberg/common/thread_utils.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#include "thread.hpp" - -namespace bb::thread_utils { - -const size_t DEFAULT_MIN_ITERS_PER_THREAD = 1 << 4; - -/** - * @brief calculates number of threads to create based on minimum iterations per thread - * @details Finds the number of cpus with get_num_cpus(), and calculates `desired_num_threads` - * Returns the min of `desired_num_threads` and `max_num_theads`. - * Note that it will not calculate a power of 2 necessarily, use `calculate_num_threads_pow2` instead - * - * @param num_iterations - * @param min_iterations_per_thread - * @return size_t - */ -size_t calculate_num_threads(size_t num_iterations, size_t min_iterations_per_thread = DEFAULT_MIN_ITERS_PER_THREAD); - -/** - * @brief calculates number of threads to create based on minimum iterations per thread, guaranteed power of 2 - * @details Same functionality as `calculate_num_threads` but guaranteed power of 2 - * @param num_iterations - * @param min_iterations_per_thread - * @return size_t - */ -size_t calculate_num_threads_pow2(size_t num_iterations, - size_t min_iterations_per_thread = DEFAULT_MIN_ITERS_PER_THREAD); - -} // namespace bb::thread_utils \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.cpp index 53c0a84b07b..802fcc02647 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.cpp @@ -4,8 +4,6 @@ using namespace bb; -extern "C" { - WASM_EXPORT void blake2s(uint8_t const* data, out_buf32 out) { std::vector inputv; @@ -31,4 +29,3 @@ WASM_EXPORT void blake2s_to_field_(uint8_t const* data, fr::out_buf r) auto result = bb::fr::serialize_from_buffer(output.data()); bb::fr::serialize_to_buffer(result, r); } -} diff --git a/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.hpp index cf124a5a6c9..c1e14c07a00 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.hpp @@ -3,11 +3,5 @@ #include #include -extern "C" { - -using namespace bb; - WASM_EXPORT void blake2s(uint8_t const* data, out_buf32 r); - WASM_EXPORT void blake2s_to_field_(uint8_t const* data, fr::out_buf r); -} diff --git a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp index db8808a8c84..8c0c8295c23 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp @@ -1,6 +1,9 @@ #include "ecdsa.hpp" #include +using namespace bb; +using namespace bb::crypto; + WASM_EXPORT void ecdsa__compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf) { auto priv_key = from_buffer(private_key); @@ -18,9 +21,9 @@ WASM_EXPORT void ecdsa__construct_signature(uint8_t const* message, using serialize::write; auto priv_key = from_buffer(private_key); secp256k1::g1::affine_element pub_key = secp256k1::g1::one * priv_key; - bb::crypto::ecdsa_key_pair key_pair = { priv_key, pub_key }; + ecdsa_key_pair key_pair = { priv_key, pub_key }; - auto sig = bb::crypto::ecdsa_construct_signature( + auto sig = ecdsa_construct_signature( std::string((char*)message, msg_len), key_pair); write(output_sig_r, sig.r); write(output_sig_s, sig.s); @@ -39,10 +42,9 @@ WASM_EXPORT void ecdsa__recover_public_key_from_signature(uint8_t const* message std::copy(sig_s, sig_s + 32, s.begin()); const uint8_t v = *sig_v; - bb::crypto::ecdsa_signature sig = { r, s, v }; - auto recovered_pub_key = - bb::crypto::ecdsa_recover_public_key( - std::string((char*)message, msg_len), sig); + ecdsa_signature sig = { r, s, v }; + auto recovered_pub_key = ecdsa_recover_public_key( + std::string((char*)message, msg_len), sig); serialize::write(output_pub_key, recovered_pub_key); } @@ -59,7 +61,7 @@ WASM_EXPORT bool ecdsa__verify_signature(uint8_t const* message, std::copy(sig_s, sig_s + 32, s.begin()); const uint8_t v = *sig_v; - bb::crypto::ecdsa_signature sig = { r, s, v }; - return bb::crypto::ecdsa_verify_signature( + ecdsa_signature sig = { r, s, v }; + return ecdsa_verify_signature( std::string((char*)message, msg_len), pubk, sig); } diff --git a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.test.cpp index 507c3378f26..8caa089ce7a 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.test.cpp @@ -7,10 +7,11 @@ #include using namespace bb; +using namespace bb::crypto; TEST(ecdsa, msgpack) { - auto [actual, expected] = msgpack_roundtrip(crypto::ecdsa_signature{}); + auto [actual, expected] = msgpack_roundtrip(ecdsa_signature{}); EXPECT_EQ(actual, expected); } @@ -18,14 +19,14 @@ TEST(ecdsa, verify_signature_grumpkin_sha256) { std::string message = "The quick brown dog jumped over the lazy fox."; - crypto::ecdsa_key_pair account; + ecdsa_key_pair account; account.private_key = grumpkin::fr::random_element(); account.public_key = grumpkin::g1::one * account.private_key; - crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature(message, account); + ecdsa_signature signature = + ecdsa_construct_signature(message, account); - bool result = crypto::ecdsa_verify_signature( + bool result = ecdsa_verify_signature( message, account.public_key, signature); EXPECT_EQ(result, true); @@ -35,14 +36,14 @@ TEST(ecdsa, verify_signature_secp256r1_sha256) { std::string message = "The quick brown dog jumped over the lazy fox."; - crypto::ecdsa_key_pair account; + ecdsa_key_pair account; account.private_key = secp256r1::fr::random_element(); account.public_key = secp256r1::g1::one * account.private_key; - crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature(message, account); + ecdsa_signature signature = + ecdsa_construct_signature(message, account); - bool result = crypto::ecdsa_verify_signature( + bool result = ecdsa_verify_signature( message, account.public_key, signature); EXPECT_EQ(result, true); @@ -52,18 +53,18 @@ TEST(ecdsa, recover_public_key_secp256k1_sha256) { std::string message = "The quick brown dog jumped over the lazy fox."; - crypto::ecdsa_key_pair account; + ecdsa_key_pair account; account.private_key = secp256k1::fr::random_element(); account.public_key = secp256k1::g1::one * account.private_key; - crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature(message, account); + ecdsa_signature signature = + ecdsa_construct_signature(message, account); - bool result = crypto::ecdsa_verify_signature( + bool result = ecdsa_verify_signature( message, account.public_key, signature); auto recovered_public_key = - crypto::ecdsa_recover_public_key(message, signature); + ecdsa_recover_public_key(message, signature); EXPECT_EQ(result, true); EXPECT_EQ(recovered_public_key, account.public_key); @@ -73,18 +74,18 @@ TEST(ecdsa, recover_public_key_secp256r1_sha256) { std::string message = "The quick brown dog jumped over the lazy fox."; - crypto::ecdsa_key_pair account; + ecdsa_key_pair account; account.private_key = secp256r1::fr::random_element(); account.public_key = secp256r1::g1::one * account.private_key; - crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature(message, account); + ecdsa_signature signature = + ecdsa_construct_signature(message, account); - bool result = crypto::ecdsa_verify_signature( + bool result = ecdsa_verify_signature( message, account.public_key, signature); auto recovered_public_key = - crypto::ecdsa_recover_public_key(message, signature); + ecdsa_recover_public_key(message, signature); EXPECT_EQ(result, true); EXPECT_EQ(recovered_public_key, account.public_key); @@ -96,19 +97,18 @@ TEST(ecdsa, check_overflowing_r_and_s_are_rejected) std::vector message_vec = utils::hex_to_bytes("41414141"); std::string message(message_vec.begin(), message_vec.end()); - crypto::ecdsa_signature signature; + ecdsa_signature signature; grumpkin::fr private_key; grumpkin::g1::affine_element public_key; - crypto::ecdsa_key_pair key_pair; + ecdsa_key_pair key_pair; // We create a private and public key and a signature private_key = grumpkin::fr::random_element(); public_key = grumpkin::g1::affine_element((grumpkin::g1::one * private_key).normalize()); key_pair = { private_key, public_key }; - signature = - crypto::ecdsa_construct_signature(message, key_pair); + signature = ecdsa_construct_signature(message, key_pair); // Check that the signature is correct - bool result = crypto::ecdsa_verify_signature( - message, public_key, signature); + bool result = + ecdsa_verify_signature(message, public_key, signature); EXPECT_TRUE(result); using serialize::read; @@ -121,8 +121,8 @@ TEST(ecdsa, check_overflowing_r_and_s_are_rejected) using serialize::write; auto* p_r_m = &signature.r[0]; write(p_r_m, new_r); - result = crypto::ecdsa_verify_signature( - message, public_key, signature); + result = + ecdsa_verify_signature(message, public_key, signature); // Signature verification should decline this signature, since it breaks specification EXPECT_FALSE(result); // Do the same for s, restore r @@ -134,8 +134,8 @@ TEST(ecdsa, check_overflowing_r_and_s_are_rejected) auto* p_r_s = &signature.s[0]; write(p_r_m, old_r); write(p_r_s, new_s); - result = crypto::ecdsa_verify_signature( - message, public_key, signature); + result = + ecdsa_verify_signature(message, public_key, signature); EXPECT_FALSE(result); } @@ -168,14 +168,14 @@ TEST(ecdsa, verify_signature_secp256r1_sha256_NIST_1) 0xef, 0x97, 0xb2, 0x18, 0xe9, 0x6f, 0x17, 0x5a, 0x3c, 0xcd, 0xda, 0x2a, 0xcc, 0x05, 0x89, 0x03, }; - crypto::ecdsa_signature sig{ r, s, 27 }; + ecdsa_signature sig{ r, s, 27 }; std::vector message_vec = utils::hex_to_bytes( "5905238877c77421f73e43ee3da6f2d9e2ccad5fc942dcec0cbd25482935faaf416983fe165b1a045ee2bcd2e6dca3bdf46" "c4310a7461f9a37960ca672d3feb5473e253605fb1ddfd28065b53cb5858a8ad28175bf9bd386a5e471ea7a65c17cc934a9" "d791e91491eb3754d03799790fe2d308d16146d5c9b0d0debd97d79ce8"); std::string message(message_vec.begin(), message_vec.end()); - bool result = crypto::ecdsa_verify_signature( - message, public_key, sig); + bool result = + ecdsa_verify_signature(message, public_key, sig); EXPECT_EQ(result, true); } diff --git a/barretenberg/cpp/src/barretenberg/crypto/hashers/hashers.hpp b/barretenberg/cpp/src/barretenberg/crypto/hashers/hashers.hpp index f19224941d1..63dba9cd232 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/hashers/hashers.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/hashers/hashers.hpp @@ -6,6 +6,8 @@ #include "memory.h" #include + +namespace bb::crypto { struct KeccakHasher { static constexpr size_t BLOCK_SIZE = 64; static constexpr size_t OUTPUT_SIZE = 32; @@ -25,11 +27,12 @@ struct Sha256Hasher { static constexpr size_t BLOCK_SIZE = 64; static constexpr size_t OUTPUT_SIZE = 32; - template > static auto hash(const B& message) { return sha256::sha256(message); } + template > static auto hash(const B& message) { return sha256(message); } }; struct Blake2sHasher { static constexpr size_t BLOCK_SIZE = 64; static constexpr size_t OUTPUT_SIZE = 32; - static auto hash(const std::vector& message) { return bb::crypto::blake2s(message); } + static auto hash(const std::vector& message) { return blake2s(message); } }; +} // namespace bb::crypto \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/hmac/hmac.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/hmac/hmac.test.cpp index 020ceedaf2c..71340a36556 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/hmac/hmac.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/hmac/hmac.test.cpp @@ -9,6 +9,7 @@ #include using namespace bb; +using namespace bb::crypto; std::array hex_to_bytes(const std::string& hex) { @@ -108,7 +109,7 @@ TEST(hmac, ValidateHMAC) }; for (const auto& [key_string, message, expected] : test_vectors) { - std::array result = crypto::hmac(message, key_string); + std::array result = hmac(message, key_string); EXPECT_EQ(result, hex_to_bytes(expected)); } diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp index 0d08ccff975..cf0f544090c 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp @@ -3,16 +3,13 @@ #include "barretenberg/common/serialize.hpp" #include "pedersen.hpp" -extern "C" { - using namespace bb; -WASM_EXPORT void pedersen_commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output) +WASM_EXPORT void pedersen_commit(fr::vec_in_buf inputs_buffer, grumpkin::g1::affine_element::out_buf output) { std::vector to_commit; read(inputs_buffer, to_commit); grumpkin::g1::affine_element pedersen_commitment = crypto::pedersen_commitment::commit_native(to_commit); serialize::write(output, pedersen_commitment); -} } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp index a4a37b9eac5..d90b4234cab 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.hpp @@ -3,10 +3,4 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" -extern "C" { - -using namespace bb; -using affine_element = grumpkin::g1::affine_element; - -WASM_EXPORT void pedersen_commit(fr::vec_in_buf inputs_buffer, affine_element::out_buf output); -} \ No newline at end of file +WASM_EXPORT void pedersen_commit(bb::fr::vec_in_buf inputs_buffer, bb::grumpkin::g1::affine_element::out_buf output); \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp index b455ab5d6d5..bb8a8ba3bad 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp @@ -3,42 +3,41 @@ #include "barretenberg/common/serialize.hpp" #include "pedersen.hpp" -extern "C" { +using namespace bb; -WASM_EXPORT void pedersen_hash(bb::fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, bb::fr::out_buf output) +WASM_EXPORT void pedersen_hash(fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, fr::out_buf output) { std::vector to_hash; read(inputs_buffer, to_hash); - bb::crypto::GeneratorContext ctx; + crypto::GeneratorContext ctx; ctx.offset = static_cast(ntohl(*hash_index)); - auto r = bb::crypto::pedersen_hash::hash(to_hash, ctx); - bb::fr::serialize_to_buffer(r, output); + auto r = crypto::pedersen_hash::hash(to_hash, ctx); + fr::serialize_to_buffer(r, output); } -WASM_EXPORT void pedersen_hashes(bb::fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, bb::fr::out_buf output) +WASM_EXPORT void pedersen_hashes(fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, fr::out_buf output) { std::vector to_hash; read(inputs_buffer, to_hash); - bb::crypto::GeneratorContext ctx; + crypto::GeneratorContext ctx; ctx.offset = static_cast(ntohl(*hash_index)); const size_t numHashes = to_hash.size() / 2; std::vector results; size_t count = 0; while (count < numHashes) { - auto r = bb::crypto::pedersen_hash::hash({ to_hash[count * 2], to_hash[count * 2 + 1] }, ctx); + auto r = crypto::pedersen_hash::hash({ to_hash[count * 2], to_hash[count * 2 + 1] }, ctx); results.push_back(r); ++count; } write(output, results); } -WASM_EXPORT void pedersen_hash_buffer(uint8_t const* input_buffer, uint32_t const* hash_index, bb::fr::out_buf output) +WASM_EXPORT void pedersen_hash_buffer(uint8_t const* input_buffer, uint32_t const* hash_index, fr::out_buf output) { std::vector to_hash; read(input_buffer, to_hash); - bb::crypto::GeneratorContext ctx; + crypto::GeneratorContext ctx; ctx.offset = static_cast(ntohl(*hash_index)); - auto r = bb::crypto::pedersen_hash::hash_buffer(to_hash, ctx); - bb::fr::serialize_to_buffer(r, output); -} + auto r = crypto::pedersen_hash::hash_buffer(to_hash, ctx); + fr::serialize_to_buffer(r, output); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp index ecd51260201..cb39f6a6a42 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp @@ -3,9 +3,6 @@ #include "barretenberg/common/wasm_export.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" -extern "C" { - WASM_EXPORT void pedersen_hash(bb::fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, bb::fr::out_buf output); WASM_EXPORT void pedersen_hashes(bb::fr::vec_in_buf inputs_buffer, uint32_t const* hash_index, bb::fr::out_buf output); -WASM_EXPORT void pedersen_hash_buffer(uint8_t const* input_buffer, uint32_t const* hash_index, bb::fr::out_buf output); -} \ No newline at end of file +WASM_EXPORT void pedersen_hash_buffer(uint8_t const* input_buffer, uint32_t const* hash_index, bb::fr::out_buf output); \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.cpp index bd43c64915b..714b9456702 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.cpp @@ -4,17 +4,17 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "poseidon2.hpp" -extern "C" { +using namespace bb; -WASM_EXPORT void poseidon_hash(bb::fr::vec_in_buf inputs_buffer, bb::fr::out_buf output) +WASM_EXPORT void poseidon_hash(fr::vec_in_buf inputs_buffer, fr::out_buf output) { std::vector to_hash; read(inputs_buffer, to_hash); - auto r = bb::crypto::Poseidon2::hash(to_hash); - bb::fr::serialize_to_buffer(r, output); + auto r = crypto::Poseidon2::hash(to_hash); + fr::serialize_to_buffer(r, output); } -WASM_EXPORT void poseidon_hashes(bb::fr::vec_in_buf inputs_buffer, bb::fr::out_buf output) +WASM_EXPORT void poseidon_hashes(fr::vec_in_buf inputs_buffer, fr::out_buf output) { std::vector to_hash; read(inputs_buffer, to_hash); @@ -22,11 +22,10 @@ WASM_EXPORT void poseidon_hashes(bb::fr::vec_in_buf inputs_buffer, bb::fr::out_b std::vector results; size_t count = 0; while (count < numHashes) { - auto r = bb::crypto::Poseidon2::hash( + auto r = crypto::Poseidon2::hash( { to_hash[count * 2], to_hash[count * 2 + 1] }); results.push_back(r); ++count; } write(output, results); -} } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp index c7dc5855548..9915e082576 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/c_bind.hpp @@ -3,8 +3,5 @@ #include "barretenberg/common/wasm_export.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" -extern "C" { - WASM_EXPORT void poseidon_hash(bb::fr::vec_in_buf inputs_buffer, bb::fr::out_buf output); -WASM_EXPORT void poseidon_hashes(bb::fr::vec_in_buf inputs_buffer, bb::fr::out_buf output); -} \ No newline at end of file +WASM_EXPORT void poseidon_hashes(bb::fr::vec_in_buf inputs_buffer, bb::fr::out_buf output); \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp index 55abbfa0bdb..79cc4b44767 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp @@ -2,8 +2,6 @@ #include "multisig.hpp" #include "schnorr.hpp" -extern "C" { - using namespace bb; using affine_element = grumpkin::g1::affine_element; using multisig = crypto::schnorr_multisig; @@ -147,4 +145,3 @@ WASM_EXPORT void schnorr_multisig_combine_signatures(uint8_t const* message_buf, *success = false; } } -} diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp index ba2049cc1e7..9e4991ff7c3 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp @@ -3,11 +3,11 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "multisig.hpp" -extern "C" { - using namespace bb; +using namespace bb::crypto; + using affine_element = grumpkin::g1::affine_element; -using multisig = crypto::schnorr_multisig; +using multisig = schnorr_multisig; WASM_EXPORT void schnorr_compute_public_key(fr::in_buf private_key, affine_element::out_buf public_key_buf); WASM_EXPORT void schnorr_negate_public_key(affine_element::in_buf public_key_buffer, affine_element::out_buf output); @@ -42,5 +42,4 @@ WASM_EXPORT void schnorr_multisig_combine_signatures(uint8_t const* message, fq::vec_in_buf round_two_buf, out_buf32 s, out_buf32 e, - bool* success); -} + bool* success); \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.test.cpp index fdff67dfdfb..1ebaa1e0ffe 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.test.cpp @@ -4,7 +4,9 @@ #include "./multisig.hpp" using namespace bb; +using namespace bb::crypto; +namespace { template struct MultisigTest : public ::testing::Test { using G = grumpkin::g1; using Fr = grumpkin::fr; @@ -63,6 +65,8 @@ template struct MultisigTest : public ::testing::Test { }; using HashTypes = ::testing::Types; +} // namespace + TYPED_TEST_SUITE(MultisigTest, HashTypes); TYPED_TEST(MultisigTest, verify_multi_signature_blake2s) diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/proof_of_possession.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/proof_of_possession.test.cpp index 6432209fc85..b08f122205a 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/proof_of_possession.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/proof_of_possession.test.cpp @@ -4,11 +4,12 @@ #include using namespace bb; +using namespace bb::crypto; template struct ProofOfPossessionTest : public ::testing::Test { using G = grumpkin::g1; using Fr = grumpkin::fr; - using KeyPair = crypto::schnorr_key_pair; + using KeyPair = schnorr_key_pair; static KeyPair generate_account() { @@ -26,7 +27,7 @@ TYPED_TEST(ProofOfPossessionTest, valid_proof) { using G = grumpkin::g1; using Hash = TypeParam; - using Proof = crypto::SchnorrProofOfPossession; + using Proof = SchnorrProofOfPossession; const auto account = this->generate_account(); const auto proof = Proof(account); @@ -37,7 +38,7 @@ TYPED_TEST(ProofOfPossessionTest, invalid_empty_proof) { using G = grumpkin::g1; using Hash = TypeParam; - using Proof = crypto::SchnorrProofOfPossession; + using Proof = SchnorrProofOfPossession; const auto account = this->generate_account(); const auto proof = Proof(); @@ -48,7 +49,7 @@ TYPED_TEST(ProofOfPossessionTest, fail_with_different_account) { using G = grumpkin::g1; using Hash = TypeParam; - using Proof = crypto::SchnorrProofOfPossession; + using Proof = SchnorrProofOfPossession; const auto account1 = this->generate_account(); const auto account2 = this->generate_account(); @@ -60,7 +61,7 @@ TYPED_TEST(ProofOfPossessionTest, fail_zero_challenge) { using G = grumpkin::g1; using Hash = TypeParam; - using Proof = crypto::SchnorrProofOfPossession; + using Proof = SchnorrProofOfPossession; const auto account = this->generate_account(); auto proof = Proof(account); @@ -74,7 +75,7 @@ TYPED_TEST(ProofOfPossessionTest, fail_zero_response) { using G = grumpkin::g1; using Hash = TypeParam; - using Proof = crypto::SchnorrProofOfPossession; + using Proof = SchnorrProofOfPossession; const auto account = this->generate_account(); auto proof = Proof(account); @@ -87,7 +88,7 @@ TYPED_TEST(ProofOfPossessionTest, serialize) { using G = grumpkin::g1; using Hash = TypeParam; - using Proof = crypto::SchnorrProofOfPossession; + using Proof = SchnorrProofOfPossession; const auto account = this->generate_account(); const auto proof = Proof(account); EXPECT_TRUE(proof.verify(account.public_key)); diff --git a/barretenberg/cpp/src/barretenberg/crypto/sha256/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/sha256/c_bind.cpp index 7221eaa8a88..ab6532ee675 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/sha256/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/sha256/c_bind.cpp @@ -1,6 +1,8 @@ #include "barretenberg/common/wasm_export.hpp" #include "sha256.hpp" +using namespace bb; + WASM_EXPORT void sha256__hash(uint8_t* in, const size_t length, uint8_t* r) { std::vector message; @@ -8,7 +10,7 @@ WASM_EXPORT void sha256__hash(uint8_t* in, const size_t length, uint8_t* r) for (size_t i = 0; i < length; ++i) { message.emplace_back(in[i]); } - const auto output = sha256::sha256(message); + const auto output = crypto::sha256(message); for (size_t i = 0; i < 32; ++i) { r[i] = output[i]; } diff --git a/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.cpp b/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.cpp index 4a358c56cbf..9efad58221e 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.cpp @@ -4,8 +4,6 @@ #include #include -namespace sha256 { - namespace { constexpr uint32_t init_constants[8]{ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }; @@ -28,6 +26,7 @@ constexpr uint32_t ror(uint32_t val, uint32_t shift) } // namespace +namespace bb::crypto { void prepare_constants(std::array& input) { input[0] = init_constants[0]; @@ -108,7 +107,7 @@ std::array sha256_block(const std::array& h_init, cons return output; } -hash sha256_block(const std::vector& input) +Sha256Hash sha256_block(const std::vector& input) { ASSERT(input.size() == 64); std::array result; @@ -122,7 +121,7 @@ hash sha256_block(const std::vector& input) } result = sha256_block(result, hash_input); - hash output; + Sha256Hash output; memcpy((void*)&output[0], (void*)&result[0], 32); if (is_little_endian()) { uint32_t* output_uint32 = (uint32_t*)&output[0]; @@ -134,7 +133,7 @@ hash sha256_block(const std::vector& input) return output; } -template hash sha256(const ByteContainer& input) +template Sha256Hash sha256(const ByteContainer& input) { std::vector message_schedule; @@ -165,7 +164,7 @@ template hash sha256(const ByteContainer& input) rolling_hash = sha256_block(rolling_hash, hash_input); } - hash output; + Sha256Hash output; memcpy((void*)&output[0], (void*)&rolling_hash[0], 32); if (is_little_endian()) { uint32_t* output_uint32 = (uint32_t*)&output[0]; @@ -177,9 +176,9 @@ template hash sha256(const ByteContainer& input) return output; } -template hash sha256>(const std::vector& input); -template hash sha256>(const std::array& input); -template hash sha256(const std::string& input); -template hash sha256>(const std::span& input); +template Sha256Hash sha256>(const std::vector& input); +template Sha256Hash sha256>(const std::array& input); +template Sha256Hash sha256(const std::string& input); +template Sha256Hash sha256>(const std::span& input); -} // namespace sha256 +} // namespace bb::crypto diff --git a/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.hpp b/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.hpp index 0a121bfe63e..01553fe035a 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.hpp @@ -7,34 +7,34 @@ #include #include -namespace sha256 { +namespace bb::crypto { -using hash = std::array; +using Sha256Hash = std::array; -hash sha256_block(const std::vector& input); +Sha256Hash sha256_block(const std::vector& input); -template hash sha256(const T& input); +template Sha256Hash sha256(const T& input); inline bb::fr sha256_to_field(std::vector const& input) { - auto result = sha256::sha256(input); + auto result = sha256(input); return from_buffer(&result[0]); } -inline bool operator==(hash const& lhs, std::vector const& rhs) +inline bool operator==(Sha256Hash const& lhs, std::vector const& rhs) { return std::equal(lhs.begin(), lhs.end(), rhs.begin()); } -} // namespace sha256 +} // namespace bb::crypto namespace std { -inline bool operator==(std::vector const& lhs, sha256::hash const& rhs) +inline bool operator==(std::vector const& lhs, bb::crypto::Sha256Hash const& rhs) { return std::equal(lhs.begin(), lhs.end(), rhs.begin()); } -inline std::ostream& operator<<(std::ostream& os, sha256::hash const& arr) +inline std::ostream& operator<<(std::ostream& os, bb::crypto::Sha256Hash const& arr) { std::ios_base::fmtflags f(os.flags()); os << std::hex << std::setfill('0'); diff --git a/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.test.cpp index 57f6415410b..a356a72a65b 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.test.cpp @@ -3,15 +3,18 @@ #include #include +using namespace bb; +using namespace bb::crypto; + TEST(misc_sha256, test_NIST_vector_one) { std::string input_str = "abc"; std::vector input; std::copy(input_str.begin(), input_str.end(), std::back_inserter(input)); - auto result = sha256::sha256(input); + auto result = sha256(input); - sha256::hash expected{ + Sha256Hash expected{ 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA, 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23, 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C, 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD, }; @@ -27,9 +30,9 @@ TEST(misc_sha256, test_NIST_vector_two) std::vector input; std::copy(input_str.begin(), input_str.end(), std::back_inserter(input)); - auto result = sha256::sha256(input); + auto result = sha256(input); - sha256::hash expected{ + Sha256Hash expected{ 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8, 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39, 0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67, 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1, }; @@ -43,9 +46,9 @@ TEST(misc_sha256, test_NIST_vector_three) { std::vector input; input.push_back(0xbd); - auto result = sha256::sha256(input); + auto result = sha256(input); - sha256::hash expected{ + Sha256Hash expected{ 0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70, 0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b, }; @@ -59,9 +62,9 @@ TEST(misc_sha256, test_NIST_vector_four) { std::vector input{ 0xc9, 0x8c, 0x8e, 0x55 }; - auto result = sha256::sha256(input); + auto result = sha256(input); - sha256::hash expected{ + Sha256Hash expected{ 0x7a, 0xbc, 0x22, 0xc0, 0xae, 0x5a, 0xf2, 0x6c, 0xe9, 0x3d, 0xbb, 0x94, 0x43, 0x3a, 0x0e, 0x0b, 0x2e, 0x11, 0x9d, 0x01, 0x4f, 0x8e, 0x7f, 0x65, 0xbd, 0x56, 0xc6, 0x1c, 0xcc, 0xcd, 0x95, 0x04, }; @@ -87,9 +90,9 @@ TEST(misc_sha256, test_NIST_vector_five) std::vector input; std::copy(input_str.begin(), input_str.end(), std::back_inserter(input)); - auto result = sha256::sha256(input); + auto result = sha256(input); - sha256::hash expected{ + Sha256Hash expected{ 0xc2, 0xe6, 0x86, 0x82, 0x34, 0x89, 0xce, 0xd2, 0x01, 0x7f, 0x60, 0x59, 0xb8, 0xb2, 0x39, 0x31, 0x8b, 0x63, 0x64, 0xf6, 0xdc, 0xd8, 0x35, 0xd0, 0xa5, 0x19, 0x10, 0x5a, 0x1e, 0xad, 0xd6, 0xe4, }; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp index 481ceb5ee34..cf36bbd1c0b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp @@ -7,11 +7,13 @@ #include "barretenberg/serialize/test_helper.hpp" #include "ecdsa_secp256k1.hpp" +using namespace bb; +using namespace bb::crypto; using namespace acir_format; class AcirFormatTests : public ::testing::Test { protected: - static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } + static void SetUpTestSuite() { srs::init_crs_factory("../srs_db/ignition"); } }; TEST_F(AcirFormatTests, TestASingleConstraintNoPubInputs) { @@ -249,12 +251,11 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass) .block_constraints = {} }; std::string message_string = "tenletters"; - crypto::schnorr_key_pair account; + schnorr_key_pair account; account.private_key = grumpkin::fr::random_element(); account.public_key = grumpkin::g1::one * account.private_key; - crypto::schnorr_signature signature_raw = - crypto::schnorr_construct_signature(message_string, - account); + schnorr_signature signature_raw = + schnorr_construct_signature(message_string, account); uint256_t pub_x = account.public_key.x; uint256_t pub_y = account.public_key.y; WitnessVector witness{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, pub_x, pub_y, 5, 202, 31, 146, @@ -346,12 +347,11 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange) }; std::string message_string = "tenletters"; - crypto::schnorr_key_pair account; + schnorr_key_pair account; account.private_key = grumpkin::fr::random_element(); account.public_key = grumpkin::g1::one * account.private_key; - crypto::schnorr_signature signature_raw = - crypto::schnorr_construct_signature(message_string, - account); + schnorr_signature signature_raw = + schnorr_construct_signature(message_string, account); uint256_t pub_x = account.public_key.x; uint256_t pub_y = account.public_key.y; WitnessVector witness{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, pub_x, pub_y, 5, 202, 31, 146, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.cpp index f4d5ea9def0..a3b92e8626b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.cpp @@ -18,28 +18,20 @@ ModulusId modulus_param_to_id(ModulusParam param) Bn254FrParams::modulus_2 == param.modulus_2 && Bn254FrParams::modulus_3 == param.modulus_3) { return ModulusId::BN254_FR; } - if (secp256k1::Secp256k1FqParams::modulus_0 == param.modulus_0 && - secp256k1::Secp256k1FqParams::modulus_1 == param.modulus_1 && - secp256k1::Secp256k1FqParams::modulus_2 == param.modulus_2 && - secp256k1::Secp256k1FqParams::modulus_3 == param.modulus_3) { + if (secp256k1::FqParams::modulus_0 == param.modulus_0 && secp256k1::FqParams::modulus_1 == param.modulus_1 && + secp256k1::FqParams::modulus_2 == param.modulus_2 && secp256k1::FqParams::modulus_3 == param.modulus_3) { return ModulusId::SECP256K1_FQ; } - if (secp256k1::Secp256k1FrParams::modulus_0 == param.modulus_0 && - secp256k1::Secp256k1FrParams::modulus_1 == param.modulus_1 && - secp256k1::Secp256k1FrParams::modulus_2 == param.modulus_2 && - secp256k1::Secp256k1FrParams::modulus_3 == param.modulus_3) { + if (secp256k1::FrParams::modulus_0 == param.modulus_0 && secp256k1::FrParams::modulus_1 == param.modulus_1 && + secp256k1::FrParams::modulus_2 == param.modulus_2 && secp256k1::FrParams::modulus_3 == param.modulus_3) { return ModulusId::SECP256K1_FR; } - if (secp256r1::Secp256r1FqParams::modulus_0 == param.modulus_0 && - secp256r1::Secp256r1FqParams::modulus_1 == param.modulus_1 && - secp256r1::Secp256r1FqParams::modulus_2 == param.modulus_2 && - secp256r1::Secp256r1FqParams::modulus_3 == param.modulus_3) { + if (secp256r1::FqParams::modulus_0 == param.modulus_0 && secp256r1::FqParams::modulus_1 == param.modulus_1 && + secp256r1::FqParams::modulus_2 == param.modulus_2 && secp256r1::FqParams::modulus_3 == param.modulus_3) { return ModulusId::SECP256R1_FQ; } - if (secp256r1::Secp256r1FrParams::modulus_0 == param.modulus_0 && - secp256r1::Secp256r1FrParams::modulus_1 == param.modulus_1 && - secp256r1::Secp256r1FrParams::modulus_2 == param.modulus_2 && - secp256r1::Secp256r1FrParams::modulus_3 == param.modulus_3) { + if (secp256r1::FrParams::modulus_0 == param.modulus_0 && secp256r1::FrParams::modulus_1 == param.modulus_1 && + secp256r1::FrParams::modulus_2 == param.modulus_2 && secp256r1::FrParams::modulus_3 == param.modulus_3) { return ModulusId::SECP256R1_FR; } @@ -284,10 +276,10 @@ void create_bigint_from_le_bytes_constraint(Builder& builder, { using big_bn254_fq = bb::stdlib::bigfield; using big_bn254_fr = bb::stdlib::bigfield; - using big_secp256k1_fq = bb::stdlib::bigfield; - using big_secp256k1_fr = bb::stdlib::bigfield; - using big_secp256r1_fq = bb::stdlib::bigfield; - using big_secp256r1_fr = bb::stdlib::bigfield; + using big_secp256k1_fq = bb::stdlib::bigfield; + using big_secp256k1_fr = bb::stdlib::bigfield; + using big_secp256r1_fq = bb::stdlib::bigfield; + using big_secp256r1_fr = bb::stdlib::bigfield; using field_ct = bb::stdlib::field_t; using byte_array_ct = bb::stdlib::byte_array; @@ -369,10 +361,10 @@ void create_bigint_to_le_bytes_constraint(Builder& builder, { using big_bn254_fq = bb::stdlib::bigfield; using big_bn254_fr = bb::stdlib::bigfield; - using big_secp256k1_fq = bb::stdlib::bigfield; - using big_secp256k1_fr = bb::stdlib::bigfield; - using big_secp256r1_fq = bb::stdlib::bigfield; - using big_secp256r1_fr = bb::stdlib::bigfield; + using big_secp256k1_fq = bb::stdlib::bigfield; + using big_secp256k1_fr = bb::stdlib::bigfield; + using big_secp256r1_fq = bb::stdlib::bigfield; + using big_secp256r1_fr = bb::stdlib::bigfield; auto modulus_id = dsl_bigints.get_modulus_id(input.input); bb::stdlib::byte_array byte_array; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.hpp index 1feb0fffce1..27e9353efb4 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.hpp @@ -64,10 +64,10 @@ class ModulusParam { template class DSLBigInts { using big_bn254_fq = bb::stdlib::bigfield; using big_bn254_fr = bb::stdlib::bigfield; - using big_secp256k1_fq = bb::stdlib::bigfield; - using big_secp256k1_fr = bb::stdlib::bigfield; - using big_secp256r1_fq = bb::stdlib::bigfield; - using big_secp256r1_fr = bb::stdlib::bigfield; + using big_secp256k1_fq = bb::stdlib::bigfield; + using big_secp256k1_fr = bb::stdlib::bigfield; + using big_secp256r1_fq = bb::stdlib::bigfield; + using big_secp256r1_fr = bb::stdlib::bigfield; private: std::map m_bn254_fq; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp index ce6ff2dafc5..863c4f7b067 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp @@ -167,7 +167,7 @@ template void dummy_ecdsa_constraint(Builder& builder, EcdsaS uint256_t pub_y_value = account.public_key.y; std::string message_string = "Instructions unclear, ask again later."; crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature( + crypto::ecdsa_construct_signature( message_string, account); // Create new variables which will reference the valid public key and signature. diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp index 9ffffbabdd1..6d8135cf36f 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp @@ -7,6 +7,8 @@ #include #include +using namespace bb; +using namespace bb::crypto; using namespace acir_format; using curve_ct = stdlib::secp256k1; @@ -23,15 +25,14 @@ size_t generate_ecdsa_constraint(EcdsaSecp256k1Constraint& ecdsa_constraint, Wit // NOTE: If the hash being used outputs more than 32 bytes, then big-field will panic std::vector message_buffer; std::copy(message_string.begin(), message_string.end(), std::back_inserter(message_buffer)); - auto hashed_message = sha256::sha256(message_buffer); + auto hashed_message = sha256(message_buffer); - crypto::ecdsa_key_pair account; + ecdsa_key_pair account; account.private_key = curve_ct::fr::random_element(); account.public_key = curve_ct::g1::one * account.private_key; - crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature(message_string, - account); + ecdsa_signature signature = + ecdsa_construct_signature(message_string, account); uint256_t pub_x_value = account.public_key.x; uint256_t pub_y_value = account.public_key.y; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.cpp index 079c7169794..7ac18687808 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.cpp @@ -3,10 +3,12 @@ #include "barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp" #include "ecdsa_secp256k1.hpp" -namespace acir_format { - +using namespace bb; +using namespace bb::crypto; using namespace bb::plonk; +namespace acir_format { + secp256r1_ct::g1_ct ecdsa_convert_inputs(Builder* ctx, const secp256r1::g1::affine_element& input) { uint256_t x_u256(input.x); @@ -98,15 +100,14 @@ template void dummy_ecdsa_constraint(Builder& builder, EcdsaS // NOTE: If the hash being used outputs more than 32 bytes, then big-field will panic std::vector message_buffer; std::copy(message_string.begin(), message_string.end(), std::back_inserter(message_buffer)); - auto hashed_message = sha256::sha256(message_buffer); + auto hashed_message = sha256(message_buffer); - crypto::ecdsa_key_pair account; + ecdsa_key_pair account; account.private_key = 10; account.public_key = secp256r1::g1::one * account.private_key; - crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature(message_string, - account); + ecdsa_signature signature = + ecdsa_construct_signature(message_string, account); uint256_t pub_x_value = account.public_key.x; uint256_t pub_y_value = account.public_key.y; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp index 99c28fdf33b..1a6827f9989 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp @@ -7,6 +7,8 @@ #include #include +using namespace bb; +using namespace bb::crypto; using namespace acir_format; using curve_ct = stdlib::secp256r1; @@ -17,7 +19,7 @@ size_t generate_r1_constraints(EcdsaSecp256r1Constraint& ecdsa_r1_constraint, uint256_t pub_x_value, uint256_t pub_y_value, std::array hashed_message, - crypto::ecdsa_signature signature) + ecdsa_signature signature) { std::vector message_in; @@ -77,15 +79,14 @@ size_t generate_ecdsa_constraint(EcdsaSecp256r1Constraint& ecdsa_r1_constraint, // NOTE: If the hash being used outputs more than 32 bytes, then big-field will panic std::vector message_buffer; std::copy(message_string.begin(), message_string.end(), std::back_inserter(message_buffer)); - auto hashed_message = sha256::sha256(message_buffer); + auto hashed_message = sha256(message_buffer); - crypto::ecdsa_key_pair account; + ecdsa_key_pair account; account.private_key = curve_ct::fr::random_element(); account.public_key = curve_ct::g1::one * account.private_key; - crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature(message_string, - account); + ecdsa_signature signature = + ecdsa_construct_signature(message_string, account); return generate_r1_constraints( ecdsa_r1_constraint, witness_values, account.public_key.x, account.public_key.y, hashed_message, signature); @@ -106,15 +107,13 @@ TEST(ECDSASecp256r1, test_hardcoded) uint256_t pub_key_y = uint256_t("136093d7012e509a73715cbd0b00a3cc0ff4b5c01b3ffa196ab1fb327036b8e6"); // 0x2c70a8d084b62bfc5ce03641caf9f72ad4da8c81bfe6ec9487bb5e1bef62a13218ad9ee29eaf351fdc50f1520c425e9b908a07278b43b0ec7b872778c14e0784 - crypto::ecdsa_signature signature = { - .r = { 44, 112, 168, 208, 132, 182, 43, 252, 92, 224, 54, 65, 202, 249, 247, 42, - 212, 218, 140, 129, 191, 230, 236, 148, 135, 187, 94, 27, 239, 98, 161, 50 }, - .s = { 24, 173, 158, 226, 158, 175, 53, 31, 220, 80, 241, 82, 12, 66, 94, 155, - 144, 138, 7, 39, 139, 67, 176, 236, 123, 135, 39, 120, 193, 78, 7, 132 }, - .v = 0 - }; + ecdsa_signature signature = { .r = { 44, 112, 168, 208, 132, 182, 43, 252, 92, 224, 54, 65, 202, 249, 247, 42, + 212, 218, 140, 129, 191, 230, 236, 148, 135, 187, 94, 27, 239, 98, 161, 50 }, + .s = { 24, 173, 158, 226, 158, 175, 53, 31, 220, 80, 241, 82, 12, 66, 94, 155, + 144, 138, 7, 39, 139, 67, 176, 236, 123, 135, 39, 120, 193, 78, 7, 132 }, + .v = 0 }; - crypto::ecdsa_key_pair account; + ecdsa_key_pair account; account.private_key = curve_ct::fr(uint256_t("0202020202020202020202020202020202020202020202020202020202020202")); account.public_key = curve_ct::g1::one * account.private_key; @@ -152,8 +151,8 @@ TEST(ECDSASecp256r1, test_hardcoded) }; secp256r1::g1::affine_element pub_key = { pub_key_x, pub_key_y }; - bool we_ballin = crypto::ecdsa_verify_signature( - message, pub_key, signature); + bool we_ballin = + ecdsa_verify_signature(message, pub_key, signature); EXPECT_EQ(we_ballin, true); auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness_values); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp index c7fae9f8c19..b3d540b4ddc 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp @@ -123,10 +123,10 @@ std::string AcirComposer::get_solidity_verifier() std::vector AcirComposer::serialize_proof_into_fields(std::vector const& proof, size_t num_inner_public_inputs) { - transcript::StandardTranscript transcript(proof, - acir_format::Composer::create_manifest(num_inner_public_inputs), - transcript::HashType::PedersenBlake3s, - 16); + plonk::transcript::StandardTranscript transcript(proof, + acir_format::Composer::create_manifest(num_inner_public_inputs), + plonk::transcript::HashType::PedersenBlake3s, + 16); return acir_format::export_transcript_in_recursion_format(transcript); } diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/c_bind.cpp b/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/c_bind.cpp index 39f5d688a96..c7fac7ef7c6 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/c_bind.cpp @@ -2,6 +2,8 @@ #include "barretenberg/common/wasm_export.hpp" #include "grumpkin.hpp" +using namespace bb; + // Silencing warnings about reserved identifiers. Fixing would break downstream code that calls our WASM API. // NOLINTBEGIN(cert-dcl37-c, cert-dcl51-cpp, bugprone-reserved-identifier) WASM_EXPORT void ecc_grumpkin__mul(uint8_t const* point_buf, uint8_t const* scalar_buf, uint8_t* result) diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/grumpkin.hpp b/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/grumpkin.hpp index cfe12ad286f..fd6e1c36268 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/grumpkin.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/grumpkin.hpp @@ -4,14 +4,14 @@ #include "../bn254/fq.hpp" #include "../bn254/fr.hpp" -namespace grumpkin { +namespace bb::grumpkin { constexpr size_t MAX_NO_WRAP_INTEGER_BIT_LENGTH = 252; using fq = bb::fr; using fr = bb::fq; -struct GrumpkinG1Params { +struct G1Params { static constexpr bool USE_ENDOMORPHISM = true; static constexpr bool can_hash_to_curve = true; static constexpr bool small_elements = true; @@ -26,9 +26,9 @@ struct GrumpkinG1Params { 0x11b2dff1448c41d8UL, 0x23d3446f21c77dc3UL, 0xaa7b8cf435dfafbbUL, 0x14b34cf69dc25d68UL }; }; -using g1 = bb::group; +using g1 = bb::group; -}; // namespace grumpkin +}; // namespace bb::grumpkin namespace bb::curve { class Grumpkin { diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp index 62eb7c4e953..25a76fd1970 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp @@ -1,5 +1,7 @@ #include "secp256k1.hpp" +using namespace bb; + // Silencing warnings about reserved identifiers. Fixing would break downstream code that calls our WASM API. // NOLINTBEGIN(cert-dcl37-c, cert-dcl51-cpp, bugprone-reserved-identifier) WASM_EXPORT void ecc_secp256k1__mul(uint8_t const* point_buf, uint8_t const* scalar_buf, uint8_t* result) diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.hpp b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.hpp index ce10122791c..1d78dd1b3d1 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.hpp @@ -5,9 +5,9 @@ #include "../types.hpp" // NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays) -namespace secp256k1 { -struct Secp256k1FqParams { +namespace bb::secp256k1 { +struct FqParams { static constexpr uint64_t modulus_0 = 0xFFFFFFFEFFFFFC2FULL; static constexpr uint64_t modulus_1 = 0xFFFFFFFFFFFFFFFFULL; static constexpr uint64_t modulus_2 = 0xFFFFFFFFFFFFFFFFULL; @@ -44,8 +44,9 @@ struct Secp256k1FqParams { static constexpr uint64_t primitive_root_2 = 0UL; static constexpr uint64_t primitive_root_3 = 0UL; }; +using fq = field; -struct Secp256k1FrParams { +struct FrParams { static constexpr uint64_t modulus_0 = 0xBFD25E8CD0364141ULL; static constexpr uint64_t modulus_1 = 0xBAAEDCE6AF48A03BULL; static constexpr uint64_t modulus_2 = 0xFFFFFFFFFFFFFFFEULL; @@ -99,11 +100,9 @@ struct Secp256k1FrParams { static constexpr uint64_t primitive_root_2 = 0UL; static constexpr uint64_t primitive_root_3 = 0UL; }; +using fr = field; -using fq = bb::field; -using fr = bb::field; - -struct Secp256k1G1Params { +struct G1Params { static constexpr bool USE_ENDOMORPHISM = false; static constexpr bool can_hash_to_curve = true; static constexpr bool small_elements = true; @@ -117,9 +116,8 @@ struct Secp256k1G1Params { static constexpr fq one_y = fq(0x9C47D08FFB10D4B8UL, 0xFD17B448A6855419UL, 0x5DA4FBFC0E1108A8UL, 0x483ADA7726A3C465UL).to_montgomery_form(); }; - -using g1 = bb::group, bb::field, Secp256k1G1Params>; -} // namespace secp256k1 +using g1 = group; +} // namespace bb::secp256k1 namespace bb::curve { class SECP256K1 { diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.test.cpp b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.test.cpp index 7fa8bee9ae6..82902e1c3f8 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.test.cpp @@ -6,10 +6,10 @@ using namespace bb; namespace { auto& engine = numeric::get_debug_randomness(); -constexpr uint256_t test_fq_mod(secp256k1::Secp256k1FqParams::modulus_0, - secp256k1::Secp256k1FqParams::modulus_1, - secp256k1::Secp256k1FqParams::modulus_2, - secp256k1::Secp256k1FqParams::modulus_3); +constexpr uint256_t test_fq_mod(secp256k1::FqParams::modulus_0, + secp256k1::FqParams::modulus_1, + secp256k1::FqParams::modulus_2, + secp256k1::FqParams::modulus_3); uint256_t get_fq_element() { diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1_endo_notes.hpp b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1_endo_notes.hpp index 74bc2adf4d9..d9868d1b391 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1_endo_notes.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1_endo_notes.hpp @@ -3,7 +3,7 @@ #include "barretenberg/numeric/uintx/uintx.hpp" #include "secp256k1.hpp" -namespace secp256k1_params { +namespace bb::secp256k1 { struct basis_vectors { uint64_t endo_g1_lo = 0; uint64_t endo_g1_mid = 0; @@ -161,4 +161,4 @@ struct basis_vectors { std::cerr << "could not find endomorphism scalars???" << std::endl; return { secp256k1::fq(0), secp256k1::fr(0) }; } -}; // namespace secp256k1_params +}; // namespace bb::secp256k1 diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.hpp b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.hpp index e28e86c1675..3835bfce10f 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.hpp @@ -3,9 +3,9 @@ #include "../../fields/field.hpp" #include "../../groups/group.hpp" -namespace secp256r1 { +namespace bb::secp256r1 { // NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays) -struct Secp256r1FqParams { +struct FqParams { static constexpr uint64_t modulus_0 = 0xFFFFFFFFFFFFFFFFULL; static constexpr uint64_t modulus_1 = 0x00000000FFFFFFFFULL; static constexpr uint64_t modulus_2 = 0X0000000000000000ULL; @@ -43,8 +43,9 @@ struct Secp256r1FqParams { static constexpr uint64_t primitive_root_2 = 0UL; static constexpr uint64_t primitive_root_3 = 0UL; }; +using fq = field; -struct Secp256r1FrParams { +struct FrParams { static constexpr uint64_t modulus_0 = 0xF3B9CAC2FC632551ULL; static constexpr uint64_t modulus_1 = 0xBCE6FAADA7179E84ULL; static constexpr uint64_t modulus_2 = 0xFFFFFFFFFFFFFFFFULL; @@ -83,11 +84,9 @@ struct Secp256r1FrParams { static constexpr uint64_t primitive_root_2 = 0UL; static constexpr uint64_t primitive_root_3 = 0UL; }; +using fr = field; -using fq = bb::field; -using fr = bb::field; - -struct Secp256r1G1Params { +struct G1Params { static constexpr bool USE_ENDOMORPHISM = false; static constexpr bool can_hash_to_curve = true; static constexpr bool small_elements = true; @@ -103,9 +102,8 @@ struct Secp256r1G1Params { static constexpr fq one_y = fq(0xCBB6406837BF51F5, 0x2BCE33576B315ECE, 0x8EE7EB4A7C0F9E16, 0x4FE342E2FE1A7F9B).to_montgomery_form(); }; - -using g1 = bb::group, bb::field, Secp256r1G1Params>; -} // namespace secp256r1 +using g1 = group; +} // namespace bb::secp256r1 namespace bb::curve { class SECP256R1 { diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.test.cpp b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.test.cpp index 03f5a4bc8d1..3e993586242 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.test.cpp @@ -6,10 +6,10 @@ using namespace bb; namespace { auto& engine = numeric::get_debug_randomness(); -constexpr uint256_t test_fq_mod(secp256r1::Secp256r1FqParams::modulus_0, - secp256r1::Secp256r1FqParams::modulus_1, - secp256r1::Secp256r1FqParams::modulus_2, - secp256r1::Secp256r1FqParams::modulus_3); +constexpr uint256_t test_fq_mod(secp256r1::FqParams::modulus_0, + secp256r1::FqParams::modulus_1, + secp256r1::FqParams::modulus_2, + secp256r1::FqParams::modulus_3); uint256_t get_fq_element() { diff --git a/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.test.cpp b/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.test.cpp index d39cdca31e1..38f0518fb34 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.test.cpp @@ -18,6 +18,9 @@ using ::testing::ElementsAreArray; using ::testing::Eq; using ::testing::Property; +using namespace bb; + +namespace { template class TestAffineElement : public testing::Test { using element = typename G1::element; using affine_element = typename G1::affine_element; @@ -98,6 +101,7 @@ template class TestAffineElement : public testing::Test { }; using TestTypes = testing::Types; +} // namespace TYPED_TEST_SUITE(TestAffineElement, TestTypes); diff --git a/barretenberg/cpp/src/barretenberg/env/data_store.cpp b/barretenberg/cpp/src/barretenberg/env/data_store.cpp index fba8fec60a9..84aad721a8b 100644 --- a/barretenberg/cpp/src/barretenberg/env/data_store.cpp +++ b/barretenberg/cpp/src/barretenberg/env/data_store.cpp @@ -17,7 +17,7 @@ void set_data(char const* key, uint8_t const* addr, size_t length) { std::string k = key; store[k] = std::vector(addr, addr + length); - // info("set data: ", key, " length: ", length, " hash: ", sha256::sha256(store[k])); + // info("set data: ", key, " length: ", length, " hash: ", crypto::sha256(store[k])); // std::ofstream file("/mnt/user-data/charlie/debugging/x86_" + k, std::ios::binary); // file.write(reinterpret_cast(addr), (std::streamsize)length); } diff --git a/barretenberg/cpp/src/barretenberg/grumpkin_srs_gen/grumpkin_srs_gen.cpp b/barretenberg/cpp/src/barretenberg/grumpkin_srs_gen/grumpkin_srs_gen.cpp index ebd807012aa..df09826a132 100644 --- a/barretenberg/cpp/src/barretenberg/grumpkin_srs_gen/grumpkin_srs_gen.cpp +++ b/barretenberg/cpp/src/barretenberg/grumpkin_srs_gen/grumpkin_srs_gen.cpp @@ -7,6 +7,8 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "barretenberg/srs/io.hpp" +using namespace bb; + const std::string protocol_name = "BARRETENBERG_GRUMPKIN_IPA_CRS"; /** * @brief Generates a monomial basis Grumpkin SRS. @@ -32,7 +34,7 @@ int main(int argc, char** argv) // write the files to the dir that was given. std::filesystem::create_directories(std::filesystem::path(srs_path) / "monomial"); - std::vector srs(subgroup_size); + std::vector srs(subgroup_size); std::vector hash_input; @@ -51,7 +53,7 @@ int main(int argc, char** argv) hash_input.insert(hash_input.end(), reinterpret_cast(&point_attempt_le_order), reinterpret_cast(&point_attempt_le_order) + sizeof(uint64_t)); - auto hash_result = sha256::sha256(hash_input); + auto hash_result = crypto::sha256(hash_input); uint256_t hash_result_uint(ntohll(*reinterpret_cast(hash_result.data())), ntohll(*reinterpret_cast(hash_result.data() + sizeof(uint64_t))), ntohll(*reinterpret_cast(hash_result.data() + 2 * sizeof(uint64_t))), diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_js_parity.test.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_js_parity.test.cpp index ca3cbf3e2cb..b45627e3db0 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_js_parity.test.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_js_parity.test.cpp @@ -128,7 +128,7 @@ TEST_F(join_split_js_parity_tests, test_full_proof) tx.signature.s = { 0 }; // To assert that the C++ and TypeScript code produces the same input data. - info("tx buffer hash: ", sha256::sha256(to_buffer(tx))); + info("tx buffer hash: ", crypto::sha256(to_buffer(tx))); auto proof = sign_and_create_proof(tx, { private_key, public_key }); auto proof_data = inner_proof_data(proof.proof_data); diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.cpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.cpp index 0022b3de741..648af6fc529 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.cpp @@ -136,7 +136,7 @@ verification_key& verification_key::operator=(verification_key&& other) noexcept return *this; } -sha256::hash verification_key::sha256_hash() +crypto::Sha256Hash verification_key::sha256_hash() { std::vector vk_data; vk_data.emplace_back(static_cast(circuit_type)); @@ -150,7 +150,7 @@ sha256::hash verification_key::sha256_hash() for (auto& index : recursive_proof_public_input_indices) { vk_data.emplace_back(index); } - return sha256::sha256(to_buffer(vk_data)); + return crypto::sha256(to_buffer(vk_data)); } } // namespace bb::plonk diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.hpp index c09c8d32558..40767e8e9f0 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.hpp @@ -64,7 +64,7 @@ struct verification_key { verification_key& operator=(const verification_key& other) = delete; ~verification_key() = default; - sha256::hash sha256_hash(); + crypto::Sha256Hash sha256_hash(); [[nodiscard]] verification_key_data as_data() const { diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/verifier/verifier.test.cpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/verifier/verifier.test.cpp index 10a50a38edb..683145c85b8 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/verifier/verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/verifier/verifier.test.cpp @@ -11,7 +11,7 @@ #include "barretenberg/srs/factories/file_crs_factory.hpp" #include -namespace verifier_helpers { +namespace bb::plonk { using namespace bb; using namespace bb::plonk; @@ -238,15 +238,15 @@ plonk::Prover generate_test_data(const size_t n) state.commitment_scheme = std::move(kate_commitment_scheme); return state; } -} // namespace verifier_helpers +} // namespace bb::plonk TEST(verifier, verify_arithmetic_proof_small) { size_t n = 8; - plonk::Prover state = verifier_helpers::generate_test_data(n); + plonk::Prover state = bb::plonk::generate_test_data(n); - auto verifier = verifier_helpers::generate_verifier(state.key); + auto verifier = bb::plonk::generate_verifier(state.key); // construct proof plonk::proof proof = state.construct_proof(); @@ -262,9 +262,9 @@ TEST(verifier, verify_arithmetic_proof) { size_t n = 1 << 14; - plonk::Prover state = verifier_helpers::generate_test_data(n); + plonk::Prover state = bb::plonk::generate_test_data(n); - auto verifier = verifier_helpers::generate_verifier(state.key); + auto verifier = bb::plonk::generate_verifier(state.key); // construct proof plonk::proof proof = state.construct_proof(); @@ -280,9 +280,9 @@ TEST(verifier, verify_damaged_proof) { size_t n = 8; - plonk::Prover state = verifier_helpers::generate_test_data(n); + plonk::Prover state = bb::plonk::generate_test_data(n); - auto verifier = verifier_helpers::generate_verifier(state.key); + auto verifier = bb::plonk::generate_verifier(state.key); // Create empty proof plonk::proof proof = {}; diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/random_widget.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/random_widget.hpp index ffef68eb690..f5d25e6dfec 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/random_widget.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/random_widget.hpp @@ -4,7 +4,7 @@ #include "barretenberg/plonk/work_queue/work_queue.hpp" #include -namespace transcript { +namespace bb::plonk::transcript { class Transcript; } namespace bb::plonk { diff --git a/barretenberg/cpp/src/barretenberg/plonk/transcript/manifest.hpp b/barretenberg/cpp/src/barretenberg/plonk/transcript/manifest.hpp index 4cc4e09cabf..6ae9a957ca9 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/transcript/manifest.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/transcript/manifest.hpp @@ -2,7 +2,7 @@ #include #include -namespace transcript { +namespace bb::plonk::transcript { /** * Composers used Manifest to define the structure of the protocol: * 1. What data is used in each round of the protocols @@ -81,5 +81,5 @@ class Manifest { private: std::vector round_manifests; size_t num_rounds; -}; // namespace transcript -} // namespace transcript +}; // namespace bb::plonk::transcript +} // namespace bb::plonk::transcript diff --git a/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.cpp b/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.cpp index 168ad725aff..13b6cfe39b6 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.cpp @@ -12,7 +12,7 @@ #include #include -namespace transcript { +namespace bb::plonk::transcript { // Set to 1 to enable some logging. #if 0 @@ -444,4 +444,4 @@ std::vector Transcript::export_transcript() const return buffer; } -} // namespace transcript +} // namespace bb::plonk::transcript diff --git a/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.hpp b/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.hpp index e32c4591d87..f41e0710b34 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.hpp @@ -7,7 +7,7 @@ #include #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" -namespace transcript { +namespace bb::plonk::transcript { struct Keccak256Hasher { static constexpr size_t SECURITY_PARAMETER_SIZE = 32; @@ -119,4 +119,4 @@ class Transcript { std::map challenge_map; }; -} // namespace transcript +} // namespace bb::plonk::transcript diff --git a/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.test.cpp b/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.test.cpp index 37ef74ff9a8..58600a98c0f 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.test.cpp @@ -6,6 +6,7 @@ #include using namespace bb; +using namespace bb::plonk; namespace { transcript::Manifest create_manifest(const size_t num_public_inputs) diff --git a/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript_wrappers.cpp b/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript_wrappers.cpp index 8daee814934..b429a254045 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript_wrappers.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript_wrappers.cpp @@ -2,7 +2,7 @@ #include "manifest.hpp" #include -namespace transcript { +namespace bb::plonk::transcript { void StandardTranscript::add_field_element(const std::string& element_name, const bb::fr& element) { add_element(element_name, element.to_buffer()); @@ -33,4 +33,4 @@ bb::fr StandardTranscript::get_challenge_field_element_from_map(const std::strin { return bb::fr::serialize_from_buffer(&(get_challenge_from_map(challenge_name, challenge_map_name))[0]); } -} // namespace transcript +} // namespace bb::plonk::transcript diff --git a/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript_wrappers.hpp b/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript_wrappers.hpp index b5938eccd16..cf2fd4080e0 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript_wrappers.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript_wrappers.hpp @@ -5,7 +5,7 @@ #include "barretenberg/ecc/curves/bn254/g1.hpp" #include -namespace transcript { +namespace bb::plonk::transcript { /** * Transcript extended with functions for easy * field element setting/getting @@ -58,4 +58,4 @@ class StandardTranscript : public Transcript { bb::fr get_mock_challenge() { return bb::fr::random_element(); }; }; -} // namespace transcript +} // namespace bb::plonk::transcript diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp index 1c77dfa083e..9971d6943cf 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp @@ -2,7 +2,6 @@ #include "barretenberg/common/assert.hpp" #include "barretenberg/common/slab_allocator.hpp" #include "barretenberg/common/thread.hpp" -#include "barretenberg/common/thread_utils.hpp" #include "barretenberg/numeric/bitop/pow.hpp" #include "polynomial_arithmetic.hpp" #include @@ -369,8 +368,7 @@ template void Polynomial::add_scaled(std::span other const size_t other_size = other.size(); ASSERT(in_place_operation_viable(other_size)); - // Calculates number of threads with thread_utils::calculate_num_threads - size_t num_threads = thread_utils::calculate_num_threads(other_size); + size_t num_threads = calculate_num_threads(other_size); size_t range_per_thread = other_size / num_threads; size_t leftovers = other_size - (range_per_thread * num_threads); parallel_for(num_threads, [&](size_t j) { @@ -387,7 +385,7 @@ template Polynomial& Polynomial::operator+=(std::span Polynomial& Polynomial::operator-=(std::span Polynomial& Polynomial::operator*=(const Fr scali { ASSERT(in_place_operation_viable()); - size_t num_threads = thread_utils::calculate_num_threads(size_); + size_t num_threads = calculate_num_threads(size_); size_t range_per_thread = size_ / num_threads; size_t leftovers = size_ - (range_per_thread * num_threads); parallel_for(num_threads, [&](size_t j) { diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp index 305585773e4..8ca718a4796 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp @@ -58,7 +58,7 @@ template class Polynomial { */ Polynomial share() const; - std::array hash() const { return sha256::sha256(byte_span()); } + std::array hash() const { return crypto::sha256(byte_span()); } void clear() { diff --git a/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp b/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp index 2efeef68588..9079724c98a 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp @@ -1,6 +1,6 @@ #pragma once #include "barretenberg/common/thread.hpp" -#include "barretenberg/common/thread_utils.hpp" + #include #include namespace bb { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/instance_inspector.hpp b/barretenberg/cpp/src/barretenberg/proof_system/instance_inspector.hpp index dea90fe4ea1..d0913aef1c4 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/instance_inspector.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/instance_inspector.hpp @@ -2,7 +2,7 @@ #include "barretenberg/common/log.hpp" -namespace instance_inspector { +namespace bb::instance_inspector { // Determine whether a polynomial has at least one non-zero coefficient bool is_non_zero(auto& polynomial) @@ -66,4 +66,4 @@ void print_databus_info(auto& prover_instance) info(); } -} // namespace instance_inspector \ No newline at end of file +} // namespace bb::instance_inspector \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/proof_system/plookup_tables/non_native_group_generator.hpp b/barretenberg/cpp/src/barretenberg/proof_system/plookup_tables/non_native_group_generator.hpp index b57e9247e65..857ef29e53f 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/plookup_tables/non_native_group_generator.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/plookup_tables/non_native_group_generator.hpp @@ -15,28 +15,28 @@ template class ecc_generator_table { * Store arrays of precomputed 8-bit lookup tables for generator point coordinates (and their endomorphism *equivalents) **/ - inline static std::array, 256> generator_endo_xlo_table; - inline static std::array, 256> generator_endo_xhi_table; - inline static std::array, 256> generator_xlo_table; - inline static std::array, 256> generator_xhi_table; - inline static std::array, 256> generator_ylo_table; - inline static std::array, 256> generator_yhi_table; - inline static std::array, 256> generator_xyprime_table; - inline static std::array, 256> generator_endo_xyprime_table; + inline static std::array, 256> generator_endo_xlo_table; + inline static std::array, 256> generator_endo_xhi_table; + inline static std::array, 256> generator_xlo_table; + inline static std::array, 256> generator_xhi_table; + inline static std::array, 256> generator_ylo_table; + inline static std::array, 256> generator_yhi_table; + inline static std::array, 256> generator_xyprime_table; + inline static std::array, 256> generator_endo_xyprime_table; inline static bool init = false; static void init_generator_tables(); static size_t convert_position_to_shifted_naf(const size_t position); static size_t convert_shifted_naf_to_position(const size_t shifted_naf); - static std::array get_xlo_endo_values(const std::array key); - static std::array get_xhi_endo_values(const std::array key); - static std::array get_xlo_values(const std::array key); - static std::array get_xhi_values(const std::array key); - static std::array get_ylo_values(const std::array key); - static std::array get_yhi_values(const std::array key); - static std::array get_xyprime_values(const std::array key); - static std::array get_xyprime_endo_values(const std::array key); + static std::array get_xlo_endo_values(const std::array key); + static std::array get_xhi_endo_values(const std::array key); + static std::array get_xlo_values(const std::array key); + static std::array get_xhi_values(const std::array key); + static std::array get_ylo_values(const std::array key); + static std::array get_yhi_values(const std::array key); + static std::array get_xyprime_values(const std::array key); + static std::array get_xyprime_endo_values(const std::array key); static BasicTable generate_xlo_table(BasicTableId id, const size_t table_index); static BasicTable generate_xhi_table(BasicTableId id, const size_t table_index); static BasicTable generate_xlo_endo_table(BasicTableId id, const size_t table_index); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/plookup_tables/sha256.hpp b/barretenberg/cpp/src/barretenberg/proof_system/plookup_tables/sha256.hpp index 02465bc15d8..a63b94cd20d 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/plookup_tables/sha256.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/plookup_tables/sha256.hpp @@ -91,7 +91,7 @@ static constexpr uint64_t witness_extension_normalization_table[16]{ 2, }; -inline BasicTable generate_witness_extension_normalization_table(BasicTableId id, const size_t table_index) +inline plookup::BasicTable generate_witness_extension_normalization_table(BasicTableId id, const size_t table_index) { return sparse_tables::generate_sparse_normalization_table<16, 3, witness_extension_normalization_table>( id, table_index); diff --git a/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/ecdsa_circuit.hpp b/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/ecdsa_circuit.hpp index a20ab1c4bbe..a8001611fc5 100644 --- a/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/ecdsa_circuit.hpp +++ b/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/ecdsa_circuit.hpp @@ -48,13 +48,13 @@ template class EcdsaCircuit { account.public_key = curve::g1::one * account.private_key; // UNCONSTRAINED: create a sig - crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature( + crypto::ecdsa_signature signature = crypto:: + ecdsa_construct_signature( message_string, account); // UNCONSTRAINED: verify the created signature - bool dry_run = - crypto::ecdsa_verify_signature( + bool dry_run = crypto:: + ecdsa_verify_signature( message_string, account.public_key, signature); if (!dry_run) { throw_or_abort("[non circuit]: Sig verification failed"); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.test.cpp index 69aedf7e435..93191f8f8cc 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.test.cpp @@ -7,6 +7,7 @@ #include "ecdsa.hpp" using namespace bb; +using namespace bb::crypto; using Builder = UltraCircuitBuilder; using curve_ = stdlib::secp256k1; @@ -19,14 +20,14 @@ TEST(stdlib_ecdsa, verify_signature) // whaaablaghaaglerijgeriij std::string message_string = "Instructions unclear, ask again later."; - crypto::ecdsa_key_pair account; + ecdsa_key_pair account; account.private_key = curve_::fr::random_element(); account.public_key = curve_::g1::one * account.private_key; - crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature(message_string, account); + ecdsa_signature signature = + ecdsa_construct_signature(message_string, account); - bool first_result = crypto::ecdsa_verify_signature( + bool first_result = ecdsa_verify_signature( message_string, account.public_key, signature); EXPECT_EQ(first_result, true); @@ -60,14 +61,14 @@ TEST(stdlib_ecdsa, verify_r1_signature) std::string message_string = "Instructions unclear, ask again later."; - crypto::ecdsa_key_pair account; + ecdsa_key_pair account; account.private_key = curveR1::fr::random_element(); account.public_key = curveR1::g1::one * account.private_key; - crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature(message_string, account); + ecdsa_signature signature = + ecdsa_construct_signature(message_string, account); - bool first_result = crypto::ecdsa_verify_signature( + bool first_result = ecdsa_verify_signature( message_string, account.public_key, signature); EXPECT_EQ(first_result, true); @@ -102,14 +103,14 @@ TEST(stdlib_ecdsa, ecdsa_verify_signature_noassert_succeed) // whaaablaghaaglerijgeriij std::string message_string = "Instructions unclear, ask again later."; - crypto::ecdsa_key_pair account; + ecdsa_key_pair account; account.private_key = curve_::fr::random_element(); account.public_key = curve_::g1::one * account.private_key; - crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature(message_string, account); + ecdsa_signature signature = + ecdsa_construct_signature(message_string, account); - bool first_result = crypto::ecdsa_verify_signature( + bool first_result = ecdsa_verify_signature( message_string, account.public_key, signature); EXPECT_EQ(first_result, true); @@ -146,17 +147,17 @@ TEST(stdlib_ecdsa, ecdsa_verify_signature_noassert_fail) // whaaablaghaaglerijgeriij std::string message_string = "Instructions unclear, ask again later."; - crypto::ecdsa_key_pair account; + ecdsa_key_pair account; account.private_key = curve_::fr::random_element(); account.public_key = curve_::g1::one * account.private_key; - crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature(message_string, account); + ecdsa_signature signature = + ecdsa_construct_signature(message_string, account); // tamper w. signature to make fail signature.r[0] += 1; - bool first_result = crypto::ecdsa_verify_signature( + bool first_result = ecdsa_verify_signature( message_string, account.public_key, signature); EXPECT_EQ(first_result, false); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp index ee0078f0f33..ae6731c06a7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp @@ -245,10 +245,10 @@ template void generate_ecdsa_verification_test_circuit(Builde account.public_key = curve::g1::one * account.private_key; crypto::ecdsa_signature signature = - crypto::ecdsa_construct_signature(message_string, account); + crypto::ecdsa_construct_signature(message_string, account); - bool first_result = - crypto::ecdsa_verify_signature(message_string, account.public_key, signature); + bool first_result = crypto::ecdsa_verify_signature( + message_string, account.public_key, signature); static_cast(first_result); // TODO(Cody): This is not used anywhere. std::vector rr(signature.r.begin(), signature.r.end()); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp index 6c5bfe9573f..add048b26f7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp @@ -7,6 +7,7 @@ using namespace bb; using namespace bb::stdlib; +using namespace bb::crypto; using Builder = UltraCircuitBuilder; using bool_ct = bool_t; @@ -28,15 +29,15 @@ TEST(stdlib_schnorr, schnorr_verify_signature) Builder builder = Builder(); auto message_string = longer_string.substr(0, i); - crypto::schnorr_key_pair account; + schnorr_key_pair account; account.private_key = grumpkin::fr::random_element(); account.public_key = grumpkin::g1::one * account.private_key; - crypto::schnorr_signature signature = - crypto::schnorr_construct_signature(message_string, - account); + schnorr_signature signature = + schnorr_construct_signature(message_string, + account); - bool first_result = crypto::schnorr_verify_signature( + bool first_result = schnorr_verify_signature( message_string, account.public_key, signature); EXPECT_EQ(first_result, true); @@ -63,22 +64,21 @@ TEST(stdlib_schnorr, verify_signature_failure) std::string message_string = "This is a test string of length 34"; // create key pair 1 - crypto::schnorr_key_pair account1; + schnorr_key_pair account1; account1.private_key = grumpkin::fr::random_element(); account1.public_key = grumpkin::g1::one * account1.private_key; // create key pair 2 - crypto::schnorr_key_pair account2; + schnorr_key_pair account2; account2.private_key = grumpkin::fr::random_element(); account2.public_key = grumpkin::g1::one * account2.private_key; // sign the message with account 1 private key - crypto::schnorr_signature signature = - crypto::schnorr_construct_signature(message_string, - account1); + schnorr_signature signature = + schnorr_construct_signature(message_string, account1); // check native verification with account 2 public key fails - bool native_result = crypto::schnorr_verify_signature( + bool native_result = schnorr_verify_signature( message_string, account2.public_key, signature); EXPECT_EQ(native_result, false); @@ -106,15 +106,14 @@ TEST(stdlib_schnorr, schnorr_signature_verification_result) Builder builder = Builder(); - crypto::schnorr_key_pair account; + schnorr_key_pair account; account.private_key = grumpkin::fr::random_element(); account.public_key = grumpkin::g1::one * account.private_key; - crypto::schnorr_signature signature = - crypto::schnorr_construct_signature(longer_string, - account); + schnorr_signature signature = + schnorr_construct_signature(longer_string, account); - bool first_result = crypto::schnorr_verify_signature( + bool first_result = schnorr_verify_signature( longer_string, account.public_key, signature); EXPECT_EQ(first_result, true); @@ -142,22 +141,21 @@ TEST(stdlib_schnorr, signature_verification_result_failure) std::string message_string = "This is a test string of length 34"; // create key pair 1 - crypto::schnorr_key_pair account1; + schnorr_key_pair account1; account1.private_key = grumpkin::fr::random_element(); account1.public_key = grumpkin::g1::one * account1.private_key; // create key pair 2 - crypto::schnorr_key_pair account2; + schnorr_key_pair account2; account2.private_key = grumpkin::fr::random_element(); account2.public_key = grumpkin::g1::one * account2.private_key; // sign the message with account 1 private key - crypto::schnorr_signature signature = - crypto::schnorr_construct_signature(message_string, - account1); + schnorr_signature signature = + schnorr_construct_signature(message_string, account1); // check native verification with account 2 public key fails - bool native_result = crypto::schnorr_verify_signature( + bool native_result = schnorr_verify_signature( message_string, account2.public_key, signature); EXPECT_EQ(native_result, false); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp index 9d7e3299b61..14311725e74 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp @@ -375,7 +375,7 @@ TEST(stdlib_sha256, test_input_len_multiple) auto circuit_output = output_bits.get_value(); - auto expected = sha256::sha256(input_buf); + auto expected = crypto::sha256(input_buf); EXPECT_EQ(circuit_output, expected); } @@ -419,7 +419,7 @@ TEST(stdlib_sha256, test_input_str_len_multiple) auto circuit_output = output_bits.get_value(); - auto expected = sha256::sha256(input_buf); + auto expected = crypto::sha256(input_buf); EXPECT_EQ(circuit_output, expected); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/secp256k1.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/secp256k1.hpp index 9ab05338b66..4c619deaa6d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/secp256k1.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/secp256k1.hpp @@ -11,9 +11,9 @@ namespace bb::stdlib { template struct secp256k1 { static constexpr bb::CurveType type = bb::CurveType::SECP256K1; - using fq = ::secp256k1::fq; - using fr = ::secp256k1::fr; - using g1 = ::secp256k1::g1; + using fq = ::bb::secp256k1::fq; + using fr = ::bb::secp256k1::fr; + using g1 = ::bb::secp256k1::g1; using Builder = CircuitType; using witness_ct = witness_t; @@ -23,8 +23,8 @@ template struct secp256k1 { using bool_ct = bool_t; using uint32_ct = stdlib::uint32; - using fq_ct = bigfield; - using bigfr_ct = bigfield; + using fq_ct = bigfield; + using bigfr_ct = bigfield; using g1_ct = element; using g1_bigfr_ct = element; }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/secp256r1.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/secp256r1.hpp index 01a8038adb3..a6593e4f831 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/secp256r1.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/secp256r1.hpp @@ -23,8 +23,8 @@ template struct secp256r1 { typedef bool_t bool_ct; typedef stdlib::uint32 uint32_ct; - typedef bigfield fq_ct; - typedef bigfield bigfr_ct; + typedef bigfield fq_ct; + typedef bigfield bigfr_ct; typedef element g1_ct; typedef element g1_bigfr_ct; }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.fuzzer.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.fuzzer.hpp index fbe473f2456..9c2ba3f4e7b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.fuzzer.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.fuzzer.hpp @@ -1567,7 +1567,7 @@ template class FieldBase { // Check assert conditions if ((lsb > msb) || (msb > 252) || (static_cast(stack[first_index].f().get_value()) >= - (static_cast(1) << grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH))) { + (static_cast(1) << bb::grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH))) { return 0; } PRINT_SLICE(first_index, lsb, msb, stack) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.fuzzer.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.fuzzer.hpp index f650be4e4ac..f5d573c56bf 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.fuzzer.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.fuzzer.hpp @@ -1252,7 +1252,7 @@ template class SafeUintFuzzBase { // Check assert conditions if ((lsb > msb) || (msb > 252) || (static_cast(stack[first_index].suint.get_value()) >= - (static_cast(1) << grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH))) { + (static_cast(1) << bb::grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH))) { return 0; } PRINT_SLICE(first_index, lsb, msb, stack) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.hpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.hpp index 0171163d10f..1da50427daf 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.hpp @@ -23,17 +23,17 @@ template class Transcript { using group_pt = element; using Key = verification_key>; - Transcript(Builder* in_context, const transcript::Manifest& input_manifest) + Transcript(Builder* in_context, const plonk::transcript::Manifest& input_manifest) : context(in_context) - , transcript_base(input_manifest, transcript::HashType::PedersenBlake3s, 16) + , transcript_base(input_manifest, plonk::transcript::HashType::PedersenBlake3s, 16) , current_challenge(in_context) {} Transcript(Builder* in_context, const std::vector& input_transcript, - const transcript::Manifest& input_manifest) + const plonk::transcript::Manifest& input_manifest) : context(in_context) - , transcript_base(input_transcript, input_manifest, transcript::HashType::PedersenBlake3s, 16) + , transcript_base(input_transcript, input_manifest, plonk::transcript::HashType::PedersenBlake3s, 16) , current_challenge(in_context) /*, transcript_bytes(in_context) */ { @@ -55,11 +55,11 @@ template class Transcript { * @param num_public_inputs */ Transcript(Builder* in_context, - const transcript::Manifest& input_manifest, + const plonk::transcript::Manifest& input_manifest, const std::vector& field_buffer, const size_t num_public_inputs) : context(in_context) - , transcript_base(input_manifest, transcript::HashType::PedersenBlake3s, 16) + , transcript_base(input_manifest, plonk::transcript::HashType::PedersenBlake3s, 16) , current_challenge(in_context) { size_t count = 0; @@ -92,7 +92,7 @@ template class Transcript { } } - transcript::Manifest get_manifest() const { return transcript_base.get_manifest(); } + plonk::transcript::Manifest get_manifest() const { return transcript_base.get_manifest(); } int check_field_element_cache(const std::string& element_name) const { @@ -388,7 +388,7 @@ template class Transcript { Builder* context; private: - transcript::Transcript transcript_base; + plonk::transcript::Transcript transcript_base; field_pt current_challenge; mutable std::vector field_vector_keys; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.test.cpp index 7f6b856a253..78acde2d5f7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.test.cpp @@ -5,7 +5,10 @@ #include "barretenberg/transcript/transcript.hpp" #include "transcript.hpp" -namespace bb::stdlib::recursion { +namespace { +using namespace bb; +using namespace bb::plonk; +using namespace bb::stdlib::recursion; // TODO(Cody): Testing only one circuit type. using Builder = StandardCircuitBuilder; @@ -19,7 +22,6 @@ using fq_t = stdlib::bigfield; using group_t = stdlib::element; using transcript_ct = Transcript; -namespace { transcript::Manifest create_manifest(const size_t num_public_inputs) { // add public inputs.... @@ -53,7 +55,6 @@ transcript::Manifest create_manifest(const size_t num_public_inputs) { { "PI_Z", g1_size, false }, { "PI_Z_OMEGA", g1_size, false } }, "separator", 1) }); return output; } -} // namespace struct TestData { std::vector g1_elements; @@ -178,6 +179,7 @@ transcript_ct get_circuit_transcript(Builder* context, const TestData& data) transcript.apply_fiat_shamir("separator"); return transcript; } +} // namespace TEST(stdlib_transcript, validate_transcript) { @@ -271,5 +273,4 @@ TEST(stdlib_transcript, validate_transcript) auto result = builder.check_circuit(); EXPECT_EQ(result, true); -} -} // namespace bb::stdlib::recursion \ No newline at end of file +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/program_settings.hpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/program_settings.hpp index 3ef8bcfe0dd..6cdbcac8fa8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/program_settings.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/program_settings.hpp @@ -22,7 +22,7 @@ template class recursive_ultra_verifier_settings : public plonk using PlookupAuxiliaryWidget = bb::plonk::VerifierPlookupAuxiliaryWidget; static constexpr size_t num_challenge_bytes = 16; - static constexpr transcript::HashType hash_type = transcript::HashType::PedersenBlake3s; + static constexpr plonk::transcript::HashType hash_type = plonk::transcript::HashType::PedersenBlake3s; // idpolys is a flag that describes whether we're using Vitalik's trick of using trivial identity permutation // polynomials (id_poly = false); OR whether the identity permutation polynomials are circuit-specific and stored in // the proving/verification key (id_poly = true). @@ -96,7 +96,7 @@ class recursive_ultra_to_standard_verifier_settings : public recursive_ultra_ver using EllipticWidget = bb::plonk::VerifierEllipticWidget; using PlookupAuxiliaryWidget = bb::plonk::VerifierPlookupAuxiliaryWidget; - static constexpr transcript::HashType hash_type = transcript::HashType::PedersenBlake3s; + static constexpr plonk::transcript::HashType hash_type = plonk::transcript::HashType::PedersenBlake3s; }; } // namespace bb::stdlib::recursion diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.hpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.hpp index d3ad8d53d6e..76ba6f976a7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.hpp @@ -174,7 +174,7 @@ lagrange_evaluations get_lagrange_evaluations( template aggregation_state verify_proof(typename Curve::Builder* context, std::shared_ptr> key, - const transcript::Manifest& manifest, + const plonk::transcript::Manifest& manifest, const plonk::proof& proof, const aggregation_state previous_output = aggregation_state()) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.test.cpp index b3d9cadc6ce..111f308508d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.test.cpp @@ -168,7 +168,7 @@ template class stdlib_verifier : public testing::Test { info("Native result: ", native_result); } - transcript::Manifest recursive_manifest = InnerComposer::create_manifest(prover.key->num_public_inputs); + plonk::transcript::Manifest recursive_manifest = InnerComposer::create_manifest(prover.key->num_public_inputs); auto output = recursion::verify_proof( &outer_builder, verification_key, recursive_manifest, proof_to_recursively_verify); @@ -194,7 +194,7 @@ template class stdlib_verifier : public testing::Test { plonk::proof proof_to_recursively_verify_a = prover.construct_proof(); - transcript::Manifest recursive_manifest = InnerComposer::create_manifest(prover.key->num_public_inputs); + plonk::transcript::Manifest recursive_manifest = InnerComposer::create_manifest(prover.key->num_public_inputs); auto previous_output = recursion::verify_proof( &outer_circuit, verification_key, recursive_manifest, proof_to_recursively_verify_a); @@ -263,7 +263,8 @@ template class stdlib_verifier : public testing::Test { plonk::proof recursive_proof = proof_type ? prover_a.construct_proof() : prover_b.construct_proof(); - transcript::Manifest recursive_manifest = InnerComposer::create_manifest(prover_a.key->num_public_inputs); + plonk::transcript::Manifest recursive_manifest = + InnerComposer::create_manifest(prover_a.key->num_public_inputs); stdlib::recursion::aggregation_state output = stdlib::recursion::verify_proof( diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index 5e9edef2f96..8f308808749 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -1,6 +1,5 @@ #pragma once #include "barretenberg/common/thread.hpp" -#include "barretenberg/common/thread_utils.hpp" #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/polynomials/pow.hpp" #include "barretenberg/relations/relation_parameters.hpp" @@ -121,7 +120,7 @@ template class SumcheckProverRound { // on a specified minimum number of iterations per thread. This eventually leads to the use of a single thread. // For now we use a power of 2 number of threads simply to ensure the round size is evenly divided. size_t min_iterations_per_thread = 1 << 6; // min number of iterations for which we'll spin up a unique thread - size_t num_threads = bb::thread_utils::calculate_num_threads_pow2(round_size, min_iterations_per_thread); + size_t num_threads = bb::calculate_num_threads_pow2(round_size, min_iterations_per_thread); size_t iterations_per_thread = round_size / num_threads; // actual iterations per thread // Construct univariate accumulator containers; one per thread diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.hpp index 5e033178cba..4bd084c20af 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.hpp @@ -71,4 +71,4 @@ class GoblinTranslatorComposer { return commitment_key; }; }; -} // namespace bb \ No newline at end of file +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp index 65371cffbe3..15922db4d75 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp @@ -1,6 +1,6 @@ #include "avm_alu_trace.hpp" -namespace avm_trace { +namespace bb::avm_trace { /** * @brief Constructor of Alu trace builder of AVM. Only serves to set the capacity of the @@ -431,4 +431,4 @@ FF AvmAluTraceBuilder::op_eq(FF const& a, FF const& b, AvmMemoryTag in_tag, uint return res; } -} // namespace avm_trace +} // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp index 7505a1f5030..49691f3faaf 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp @@ -2,7 +2,7 @@ #include "avm_common.hpp" -namespace avm_trace { +namespace bb::avm_trace { class AvmAluTraceBuilder { @@ -52,4 +52,4 @@ class AvmAluTraceBuilder { private: std::vector alu_trace; }; -} // namespace avm_trace +} // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp index 8f163717ee2..b163d40c6e0 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp @@ -4,7 +4,7 @@ #include "barretenberg/proof_system/circuit_builder/generated/avm_circuit_builder.hpp" #include -namespace avm_trace { +namespace bb::avm_trace { using Flavor = bb::AvmFlavor; using FF = Flavor::FF; @@ -18,4 +18,4 @@ enum class IntermRegister : uint32_t { IA = 0, IB = 1, IC = 2 }; enum class AvmMemoryTag : uint32_t { U0 = 0, U8 = 1, U16 = 2, U32 = 3, U64 = 4, U128 = 5, FF = 6 }; static const uint32_t MAX_MEM_TAG = 6; -} // namespace avm_trace +} // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp index f47680adc04..d2a7daf9bfa 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp @@ -9,7 +9,7 @@ #include #include -namespace avm_trace { +namespace bb::avm_trace { namespace { @@ -177,4 +177,4 @@ std::vector Deserialization::parse(std::vector const& byte } return instructions; }; -} // namespace avm_trace +} // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.hpp index 97853629c72..6b58fa299f7 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.hpp @@ -10,7 +10,7 @@ #include #include -namespace avm_trace { +namespace bb::avm_trace { // Possible types for an instruction's operand in its wire format. (Keep in sync with TS code. // See avm/serialization/instruction_serialization.ts). @@ -24,4 +24,4 @@ class Deserialization { static std::vector parse(std::vector const& bytecode); }; -} // namespace avm_trace \ No newline at end of file +} // namespace bb::avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp index 70963e630cc..81c738a4691 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp @@ -15,7 +15,7 @@ using namespace bb; -namespace avm_trace { +namespace bb::avm_trace { /** * @brief Run the bytecode, generate the corresponding execution trace and prove the correctness @@ -149,4 +149,4 @@ std::vector Execution::gen_trace(std::vector const& instructio return trace_builder.finalize(); } -} // namespace avm_trace +} // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp index 9450bad4bbe..5a324eaee73 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp @@ -8,7 +8,7 @@ #include #include -namespace avm_trace { +namespace bb::avm_trace { class Execution { public: @@ -19,4 +19,4 @@ class Execution { static bb::HonkProof run_and_prove(std::vector const& bytecode, std::vector const& calldata = {}); }; -} // namespace avm_trace \ No newline at end of file +} // namespace bb::avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.cpp index 2129c0a3e77..9101a32ee3a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.cpp @@ -1,6 +1,6 @@ #include "avm_helper.hpp" -namespace avm_trace { +namespace bb::avm_trace { /** * @brief Routine to log some slice of a trace of the AVM. Used to debug or in some unit tests. @@ -71,4 +71,4 @@ void log_avm_trace(std::vector const& trace, size_t beg, size_t end) } } -} // namespace avm_trace +} // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.hpp index db262658bf6..8b5f1140f38 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.hpp @@ -2,8 +2,8 @@ #include "avm_common.hpp" -namespace avm_trace { +namespace bb::avm_trace { void log_avm_trace(std::vector const& trace, size_t beg, size_t end); -} // namespace avm_trace \ No newline at end of file +} // namespace bb::avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_instructions.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_instructions.hpp index 01cfdd4b80f..751b7fd3990 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_instructions.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_instructions.hpp @@ -6,7 +6,7 @@ #include #include -namespace avm_trace { +namespace bb::avm_trace { using Operand = std::variant; @@ -21,4 +21,4 @@ class Instruction { , operands(std::move(operands)){}; }; -} // namespace avm_trace \ No newline at end of file +} // namespace bb::avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp index b0746af1d29..d680159aef1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp @@ -1,7 +1,7 @@ #include "avm_mem_trace.hpp" #include "barretenberg/vm/avm_trace/avm_common.hpp" -namespace avm_trace { +namespace bb::avm_trace { /** * @brief Constructor of a memory trace builder of AVM. Only serves to set the capacity of the @@ -214,4 +214,4 @@ void AvmMemTraceBuilder::write_into_memory( store_in_mem_trace(clk, interm_reg, addr, val, m_in_tag); } -} // namespace avm_trace \ No newline at end of file +} // namespace bb::avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.hpp index 43adab419ea..f6bd30c0937 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.hpp @@ -2,7 +2,7 @@ #include "avm_common.hpp" -namespace avm_trace { +namespace bb::avm_trace { class AvmMemTraceBuilder { @@ -94,4 +94,4 @@ class AvmMemTraceBuilder { void store_in_mem_trace( uint32_t clk, IntermRegister interm_reg, uint32_t addr, FF const& val, AvmMemoryTag m_in_tag); }; -} // namespace avm_trace \ No newline at end of file +} // namespace bb::avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.cpp index b5e16c06a24..c460195db3d 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.cpp @@ -4,7 +4,7 @@ #include #include -namespace avm_trace { +namespace bb::avm_trace { const std::unordered_map Bytecode::OPERANDS_NUM = { // Compute @@ -168,4 +168,4 @@ std::string to_hex(OpCode opcode) return stream.str(); } -} // namespace avm_trace +} // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.hpp index e2520ba5448..5fa3cac9add 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.hpp @@ -5,7 +5,7 @@ #include #include -namespace avm_trace { +namespace bb::avm_trace { /** * All AVM opcodes (Keep in sync with TS counterpart code opcodes.ts) @@ -108,4 +108,4 @@ class Bytecode { std::string to_hex(OpCode opcode); -} // namespace avm_trace \ No newline at end of file +} // namespace bb::avm_trace \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp index 35639ae7276..a7784391b04 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp @@ -10,7 +10,7 @@ #include "avm_trace.hpp" -namespace avm_trace { +namespace bb::avm_trace { /** * @brief Constructor of a trace builder of AVM. Only serves to set the capacity of the @@ -800,4 +800,4 @@ std::vector AvmTraceBuilder::finalize() return trace; } -} // namespace avm_trace +} // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp index d1d354aee06..19971def2e4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp @@ -10,7 +10,7 @@ #include "barretenberg/relations/generated/avm/avm_main.hpp" -namespace avm_trace { +namespace bb::avm_trace { // This is the internal context that we keep along the lifecycle of bytecode execution // to iteratively build the whole trace. This is effectively performing witness generation. @@ -84,4 +84,4 @@ class AvmTraceBuilder { uint32_t internal_return_ptr = CALLSTACK_OFFSET; std::stack internal_call_stack = {}; }; -} // namespace avm_trace +} // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp index 2e749b41536..5f9f206f31f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_arithmetic.test.cpp @@ -247,7 +247,7 @@ std::vector gen_mutated_trace_eq( } // anonymous namespace namespace tests_avm { -using namespace avm_trace; +using namespace bb::avm_trace; class AvmArithmeticTests : public ::testing::Test { public: diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp index b657e199322..b06dce1e1a4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp @@ -73,7 +73,7 @@ std::vector gen_mutated_trace_not(FF const& a, FF const& c_mutated, avm_tra } // namespace namespace tests_avm { -using namespace avm_trace; +using namespace bb::avm_trace; class AvmBitwiseTests : public ::testing::Test { public: diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp index 73d175e3232..ed1c81377ab 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp @@ -3,7 +3,7 @@ using namespace bb; namespace tests_avm { -using namespace avm_trace; +using namespace bb::avm_trace; class AvmControlFlowTests : public ::testing::Test { public: diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp index 2760088ed83..8658b461255 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp @@ -15,7 +15,7 @@ namespace tests_avm { using namespace bb; -using namespace avm_trace; +using namespace bb::avm_trace; using namespace testing; using bb::utils::hex_to_bytes; diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp index a14b1478d0a..815bf34d8b0 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp @@ -3,7 +3,7 @@ using namespace bb; namespace tests_avm { -using namespace avm_trace; +using namespace bb::avm_trace; class AvmMemoryTests : public ::testing::Test { public: