From 33e05717bd5da0325da2c9bc9ed4a673bd96d40e Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 23 Jan 2024 11:06:56 -0500 Subject: [PATCH] refactor(bb): rearrange namespaces (#4147) Resolves https://github.com/AztecProtocol/barretenberg/issues/794 --------- Co-authored-by: ludamad --- .../cpp/src/barretenberg/bb/get_bn254_crs.cpp | 20 +- .../cpp/src/barretenberg/bb/get_bn254_crs.hpp | 6 +- .../src/barretenberg/bb/get_grumpkin_crs.cpp | 8 +- .../src/barretenberg/bb/get_grumpkin_crs.hpp | 6 +- barretenberg/cpp/src/barretenberg/bb/main.cpp | 2 +- .../benchmark/basics_bench/basics.bench.cpp | 26 +-- .../benchmark/goblin_bench/eccvm.bench.cpp | 2 +- .../benchmark/goblin_bench/goblin.bench.cpp | 2 +- .../benchmark/ipa_bench/ipa.bench.cpp | 2 +- .../plonk_bench/standard_plonk.bench.cpp | 6 +- .../protogalaxy_bench/protogalaxy.bench.cpp | 4 +- .../relations_bench/barycentric.bench.cpp | 2 +- .../relations_bench/relations.bench.cpp | 2 +- ...enchmark_utilities.hpp => mock_proofs.hpp} | 83 ++++---- .../ultra_bench/ultra_honk.bench.cpp | 20 +- .../ultra_bench/ultra_honk_rounds.bench.cpp | 6 +- .../ultra_bench/ultra_plonk.bench.cpp | 20 +- .../ultra_bench/ultra_plonk_rounds.bench.cpp | 6 +- .../benchmark/widgets_bench/widget.bench.cpp | 6 +- .../commitment_key.test.hpp | 4 +- .../commitment_schemes/gemini/gemini.test.cpp | 7 +- .../commitment_schemes/ipa/ipa.test.cpp | 6 +- .../commitment_schemes/kzg/kzg.test.cpp | 2 +- .../cpp/src/barretenberg/common/ref_array.hpp | 5 +- .../src/barretenberg/common/ref_vector.hpp | 5 +- .../cpp/src/barretenberg/common/std_array.hpp | 4 +- .../src/barretenberg/common/std_vector.hpp | 5 +- .../cpp/src/barretenberg/common/thread.hpp | 2 +- .../crypto/aes128/aes128.test.cpp | 10 +- .../crypto/blake2s/blake2-impl.hpp | 4 +- .../barretenberg/crypto/blake2s/blake2s.cpp | 10 +- .../barretenberg/crypto/blake2s/blake2s.hpp | 4 +- .../crypto/blake2s/blake2s.test.cpp | 4 +- .../barretenberg/crypto/blake2s/c_bind.cpp | 6 +- .../crypto/blake3s/blake3s.test.cpp | 4 +- .../src/barretenberg/crypto/ecdsa/c_bind.cpp | 12 +- .../src/barretenberg/crypto/ecdsa/ecdsa.hpp | 22 +- .../barretenberg/crypto/ecdsa/ecdsa.test.cpp | 56 +++--- .../barretenberg/crypto/ecdsa/ecdsa_impl.hpp | 14 +- .../barretenberg/crypto/hashers/hashers.hpp | 2 +- .../barretenberg/crypto/hmac/hmac.test.cpp | 4 +- .../crypto/poseidon2/poseidon2.test.cpp | 34 ++-- .../poseidon2/poseidon2_permutation.test.cpp | 38 ++-- .../barretenberg/crypto/schnorr/c_bind.cpp | 24 +-- .../barretenberg/crypto/schnorr/c_bind.hpp | 2 +- .../barretenberg/crypto/schnorr/multisig.hpp | 34 ++-- .../crypto/schnorr/multisig.test.cpp | 20 +- .../crypto/schnorr/proof_of_possession.hpp | 16 +- .../schnorr/proof_of_possession.test.cpp | 14 +- .../barretenberg/crypto/schnorr/schnorr.hpp | 22 +- .../barretenberg/crypto/schnorr/schnorr.tcc | 20 +- .../crypto/schnorr/schnorr.test.cpp | 62 +++--- .../dsl/acir_format/acir_format.cpp | 8 +- .../dsl/acir_format/acir_format.hpp | 8 +- .../dsl/acir_format/acir_format.test.cpp | 170 ++++++++-------- .../acir_format/acir_to_constraint_buf.hpp | 8 +- .../dsl/acir_format/block_constraint.test.cpp | 21 +- .../dsl/acir_format/ecdsa_secp256k1.cpp | 26 +-- .../dsl/acir_format/ecdsa_secp256k1.hpp | 2 +- .../dsl/acir_format/ecdsa_secp256k1.test.cpp | 19 +- .../dsl/acir_format/ecdsa_secp256r1.cpp | 24 +-- .../dsl/acir_format/ecdsa_secp256r1.test.cpp | 30 +-- .../acir_format/recursion_constraint.test.cpp | 91 +++++---- .../dsl/acir_format/schnorr_verify.cpp | 10 +- .../dsl/acir_proofs/acir_composer.cpp | 4 +- .../dsl/acir_proofs/acir_composer.hpp | 2 +- .../dsl/acir_proofs/goblin_acir_composer.cpp | 5 +- .../dsl/acir_proofs/goblin_acir_composer.hpp | 4 +- .../cpp/src/barretenberg/dsl/types.hpp | 2 +- .../barretenberg/ecc/curves/bn254/bn254.hpp | 4 +- .../barretenberg/ecc/curves/bn254/g1.test.cpp | 4 +- .../barretenberg/ecc/curves/bn254/g2.test.cpp | 2 +- .../ecc/curves/grumpkin/grumpkin.hpp | 4 +- .../ecc/curves/grumpkin/grumpkin.test.cpp | 5 +- .../ecc/curves/secp256k1/secp256k1.hpp | 4 +- .../ecc/curves/secp256k1/secp256k1.test.cpp | 9 +- .../ecc/curves/secp256r1/secp256r1.hpp | 4 +- .../ecc/curves/secp256r1/secp256r1.test.cpp | 9 +- .../src/barretenberg/ecc/fields/field12.hpp | 2 +- .../src/barretenberg/ecc/fields/field2.hpp | 2 +- .../ecc/fields/field2_declarations.hpp | 8 +- .../src/barretenberg/ecc/fields/field6.hpp | 2 +- .../ecc/fields/field_declarations.hpp | 2 +- .../barretenberg/ecc/fields/field_impl.hpp | 4 +- .../ecc/groups/affine_element.hpp | 2 +- .../ecc/groups/affine_element_impl.hpp | 4 +- .../src/barretenberg/ecc/groups/element.hpp | 4 +- .../barretenberg/ecc/groups/element_impl.hpp | 4 +- .../src/barretenberg/ecc/groups/wnaf.test.cpp | 4 +- .../eccvm/eccvm_composer.test.cpp | 14 +- .../eccvm/eccvm_transcript.test.cpp | 11 +- .../src/barretenberg/flavor/flavor.test.cpp | 10 +- .../goblin/full_goblin_recursion.test.cpp | 10 +- .../grumpkin_srs_gen/grumpkin_srs_gen.cpp | 2 +- .../fixtures/user_context.hpp | 8 +- .../inner_proof_data.test.cpp | 2 +- .../proofs/join_split/join_split.test.cpp | 22 +- .../proofs/join_split/join_split_circuit.cpp | 4 +- .../proofs/join_split/join_split_circuit.hpp | 2 +- .../join_split/join_split_js_parity.test.cpp | 4 +- .../proofs/join_split/join_split_tx.hpp | 2 +- .../proofs/join_split/join_split_tx.test.cpp | 2 +- .../proofs/join_split/sign_join_split_tx.cpp | 10 +- .../proofs/join_split/sign_join_split_tx.hpp | 4 +- .../proofs/join_split/verify_signature.hpp | 4 +- .../circuit/value/compute_nullifier.test.cpp | 2 +- .../notes/circuit/value/value_note.test.cpp | 6 +- .../notes/native/value/compute_nullifier.cpp | 2 +- .../barretenberg/join_split_example/types.hpp | 6 +- .../numeric/bitop/count_leading_zeros.hpp | 4 +- .../bitop/count_leading_zeros.test.cpp | 2 + .../barretenberg/numeric/bitop/get_msb.hpp | 4 +- .../numeric/bitop/get_msb.test.cpp | 2 + .../barretenberg/numeric/bitop/keep_n_lsb.hpp | 4 +- .../src/barretenberg/numeric/bitop/pow.hpp | 4 +- .../src/barretenberg/numeric/bitop/rotate.hpp | 4 +- .../numeric/bitop/sparse_form.hpp | 4 +- .../barretenberg/numeric/random/engine.cpp | 14 +- .../barretenberg/numeric/random/engine.hpp | 22 +- .../numeric/random/engine.test.cpp | 12 +- .../barretenberg/numeric/uint128/uint128.hpp | 4 +- .../numeric/uint128/uint128.test.cpp | 8 +- .../numeric/uint128/uint128_impl.hpp | 4 +- .../barretenberg/numeric/uint256/uint256.hpp | 6 +- .../numeric/uint256/uint256.test.cpp | 6 +- .../numeric/uint256/uint256_impl.hpp | 4 +- .../src/barretenberg/numeric/uintx/uintx.hpp | 8 +- .../barretenberg/numeric/uintx/uintx.test.cpp | 24 ++- .../barretenberg/numeric/uintx/uintx_impl.hpp | 4 +- .../plonk/composer/standard_composer.test.cpp | 2 +- .../plonk/composer/ultra_composer.test.cpp | 12 +- .../commitment_scheme.test.cpp | 2 +- .../plonk/proof_system/prover/prover.test.cpp | 3 +- .../proving_key/proving_key.test.cpp | 4 +- .../public_inputs/public_inputs.test.cpp | 2 +- .../verification_key.test.cpp | 10 +- .../proof_system/verifier/verifier.test.cpp | 2 +- .../plonk/transcript/transcript.test.cpp | 6 +- .../polynomials/barycentric.test.cpp | 4 +- .../polynomial_arithmetic.test.cpp | 2 +- .../src/barretenberg/polynomials/pow.test.cpp | 23 +-- .../polynomials/univariate.test.cpp | 124 +++++------- .../eccvm/eccvm_builder_types.hpp | 4 +- .../eccvm/eccvm_circuit_builder.hpp | 20 +- .../eccvm/eccvm_circuit_builder.test.cpp | 31 ++- .../circuit_builder/eccvm/msm_builder.hpp | 8 +- .../eccvm/precomputed_tables_builder.hpp | 10 +- .../eccvm/transcript_builder.hpp | 4 +- ...goblin_translator_circuit_builder.test.cpp | 13 +- .../goblin_translator_mini.fuzzer.cpp | 7 +- .../goblin_ultra_circuit_builder.test.cpp | 2 +- .../standard_circuit_builder.test.cpp | 6 +- .../toy_avm/toy_avm_circuit_builder.test.cpp | 9 +- .../ultra_circuit_builder.test.cpp | 6 +- .../composer/composer_lib.test.cpp | 6 +- .../composer/permutation_lib.test.cpp | 6 +- .../library/grand_product_library.test.cpp | 21 +- .../proof_system/op_queue/ecc_op_queue.hpp | 2 +- .../op_queue/ecc_op_queue.test.cpp | 9 +- .../protogalaxy/combiner.test.cpp | 51 +++-- .../relations/nested_containers.test.cpp | 12 +- .../relations/relation_manual.test.cpp | 15 +- ...n_translator_relation_consistency.test.cpp | 4 - .../ultra_relation_consistency.test.cpp | 6 +- .../serialize/msgpack_schema.test.cpp | 25 +-- .../smt_verification/smt_bigfield.test.cpp | 6 +- .../smt_verification/smt_examples.test.cpp | 8 +- .../smt_verification/smt_polynomials.test.cpp | 8 +- .../circuits/ecdsa_circuit.hpp | 28 ++- .../solidity_helpers/proof_gen.cpp | 2 +- .../srs/factories/mem_crs_factory.test.cpp | 4 +- .../factories/mem_grumpkin_crs_factory.cpp | 2 +- .../cpp/src/barretenberg/srs/global_crs.cpp | 8 +- .../srs/scalar_multiplication.test.cpp | 188 +++++++++--------- .../commitment/pedersen/pedersen.test.cpp | 7 +- .../stdlib/encryption/aes128/aes128.test.cpp | 4 +- .../stdlib/encryption/ecdsa/ecdsa.hpp | 29 +-- .../stdlib/encryption/ecdsa/ecdsa.test.cpp | 103 +++++----- .../stdlib/encryption/ecdsa/ecdsa_impl.hpp | 25 +-- .../stdlib/encryption/schnorr/schnorr.cpp | 52 +++-- .../stdlib/encryption/schnorr/schnorr.hpp | 25 ++- .../encryption/schnorr/schnorr.test.cpp | 75 ++++--- .../stdlib/hash/blake2s/blake2s.test.cpp | 10 +- .../stdlib/hash/blake3s/blake3s.test.cpp | 4 +- .../stdlib/hash/keccak/keccak.test.cpp | 6 +- .../stdlib/hash/pedersen/pedersen.test.cpp | 35 ++-- .../stdlib/hash/poseidon2/poseidon2.test.cpp | 9 +- .../stdlib/hash/sha256/sha256.test.cpp | 67 +++---- .../stdlib/merkle_tree/hash.test.cpp | 5 +- .../stdlib/merkle_tree/membership.test.cpp | 13 +- .../stdlib/merkle_tree/merkle_tree.bench.cpp | 2 +- .../stdlib/merkle_tree/merkle_tree.test.cpp | 9 +- .../nullifier_tree/nullifier_tree.test.cpp | 4 +- .../primitives/bigfield/bigfield.test.cpp | 30 ++- .../primitives/biggroup/biggroup.test.cpp | 14 +- .../biggroup/biggroup_goblin.test.cpp | 2 +- .../primitives/bit_array/bit_array.test.cpp | 5 +- .../stdlib/primitives/bool/bool.test.cpp | 4 +- .../primitives/byte_array/byte_array.test.cpp | 3 - .../stdlib/primitives/curves/secp256k1.hpp | 28 +-- .../stdlib/primitives/field/array.test.cpp | 7 +- .../stdlib/primitives/field/field.test.cpp | 50 +++-- .../primitives/group/cycle_group.test.cpp | 5 +- .../stdlib/primitives/logic/logic.test.cpp | 9 +- .../primitives/memory/dynamic_array.test.cpp | 7 +- .../primitives/memory/ram_table.test.cpp | 17 +- .../primitives/memory/rom_table.test.cpp | 9 +- .../packed_byte_array.test.cpp | 5 +- .../primitives/plookup/plookup.test.cpp | 74 +++---- .../primitives/safe_uint/safe_uint.test.cpp | 6 +- .../stdlib/primitives/uint/uint.test.cpp | 11 +- .../honk/transcript/transcript.test.cpp | 6 +- .../recursion/transcript/transcript.test.cpp | 23 +-- .../verification_key.test.cpp | 6 +- .../recursion/verifier/verifier.test.cpp | 18 +- .../src/barretenberg/stdlib/types/ultra.hpp | 4 +- .../instance/prover_instance.test.cpp | 5 +- .../sumcheck/partial_evaluation.test.cpp | 3 - .../barretenberg/sumcheck/sumcheck.test.cpp | 22 +- .../sumcheck/sumcheck_round.test.cpp | 18 +- .../transcript/transcript.test.cpp | 12 +- .../goblin_translator_composer.test.cpp | 16 +- .../ultra_honk/databus_composer.test.cpp | 10 +- .../ultra_honk/goblin_ultra_composer.test.cpp | 16 +- .../goblin_ultra_transcript.test.cpp | 3 +- .../ultra_honk/protogalaxy.test.cpp | 21 +- .../ultra_honk/relation_correctness.test.cpp | 46 ++--- .../barretenberg/ultra_honk/sumcheck.test.cpp | 21 +- .../ultra_honk/ultra_composer.test.cpp | 79 ++++---- .../ultra_honk/ultra_transcript.test.cpp | 3 +- .../vm/tests/AvmMini_arithmetic.test.cpp | 15 +- .../vm/tests/AvmMini_control_flow.test.cpp | 5 +- .../vm/tests/AvmMini_memory.test.cpp | 6 +- .../barretenberg/vm/tests/helpers.test.cpp | 11 +- .../barretenberg/vm/tests/helpers.test.hpp | 2 - .../src/aztec3/utils/types/circuit_types.hpp | 2 +- 236 files changed, 1608 insertions(+), 1757 deletions(-) rename barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/{benchmark_utilities.hpp => mock_proofs.hpp} (69%) diff --git a/barretenberg/cpp/src/barretenberg/bb/get_bn254_crs.cpp b/barretenberg/cpp/src/barretenberg/bb/get_bn254_crs.cpp index f724fad7ca0..a0cc5f3b06d 100644 --- a/barretenberg/cpp/src/barretenberg/bb/get_bn254_crs.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/get_bn254_crs.cpp @@ -1,6 +1,7 @@ #include "get_bn254_crs.hpp" #include "barretenberg/bb/file_io.hpp" +namespace { std::vector download_bn254_g1_data(size_t num_points) { size_t g1_end = num_points * 64 - 1; @@ -26,8 +27,10 @@ std::vector download_bn254_g2_data() std::string command = "curl -s '" + url + "'"; return exec_pipe(command); } +} // namespace -std::vector get_bn254_g1_data(const std::filesystem::path& path, size_t num_points) +namespace bb { +std::vector get_bn254_g1_data(const std::filesystem::path& path, size_t num_points) { std::filesystem::create_directories(path); @@ -37,9 +40,9 @@ std::vector get_bn254_g1_data(const std::filesystem::pat if (g1_file_size >= num_points * 64 && g1_file_size % 64 == 0) { vinfo("using cached crs of size ", std::to_string(g1_file_size / 64), " at ", g1_path); auto data = read_file(g1_path, g1_file_size); - auto points = std::vector(num_points); + auto points = std::vector(num_points); for (size_t i = 0; i < num_points; ++i) { - points[i] = from_buffer(data, i * 64); + points[i] = from_buffer(data, i * 64); } return points; } @@ -48,14 +51,14 @@ std::vector get_bn254_g1_data(const std::filesystem::pat auto data = download_bn254_g1_data(num_points); write_file(g1_path, data); - auto points = std::vector(num_points); + auto points = std::vector(num_points); for (size_t i = 0; i < num_points; ++i) { - points[i] = from_buffer(data, i * 64); + points[i] = from_buffer(data, i * 64); } return points; } -bb::g2::affine_element get_bn254_g2_data(const std::filesystem::path& path) +g2::affine_element get_bn254_g2_data(const std::filesystem::path& path) { std::filesystem::create_directories(path); @@ -64,10 +67,11 @@ bb::g2::affine_element get_bn254_g2_data(const std::filesystem::path& path) if (g2_file_size == 128) { auto data = read_file(g2_path); - return from_buffer(data.data()); + return from_buffer(data.data()); } auto data = download_bn254_g2_data(); write_file(g2_path, data); - return from_buffer(data.data()); + return from_buffer(data.data()); } +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/bb/get_bn254_crs.hpp b/barretenberg/cpp/src/barretenberg/bb/get_bn254_crs.hpp index 230e074f219..4ceb3557813 100644 --- a/barretenberg/cpp/src/barretenberg/bb/get_bn254_crs.hpp +++ b/barretenberg/cpp/src/barretenberg/bb/get_bn254_crs.hpp @@ -8,5 +8,7 @@ #include #include -std::vector get_bn254_g1_data(const std::filesystem::path& path, size_t num_points); -bb::g2::affine_element get_bn254_g2_data(const std::filesystem::path& path); \ No newline at end of file +namespace bb { +std::vector get_bn254_g1_data(const std::filesystem::path& path, size_t num_points); +g2::affine_element get_bn254_g2_data(const std::filesystem::path& path); +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.cpp b/barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.cpp index fca6a54de7b..1942c278ea4 100644 --- a/barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.cpp @@ -1,5 +1,6 @@ #include "get_grumpkin_crs.hpp" +namespace { std::vector download_grumpkin_g1_data(size_t num_points) { size_t g1_start = 28; @@ -19,7 +20,9 @@ std::vector download_grumpkin_g1_data(size_t num_points) return data; } +} // namespace +namespace bb { std::vector get_grumpkin_g1_data(const std::filesystem::path& path, size_t num_points) { std::filesystem::create_directories(path); @@ -35,7 +38,7 @@ std::vector get_grumpkin_g1_data(const std::file auto data = read_file(file, 28 + num_points * 64); auto points = std::vector(num_points); auto size_of_points_in_bytes = num_points * 64; - bb::srs::IO::read_affine_elements_from_buffer( + srs::IO::read_affine_elements_from_buffer( points.data(), (char*)data.data(), size_of_points_in_bytes); return points; } @@ -52,6 +55,7 @@ std::vector get_grumpkin_g1_data(const std::file new_size_file.close(); auto points = std::vector(num_points); - bb::srs::IO::read_affine_elements_from_buffer(points.data(), (char*)data.data(), data.size()); + srs::IO::read_affine_elements_from_buffer(points.data(), (char*)data.data(), data.size()); return points; } +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.hpp b/barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.hpp index 894885ce97e..5c8f9fcef16 100644 --- a/barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.hpp +++ b/barretenberg/cpp/src/barretenberg/bb/get_grumpkin_crs.hpp @@ -8,4 +8,8 @@ #include #include -std::vector get_grumpkin_g1_data(const std::filesystem::path& path, size_t num_points); \ No newline at end of file +namespace bb { + +std::vector get_grumpkin_g1_data(const std::filesystem::path& path, size_t num_points); + +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index b3d45629600..6c567b00bcd 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -72,7 +72,7 @@ acir_format::WitnessVector get_witness(std::string const& witness_path) return acir_format::witness_buf_to_witness_data(witness_data); } -acir_format::acir_format get_constraint_system(std::string const& bytecode_path) +acir_format::AcirFormat get_constraint_system(std::string const& bytecode_path) { auto bytecode = get_bytecode(bytecode_path); return acir_format::circuit_buf_to_acir_format(bytecode); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/basics.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/basics.bench.cpp index 1d1cc37718a..c3bf090f2cf 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/basics.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/basics.bench.cpp @@ -40,7 +40,7 @@ using Fr = Curve::ScalarField; */ void parallel_for_field_element_addition(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); size_t num_cpus = get_num_cpus(); std::vector> copy_vector(num_cpus); for (size_t i = 0; i < num_cpus; i++) { @@ -72,7 +72,7 @@ void parallel_for_field_element_addition(State& state) */ void ff_addition(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); std::vector copy_vector(2); for (size_t j = 0; j < 2; j++) { copy_vector.emplace_back(Fr::random_element(&engine)); @@ -97,7 +97,7 @@ void ff_addition(State& state) */ void ff_multiplication(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); std::vector copy_vector(2); for (size_t j = 0; j < 2; j++) { copy_vector.emplace_back(Fr::random_element(&engine)); @@ -122,7 +122,7 @@ void ff_multiplication(State& state) */ void ff_sqr(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); std::vector copy_vector(2); for (size_t j = 0; j < 2; j++) { copy_vector.emplace_back(Fr::random_element(&engine)); @@ -147,7 +147,7 @@ void ff_sqr(State& state) */ void ff_invert(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); auto element = Fr::random_element(&engine); for (auto _ : state) { @@ -168,7 +168,7 @@ void ff_invert(State& state) */ void ff_to_montgomery(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); auto element = Fr::random_element(&engine); for (auto _ : state) { @@ -188,7 +188,7 @@ void ff_to_montgomery(State& state) */ void ff_from_montgomery(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); auto element = Fr::random_element(&engine); for (auto _ : state) { @@ -209,7 +209,7 @@ void ff_from_montgomery(State& state) */ void ff_reduce(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); auto element = Fr::random_element(&engine); for (auto _ : state) { @@ -230,7 +230,7 @@ void ff_reduce(State& state) */ void projective_point_addition(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); std::vector copy_vector(2); for (size_t j = 0; j < 2; j++) { copy_vector.emplace_back(Curve::Element::random_element(&engine)); @@ -255,7 +255,7 @@ void projective_point_addition(State& state) */ void projective_point_accidental_doubling(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); std::vector copy_vector(2); for (size_t j = 0; j < 2; j++) { copy_vector.emplace_back(Curve::Element::random_element(&engine)); @@ -280,7 +280,7 @@ void projective_point_accidental_doubling(State& state) */ void projective_point_doubling(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); std::vector copy_vector(2); for (size_t j = 0; j < 2; j++) { copy_vector.emplace_back(Curve::Element::random_element(&engine)); @@ -305,7 +305,7 @@ void projective_point_doubling(State& state) */ void scalar_multiplication(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); Curve::Element element = Curve::Element::random_element(&engine); Fr scalar = Fr::random_element(&engine); @@ -347,7 +347,7 @@ void cycle_waste(State& state) void sequential_copy(State& state) { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); for (auto _ : state) { state.PauseTiming(); size_t num_cycles = 1 << static_cast(state.range(0)); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/eccvm.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/eccvm.bench.cpp index 630484837e1..4c89b375de5 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/eccvm.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/eccvm.bench.cpp @@ -1,6 +1,6 @@ #include -#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp" +#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp" #include "barretenberg/eccvm/eccvm_composer.hpp" #include "barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp" diff --git a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/goblin.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/goblin.bench.cpp index d5416f24799..839c8237de4 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/goblin.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/goblin.bench.cpp @@ -1,7 +1,7 @@ #include -#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp" +#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp" #include "barretenberg/goblin/goblin.hpp" #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp index 900b6cdbdf0..3a25ee93dfd 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp @@ -28,7 +28,7 @@ std::vector opening_claims(MAX_POLYNOMIAL_DEGREE_LOG2 - MIN_POLYNO void ipa_open(State& state) noexcept { - numeric::random::Engine& engine = numeric::random::get_debug_engine(); + numeric::RNG& engine = numeric::get_debug_randomness(); for (auto _ : state) { state.PauseTiming(); size_t n = 1 << static_cast(state.range(0)); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/standard_plonk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/standard_plonk.bench.cpp index 71d790519c0..1a1eff70e7a 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/standard_plonk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/standard_plonk.bench.cpp @@ -1,4 +1,4 @@ -#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp" +#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp" #include "barretenberg/plonk/composer/standard_composer.hpp" #include "barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp" @@ -13,8 +13,8 @@ using StandardPlonk = bb::plonk::StandardComposer; static void construct_proof_standard_power_of_2(State& state) noexcept { auto log2_of_gates = static_cast(state.range(0)); - bench_utils::construct_proof_with_specified_num_iterations( - state, &bench_utils::generate_basic_arithmetic_circuit, log2_of_gates); + bb::mock_proofs::construct_proof_with_specified_num_iterations( + state, &bb::mock_proofs::generate_basic_arithmetic_circuit, log2_of_gates); } BENCHMARK(construct_proof_standard_power_of_2) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp index 80fd2e0d3b5..a4164418e4a 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp @@ -1,6 +1,6 @@ #include -#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp" +#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "barretenberg/ultra_honk/ultra_composer.hpp" @@ -23,7 +23,7 @@ void fold_one(State& state) noexcept const auto construct_instance = [&]() { Builder builder; - bench_utils::generate_basic_arithmetic_circuit(builder, log2_num_gates); + bb::mock_proofs::generate_basic_arithmetic_circuit(builder, log2_num_gates); return composer.create_instance(builder); }; diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp index 19572fe6a0e..b11d6b4771a 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp @@ -5,7 +5,7 @@ using namespace benchmark; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = bb::numeric::get_debug_randomness(); } using FF = bb::fr; diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp index e683523a7e3..7541c609754 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -5,7 +5,7 @@ #include namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = bb::numeric::get_debug_randomness(); } using namespace bb::honk::sumcheck; diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_proofs.hpp similarity index 69% rename from barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp rename to barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_proofs.hpp index d7fe8886507..6bbc81a5872 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_proofs.hpp @@ -20,9 +20,7 @@ #include "barretenberg/ultra_honk/ultra_composer.hpp" #include "barretenberg/ultra_honk/ultra_prover.hpp" -using namespace benchmark; - -namespace bench_utils { +namespace bb::mock_proofs { /** * @brief Generate test circuit with basic arithmetic operations @@ -32,9 +30,9 @@ namespace bench_utils { */ template void generate_basic_arithmetic_circuit(Builder& builder, size_t log2_num_gates) { - bb::stdlib::field_t a(bb::stdlib::witness_t(&builder, bb::fr::random_element())); - bb::stdlib::field_t b(bb::stdlib::witness_t(&builder, bb::fr::random_element())); - bb::stdlib::field_t c(&builder); + stdlib::field_t a(stdlib::witness_t(&builder, fr::random_element())); + stdlib::field_t b(stdlib::witness_t(&builder, fr::random_element())); + stdlib::field_t c(&builder); size_t passes = (1UL << log2_num_gates) / 4 - 4; if (static_cast(passes) <= 0) { throw std::runtime_error("too few gates"); @@ -58,9 +56,9 @@ template void generate_sha256_test_circuit(Builder& builder, { std::string in; in.resize(32); - bb::stdlib::packed_byte_array input(&builder, in); + stdlib::packed_byte_array input(&builder, in); for (size_t i = 0; i < num_iterations; i++) { - input = bb::stdlib::sha256(input); + input = stdlib::sha256(input); } } @@ -74,9 +72,9 @@ template void generate_keccak_test_circuit(Builder& builder, { std::string in = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01"; - bb::stdlib::byte_array input(&builder, in); + stdlib::byte_array input(&builder, in); for (size_t i = 0; i < num_iterations; i++) { - input = bb::stdlib::keccak::hash(input); + input = stdlib::keccak::hash(input); } } @@ -88,24 +86,24 @@ template void generate_keccak_test_circuit(Builder& builder, */ template void generate_ecdsa_verification_test_circuit(Builder& builder, size_t num_iterations) { - using curve = bb::stdlib::secp256k1; + using curve = stdlib::secp256k1; using fr = typename curve::fr; using fq = typename curve::fq; using g1 = typename curve::g1; std::string message_string = "Instructions unclear, ask again later."; - crypto::ecdsa::key_pair account; + crypto::ecdsa_key_pair account; for (size_t i = 0; i < num_iterations; i++) { // Generate unique signature for each iteration 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); + crypto::ecdsa_signature signature = + crypto::ecdsa_construct_signature(message_string, account); bool first_result = - crypto::ecdsa::verify_signature(message_string, account.public_key, signature); + 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()); @@ -114,18 +112,18 @@ template void generate_ecdsa_verification_test_circuit(Builde typename curve::g1_bigfr_ct public_key = curve::g1_bigfr_ct::from_witness(&builder, account.public_key); - bb::stdlib::ecdsa::signature sig{ typename curve::byte_array_ct(&builder, rr), - typename curve::byte_array_ct(&builder, ss), - bb::stdlib::uint8(&builder, vv) }; + stdlib::ecdsa_signature sig{ typename curve::byte_array_ct(&builder, rr), + typename curve::byte_array_ct(&builder, ss), + stdlib::uint8(&builder, vv) }; typename curve::byte_array_ct message(&builder, message_string); // Verify ecdsa signature - bb::stdlib::ecdsa::verify_signature(message, public_key, sig); + stdlib::ecdsa_verify_signature(message, public_key, sig); } } @@ -137,7 +135,7 @@ template void generate_ecdsa_verification_test_circuit(Builde */ template void generate_merkle_membership_test_circuit(Builder& builder, size_t num_iterations) { - using namespace bb::stdlib; + using namespace stdlib; using field_ct = field_t; using witness_ct = witness_t; using witness_ct = witness_t; @@ -164,33 +162,32 @@ template void generate_merkle_membership_test_circuit(Builder } // ultrahonk -inline bb::honk::UltraProver get_prover(bb::honk::UltraComposer& composer, - void (*test_circuit_function)(bb::honk::UltraComposer::CircuitBuilder&, size_t), - size_t num_iterations) +inline honk::UltraProver get_prover(honk::UltraComposer& composer, + void (*test_circuit_function)(honk::UltraComposer::CircuitBuilder&, size_t), + size_t num_iterations) { - bb::honk::UltraComposer::CircuitBuilder builder; + honk::UltraComposer::CircuitBuilder builder; test_circuit_function(builder, num_iterations); - std::shared_ptr instance = composer.create_instance(builder); + std::shared_ptr instance = composer.create_instance(builder); return composer.create_prover(instance); } // standard plonk -inline bb::plonk::Prover get_prover(bb::plonk::StandardComposer& composer, - void (*test_circuit_function)(bb::StandardCircuitBuilder&, size_t), - size_t num_iterations) +inline plonk::Prover get_prover(plonk::StandardComposer& composer, + void (*test_circuit_function)(StandardCircuitBuilder&, size_t), + size_t num_iterations) { - bb::StandardCircuitBuilder builder; + StandardCircuitBuilder builder; test_circuit_function(builder, num_iterations); return composer.create_prover(builder); } // ultraplonk -inline bb::plonk::UltraProver get_prover(bb::plonk::UltraComposer& composer, - void (*test_circuit_function)(bb::honk::UltraComposer::CircuitBuilder&, - size_t), - size_t num_iterations) +inline plonk::UltraProver get_prover(plonk::UltraComposer& composer, + void (*test_circuit_function)(honk::UltraComposer::CircuitBuilder&, size_t), + size_t num_iterations) { - bb::plonk::UltraComposer::CircuitBuilder builder; + plonk::UltraComposer::CircuitBuilder builder; test_circuit_function(builder, num_iterations); return composer.create_prover(builder); } @@ -205,10 +202,12 @@ inline bb::plonk::UltraProver get_prover(bb::plonk::UltraComposer& composer, * @param test_circuit_function */ template -void construct_proof_with_specified_num_iterations( - State& state, void (*test_circuit_function)(typename Composer::CircuitBuilder&, size_t), size_t num_iterations) +void construct_proof_with_specified_num_iterations(benchmark::State& state, + void (*test_circuit_function)(typename Composer::CircuitBuilder&, + size_t), + size_t num_iterations) { - bb::srs::init_crs_factory("../srs_db/ignition"); + srs::init_crs_factory("../srs_db/ignition"); Composer composer; @@ -223,4 +222,4 @@ void construct_proof_with_specified_num_iterations( } } -} // namespace bench_utils +} // namespace bb::mock_proofs diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp index 1109a928f4c..f560475a7af 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp @@ -1,6 +1,6 @@ #include -#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp" +#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "barretenberg/ultra_honk/ultra_composer.hpp" @@ -14,7 +14,7 @@ static void construct_proof_ultrahonk(State& state, void (*test_circuit_function)(UltraCircuitBuilder&, size_t)) noexcept { size_t num_iterations = 10; // 10x the circuit - bench_utils::construct_proof_with_specified_num_iterations( + bb::mock_proofs::construct_proof_with_specified_num_iterations( state, test_circuit_function, num_iterations); } @@ -24,22 +24,26 @@ static void construct_proof_ultrahonk(State& state, static void construct_proof_ultrahonk_power_of_2(State& state) noexcept { auto log2_of_gates = static_cast(state.range(0)); - bench_utils::construct_proof_with_specified_num_iterations( - state, &bench_utils::generate_basic_arithmetic_circuit, log2_of_gates); + bb::mock_proofs::construct_proof_with_specified_num_iterations( + state, &bb::mock_proofs::generate_basic_arithmetic_circuit, log2_of_gates); } // Define benchmarks -BENCHMARK_CAPTURE(construct_proof_ultrahonk, sha256, &bench_utils::generate_sha256_test_circuit) +BENCHMARK_CAPTURE(construct_proof_ultrahonk, + sha256, + &bb::mock_proofs::generate_sha256_test_circuit) ->Unit(kMillisecond); -BENCHMARK_CAPTURE(construct_proof_ultrahonk, keccak, &bench_utils::generate_keccak_test_circuit) +BENCHMARK_CAPTURE(construct_proof_ultrahonk, + keccak, + &bb::mock_proofs::generate_keccak_test_circuit) ->Unit(kMillisecond); BENCHMARK_CAPTURE(construct_proof_ultrahonk, ecdsa_verification, - &bench_utils::generate_ecdsa_verification_test_circuit) + &bb::mock_proofs::generate_ecdsa_verification_test_circuit) ->Unit(kMillisecond); BENCHMARK_CAPTURE(construct_proof_ultrahonk, merkle_membership, - &bench_utils::generate_merkle_membership_test_circuit) + &bb::mock_proofs::generate_merkle_membership_test_circuit) ->Unit(kMillisecond); BENCHMARK(construct_proof_ultrahonk_power_of_2) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp index b36e168b446..8fd06307cec 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp @@ -1,6 +1,6 @@ #include -#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp" +#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "barretenberg/ultra_honk/ultra_composer.hpp" #include "barretenberg/ultra_honk/ultra_prover.hpp" @@ -55,8 +55,8 @@ BBERG_PROFILE static void test_round(State& state, size_t index) noexcept state.PauseTiming(); honk::UltraComposer composer; // TODO(https://github.com/AztecProtocol/barretenberg/issues/761) benchmark both sparse and dense circuits - honk::UltraProver prover = bench_utils::get_prover( - composer, &bench_utils::generate_ecdsa_verification_test_circuit, 10); + honk::UltraProver prover = bb::mock_proofs::get_prover( + composer, &bb::mock_proofs::generate_ecdsa_verification_test_circuit, 10); test_round_inner(state, prover, index); state.ResumeTiming(); // NOTE: google bench is very finnicky, must end in ResumeTiming() for correctness diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk.bench.cpp index 0f16f152d2c..a02fba5eb8a 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk.bench.cpp @@ -1,4 +1,4 @@ -#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp" +#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" @@ -12,7 +12,7 @@ static void construct_proof_ultraplonk(State& state, void (*test_circuit_function)(UltraCircuitBuilder&, size_t)) noexcept { size_t num_iterations = 10; // 10x the circuit - bench_utils::construct_proof_with_specified_num_iterations( + bb::mock_proofs::construct_proof_with_specified_num_iterations( state, test_circuit_function, num_iterations); } @@ -22,22 +22,26 @@ static void construct_proof_ultraplonk(State& state, static void construct_proof_ultraplonk_power_of_2(State& state) noexcept { auto log2_of_gates = static_cast(state.range(0)); - bench_utils::construct_proof_with_specified_num_iterations( - state, &bench_utils::generate_basic_arithmetic_circuit, log2_of_gates); + bb::mock_proofs::construct_proof_with_specified_num_iterations( + state, &bb::mock_proofs::generate_basic_arithmetic_circuit, log2_of_gates); } // Define benchmarks -BENCHMARK_CAPTURE(construct_proof_ultraplonk, sha256, &bench_utils::generate_sha256_test_circuit) +BENCHMARK_CAPTURE(construct_proof_ultraplonk, + sha256, + &bb::mock_proofs::generate_sha256_test_circuit) ->Unit(kMillisecond); -BENCHMARK_CAPTURE(construct_proof_ultraplonk, keccak, &bench_utils::generate_keccak_test_circuit) +BENCHMARK_CAPTURE(construct_proof_ultraplonk, + keccak, + &bb::mock_proofs::generate_keccak_test_circuit) ->Unit(kMillisecond); BENCHMARK_CAPTURE(construct_proof_ultraplonk, ecdsa_verification, - &bench_utils::generate_ecdsa_verification_test_circuit) + &bb::mock_proofs::generate_ecdsa_verification_test_circuit) ->Unit(kMillisecond); BENCHMARK_CAPTURE(construct_proof_ultraplonk, merkle_membership, - &bench_utils::generate_merkle_membership_test_circuit) + &bb::mock_proofs::generate_merkle_membership_test_circuit) ->Unit(kMillisecond); BENCHMARK(construct_proof_ultraplonk_power_of_2) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk_rounds.bench.cpp index 8565dd96fbe..b78b825ce77 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk_rounds.bench.cpp @@ -1,6 +1,6 @@ #include -#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp" +#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" using namespace benchmark; @@ -54,8 +54,8 @@ BBERG_PROFILE static void test_round(State& state, size_t index) noexcept state.PauseTiming(); plonk::UltraComposer composer; // TODO: https://github.com/AztecProtocol/barretenberg/issues/761 benchmark both sparse and dense circuits - plonk::UltraProver prover = bench_utils::get_prover( - composer, &bench_utils::generate_ecdsa_verification_test_circuit, 10); + plonk::UltraProver prover = bb::mock_proofs::get_prover( + composer, &bb::mock_proofs::generate_ecdsa_verification_test_circuit, 10); test_round_inner(state, prover, index); // NOTE: google bench is very finnicky, must end in ResumeTiming() for correctness state.ResumeTiming(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp index b96f9f6ce78..9b94063e3c2 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp @@ -1,4 +1,4 @@ -#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp" +#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp" #include "barretenberg/flavor/goblin_ultra.hpp" #include "barretenberg/flavor/ultra.hpp" #include "barretenberg/plonk/composer/standard_composer.hpp" @@ -19,7 +19,7 @@ // #define GET_PER_ROW_TIME namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = bb::numeric::get_debug_randomness(); } namespace bb::plonk { @@ -39,7 +39,7 @@ BasicPlonkKeyAndTranscript get_plonk_key_and_transcript() bb::srs::init_crs_factory("../srs_db/ignition"); auto inner_composer = plonk::UltraComposer(); auto builder = typename plonk::UltraComposer::CircuitBuilder(); - bench_utils::generate_basic_arithmetic_circuit(builder, 16); + bb::mock_proofs::generate_basic_arithmetic_circuit(builder, 16); UltraProver inner_prover = inner_composer.create_prover(builder); #ifdef GET_PER_ROW_TIME if (!(inner_prover.key->circuit_size == WIDGET_BENCH_TEST_CIRCUIT_SIZE)) { diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp index df031f7404d..3350e2ed867 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.test.hpp @@ -75,7 +75,7 @@ template class CommitmentTest : public ::testing::Test { public: CommitmentTest() - : engine{ &numeric::random::get_engine() } + : engine{ &numeric::get_randomness() } {} std::shared_ptr ck() { return commitment_key; } @@ -170,7 +170,7 @@ template class CommitmentTest : public ::testing::Test { } } - numeric::random::Engine* engine; + numeric::RNG* engine; // Per-test-suite set-up. // Called before the first test in this test suite. diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.test.cpp index 1d6dd6779c2..09f65bbc635 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini.test.cpp @@ -7,7 +7,10 @@ #include #include -namespace bb::honk::pcs::gemini { +using namespace bb; +using namespace bb::honk; +using namespace bb::honk::pcs; +using namespace bb::honk::pcs::gemini; template class GeminiTest : public CommitmentTest { using GeminiProver = GeminiProver_; @@ -237,5 +240,3 @@ TYPED_TEST(GeminiTest, DoubleWithShift) multilinear_commitments, multilinear_commitments_to_be_shifted); } - -} // namespace bb::honk::pcs::gemini diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp index 3a9c26d1961..6aafab2fd15 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.test.cpp @@ -8,8 +8,11 @@ #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" #include + using namespace bb; -namespace bb::honk::pcs::ipa::test { +using namespace bb::honk; +using namespace bb::honk::pcs; +using namespace bb::honk::pcs::ipa; using Curve = curve::Grumpkin; @@ -176,4 +179,3 @@ TEST_F(IPATest, GeminiShplonkIPAWithShift) EXPECT_EQ(verified, true); } -} // namespace bb::honk::pcs::ipa::test diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp index 5e933bb7d6c..30c02c0543a 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp @@ -32,7 +32,7 @@ TYPED_TEST(KZGTest, single) using Fr = typename TypeParam::ScalarField; auto witness = this->random_polynomial(n); - bb::g1::element commitment = this->commit(witness); + g1::element commitment = this->commit(witness); auto challenge = Fr::random_element(); auto evaluation = witness.evaluate(challenge); diff --git a/barretenberg/cpp/src/barretenberg/common/ref_array.hpp b/barretenberg/cpp/src/barretenberg/common/ref_array.hpp index 95224d8f7da..b85556fa6d9 100644 --- a/barretenberg/cpp/src/barretenberg/common/ref_array.hpp +++ b/barretenberg/cpp/src/barretenberg/common/ref_array.hpp @@ -5,7 +5,7 @@ #include #include -// TODO(https://github.com/AztecProtocol/barretenberg/issues/794) namespace this once convenient +namespace bb { /** * @brief A template class for a reference array. Behaves as if std::array was possible. * @@ -134,4 +134,5 @@ template RefArray concatenate(con (..., copy_into(ref_arrays, offset)); return RefArray{ concatenated }; -} \ No newline at end of file +} +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/common/ref_vector.hpp b/barretenberg/cpp/src/barretenberg/common/ref_vector.hpp index 523d75b8f5f..c74d1b52c19 100644 --- a/barretenberg/cpp/src/barretenberg/common/ref_vector.hpp +++ b/barretenberg/cpp/src/barretenberg/common/ref_vector.hpp @@ -6,7 +6,7 @@ #include #include -// TODO(https://github.com/AztecProtocol/barretenberg/issues/794) namespace this once convenient +namespace bb { /** * @brief A template class for a reference vector. Behaves as if std::vector was possible. * @@ -147,4 +147,5 @@ template static std::vector> to_vector_of_ref_vectors( result.push_back(RefVector{ inner }); } return result; -} \ No newline at end of file +} +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/common/std_array.hpp b/barretenberg/cpp/src/barretenberg/common/std_array.hpp index 850464ae36a..cb70e124a67 100644 --- a/barretenberg/cpp/src/barretenberg/common/std_array.hpp +++ b/barretenberg/cpp/src/barretenberg/common/std_array.hpp @@ -2,7 +2,7 @@ #include -// TODO(https://github.com/AztecProtocol/barretenberg/issues/794) namespace this once convenient +namespace bb { /** * @brief Concatenates multiple std::array objects into a single array. * @@ -37,3 +37,5 @@ template std::array concatenate(c return result; } + +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/common/std_vector.hpp b/barretenberg/cpp/src/barretenberg/common/std_vector.hpp index c3bf373820c..f363b74635c 100644 --- a/barretenberg/cpp/src/barretenberg/common/std_vector.hpp +++ b/barretenberg/cpp/src/barretenberg/common/std_vector.hpp @@ -1,7 +1,7 @@ #pragma once #include -// TODO(https://github.com/AztecProtocol/barretenberg/issues/794) namespace this once convenient +namespace bb { /** * @brief Concatenates multiple std::vector objects into a single std::vector. * @@ -22,4 +22,5 @@ template std::vector concatenate(const std::vector& vector, c (append(vectors), ...); return concatenated; -} \ No newline at end of file +} +} // 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 8c67ca84d0a..c2d3ec76744 100644 --- a/barretenberg/cpp/src/barretenberg/common/thread.hpp +++ b/barretenberg/cpp/src/barretenberg/common/thread.hpp @@ -19,7 +19,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 << numeric::get_msb(get_num_cpus())); + return static_cast(1ULL << bb::numeric::get_msb(get_num_cpus())); } void parallel_for(size_t num_iterations, const std::function& func); diff --git a/barretenberg/cpp/src/barretenberg/crypto/aes128/aes128.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/aes128/aes128.test.cpp index e1880264942..eae0f4f1c45 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/aes128/aes128.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/aes128/aes128.test.cpp @@ -2,6 +2,8 @@ #include +using namespace bb; + TEST(aes128, verify_cipher) { @@ -12,8 +14,8 @@ TEST(aes128, verify_cipher) uint8_t state[16]{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a }; uint8_t round_key[176]; - bb::crypto::aes128_expand_key(key, round_key); - bb::crypto::aes128_cipher(state, round_key); + crypto::aes128_expand_key(key, round_key); + crypto::aes128_cipher(state, round_key); for (size_t i = 0; i < 16; ++i) { EXPECT_EQ(state[i], expected[i]); @@ -33,7 +35,7 @@ TEST(aes128, encrypt_buffer_cbc) 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }; - bb::crypto::aes128_encrypt_buffer_cbc(in, iv, key, 64); + crypto::aes128_encrypt_buffer_cbc(in, iv, key, 64); for (size_t i = 0; i < 64; ++i) { EXPECT_EQ(in[i], out[i]); @@ -53,7 +55,7 @@ TEST(aes128, decrypt_buffer_cbc) 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }; - bb::crypto::aes128_decrypt_buffer_cbc(in, iv, key, 64); + crypto::aes128_decrypt_buffer_cbc(in, iv, key, 64); for (size_t i = 0; i < 64; ++i) { EXPECT_EQ(in[i], out[i]); diff --git a/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2-impl.hpp b/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2-impl.hpp index 9d286bd579b..4b6addc9ddd 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2-impl.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2-impl.hpp @@ -18,7 +18,7 @@ #include #include -namespace blake2 { +namespace bb::crypto { #if !defined(__cplusplus) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) #if defined(_MSC_VER) @@ -146,6 +146,6 @@ static BLAKE2_INLINE void secure_zero_memory(void* v, size_t n) memset_v(v, 0, n); } -} // namespace blake2 +} // namespace bb::crypto #endif \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2s.cpp b/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2s.cpp index 6fd5ae3c349..ea4d44259db 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2s.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2s.cpp @@ -13,14 +13,14 @@ https://blake2.net. */ -#include -#include -#include +#include +#include +#include #include "blake2-impl.hpp" #include "blake2s.hpp" -namespace blake2 { +namespace bb::crypto { static const uint32_t blake2s_IV[8] = { 0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL, 0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL }; @@ -233,4 +233,4 @@ std::array blake2s(std::vector const& input) return output; } -} // namespace blake2 +} // namespace bb::crypto diff --git a/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2s.hpp b/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2s.hpp index c009296e5b9..9c5ce71abe0 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2s.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2s.hpp @@ -19,7 +19,7 @@ #include #include -namespace blake2 { +namespace bb::crypto { #if defined(_MSC_VER) #define BLAKE2_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop)) @@ -73,4 +73,4 @@ int blake2s_final(blake2s_state* S, void* out, size_t outlen); std::array blake2s(std::vector const& input); -} // namespace blake2 \ No newline at end of file +} // namespace bb::crypto \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2s.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2s.test.cpp index c76c889a41c..0ef048a6295 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2s.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/blake2s/blake2s.test.cpp @@ -5,6 +5,8 @@ #include #include +using namespace bb; + struct test_vector { std::string input; std::array output; @@ -382,6 +384,6 @@ TEST(misc_blake2s, test_vectors) { for (auto v : test_vectors) { std::vector input(v.input.begin(), v.input.end()); - EXPECT_EQ(blake2::blake2s(input), v.output); + EXPECT_EQ(crypto::blake2s(input), v.output); } } \ 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 07dfd3a0b31..53c0a84b07b 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/blake2s/c_bind.cpp @@ -10,14 +10,14 @@ WASM_EXPORT void blake2s(uint8_t const* data, out_buf32 out) { std::vector inputv; read(data, inputv); - auto output = blake2::blake2s(inputv); + auto output = bb::crypto::blake2s(inputv); std::copy(output.begin(), output.end(), out); } WASM_EXPORT void blake2s_to_field(uint8_t const* data, size_t length, uint8_t* r) { std::vector inputv(data, data + length); - auto output = blake2::blake2s(inputv); + auto output = bb::crypto::blake2s(inputv); auto result = bb::fr::serialize_from_buffer(output.data()); bb::fr::serialize_to_buffer(result, r); } @@ -27,7 +27,7 @@ WASM_EXPORT void blake2s_to_field_(uint8_t const* data, fr::out_buf r) { std::vector inputv; read(data, inputv); - auto output = blake2::blake2s(inputv); + auto output = bb::crypto::blake2s(inputv); auto result = bb::fr::serialize_from_buffer(output.data()); bb::fr::serialize_to_buffer(result, r); } diff --git a/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.test.cpp index c4d93f3051d..7f38889e02c 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.test.cpp @@ -8,6 +8,8 @@ #include #include +using namespace bb; + struct test_vector { std::string_view input; std::array output; @@ -392,7 +394,7 @@ static constexpr std::array test_vectors{ TEST(MiscBlake3s, TestVectors) { - bb::constexpr_for<0, 1, 73>([&]() { + constexpr_for<0, 1, 73>([&]() { constexpr auto v = test_vectors[index]; std::vector input(v.input.begin(), v.input.end()); auto result_vector = blake3::blake3s(input); diff --git a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp index 0f39a4f08eb..db8808a8c84 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp @@ -18,9 +18,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 }; + bb::crypto::ecdsa_key_pair key_pair = { priv_key, pub_key }; - auto sig = bb::crypto::ecdsa::construct_signature( + auto sig = bb::crypto::ecdsa_construct_signature( std::string((char*)message, msg_len), key_pair); write(output_sig_r, sig.r); write(output_sig_s, sig.s); @@ -39,9 +39,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 }; + bb::crypto::ecdsa_signature sig = { r, s, v }; auto recovered_pub_key = - bb::crypto::ecdsa::recover_public_key( + bb::crypto::ecdsa_recover_public_key( std::string((char*)message, msg_len), sig); serialize::write(output_pub_key, recovered_pub_key); } @@ -59,7 +59,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( + bb::crypto::ecdsa_signature sig = { r, s, v }; + return bb::crypto::ecdsa_verify_signature( std::string((char*)message, msg_len), pubk, sig); } diff --git a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.hpp b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.hpp index ad1bd516adb..dabd6374720 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.hpp @@ -8,15 +8,15 @@ #include #include -namespace bb::crypto::ecdsa { -template struct key_pair { +namespace bb::crypto { +template struct ecdsa_key_pair { Fr private_key; typename G1::affine_element public_key; // For serialization, update with any new fields MSGPACK_FIELDS(private_key, public_key); }; -struct signature { +struct ecdsa_signature { std::array r; std::array s; uint8_t v; @@ -25,27 +25,27 @@ struct signature { }; template -signature construct_signature(const std::string& message, const key_pair& account); +ecdsa_signature ecdsa_construct_signature(const std::string& message, const ecdsa_key_pair& account); template -typename G1::affine_element recover_public_key(const std::string& message, const signature& sig); +typename G1::affine_element ecdsa_recover_public_key(const std::string& message, const ecdsa_signature& sig); template -bool verify_signature(const std::string& message, - const typename G1::affine_element& public_key, - const signature& signature); +bool ecdsa_verify_signature(const std::string& message, + const typename G1::affine_element& public_key, + const ecdsa_signature& signature); -inline bool operator==(signature const& lhs, signature const& rhs) +inline bool operator==(ecdsa_signature const& lhs, ecdsa_signature const& rhs) { return lhs.r == rhs.r && lhs.s == rhs.s && lhs.v == rhs.v; } -inline std::ostream& operator<<(std::ostream& os, signature const& sig) +inline std::ostream& operator<<(std::ostream& os, ecdsa_signature const& sig) { os << "{ " << sig.r << ", " << sig.s << ", " << static_cast(sig.v) << " }"; return os; } -} // namespace bb::crypto::ecdsa +} // namespace bb::crypto #include "./ecdsa_impl.hpp" diff --git a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.test.cpp index b15e4a234be..76b324682a0 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.test.cpp @@ -9,7 +9,7 @@ using namespace bb; TEST(ecdsa, msgpack) { - auto [actual, expected] = msgpack_roundtrip(crypto::ecdsa::signature{}); + auto [actual, expected] = msgpack_roundtrip(crypto::ecdsa_signature{}); EXPECT_EQ(actual, expected); } @@ -17,14 +17,14 @@ TEST(ecdsa, verify_signature_grumpkin_sha256) { std::string message = "The quick brown dog jumped over the lazy fox."; - crypto::ecdsa::key_pair account; + crypto::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); + crypto::ecdsa_signature signature = + crypto::ecdsa_construct_signature(message, account); - bool result = crypto::ecdsa::verify_signature( + bool result = crypto::ecdsa_verify_signature( message, account.public_key, signature); EXPECT_EQ(result, true); @@ -34,14 +34,14 @@ TEST(ecdsa, verify_signature_secp256r1_sha256) { std::string message = "The quick brown dog jumped over the lazy fox."; - crypto::ecdsa::key_pair account; + crypto::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); + crypto::ecdsa_signature signature = + crypto::ecdsa_construct_signature(message, account); - bool result = crypto::ecdsa::verify_signature( + bool result = crypto::ecdsa_verify_signature( message, account.public_key, signature); EXPECT_EQ(result, true); @@ -51,19 +51,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; + crypto::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); + crypto::ecdsa_signature signature = + crypto::ecdsa_construct_signature(message, account); - bool result = crypto::ecdsa::verify_signature( + bool result = crypto::ecdsa_verify_signature( message, account.public_key, signature); auto recovered_public_key = - crypto::ecdsa::recover_public_key(message, - signature); + crypto::ecdsa_recover_public_key(message, signature); EXPECT_EQ(result, true); EXPECT_EQ(recovered_public_key, account.public_key); @@ -73,19 +72,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; + crypto::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); + crypto::ecdsa_signature signature = + crypto::ecdsa_construct_signature(message, account); - bool result = crypto::ecdsa::verify_signature( + bool result = crypto::ecdsa_verify_signature( message, account.public_key, signature); auto recovered_public_key = - crypto::ecdsa::recover_public_key(message, - signature); + crypto::ecdsa_recover_public_key(message, signature); EXPECT_EQ(result, true); EXPECT_EQ(recovered_public_key, account.public_key); @@ -110,18 +108,18 @@ TEST(ecdsa, check_overflowing_r_and_s_are_rejected) std::vector message_vec = HexToBytes("41414141"); std::string message(message_vec.begin(), message_vec.end()); - crypto::ecdsa::signature signature; + crypto::ecdsa_signature signature; grumpkin::fr private_key; grumpkin::g1::affine_element public_key; - crypto::ecdsa::key_pair key_pair; + crypto::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); + crypto::ecdsa_construct_signature(message, key_pair); // Check that the signature is correct - bool result = crypto::ecdsa::verify_signature( + bool result = crypto::ecdsa_verify_signature( message, public_key, signature); EXPECT_TRUE(result); using serialize::read; @@ -135,7 +133,7 @@ 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( + result = crypto::ecdsa_verify_signature( message, public_key, signature); // Signature verification should decline this signature, since it breaks specification EXPECT_FALSE(result); @@ -148,7 +146,7 @@ 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( + result = crypto::ecdsa_verify_signature( message, public_key, signature); EXPECT_FALSE(result); } @@ -182,14 +180,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 }; + crypto::ecdsa_signature sig{ r, s, 27 }; std::vector message_vec = HexToBytes("5905238877c77421f73e43ee3da6f2d9e2ccad5fc942dcec0cbd25482935faaf416983fe165b1a045ee2bcd2e6dca3bdf46" "c4310a7461f9a37960ca672d3feb5473e253605fb1ddfd28065b53cb5858a8ad28175bf9bd386a5e471ea7a65c17cc934a9" "d791e91491eb3754d03799790fe2d308d16146d5c9b0d0debd97d79ce8"); std::string message(message_vec.begin(), message_vec.end()); - bool result = crypto::ecdsa::verify_signature( + bool result = crypto::ecdsa_verify_signature( message, public_key, sig); EXPECT_EQ(result, true); } diff --git a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa_impl.hpp b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa_impl.hpp index 1a60dc98c2b..26ae2b14004 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa_impl.hpp @@ -4,12 +4,12 @@ #include "barretenberg/common/serialize.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" -namespace bb::crypto::ecdsa { +namespace bb::crypto { template -signature construct_signature(const std::string& message, const key_pair& account) +ecdsa_signature ecdsa_construct_signature(const std::string& message, const ecdsa_key_pair& account) { - signature sig; + ecdsa_signature sig; // use HMAC in PRF mode to derive 32-byte secret `k` std::vector pkey_buffer; @@ -52,7 +52,7 @@ signature construct_signature(const std::string& message, const key_pair } template -typename G1::affine_element recover_public_key(const std::string& message, const signature& sig) +typename G1::affine_element ecdsa_recover_public_key(const std::string& message, const ecdsa_signature& sig) { using serialize::read; uint256_t r_uint; @@ -124,7 +124,9 @@ typename G1::affine_element recover_public_key(const std::string& message, const } template -bool verify_signature(const std::string& message, const typename G1::affine_element& public_key, const signature& sig) +bool ecdsa_verify_signature(const std::string& message, + const typename G1::affine_element& public_key, + const ecdsa_signature& sig) { using serialize::read; uint256_t r_uint; @@ -168,4 +170,4 @@ bool verify_signature(const std::string& message, const typename G1::affine_elem Fr result(Rx); return result == r; } -} // namespace bb::crypto::ecdsa +} // namespace bb::crypto diff --git a/barretenberg/cpp/src/barretenberg/crypto/hashers/hashers.hpp b/barretenberg/cpp/src/barretenberg/crypto/hashers/hashers.hpp index b3fb6e85105..f19224941d1 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/hashers/hashers.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/hashers/hashers.hpp @@ -31,5 +31,5 @@ struct Sha256Hasher { struct Blake2sHasher { static constexpr size_t BLOCK_SIZE = 64; static constexpr size_t OUTPUT_SIZE = 32; - static auto hash(const std::vector& message) { return blake2::blake2s(message); } + static auto hash(const std::vector& message) { return bb::crypto::blake2s(message); } }; diff --git a/barretenberg/cpp/src/barretenberg/crypto/hmac/hmac.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/hmac/hmac.test.cpp index 50695466e62..020ceedaf2c 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/hmac/hmac.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/hmac/hmac.test.cpp @@ -8,6 +8,8 @@ #include #include +using namespace bb; + std::array hex_to_bytes(const std::string& hex) { std::array bytes; @@ -106,7 +108,7 @@ TEST(hmac, ValidateHMAC) }; for (const auto& [key_string, message, expected] : test_vectors) { - std::array result = bb::crypto::hmac(message, key_string); + std::array result = crypto::hmac(message, key_string); EXPECT_EQ(result, hex_to_bytes(expected)); } diff --git a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2.test.cpp index 0360b569673..7903d1fceb6 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2.test.cpp @@ -6,20 +6,19 @@ using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } -namespace poseidon2_tests { TEST(Poseidon2, HashBasicTests) { - bb::fr a = bb::fr::random_element(&engine); - bb::fr b = bb::fr::random_element(&engine); - bb::fr c = bb::fr::random_element(&engine); - bb::fr d = bb::fr::random_element(&engine); + fr a = fr::random_element(&engine); + fr b = fr::random_element(&engine); + fr c = fr::random_element(&engine); + fr d = fr::random_element(&engine); - std::vector input1{ a, b, c, d }; - std::vector input2{ d, c, b, a }; + std::vector input1{ a, b, c, d }; + std::vector input2{ d, c, b, a }; auto r0 = crypto::Poseidon2::hash(input1); auto r1 = crypto::Poseidon2::hash(input1); @@ -34,15 +33,15 @@ TEST(Poseidon2, HashBasicTests) // flexibility of Poseidon's parametrisation) TEST(Poseidon2, HashConsistencyCheck) { - bb::fr a(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); - bb::fr b(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); - bb::fr c(std::string("0x9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); - bb::fr d(std::string("0x9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); + fr a(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); + fr b(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); + fr c(std::string("0x9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); + fr d(std::string("0x9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); - std::vector input{ a, b, c, d }; + std::vector input{ a, b, c, d }; auto result = crypto::Poseidon2::hash(input); - bb::fr expected(std::string("0x2f43a0f83b51a6f5fc839dea0ecec74947637802a579fa9841930a25a0bcec11")); + fr expected(std::string("0x2f43a0f83b51a6f5fc839dea0ecec74947637802a579fa9841930a25a0bcec11")); EXPECT_EQ(result, expected); } @@ -51,15 +50,14 @@ TEST(Poseidon2, HashBufferConsistencyCheck) { // 31 byte inputs because hash_buffer slicing is only injective with 31 bytes, as it slices 31 bytes for each field // element - bb::fr a(std::string("00000b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); + fr a(std::string("00000b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); auto input_vec = to_buffer(a); // takes field element and converts it to 32 bytes input_vec.erase(input_vec.begin()); // erase first byte since we want 31 bytes - std::vector input{ a }; + std::vector input{ a }; auto expected = crypto::Poseidon2::hash(input); - bb::fr result = crypto::Poseidon2::hash_buffer(input_vec); + fr result = crypto::Poseidon2::hash_buffer(input_vec); EXPECT_EQ(result, expected); } -} // namespace poseidon2_tests \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2_permutation.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2_permutation.test.cpp index 57d4b56a957..744593bcb73 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2_permutation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2_permutation.test.cpp @@ -6,11 +6,9 @@ using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } -namespace poseidon2_tests { - TEST(Poseidon2Permutation, TestVectors) { @@ -24,13 +22,13 @@ TEST(Poseidon2Permutation, TestVectors) TEST(Poseidon2Permutation, BasicTests) { - bb::fr a = bb::fr::random_element(&engine); - bb::fr b = bb::fr::random_element(&engine); - bb::fr c = bb::fr::random_element(&engine); - bb::fr d = bb::fr::random_element(&engine); + fr a = fr::random_element(&engine); + fr b = fr::random_element(&engine); + fr c = fr::random_element(&engine); + fr d = fr::random_element(&engine); - std::array input1{ a, b, c, d }; - std::array input2{ d, c, b, a }; + std::array input1{ a, b, c, d }; + std::array input2{ d, c, b, a }; auto r0 = crypto::Poseidon2Permutation::permutation(input1); auto r1 = crypto::Poseidon2Permutation::permutation(input1); @@ -45,21 +43,19 @@ TEST(Poseidon2Permutation, BasicTests) // flexibility of Poseidon's parametrisation) TEST(Poseidon2Permutation, ConsistencyCheck) { - bb::fr a(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); - bb::fr b(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); - bb::fr c(std::string("0x9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); - bb::fr d(std::string("0x9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); + fr a(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); + fr b(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); + fr c(std::string("0x9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); + fr d(std::string("0x9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789")); - std::array input{ a, b, c, d }; + std::array input{ a, b, c, d }; auto result = crypto::Poseidon2Permutation::permutation(input); - std::array expected{ - bb::fr(std::string("0x2bf1eaf87f7d27e8dc4056e9af975985bccc89077a21891d6c7b6ccce0631f95")), - bb::fr(std::string("0x0c01fa1b8d0748becafbe452c0cb0231c38224ea824554c9362518eebdd5701f")), - bb::fr(std::string("0x018555a8eb50cf07f64b019ebaf3af3c925c93e631f3ecd455db07bbb52bbdd3")), - bb::fr(std::string("0x0cbea457c91c22c6c31fd89afd2541efc2edf31736b9f721e823b2165c90fd41")), + std::array expected{ + fr(std::string("0x2bf1eaf87f7d27e8dc4056e9af975985bccc89077a21891d6c7b6ccce0631f95")), + fr(std::string("0x0c01fa1b8d0748becafbe452c0cb0231c38224ea824554c9362518eebdd5701f")), + fr(std::string("0x018555a8eb50cf07f64b019ebaf3af3c925c93e631f3ecd455db07bbb52bbdd3")), + fr(std::string("0x0cbea457c91c22c6c31fd89afd2541efc2edf31736b9f721e823b2165c90fd41")), }; EXPECT_EQ(result, expected); } - -} // namespace poseidon2_tests \ 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 fa7a66811fe..55abbfa0bdb 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp @@ -6,7 +6,7 @@ extern "C" { using namespace bb; using affine_element = grumpkin::g1::affine_element; -using multisig = crypto::schnorr::multisig; +using multisig = crypto::schnorr_multisig; using multisig_public_key = typename multisig::MultiSigPublicKey; WASM_EXPORT void schnorr_compute_public_key(uint8_t const* private_key, uint8_t* public_key_buf) @@ -32,8 +32,8 @@ WASM_EXPORT void schnorr_construct_signature(uint8_t const* message_buf, auto message = from_buffer(message_buf); auto priv_key = from_buffer(private_key); grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; - auto sig = crypto::schnorr::construct_signature(message, key_pair); + crypto::schnorr_key_pair key_pair = { priv_key, pub_key }; + auto sig = crypto::schnorr_construct_signature(message, key_pair); write(s, sig.s); write(e, sig.e); } @@ -47,18 +47,18 @@ WASM_EXPORT void schnorr_verify_signature( std::array e; std::copy(sig_s, sig_s + 32, s.begin()); std::copy(sig_e, sig_e + 32, e.begin()); - crypto::schnorr::signature sig = { s, e }; + crypto::schnorr_signature sig = { s, e }; *result = - crypto::schnorr::verify_signature(message, pubk, sig); + crypto::schnorr_verify_signature(message, pubk, sig); } WASM_EXPORT void schnorr_multisig_create_multisig_public_key(uint8_t const* private_key, uint8_t* multisig_pubkey_buf) { - using multisig = crypto::schnorr::multisig; + using multisig = crypto::schnorr_multisig; using multisig_public_key = typename multisig::MultiSigPublicKey; auto priv_key = from_buffer(private_key); grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; + crypto::schnorr_key_pair key_pair = { priv_key, pub_key }; auto agg_pubkey = multisig_public_key(key_pair); @@ -69,7 +69,7 @@ WASM_EXPORT void schnorr_multisig_validate_and_combine_signer_pubkeys(uint8_t co affine_element::out_buf combined_key_buf, bool* success) { - using multisig = crypto::schnorr::multisig; + using multisig = crypto::schnorr_multisig; auto pubkeys = from_buffer>(signer_pubkey_buf); auto combined_key = multisig::validate_and_combine_signer_pubkeys(pubkeys); @@ -86,7 +86,7 @@ WASM_EXPORT void schnorr_multisig_validate_and_combine_signer_pubkeys(uint8_t co WASM_EXPORT void schnorr_multisig_construct_signature_round_1(uint8_t* round_one_public_output_buf, uint8_t* round_one_private_output_buf) { - using multisig = crypto::schnorr::multisig; + using multisig = crypto::schnorr_multisig; auto [public_output, private_output] = multisig::construct_signature_round_1(); serialize::write(round_one_public_output_buf, public_output); @@ -101,11 +101,11 @@ WASM_EXPORT void schnorr_multisig_construct_signature_round_2(uint8_t const* mes uint8_t* round_two_buf, bool* success) { - using multisig = crypto::schnorr::multisig; + using multisig = crypto::schnorr_multisig; auto message = from_buffer(message_buf); auto priv_key = from_buffer(private_key); grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - crypto::schnorr::key_pair key_pair = { priv_key, pub_key }; + crypto::schnorr_key_pair key_pair = { priv_key, pub_key }; auto signer_pubkeys = from_buffer>(signer_pubkeys_buf); auto round_one_outputs = from_buffer>(round_one_public_buf); @@ -130,7 +130,7 @@ WASM_EXPORT void schnorr_multisig_combine_signatures(uint8_t const* message_buf, uint8_t* e, bool* success) { - using multisig = crypto::schnorr::multisig; + using multisig = crypto::schnorr_multisig; auto message = from_buffer(message_buf); auto signer_pubkeys = from_buffer>(signer_pubkeys_buf); diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp index f18caabe3fe..ba2049cc1e7 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.hpp @@ -7,7 +7,7 @@ extern "C" { using namespace bb; using affine_element = grumpkin::g1::affine_element; -using multisig = crypto::schnorr::multisig; +using multisig = crypto::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); diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.hpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.hpp index 525ec577a6e..4d48bfaec94 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.hpp @@ -12,7 +12,7 @@ #include "proof_of_possession.hpp" #include "schnorr.hpp" -namespace bb::crypto::schnorr { +namespace bb::crypto { /** * @brief Implements the SpeedyMuSig protocol; a secure 2-round interactive multisignature scheme @@ -25,7 +25,7 @@ namespace bb::crypto::schnorr { * * @details SpeedyMuSig paper at https://eprint.iacr.org/2021/1375.pdf */ -template class multisig { +template class schnorr_multisig { // ensure that a different hash function is used for signature and proof of possession/nonce. // we can apply domain separation for HashRegNon but not for HashSig, so this ensures all hash functions @@ -37,7 +37,7 @@ template cl using Fr = typename G1::subgroup_field; using affine_element = typename G1::affine_element; using element = typename G1::element; - using key_pair = crypto::schnorr::key_pair; + using key_pair = crypto::schnorr_key_pair; /** * @brief MultiSigPublicKey wraps a signer's public key g1::affine_element @@ -56,7 +56,7 @@ template cl affine_element public_key = G1::affine_point_at_infinity; // proof of knowledge of the secret_key for public_key - ProofOfPossession proof_of_possession; + SchnorrProofOfPossession proof_of_possession; // For serialization, update with any new fields MSGPACK_FIELDS(public_key, proof_of_possession); @@ -69,15 +69,15 @@ template cl {} // Needed to appease MSGPACK_FIELDS MultiSigPublicKey(const affine_element& public_key, - const ProofOfPossession& proof_of_possession) + const SchnorrProofOfPossession& proof_of_possession) : public_key(public_key) , proof_of_possession(proof_of_possession) {} }; struct RoundOnePrivateOutput { - typedef uint8_t const* in_buf; - typedef uint8_t* out_buf; + using in_buf = const uint8_t*; + using out_buf = uint8_t*; Fr r; Fr s; @@ -86,10 +86,10 @@ template cl }; struct RoundOnePublicOutput { - typedef uint8_t const* in_buf; - typedef uint8_t const* vec_in_buf; - typedef uint8_t* out_buf; - typedef uint8_t** vec_out_buf; + using in_buf = const uint8_t*; + using vec_in_buf = const uint8_t*; + using out_buf = uint8_t*; + using vec_out_buf = uint8_t**; // R = r⋅G affine_element R; @@ -371,7 +371,7 @@ template cl affine_element R = construct_multisig_nonce(a, round_1_nonces); // Now we have the multisig nonce, compute schnorr challenge e (termed `c` in the speedyMuSig paper) - auto e_buf = generate_schnorr_challenge(message, *aggregate_pubkey, R); + auto e_buf = schnorr_generate_challenge(message, *aggregate_pubkey, R); Fr e = Fr::serialize_from_buffer(&e_buf[0]); // output of round 2 is z @@ -391,7 +391,7 @@ template cl * @return signature it's a Schnorr signature! Looks identical to a regular non-multisig Schnorr signature. * @return std::nullopt if any of the signature shares are invalid */ - static std::optional combine_signatures( + static std::optional combine_signatures( const std::string& message, const std::vector& signer_pubkeys, const std::vector& round_1_nonces, @@ -423,9 +423,9 @@ template cl // compute aggregate nonce R = R1 + ... + Rn + S1 * a + ... + Sn * a affine_element R = construct_multisig_nonce(a, round_1_nonces); - auto e_buf = generate_schnorr_challenge(message, *aggregate_pubkey, R); + auto e_buf = schnorr_generate_challenge(message, *aggregate_pubkey, R); - signature sig; + schnorr_signature sig; // copy e as its raw bit representation (without modular reduction) std::copy(e_buf.begin(), e_buf.end(), sig.e.begin()); @@ -437,11 +437,11 @@ template cl Fr::serialize_to_buffer(s, &sig.s[0]); // verify the final signature before returning - if (!verify_signature(message, *aggregate_pubkey, sig)) { + if (!schnorr_verify_signature(message, *aggregate_pubkey, sig)) { return std::nullopt; } return sig; } }; -} // namespace bb::crypto::schnorr +} // namespace bb::crypto diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.test.cpp index e21f8231e7b..fdff67dfdfb 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.test.cpp @@ -8,8 +8,8 @@ using namespace bb; template struct MultisigTest : public ::testing::Test { using G = grumpkin::g1; using Fr = grumpkin::fr; - using KeyPair = crypto::schnorr::key_pair; - using multisig = crypto::schnorr::multisig; + using KeyPair = crypto::schnorr_key_pair; + using multisig = crypto::schnorr_multisig; using multisig_public_key = typename multisig::MultiSigPublicKey; static KeyPair generate_account() @@ -31,9 +31,9 @@ template struct MultisigTest : public ::testing::Test { return signer_pubkeys; } - static std::optional create_multisig(const std::string& message, - const std::vector& accounts, - const bool tamper_proof_of_possession = false) + static std::optional create_multisig(const std::string& message, + const std::vector& accounts, + const bool tamper_proof_of_possession = false) { std::vector round1_pub; std::vector round1_priv; @@ -70,8 +70,8 @@ TYPED_TEST(MultisigTest, verify_multi_signature_blake2s) using G = grumpkin::g1; using Fr = grumpkin::fr; using Fq = grumpkin::fq; - using KeyPair = crypto::schnorr::key_pair; - using multisig = crypto::schnorr::multisig; + using KeyPair = crypto::schnorr_key_pair; + using multisig = crypto::schnorr_multisig; std::string message = "The quick brown dog jumped over the lazy fox."; @@ -88,7 +88,7 @@ TYPED_TEST(MultisigTest, verify_multi_signature_blake2s) auto pub_key = multisig::validate_and_combine_signer_pubkeys(this->create_signer_pubkeys(accounts)); ASSERT_TRUE(pub_key.has_value()); - bool result = crypto::schnorr::verify_signature(message, *pub_key, *signature); + bool result = crypto::schnorr_verify_signature(message, *pub_key, *signature); EXPECT_EQ(result, true); } @@ -97,7 +97,7 @@ TYPED_TEST(MultisigTest, multi_signature_fails_if_proof_of_possession_invalid) { using G = grumpkin::g1; using Fr = grumpkin::fr; - using KeyPair = crypto::schnorr::key_pair; + using KeyPair = crypto::schnorr_key_pair; std::string message = "The quick brown dog jumped over the lazy fox."; @@ -116,7 +116,7 @@ TYPED_TEST(MultisigTest, multi_signature_fails_if_duplicates) { using G = grumpkin::g1; using Fr = grumpkin::fr; - using KeyPair = crypto::schnorr::key_pair; + using KeyPair = crypto::schnorr_key_pair; std::string message = "The quick brown dog jumped over the lazy fox."; diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/proof_of_possession.hpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/proof_of_possession.hpp index b54d6ff3c8d..f99878900c5 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/proof_of_possession.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/proof_of_possession.hpp @@ -5,7 +5,7 @@ #include "barretenberg/common/serialize.hpp" #include "schnorr.hpp" -namespace bb::crypto::schnorr { +namespace bb::crypto { /** * @brief A proof of possession is a Schnorr proof of knowledge of a secret key corresponding to a given public key. @@ -15,12 +15,12 @@ namespace bb::crypto::schnorr { * @tparam G1 group over which the key pair was generated * @tparam Hash function used to derive the Fiat-Shamir challenge */ -template struct ProofOfPossession { +template struct SchnorrProofOfPossession { using Fq = typename G1::coordinate_field; using Fr = typename G1::subgroup_field; using affine_element = typename G1::affine_element; using element = typename G1::element; - using key_pair = crypto::schnorr::key_pair; + using key_pair = crypto::schnorr_key_pair; // challenge = e = H_reg(pk,pk,R) std::array challenge; @@ -28,7 +28,7 @@ template struct ProofOfPossession { Fr response = Fr::zero(); // restore default constructor to enable deserialization - ProofOfPossession() = default; + SchnorrProofOfPossession() = default; /** * @brief Create a new proof of possession for a given account. @@ -37,7 +37,7 @@ template struct ProofOfPossession { * * @param account a key_pair (secret_key, public_key) */ - ProofOfPossession(const key_pair& account) + SchnorrProofOfPossession(const key_pair& account) { auto secret_key = account.private_key; auto public_key = account.public_key; @@ -121,17 +121,17 @@ template struct ProofOfPossession { }; template -inline void read(B& it, ProofOfPossession& proof_of_possession) +inline void read(B& it, SchnorrProofOfPossession& proof_of_possession) { read(it, proof_of_possession.challenge); read(it, proof_of_possession.response); } template -inline void write(B& buf, ProofOfPossession const& proof_of_possession) +inline void write(B& buf, SchnorrProofOfPossession const& proof_of_possession) { write(buf, proof_of_possession.challenge); write(buf, proof_of_possession.response); } -} // namespace bb::crypto::schnorr +} // namespace bb::crypto 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 92f46cc3eba..6432209fc85 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 @@ -8,7 +8,7 @@ using namespace bb; template struct ProofOfPossessionTest : public ::testing::Test { using G = grumpkin::g1; using Fr = grumpkin::fr; - using KeyPair = crypto::schnorr::key_pair; + using KeyPair = crypto::schnorr_key_pair; static KeyPair generate_account() { @@ -26,7 +26,7 @@ TYPED_TEST(ProofOfPossessionTest, valid_proof) { using G = grumpkin::g1; using Hash = TypeParam; - using Proof = crypto::schnorr::ProofOfPossession; + using Proof = crypto::SchnorrProofOfPossession; const auto account = this->generate_account(); const auto proof = Proof(account); @@ -37,7 +37,7 @@ TYPED_TEST(ProofOfPossessionTest, invalid_empty_proof) { using G = grumpkin::g1; using Hash = TypeParam; - using Proof = crypto::schnorr::ProofOfPossession; + using Proof = crypto::SchnorrProofOfPossession; const auto account = this->generate_account(); const auto proof = Proof(); @@ -48,7 +48,7 @@ TYPED_TEST(ProofOfPossessionTest, fail_with_different_account) { using G = grumpkin::g1; using Hash = TypeParam; - using Proof = crypto::schnorr::ProofOfPossession; + using Proof = crypto::SchnorrProofOfPossession; const auto account1 = this->generate_account(); const auto account2 = this->generate_account(); @@ -60,7 +60,7 @@ TYPED_TEST(ProofOfPossessionTest, fail_zero_challenge) { using G = grumpkin::g1; using Hash = TypeParam; - using Proof = crypto::schnorr::ProofOfPossession; + using Proof = crypto::SchnorrProofOfPossession; const auto account = this->generate_account(); auto proof = Proof(account); @@ -74,7 +74,7 @@ TYPED_TEST(ProofOfPossessionTest, fail_zero_response) { using G = grumpkin::g1; using Hash = TypeParam; - using Proof = crypto::schnorr::ProofOfPossession; + using Proof = crypto::SchnorrProofOfPossession; const auto account = this->generate_account(); auto proof = Proof(account); @@ -87,7 +87,7 @@ TYPED_TEST(ProofOfPossessionTest, serialize) { using G = grumpkin::g1; using Hash = TypeParam; - using Proof = crypto::schnorr::ProofOfPossession; + using Proof = crypto::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/schnorr/schnorr.hpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/schnorr.hpp index d9e60eba499..81ca306effc 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/schnorr.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/schnorr.hpp @@ -12,8 +12,8 @@ #include "barretenberg/common/streams.hpp" #include "barretenberg/serialize/msgpack.hpp" -namespace bb::crypto::schnorr { -template struct key_pair { +namespace bb::crypto { +template struct schnorr_key_pair { Fr private_key; typename G1::affine_element public_key; }; @@ -21,7 +21,7 @@ template struct key_pair { // Raw representation of a Schnorr signature (e,s). We use the short variant of Schnorr // where we include the challenge hash `e` instead of the group element R representing // the provers initial message. -struct signature { +struct schnorr_signature { // `s` is a serialized field element (also 32 bytes), representing the prover's response to // to the verifier challenge `e`. @@ -35,32 +35,34 @@ struct signature { }; template -bool verify_signature(const std::string& message, const typename G1::affine_element& public_key, const signature& sig); +bool schnorr_verify_signature(const std::string& message, + const typename G1::affine_element& public_key, + const schnorr_signature& sig); template -signature construct_signature(const std::string& message, const key_pair& account); +schnorr_signature schnorr_construct_signature(const std::string& message, const schnorr_key_pair& account); -inline bool operator==(signature const& lhs, signature const& rhs) +inline bool operator==(schnorr_signature const& lhs, schnorr_signature const& rhs) { return lhs.s == rhs.s && lhs.e == rhs.e; } -inline std::ostream& operator<<(std::ostream& os, signature const& sig) +inline std::ostream& operator<<(std::ostream& os, schnorr_signature const& sig) { os << "{ " << sig.s << ", " << sig.e << " }"; return os; } -template inline void read(B& it, key_pair& keypair) +template inline void read(B& it, schnorr_key_pair& keypair) { read(it, keypair.private_key); read(it, keypair.public_key); } -template inline void write(B& buf, key_pair const& keypair) +template inline void write(B& buf, schnorr_key_pair const& keypair) { write(buf, keypair.private_key); write(buf, keypair.public_key); } -} // namespace bb::crypto::schnorr +} // namespace bb::crypto #include "./schnorr.tcc" diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/schnorr.tcc b/barretenberg/cpp/src/barretenberg/crypto/schnorr/schnorr.tcc index fc2c69b63df..455101e7548 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/schnorr.tcc +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/schnorr.tcc @@ -5,7 +5,7 @@ #include "schnorr.hpp" -namespace bb::crypto::schnorr { +namespace bb::crypto { /** * @brief Generate the schnorr signature challenge parameter `e` given a message, signer pubkey and nonce @@ -36,7 +36,7 @@ namespace bb::crypto::schnorr { * are always private inputs to circuits) then nothing would be revealed anyway. */ template -static auto generate_schnorr_challenge(const std::string& message, +static auto schnorr_generate_challenge(const std::string& message, const typename G1::affine_element& pubkey, const typename G1::affine_element& R) { @@ -70,7 +70,7 @@ static auto generate_schnorr_challenge(const std::string& message, * @return signature */ template -signature construct_signature(const std::string& message, const key_pair& account) +schnorr_signature schnorr_construct_signature(const std::string& message, const schnorr_key_pair& account) { // sanity check to ensure our hash function produces `e_raw` // of exactly 32 bytes. @@ -93,7 +93,7 @@ signature construct_signature(const std::string& message, const key_pair typename G1::affine_element R(G1::one * k); - auto e_raw = generate_schnorr_challenge(message, public_key, R); + auto e_raw = schnorr_generate_challenge(message, public_key, R); // the conversion from e_raw results in a biased field element e Fr e = Fr::serialize_from_buffer(&e_raw[0]); Fr s = k - (private_key * e); @@ -105,17 +105,19 @@ signature construct_signature(const std::string& message, const key_pair // and e = e_uint % r, where r is the order of the curve, // and pk as the point representing the public_key, // then e•pk = e_uint•pk - signature sig; + schnorr_signature sig; Fr::serialize_to_buffer(s, &sig.s[0]); std::copy(e_raw.begin(), e_raw.end(), sig.e.begin()); return sig; } /** - * @brief Verify a Schnorr signature of the sort produced by construct_signature. + * @brief Verify a Schnorr signature of the sort produced by schnorr_construct_signature. */ template -bool verify_signature(const std::string& message, const typename G1::affine_element& public_key, const signature& sig) +bool schnorr_verify_signature(const std::string& message, + const typename G1::affine_element& public_key, + const schnorr_signature& sig) { using affine_element = typename G1::affine_element; using element = typename G1::element; @@ -148,7 +150,7 @@ bool verify_signature(const std::string& message, const typename G1::affine_elem // compare the _hashes_ rather than field elements modulo r // e = H(pedersen(r, pk.x, pk.y), m), where r = x(R) - auto target_e = generate_schnorr_challenge(message, public_key, R); + auto target_e = schnorr_generate_challenge(message, public_key, R); return std::equal(sig.e.begin(), sig.e.end(), target_e.begin(), target_e.end()); } -} // namespace bb::crypto::schnorr +} // namespace bb::crypto diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/schnorr.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/schnorr.test.cpp index 63bde7814aa..6946053a4a8 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/schnorr.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/schnorr.test.cpp @@ -3,11 +3,11 @@ #include using namespace bb; -using namespace bb::crypto::schnorr; +using namespace bb::crypto; -crypto::schnorr::key_pair generate_signature() +crypto::schnorr_key_pair generate_signature() { - crypto::schnorr::key_pair account; + crypto::schnorr_key_pair account; account.private_key = grumpkin::fr::random_element(); account.public_key = grumpkin::g1::one * account.private_key; return account; @@ -17,14 +17,14 @@ TEST(schnorr, verify_signature_keccak256) { std::string message = "The quick brown fox jumped over the lazy dog."; - crypto::schnorr::key_pair account; + crypto::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, account); + crypto::schnorr_signature signature = + crypto::schnorr_construct_signature(message, account); - bool result = crypto::schnorr::verify_signature( + bool result = crypto::schnorr_verify_signature( message, account.public_key, signature); EXPECT_EQ(result, true); @@ -34,14 +34,14 @@ TEST(schnorr, verify_signature_sha256) { std::string message = "The quick brown dog jumped over the lazy fox."; - crypto::schnorr::key_pair account; + crypto::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, account); + crypto::schnorr_signature signature = + crypto::schnorr_construct_signature(message, account); - bool result = crypto::schnorr::verify_signature( + bool result = crypto::schnorr_verify_signature( message, account.public_key, signature); EXPECT_EQ(result, true); @@ -51,15 +51,15 @@ TEST(schnorr, verify_signature_blake2s) { std::string message = "The quick brown dog jumped over the lazy fox."; - crypto::schnorr::key_pair account; + crypto::schnorr_key_pair account; // account.private_key = grumpkin::fr::random_element(); account.private_key = { 0x55555555, 0x55555555, 0x55555555, 0x55555555 }; account.public_key = grumpkin::g1::one * account.private_key; - crypto::schnorr::signature signature = - crypto::schnorr::construct_signature(message, account); + crypto::schnorr_signature signature = + crypto::schnorr_construct_signature(message, account); - bool result = crypto::schnorr::verify_signature( + bool result = crypto::schnorr_verify_signature( message, account.public_key, signature); EXPECT_EQ(result, true); @@ -78,62 +78,62 @@ TEST(schnorr, hmac_signature_consistency) // k is no longer identical, so signatures should be different. auto signature_a = - construct_signature(message_a, account_a); + schnorr_construct_signature(message_a, account_a); auto signature_b = - construct_signature(message_a, account_a); + schnorr_construct_signature(message_a, account_a); ASSERT_NE(signature_a.e, signature_b.e); ASSERT_NE(signature_a.s, signature_b.s); // same message, different accounts should give different sigs! auto signature_c = - construct_signature(message_a, account_a); + schnorr_construct_signature(message_a, account_a); auto signature_d = - construct_signature(message_a, account_b); + schnorr_construct_signature(message_a, account_b); ASSERT_NE(signature_c.e, signature_d.e); ASSERT_NE(signature_c.s, signature_d.s); // different message, same accounts should give different sigs! auto signature_e = - construct_signature(message_a, account_a); + schnorr_construct_signature(message_a, account_a); auto signature_f = - construct_signature(message_b, account_a); + schnorr_construct_signature(message_b, account_a); ASSERT_NE(signature_e.e, signature_f.e); ASSERT_NE(signature_e.s, signature_f.s); // different message, different accounts should give different sigs!! auto signature_g = - construct_signature(message_a, account_a); + schnorr_construct_signature(message_a, account_a); auto signature_h = - construct_signature(message_b, account_b); + schnorr_construct_signature(message_b, account_b); ASSERT_NE(signature_g.e, signature_h.e); ASSERT_NE(signature_g.s, signature_h.s); - bool res = verify_signature( + bool res = schnorr_verify_signature( message_a, account_a.public_key, signature_a); EXPECT_EQ(res, true); - res = verify_signature( + res = schnorr_verify_signature( message_a, account_a.public_key, signature_b); EXPECT_EQ(res, true); - res = verify_signature( + res = schnorr_verify_signature( message_a, account_a.public_key, signature_c); EXPECT_EQ(res, true); - res = verify_signature( + res = schnorr_verify_signature( message_a, account_b.public_key, signature_d); EXPECT_EQ(res, true); - res = verify_signature( + res = schnorr_verify_signature( message_a, account_a.public_key, signature_e); EXPECT_EQ(res, true); - res = verify_signature( + res = schnorr_verify_signature( message_b, account_a.public_key, signature_f); EXPECT_EQ(res, true); - res = verify_signature( + res = schnorr_verify_signature( message_a, account_a.public_key, signature_g); EXPECT_EQ(res, true); - res = verify_signature( + res = schnorr_verify_signature( message_b, account_b.public_key, signature_h); EXPECT_EQ(res, true); } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp index 7299d359bc3..02fc648a321 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -6,7 +6,7 @@ namespace acir_format { template -void build_constraints(Builder& builder, acir_format const& constraint_system, bool has_valid_witness_assignments) +void build_constraints(Builder& builder, AcirFormat const& constraint_system, bool has_valid_witness_assignments) { // Add arithmetic gates for (const auto& constraint : constraint_system.constraints) { @@ -188,7 +188,7 @@ void build_constraints(Builder& builder, acir_format const& constraint_system, b * @return Builder */ template -Builder create_circuit(const acir_format& constraint_system, size_t size_hint, WitnessVector const& witness) +Builder create_circuit(const AcirFormat& constraint_system, size_t size_hint, WitnessVector const& witness) { Builder builder{ size_hint, witness, constraint_system.public_inputs, constraint_system.varnum }; @@ -198,9 +198,9 @@ Builder create_circuit(const acir_format& constraint_system, size_t size_hint, W return builder; } -template UltraCircuitBuilder create_circuit(const acir_format& constraint_system, +template UltraCircuitBuilder create_circuit(const AcirFormat& constraint_system, size_t size_hint, WitnessVector const& witness); -template void build_constraints(GoblinUltraCircuitBuilder&, acir_format const&, bool); +template void build_constraints(GoblinUltraCircuitBuilder&, AcirFormat const&, bool); } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp index 1cd81b2edbb..a8768d340f4 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp @@ -18,7 +18,7 @@ namespace acir_format { -struct acir_format { +struct AcirFormat { // The number of witnesses in the circuit uint32_t varnum; @@ -71,15 +71,15 @@ struct acir_format { constraints, block_constraints); - friend bool operator==(acir_format const& lhs, acir_format const& rhs) = default; + friend bool operator==(AcirFormat const& lhs, AcirFormat const& rhs) = default; }; using WitnessVector = std::vector>; template -Builder create_circuit(const acir_format& constraint_system, size_t size_hint = 0, WitnessVector const& witness = {}); +Builder create_circuit(const AcirFormat& constraint_system, size_t size_hint = 0, WitnessVector const& witness = {}); template -void build_constraints(Builder& builder, acir_format const& constraint_system, bool has_valid_witness_assignments); +void build_constraints(Builder& builder, AcirFormat const& constraint_system, bool has_valid_witness_assignments); } // namespace acir_format 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 7aa0a0364ff..92e70b64a16 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,7 +7,7 @@ #include "barretenberg/serialize/test_helper.hpp" #include "ecdsa_secp256k1.hpp" -namespace acir_format::tests { +using namespace acir_format; class AcirFormatTests : public ::testing::Test { protected: @@ -27,7 +27,7 @@ TEST_F(AcirFormatTests, TestASingleConstraintNoPubInputs) .q_c = 0, }; - acir_format constraint_system{ + AcirFormat constraint_system{ .varnum = 4, .public_inputs = {}, .logic_constraints = {}, @@ -139,27 +139,27 @@ TEST_F(AcirFormatTests, TestLogicGateFromNoirCircuit) // EXPR [ (1, _4, _6) (-1, _4) 0 ] // EXPR [ (-1, _6) 1 ] - acir_format constraint_system{ .varnum = 6, - .public_inputs = { 1 }, - .logic_constraints = { logic_constraint }, - .range_constraints = { range_a, range_b }, - .sha256_constraints = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_var_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .fixed_base_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .ec_double_constraints = {}, - .recursion_constraints = {}, - .constraints = { expr_a, expr_b, expr_c, expr_d }, - .block_constraints = {} }; + AcirFormat constraint_system{ .varnum = 6, + .public_inputs = { 1 }, + .logic_constraints = { logic_constraint }, + .range_constraints = { range_a, range_b }, + .sha256_constraints = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_var_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, + .recursion_constraints = {}, + .constraints = { expr_a, expr_b, expr_c, expr_d }, + .block_constraints = {} }; uint256_t inverse_of_five = fr(5).invert(); WitnessVector witness{ @@ -202,44 +202,44 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass) .result = 76, .signature = signature, }; - acir_format constraint_system{ .varnum = 81, - .public_inputs = {}, - .logic_constraints = {}, - .range_constraints = range_constraints, - .sha256_constraints = {}, - .schnorr_constraints = { schnorr_constraint }, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_var_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .fixed_base_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .ec_double_constraints = {}, - .recursion_constraints = {}, - .constraints = { poly_triple{ - .a = schnorr_constraint.result, - .b = schnorr_constraint.result, - .c = schnorr_constraint.result, - .q_m = 0, - .q_l = 0, - .q_r = 0, - .q_o = 1, - .q_c = fr::neg_one(), - } }, - .block_constraints = {} }; + AcirFormat constraint_system{ .varnum = 81, + .public_inputs = {}, + .logic_constraints = {}, + .range_constraints = range_constraints, + .sha256_constraints = {}, + .schnorr_constraints = { schnorr_constraint }, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_var_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, + .recursion_constraints = {}, + .constraints = { poly_triple{ + .a = schnorr_constraint.result, + .b = schnorr_constraint.result, + .c = schnorr_constraint.result, + .q_m = 0, + .q_l = 0, + .q_r = 0, + .q_o = 1, + .q_c = fr::neg_one(), + } }, + .block_constraints = {} }; std::string message_string = "tenletters"; - crypto::schnorr::key_pair account; + crypto::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); + crypto::schnorr_signature signature_raw = + crypto::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, @@ -292,7 +292,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange) .result = 76, .signature = signature, }; - acir_format constraint_system{ + AcirFormat constraint_system{ .varnum = 81, .public_inputs = {}, .logic_constraints = {}, @@ -326,12 +326,12 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange) }; std::string message_string = "tenletters"; - crypto::schnorr::key_pair account; + crypto::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); + crypto::schnorr_signature signature_raw = + crypto::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, @@ -402,7 +402,7 @@ TEST_F(AcirFormatTests, TestVarKeccak) .q_c = fr::neg_one() * fr(4), }; - acir_format constraint_system{ + AcirFormat constraint_system{ .varnum = 36, .public_inputs = {}, .logic_constraints = {}, @@ -445,27 +445,27 @@ TEST_F(AcirFormatTests, TestKeccakPermutation) 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50 }, }; - acir_format constraint_system{ .varnum = 51, - .public_inputs = {}, - .logic_constraints = {}, - .range_constraints = {}, - .sha256_constraints = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_var_constraints = {}, - .keccak_permutations = { keccak_permutation }, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .fixed_base_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .ec_double_constraints = {}, - .recursion_constraints = {}, - .constraints = {}, - .block_constraints = {} }; + AcirFormat constraint_system{ .varnum = 51, + .public_inputs = {}, + .logic_constraints = {}, + .range_constraints = {}, + .sha256_constraints = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_var_constraints = {}, + .keccak_permutations = { keccak_permutation }, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, + .recursion_constraints = {}, + .constraints = {}, + .block_constraints = {} }; WitnessVector witness{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, @@ -481,5 +481,3 @@ TEST_F(AcirFormatTests, TestKeccakPermutation) EXPECT_EQ(verifier.verify_proof(proof), true); } - -} // namespace acir_format::tests diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 4e6b0f8a617..ee539a47ba2 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -96,12 +96,12 @@ poly_triple serialize_arithmetic_gate(Circuit::Expression const& arg) return pt; } -void handle_arithmetic(Circuit::Opcode::AssertZero const& arg, acir_format& af) +void handle_arithmetic(Circuit::Opcode::AssertZero const& arg, AcirFormat& af) { af.constraints.push_back(serialize_arithmetic_gate(arg.value)); } -void handle_blackbox_func_call(Circuit::Opcode::BlackBoxFuncCall const& arg, acir_format& af) +void handle_blackbox_func_call(Circuit::Opcode::BlackBoxFuncCall const& arg, AcirFormat& af) { std::visit( [&](auto&& arg) { @@ -289,11 +289,11 @@ void handle_memory_op(Circuit::Opcode::MemoryOp const& mem_op, BlockConstraint& block.trace.push_back(acir_mem_op); } -acir_format circuit_buf_to_acir_format(std::vector const& buf) +AcirFormat circuit_buf_to_acir_format(std::vector const& buf) { auto circuit = Circuit::Circuit::bincodeDeserialize(buf); - acir_format af; + AcirFormat af; // `varnum` is the true number of variables, thus we add one to the index which starts at zero af.varnum = circuit.current_witness_index + 1; af.public_inputs = join({ map(circuit.public_parameters.value, [](auto e) { return e.value; }), diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp index cb87035cae5..d90a2a7879b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp @@ -6,7 +6,7 @@ #include #include -namespace acir_format::tests { +using namespace acir_format; class UltraPlonkRAM : public ::testing::Test { protected: @@ -19,7 +19,7 @@ size_t generate_block_constraint(BlockConstraint& constraint, WitnessVector& wit witness_len++; fr two = fr::one() + fr::one(); - poly_triple a0 = poly_triple{ + poly_triple a0{ .a = 0, .b = 0, .c = 0, @@ -30,7 +30,7 @@ size_t generate_block_constraint(BlockConstraint& constraint, WitnessVector& wit .q_c = 0, }; fr three = fr::one() + two; - poly_triple a1 = poly_triple{ + poly_triple a1{ .a = 0, .b = 0, .c = 0, @@ -40,7 +40,7 @@ size_t generate_block_constraint(BlockConstraint& constraint, WitnessVector& wit .q_o = 0, .q_c = three, }; - poly_triple r1 = poly_triple{ + poly_triple r1{ .a = 0, .b = 0, .c = 0, @@ -50,7 +50,7 @@ size_t generate_block_constraint(BlockConstraint& constraint, WitnessVector& wit .q_o = 0, .q_c = fr::neg_one(), }; - poly_triple r2 = poly_triple{ + poly_triple r2{ .a = 0, .b = 0, .c = 0, @@ -60,7 +60,7 @@ size_t generate_block_constraint(BlockConstraint& constraint, WitnessVector& wit .q_o = 0, .q_c = fr::neg_one(), }; - poly_triple y = poly_triple{ + poly_triple y{ .a = 1, .b = 0, .c = 0, @@ -72,7 +72,7 @@ size_t generate_block_constraint(BlockConstraint& constraint, WitnessVector& wit }; witness_values.emplace_back(2); witness_len++; - poly_triple z = poly_triple{ + poly_triple z{ .a = 2, .b = 0, .c = 0, @@ -84,12 +84,12 @@ size_t generate_block_constraint(BlockConstraint& constraint, WitnessVector& wit }; witness_values.emplace_back(3); witness_len++; - MemOp op1 = MemOp{ + MemOp op1{ .access_type = 0, .index = r1, .value = y, }; - MemOp op2 = MemOp{ + MemOp op2{ .access_type = 0, .index = r2, .value = z, @@ -108,7 +108,7 @@ TEST_F(UltraPlonkRAM, TestBlockConstraint) BlockConstraint block; WitnessVector witness_values; size_t num_variables = generate_block_constraint(block, witness_values); - acir_format constraint_system{ + AcirFormat constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, .logic_constraints = {}, @@ -141,4 +141,3 @@ TEST_F(UltraPlonkRAM, TestBlockConstraint) auto verifier = composer.create_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } -} // namespace acir_format::tests 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 3f0d17b86b6..ce6ff2dafc5 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp @@ -6,10 +6,10 @@ namespace acir_format { using namespace bb::plonk; template -crypto::ecdsa::signature ecdsa_convert_signature(Builder& builder, std::vector signature) +crypto::ecdsa_signature ecdsa_convert_signature(Builder& builder, std::vector signature) { - crypto::ecdsa::signature signature_cr; + crypto::ecdsa_signature signature_cr; // Get the witness assignment for each witness index // Write the witness assignment to the byte_array @@ -117,9 +117,9 @@ void create_ecdsa_k1_verify_constraints(Builder& builder, std::vector ss(new_sig.s.begin(), new_sig.s.end()); uint8_t vv = new_sig.v; - stdlib::ecdsa::signature sig{ stdlib::byte_array(&builder, rr), - stdlib::byte_array(&builder, ss), - stdlib::uint8(&builder, vv) }; + stdlib::ecdsa_signature sig{ stdlib::byte_array(&builder, rr), + stdlib::byte_array(&builder, ss), + stdlib::uint8(&builder, vv) }; pub_key_x_fq.assert_is_in_field(); pub_key_y_fq.assert_is_in_field(); @@ -135,11 +135,11 @@ void create_ecdsa_k1_verify_constraints(Builder& builder, } bool_ct signature_result = - stdlib::ecdsa::verify_signature_prehashed_message_noassert( + stdlib::ecdsa_verify_signature_prehashed_message_noassert( message, public_key, sig); bool_ct signature_result_normalized = signature_result.normalize(); builder.assert_equal(signature_result_normalized.witness_index, input.result); @@ -160,14 +160,14 @@ template void dummy_ecdsa_constraint(Builder& builder, EcdsaS signature_.resize(64); // Create a valid signature with a valid public key - crypto::ecdsa::key_pair account; + crypto::ecdsa_key_pair account; account.private_key = 10; account.public_key = secp256k1_ct::g1::one * account.private_key; uint256_t pub_x_value = account.public_key.x; 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_signature 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.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp index 45633d1728e..7dd69f6af90 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp @@ -38,7 +38,7 @@ void create_ecdsa_k1_verify_constraints(Builder& builder, template void dummy_ecdsa_constraint(Builder& builder, EcdsaSecp256k1Constraint const& input); template -crypto::ecdsa::signature ecdsa_convert_signature(Builder& builder, std::vector signature); +crypto::ecdsa_signature ecdsa_convert_signature(Builder& builder, std::vector signature); witness_ct ecdsa_index_to_witness(Builder& builder, uint32_t index); template bb::stdlib::byte_array ecdsa_vector_of_bytes_to_byte_array(Builder& builder, 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 841e71a148d..5554fdd8d6d 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,8 +7,8 @@ #include #include -namespace acir_format::tests { -using curve_ct = bb::stdlib::secp256k1; +using namespace acir_format; +using curve_ct = stdlib::secp256k1; class ECDSASecp256k1 : public ::testing::Test { protected: @@ -25,13 +25,13 @@ size_t generate_ecdsa_constraint(EcdsaSecp256k1Constraint& ecdsa_constraint, Wit std::copy(message_string.begin(), message_string.end(), std::back_inserter(message_buffer)); auto hashed_message = sha256::sha256(message_buffer); - crypto::ecdsa::key_pair account; + crypto::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); + crypto::ecdsa_signature signature = + crypto::ecdsa_construct_signature(message_string, + account); uint256_t pub_x_value = account.public_key.x; uint256_t pub_y_value = account.public_key.y; @@ -87,7 +87,7 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintSucceed) EcdsaSecp256k1Constraint ecdsa_k1_constraint; WitnessVector witness_values; size_t num_variables = generate_ecdsa_constraint(ecdsa_k1_constraint, witness_values); - acir_format constraint_system{ + AcirFormat constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, .logic_constraints = {}, @@ -131,7 +131,7 @@ TEST_F(ECDSASecp256k1, TestECDSACompilesForVerifier) EcdsaSecp256k1Constraint ecdsa_k1_constraint; WitnessVector witness_values; size_t num_variables = generate_ecdsa_constraint(ecdsa_k1_constraint, witness_values); - acir_format constraint_system{ + AcirFormat constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, .logic_constraints = {}, @@ -170,7 +170,7 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintFail) // tamper with signature witness_values[witness_values.size() - 20] += 1; - acir_format constraint_system{ + AcirFormat constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, .logic_constraints = {}, @@ -203,4 +203,3 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintFail) auto verifier = composer.create_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } -} // namespace acir_format::tests 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 59e20aeda0e..079c7169794 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.cpp @@ -49,9 +49,9 @@ void create_ecdsa_r1_verify_constraints(Builder& builder, std::vector ss(new_sig.s.begin(), new_sig.s.end()); uint8_t vv = new_sig.v; - stdlib::ecdsa::signature sig{ stdlib::byte_array(&builder, rr), - stdlib::byte_array(&builder, ss), - stdlib::uint8(&builder, vv) }; + stdlib::ecdsa_signature sig{ stdlib::byte_array(&builder, rr), + stdlib::byte_array(&builder, ss), + stdlib::uint8(&builder, vv) }; pub_key_x_fq.assert_is_in_field(); pub_key_y_fq.assert_is_in_field(); @@ -67,11 +67,11 @@ void create_ecdsa_r1_verify_constraints(Builder& builder, } bool_ct signature_result = - stdlib::ecdsa::verify_signature_prehashed_message_noassert( + stdlib::ecdsa_verify_signature_prehashed_message_noassert( message, public_key, sig); bool_ct signature_result_normalized = signature_result.normalize(); builder.assert_equal(signature_result_normalized.witness_index, input.result); @@ -100,13 +100,13 @@ template void dummy_ecdsa_constraint(Builder& builder, EcdsaS std::copy(message_string.begin(), message_string.end(), std::back_inserter(message_buffer)); auto hashed_message = sha256::sha256(message_buffer); - crypto::ecdsa::key_pair account; + crypto::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); + crypto::ecdsa_signature signature = + crypto::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 72b5a616afc..ebd78e1b672 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,8 +7,9 @@ #include #include -namespace acir_format::tests { -using curve_ct = bb::stdlib::secp256r1; +using namespace acir_format; + +using curve_ct = stdlib::secp256r1; // Generate r1 constraints given pre generated pubkey, sig and message values size_t generate_r1_constraints(EcdsaSecp256r1Constraint& ecdsa_r1_constraint, @@ -16,7 +17,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) + crypto::ecdsa_signature signature) { std::vector message_in; @@ -78,13 +79,13 @@ size_t generate_ecdsa_constraint(EcdsaSecp256r1Constraint& ecdsa_r1_constraint, std::copy(message_string.begin(), message_string.end(), std::back_inserter(message_buffer)); auto hashed_message = sha256::sha256(message_buffer); - crypto::ecdsa::key_pair account; + crypto::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); + crypto::ecdsa_signature signature = + crypto::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); @@ -105,7 +106,7 @@ TEST(ECDSASecp256r1, test_hardcoded) uint256_t pub_key_y = uint256_t("136093d7012e509a73715cbd0b00a3cc0ff4b5c01b3ffa196ab1fb327036b8e6"); // 0x2c70a8d084b62bfc5ce03641caf9f72ad4da8c81bfe6ec9487bb5e1bef62a13218ad9ee29eaf351fdc50f1520c425e9b908a07278b43b0ec7b872778c14e0784 - crypto::ecdsa::signature signature = { + 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, @@ -113,7 +114,7 @@ TEST(ECDSASecp256r1, test_hardcoded) .v = 0 }; - crypto::ecdsa::key_pair account; + crypto::ecdsa_key_pair account; account.private_key = curve_ct::fr(uint256_t("0202020202020202020202020202020202020202020202020202020202020202")); account.public_key = curve_ct::g1::one * account.private_key; @@ -121,7 +122,7 @@ TEST(ECDSASecp256r1, test_hardcoded) size_t num_variables = generate_r1_constraints(ecdsa_r1_constraint, witness_values, pub_key_x, pub_key_y, hashed_message, signature); - acir_format constraint_system{ + AcirFormat constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, .logic_constraints = {}, @@ -146,7 +147,7 @@ TEST(ECDSASecp256r1, test_hardcoded) }; secp256r1::g1::affine_element pub_key = { pub_key_x, pub_key_y }; - bool we_ballin = crypto::ecdsa::verify_signature( + bool we_ballin = crypto::ecdsa_verify_signature( message, pub_key, signature); EXPECT_EQ(we_ballin, true); @@ -166,7 +167,7 @@ TEST(ECDSASecp256r1, TestECDSAConstraintSucceed) EcdsaSecp256r1Constraint ecdsa_r1_constraint; WitnessVector witness_values; size_t num_variables = generate_ecdsa_constraint(ecdsa_r1_constraint, witness_values); - acir_format constraint_system{ + AcirFormat constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, .logic_constraints = {}, @@ -209,7 +210,7 @@ TEST(ECDSASecp256r1, TestECDSACompilesForVerifier) EcdsaSecp256r1Constraint ecdsa_r1_constraint; WitnessVector witness_values; size_t num_variables = generate_ecdsa_constraint(ecdsa_r1_constraint, witness_values); - acir_format constraint_system{ + AcirFormat constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, .logic_constraints = {}, @@ -247,7 +248,7 @@ TEST(ECDSASecp256r1, TestECDSAConstraintFail) // tamper with signature witness_values[witness_values.size() - 20] += 1; - acir_format constraint_system{ + AcirFormat constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, .logic_constraints = {}, @@ -281,4 +282,3 @@ TEST(ECDSASecp256r1, TestECDSAConstraintFail) auto verifier = composer.create_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } -} // namespace acir_format::tests diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp index 457184ed025..cbbdd2a22b9 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp @@ -6,13 +6,13 @@ #include #include +using namespace acir_format; using namespace bb::plonk; class AcirRecursionConstraint : public ::testing::Test { protected: static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } }; -namespace acir_format::test { Builder create_inner_circuit() { /** @@ -81,27 +81,27 @@ Builder create_inner_circuit() .q_c = 1, }; - acir_format constraint_system{ .varnum = 6, - .public_inputs = { 1, 2 }, - .logic_constraints = { logic_constraint }, - .range_constraints = { range_a, range_b }, - .sha256_constraints = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_var_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .fixed_base_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .ec_double_constraints = {}, - .recursion_constraints = {}, - .constraints = { expr_a, expr_b, expr_c, expr_d }, - .block_constraints = {} }; + AcirFormat constraint_system{ .varnum = 6, + .public_inputs = { 1, 2 }, + .logic_constraints = { logic_constraint }, + .range_constraints = { range_a, range_b }, + .sha256_constraints = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_var_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, + .recursion_constraints = {}, + .constraints = { expr_a, expr_b, expr_c, expr_d }, + .block_constraints = {} }; uint256_t inverse_of_five = fr(5).invert(); WitnessVector witness{ @@ -143,10 +143,10 @@ Builder create_outer_circuit(std::vector& inner_circuits) transcript::HashType::PedersenBlake3s, 16); - std::vector proof_witnesses = export_transcript_in_recursion_format(transcript); + std::vector proof_witnesses = export_transcript_in_recursion_format(transcript); // - Save the public inputs so that we can set their values. // - Then truncate them from the proof because the ACIR API expects proofs without public inputs - std::vector inner_public_input_values( + std::vector inner_public_input_values( proof_witnesses.begin(), proof_witnesses.begin() + static_cast(num_inner_public_inputs)); // We want to make sure that we do not remove the nested aggregation object in the case of the proof we want to @@ -233,27 +233,27 @@ Builder create_outer_circuit(std::vector& inner_circuits) circuit_idx++; } - acir_format constraint_system{ .varnum = static_cast(witness.size()), - .public_inputs = {}, - .logic_constraints = {}, - .range_constraints = {}, - .sha256_constraints = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_var_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .fixed_base_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .ec_double_constraints = {}, - .recursion_constraints = recursion_constraints, - .constraints = {}, - .block_constraints = {} }; + AcirFormat constraint_system{ .varnum = static_cast(witness.size()), + .public_inputs = {}, + .logic_constraints = {}, + .range_constraints = {}, + .sha256_constraints = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_var_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .ec_double_constraints = {}, + .recursion_constraints = recursion_constraints, + .constraints = {}, + .block_constraints = {} }; auto outer_circuit = create_circuit(constraint_system, /*size_hint*/ 0, witness); @@ -364,4 +364,3 @@ TEST_F(AcirRecursionConstraint, TestFullRecursiveComposition) auto verifier = layer_3_composer.create_ultra_with_keccak_verifier(layer_3_circuit); EXPECT_EQ(verifier.verify_proof(proof), true); } -} // namespace acir_format::test diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp index 931ee470903..b4d7f4737d5 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp @@ -7,10 +7,10 @@ namespace acir_format { using namespace bb::stdlib; template -crypto::schnorr::signature convert_signature(Builder& builder, std::vector signature) +crypto::schnorr_signature convert_signature(Builder& builder, std::vector signature) { - crypto::schnorr::signature signature_cr; + crypto::schnorr_signature signature_cr; // Get the witness assignment for each witness index // Write the witness assignment to the byte_array @@ -75,7 +75,7 @@ template void create_schnorr_verify_constraints(Builder& buil { using witness_ct = bb::stdlib::witness_t; using cycle_group_ct = bb::stdlib::cycle_group; - using schnorr_signature_bits_ct = bb::stdlib::schnorr::signature_bits; + using schnorr_signature_bits_ct = bb::stdlib::schnorr_signature_bits; using bool_ct = bb::stdlib::bool_t; auto new_sig = convert_signature(builder, input.signature); @@ -93,9 +93,9 @@ template void create_schnorr_verify_constraints(Builder& buil cycle_group_ct pub_key{ witness_ct(&builder, pubkey_value_x), witness_ct(&builder, pubkey_value_y), false }; - schnorr_signature_bits_ct sig = schnorr::convert_signature(&builder, new_sig); + schnorr_signature_bits_ct sig = schnorr_convert_signature(&builder, new_sig); - bool_ct signature_result = schnorr::signature_verification_result(message, pub_key, sig); + bool_ct signature_result = schnorr_signature_verification_result(message, pub_key, sig); bool_ct signature_result_normalized = signature_result.normalize(); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp index 86239cbb481..072540db80f 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp @@ -24,7 +24,7 @@ AcirComposer::AcirComposer(size_t size_hint, bool verbose) * @param witness */ template -void AcirComposer::create_circuit(acir_format::acir_format& constraint_system, WitnessVector const& witness) +void AcirComposer::create_circuit(acir_format::AcirFormat& constraint_system, WitnessVector const& witness) { vinfo("building circuit..."); builder_ = acir_format::create_circuit(constraint_system, size_hint_, witness); @@ -149,7 +149,7 @@ std::vector AcirComposer::serialize_verification_key_into_fields() return acir_format::export_key_in_recursion_format(verification_key_); } -template void AcirComposer::create_circuit(acir_format::acir_format& constraint_system, +template void AcirComposer::create_circuit(acir_format::AcirFormat& constraint_system, WitnessVector const& witness); } // namespace acir_proofs diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp index 1010660ce5f..a83d7f85c95 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp @@ -17,7 +17,7 @@ class AcirComposer { AcirComposer(size_t size_hint = 0, bool verbose = true); template - void create_circuit(acir_format::acir_format& constraint_system, WitnessVector const& witness = {}); + void create_circuit(acir_format::AcirFormat& constraint_system, WitnessVector const& witness = {}); std::shared_ptr init_proving_key(); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.cpp index c5e3698d182..3b0adc0ae5c 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.cpp @@ -6,10 +6,7 @@ namespace acir_proofs { -GoblinAcirComposer::GoblinAcirComposer() {} - -void GoblinAcirComposer::create_circuit(acir_format::acir_format& constraint_system, - acir_format::WitnessVector& witness) +void GoblinAcirComposer::create_circuit(acir_format::AcirFormat& constraint_system, acir_format::WitnessVector& witness) { // Construct a builder using the witness and public input data from acir and with the goblin-owned op_queue builder_ = acir_format::GoblinBuilder{ diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.hpp index d8169202e62..6556b548045 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.hpp @@ -14,7 +14,7 @@ class GoblinAcirComposer { using WitnessVector = std::vector>; public: - GoblinAcirComposer(); + GoblinAcirComposer() = default; /** * @brief Create a GUH circuit from an acir constraint system and a witness @@ -22,7 +22,7 @@ class GoblinAcirComposer { * @param constraint_system ACIR representation of the constraints defining the circuit * @param witness The witness values known to ACIR during construction of the constraint system */ - void create_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness); + void create_circuit(acir_format::AcirFormat& constraint_system, acir_format::WitnessVector& witness); /** * @brief Accumulate a circuit via Goblin diff --git a/barretenberg/cpp/src/barretenberg/dsl/types.hpp b/barretenberg/cpp/src/barretenberg/dsl/types.hpp index 46e97b14db5..b5bf296cbf5 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/types.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/types.hpp @@ -60,7 +60,7 @@ using secp256r1_ct = bb::stdlib::secp256r1; using hash_path_ct = bb::stdlib::merkle_tree::hash_path; -using schnorr_signature_bits_ct = bb::stdlib::schnorr::signature_bits; +using schnorr_signature_bits_ct = bb::stdlib::schnorr_signature_bits; // Ultra-composer specific typesv using rom_table_ct = bb::stdlib::rom_table; diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/bn254.hpp b/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/bn254.hpp index 4b171066d86..37d42124c7e 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/bn254.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/bn254.hpp @@ -6,7 +6,7 @@ #include "../bn254/g1.hpp" #include "../bn254/g2.hpp" -namespace curve { +namespace bb::curve { class BN254 { public: using ScalarField = bb::fr; @@ -23,4 +23,4 @@ class BN254 { // with stdlib types, and "native" verification will be acheived via a simulated builder. static constexpr bool is_stdlib_type = false; }; -} // namespace curve \ No newline at end of file +} // namespace bb::curve \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/g1.test.cpp b/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/g1.test.cpp index bf7d05d14ce..e2171981250 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/g1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/g1.test.cpp @@ -3,7 +3,6 @@ using namespace bb; -namespace test_g1 { TEST(g1, RandomElement) { g1::element result = g1::element::random_element(); @@ -416,7 +415,6 @@ template void write(const T t) TEST(g1, InitializationCheck) { // NOLINTNEXTLINE not our fault googletest uses `goto`! - EXPECT_NO_THROW(write({})); + EXPECT_NO_THROW(write({})); } #endif -} // namespace test_g1 \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/g2.test.cpp b/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/g2.test.cpp index 6905aeb1023..ce198af48a9 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/g2.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/g2.test.cpp @@ -385,6 +385,6 @@ template void write(const T t) TEST(g2, InitializationCheck) { // NOLINTNEXTLINE not our fault googletest uses `goto`! - EXPECT_NO_THROW(write({})); + EXPECT_NO_THROW(write({})); } #endif \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/grumpkin.hpp b/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/grumpkin.hpp index c378aad9ee6..cfe12ad286f 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/grumpkin.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/grumpkin.hpp @@ -30,7 +30,7 @@ using g1 = bb::group; }; // namespace grumpkin -namespace curve { +namespace bb::curve { class Grumpkin { public: using ScalarField = bb::fq; @@ -44,4 +44,4 @@ class Grumpkin { // with stdlib types, and "native" verification will be acheived via a simulated builder. static constexpr bool is_stdlib_type = false; }; -} // namespace curve \ No newline at end of file +} // namespace bb::curve \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/grumpkin.test.cpp b/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/grumpkin.test.cpp index fefa6a6d0dc..5573e08ea38 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/grumpkin.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/grumpkin.test.cpp @@ -2,12 +2,12 @@ #include #include -namespace test_grumpkin { +using namespace bb; TEST(grumpkin, CheckB) { auto b = grumpkin::g1::curve_b; - bb::fr seventeen = 17; + fr seventeen = 17; EXPECT_EQ(seventeen, -b); } @@ -329,4 +329,3 @@ TEST(grumpkin, BadPoints) } EXPECT_TRUE(res); } -} // namespace test_grumpkin \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.hpp b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.hpp index 8b4a4d67367..ce10122791c 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.hpp @@ -121,7 +121,7 @@ struct Secp256k1G1Params { using g1 = bb::group, bb::field, Secp256k1G1Params>; } // namespace secp256k1 -namespace curve { +namespace bb::curve { class SECP256K1 { public: using ScalarField = secp256k1::fr; @@ -130,6 +130,6 @@ class SECP256K1 { using Element = typename Group::element; using AffineElement = typename Group::affine_element; }; -} // namespace curve +} // namespace bb::curve // NOLINTEND(cppcoreguidelines-avoid-c-arrays) 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 f89688ecbd7..7fa8bee9ae6 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/secp256k1.test.cpp @@ -2,11 +2,9 @@ #include "barretenberg/numeric/random/engine.hpp" #include -namespace test_secp256k1 { - +using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); -} +auto& engine = numeric::get_debug_randomness(); constexpr uint256_t test_fq_mod(secp256k1::Secp256k1FqParams::modulus_0, secp256k1::Secp256k1FqParams::modulus_1, @@ -21,6 +19,7 @@ uint256_t get_fq_element() } return res; } +} // namespace TEST(secp256k1, TestAdd) { @@ -504,5 +503,3 @@ TEST(secp256k1, MontgomeryMulBigBug) secp256k1::fq expected(uint256_t{ 0x60381e557e100000, 0x0, 0x0, 0x0 }); EXPECT_EQ((a_sqr == expected), true); } - -} // namespace test_secp256k1 diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.hpp b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.hpp index c4478e06b50..e28e86c1675 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.hpp @@ -107,7 +107,7 @@ struct Secp256r1G1Params { using g1 = bb::group, bb::field, Secp256r1G1Params>; } // namespace secp256r1 -namespace curve { +namespace bb::curve { class SECP256R1 { public: using ScalarField = secp256r1::fr; @@ -116,6 +116,6 @@ class SECP256R1 { using Element = typename Group::element; using AffineElement = typename Group::affine_element; }; -} // namespace curve +} // namespace bb::curve // NOLINTEND(cppcoreguidelines-avoid-c-arrays) 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 14c67245092..03f5a4bc8d1 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256r1/secp256r1.test.cpp @@ -2,11 +2,9 @@ #include "barretenberg/numeric/random/engine.hpp" #include -namespace test_secp256r1 { - +using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); -} +auto& engine = numeric::get_debug_randomness(); constexpr uint256_t test_fq_mod(secp256r1::Secp256r1FqParams::modulus_0, secp256r1::Secp256r1FqParams::modulus_1, @@ -21,6 +19,7 @@ uint256_t get_fq_element() } return res; } +} // namespace TEST(secp256r1, TestAdd) { @@ -446,5 +445,3 @@ TEST(secp256r1, MontgomeryMulBigBug) secp256r1::fr expected(uint256_t{ 0x57abc6aa0349c084, 0x65b21b232a4cb7a5, 0x5ba781948b0fcd6e, 0xd6e9e0644bda12f7 }); EXPECT_EQ((a_sqr == expected), true); } - -} // namespace test_secp256r1 diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field12.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field12.hpp index 77d6dab770d..e69ba688845 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field12.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field12.hpp @@ -238,7 +238,7 @@ template cl }; } - static constexpr field12 random_element(numeric::random::Engine* engine = nullptr) + static constexpr field12 random_element(numeric::RNG* engine = nullptr) { return { base_field::random_element(engine), diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field2.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field2.hpp index aa42dad75aa..b0cad83f0ff 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field2.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field2.hpp @@ -190,7 +190,7 @@ template constexpr void field2::self_frobenius_ma c1.self_neg(); } -template field2 field2::random_element(numeric::random::Engine* engine) +template field2 field2::random_element(numeric::RNG* engine) { return { base::random_element(engine), base::random_element(engine) }; } diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field2_declarations.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field2_declarations.hpp index ba9a1281526..d9607abfe89 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field2_declarations.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field2_declarations.hpp @@ -2,9 +2,9 @@ #include "barretenberg/numeric/uint256/uint256.hpp" -// forward declare Engine -namespace numeric::random { -class Engine; +// forward declare RNG +namespace bb::numeric { +class RNG; } namespace bb { @@ -115,7 +115,7 @@ template struct alignas(32) field2 { constexpr field2 frobenius_map() const noexcept; constexpr void self_frobenius_map() noexcept; - static field2 random_element(numeric::random::Engine* engine = nullptr); + static field2 random_element(numeric::RNG* engine = nullptr); static void serialize_to_buffer(const field2& value, uint8_t* buffer) { base_field::serialize_to_buffer(value.c0, buffer); diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field6.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field6.hpp index b69df21e2a3..0ee982f3f37 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field6.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field6.hpp @@ -190,7 +190,7 @@ template class field6 { }; } - static constexpr field6 random_element(numeric::random::Engine* engine = nullptr) + static constexpr field6 random_element(numeric::RNG* engine = nullptr) { return { base_field::random_element(engine), diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp index 192be60d0d2..3a43b2ac69e 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp @@ -437,7 +437,7 @@ template struct alignas(32) field { src = T; } - static field random_element(numeric::random::Engine* engine = nullptr) noexcept; + static field random_element(numeric::RNG* engine = nullptr) noexcept; static constexpr field multiplicative_generator() noexcept; diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp index ca322101b76..2149e131241 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp @@ -561,10 +561,10 @@ template constexpr field field::get_root_of_unity(size_t subgrou return r; } -template field field::random_element(numeric::random::Engine* engine) noexcept +template field field::random_element(numeric::RNG* engine) noexcept { if (engine == nullptr) { - engine = &numeric::random::get_engine(); + engine = &numeric::get_randomness(); } uint512_t source = engine->get_random_uint512(); diff --git a/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.hpp b/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.hpp index 528bed056d3..117dab0ff2b 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.hpp @@ -77,7 +77,7 @@ template class alignas(64) affine_el * * @return A randomly chosen point on the curve */ - static affine_element random_element(numeric::random::Engine* engine = nullptr) noexcept; + static affine_element random_element(numeric::RNG* engine = nullptr) noexcept; static constexpr affine_element hash_to_curve(const std::vector& seed, uint8_t attempt_count = 0) noexcept requires SupportsHashToCurve; diff --git a/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element_impl.hpp b/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element_impl.hpp index 3c8b0d8504f..a227ba27312 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element_impl.hpp @@ -263,10 +263,10 @@ constexpr affine_element affine_element::hash_to_curve(con } template -affine_element affine_element::random_element(numeric::random::Engine* engine) noexcept +affine_element affine_element::random_element(numeric::RNG* engine) noexcept { if (engine == nullptr) { - engine = &numeric::random::get_engine(); + engine = &numeric::get_randomness(); } Fq x; diff --git a/barretenberg/cpp/src/barretenberg/ecc/groups/element.hpp b/barretenberg/cpp/src/barretenberg/ecc/groups/element.hpp index 639b32b366b..637d3dda0a4 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/groups/element.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/groups/element.hpp @@ -49,7 +49,7 @@ template class alignas(32) element { constexpr operator affine_element() const noexcept; - static element random_element(numeric::random::Engine* engine = nullptr) noexcept; + static element random_element(numeric::RNG* engine = nullptr) noexcept; constexpr element dbl() const noexcept; constexpr void self_dbl() noexcept; @@ -106,7 +106,7 @@ template class alignas(32) element { element mul_with_endomorphism(const Fr& exponent) const noexcept; template > - static element random_coordinates_on_curve(numeric::random::Engine* engine = nullptr) noexcept; + static element random_coordinates_on_curve(numeric::RNG* engine = nullptr) noexcept; // { // bool found_one = false; // Fq yy; diff --git a/barretenberg/cpp/src/barretenberg/ecc/groups/element_impl.hpp b/barretenberg/cpp/src/barretenberg/ecc/groups/element_impl.hpp index 6a7cb0ada76..422065e4273 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/groups/element_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/groups/element_impl.hpp @@ -574,7 +574,7 @@ constexpr bool element::operator==(const element& other) const noexce } template -element element::random_element(numeric::random::Engine* engine) noexcept +element element::random_element(numeric::RNG* engine) noexcept { if constexpr (T::can_hash_to_curve) { element result = random_coordinates_on_curve(engine); @@ -1145,7 +1145,7 @@ void element::batch_normalize(element* elements, const size_t num_ele template template -element element::random_coordinates_on_curve(numeric::random::Engine* engine) noexcept +element element::random_coordinates_on_curve(numeric::RNG* engine) noexcept { bool found_one = false; Fq yy; diff --git a/barretenberg/cpp/src/barretenberg/ecc/groups/wnaf.test.cpp b/barretenberg/cpp/src/barretenberg/ecc/groups/wnaf.test.cpp index 01916f4c2bb..7890577d64c 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/groups/wnaf.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/groups/wnaf.test.cpp @@ -6,7 +6,7 @@ using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } // NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays) @@ -60,7 +60,7 @@ TEST(wnaf, WnafTwoBitWindow) constexpr uint32_t num_quads = (num_bits >> 1) + 1; uint64_t wnaf[num_quads] = { 0 }; bool skew = false; - bb::wnaf::fixed_wnaf<256, 1, window>(&input.data[0], wnaf, skew, 0); + wnaf::fixed_wnaf<256, 1, window>(&input.data[0], wnaf, skew, 0); /** * For representing even numbers, we define a skew: diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp index da81ec37eda..bd995155314 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.test.cpp @@ -12,19 +12,18 @@ #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/sumcheck/sumcheck_round.hpp" +using namespace bb; using namespace bb::honk; -namespace test_eccvm_composer { - template class ECCVMComposerTests : public ::testing::Test { protected: // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialized for every test. void SetUp() override { if constexpr (std::is_same::value) { - bb::srs::init_grumpkin_crs_factory("../srs_db/grumpkin"); + srs::init_grumpkin_crs_factory("../srs_db/grumpkin"); } else { - bb::srs::init_crs_factory("../srs_db/ignition"); + srs::init_crs_factory("../srs_db/ignition"); } }; }; @@ -33,11 +32,11 @@ using FlavorTypes = ::testing::Types; TYPED_TEST_SUITE(ECCVMComposerTests, FlavorTypes); namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } -template bb::ECCVMCircuitBuilder generate_trace(numeric::random::Engine* engine = nullptr) +template ECCVMCircuitBuilder generate_trace(numeric::RNG* engine = nullptr) { - bb::ECCVMCircuitBuilder result; + ECCVMCircuitBuilder result; using G1 = typename Flavor::CycleGroup; using Fr = typename G1::Fr; @@ -102,4 +101,3 @@ TYPED_TEST(ECCVMComposerTests, EqFails) bool verified = verifier.verify_proof(proof); ASSERT_FALSE(verified); } -} // namespace test_eccvm_composer diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_transcript.test.cpp index 65327502365..c513bc991c4 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_transcript.test.cpp @@ -6,6 +6,7 @@ #include "barretenberg/transcript/transcript.hpp" #include +using namespace bb; using namespace bb::honk; template class ECCVMTranscriptTests : public ::testing::Test { @@ -13,9 +14,9 @@ template class ECCVMTranscriptTests : public ::testing::Test { void SetUp() override { if constexpr (std::is_same::value) { - bb::srs::init_grumpkin_crs_factory("../srs_db/grumpkin"); + srs::init_grumpkin_crs_factory("../srs_db/grumpkin"); } else { - bb::srs::init_crs_factory("../srs_db/ignition"); + srs::init_crs_factory("../srs_db/ignition"); } }; using FF = typename Flavor::FF; @@ -183,9 +184,9 @@ template class ECCVMTranscriptTests : public ::testing::Test { return manifest_expected; } - bb::ECCVMCircuitBuilder generate_trace(numeric::random::Engine* engine = nullptr) + ECCVMCircuitBuilder generate_trace(numeric::RNG* engine = nullptr) { - bb::ECCVMCircuitBuilder result; + ECCVMCircuitBuilder result; using G1 = typename Flavor::CycleGroup; using Fr = typename G1::Fr; @@ -219,7 +220,7 @@ template class ECCVMTranscriptTests : public ::testing::Test { } }; -numeric::random::Engine& engine = numeric::random::get_debug_engine(); +numeric::RNG& engine = numeric::get_debug_randomness(); using FlavorTypes = testing::Types; diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp index 3a60a0c810d..3eb36f5fdc2 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp @@ -4,10 +4,11 @@ #include #include -namespace bb::test_flavor { +using namespace bb; + TEST(Flavor, Getters) { - using Flavor = bb::honk::flavor::Ultra; + using Flavor = honk::flavor::Ultra; using FF = Flavor::FF; using ProvingKey = typename Flavor::ProvingKey; @@ -42,7 +43,7 @@ TEST(Flavor, Getters) TEST(Flavor, AllEntitiesSpecialMemberFunctions) { - using Flavor = bb::honk::flavor::Ultra; + using Flavor = honk::flavor::Ultra; using FF = Flavor::FF; using PartiallyEvaluatedMultivariates = Flavor::PartiallyEvaluatedMultivariates; using Polynomial = bb::Polynomial; @@ -68,7 +69,7 @@ TEST(Flavor, AllEntitiesSpecialMemberFunctions) TEST(Flavor, GetRow) { - using Flavor = bb::honk::flavor::Ultra; + using Flavor = honk::flavor::Ultra; using FF = typename Flavor::FF; std::array, Flavor::NUM_ALL_ENTITIES> data; std::generate(data.begin(), data.end(), []() { @@ -83,4 +84,3 @@ TEST(Flavor, GetRow) EXPECT_EQ(row0.q_elliptic, prover_polynomials.q_elliptic[0]); EXPECT_EQ(row1.w_4_shift, prover_polynomials.w_4_shift[1]); } -} // namespace bb::test_flavor diff --git a/barretenberg/cpp/src/barretenberg/goblin/full_goblin_recursion.test.cpp b/barretenberg/cpp/src/barretenberg/goblin/full_goblin_recursion.test.cpp index 088a341e29f..5049b197e0a 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/full_goblin_recursion.test.cpp +++ b/barretenberg/cpp/src/barretenberg/goblin/full_goblin_recursion.test.cpp @@ -10,21 +10,20 @@ #include "barretenberg/ultra_honk/ultra_composer.hpp" #include - +using namespace bb; using namespace bb::honk; -namespace goblin_recursion_tests { class GoblinRecursionTests : public ::testing::Test { protected: static void SetUpTestSuite() { - bb::srs::init_crs_factory("../srs_db/ignition"); - bb::srs::init_grumpkin_crs_factory("../srs_db/grumpkin"); + srs::init_crs_factory("../srs_db/ignition"); + srs::init_grumpkin_crs_factory("../srs_db/grumpkin"); } using Curve = curve::BN254; using FF = Curve::ScalarField; - using GoblinUltraBuilder = bb::GoblinUltraCircuitBuilder; + using GoblinUltraBuilder = GoblinUltraCircuitBuilder; using KernelInput = Goblin::AccumulationOutput; }; @@ -61,4 +60,3 @@ TEST_F(GoblinRecursionTests, Pseudo) } // TODO(https://github.com/AztecProtocol/barretenberg/issues/787) Expand these tests. -} // namespace goblin_recursion_tests 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 f6e1f23c034..ebd807012aa 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 @@ -72,7 +72,7 @@ int main(int argc, char** argv) bb::srs::Manifest manifest{ 0, 1, static_cast(subgroup_size), 0, static_cast(subgroup_size), 0, 0 }; - bb::srs::IO::write_transcript(&srs[0], manifest, srs_path); + bb::srs::IO::write_transcript(&srs[0], manifest, srs_path); return 0; } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/fixtures/user_context.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/fixtures/user_context.hpp index 63e880b6e6d..b5eb6901ace 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/fixtures/user_context.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/fixtures/user_context.hpp @@ -5,7 +5,7 @@ namespace bb::join_split_example::fixtures { -using grumpkin_key_pair = bb::crypto::schnorr::key_pair; +using grumpkin_key_pair = bb::crypto::schnorr_key_pair; struct user_context { bb::fr note_secret; @@ -17,18 +17,18 @@ struct user_context { inline bb::fr generate_alias_hash(std::string const& alias) { std::vector inputv(alias.begin(), alias.end()); - auto output = blake2::blake2s(inputv); + auto output = bb::crypto::blake2s(inputv); return bb::fr(uint256_t(from_buffer(output.data())) >> 32); } -inline grumpkin_key_pair create_key_pair(numeric::random::Engine* engine) +inline grumpkin_key_pair create_key_pair(numeric::RNG* engine) { grumpkin::fr priv_key = grumpkin::fr::random_element(engine); grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; return { priv_key, pub_key }; } -inline user_context create_user_context(numeric::random::Engine* engine = nullptr) +inline user_context create_user_context(numeric::RNG* engine = nullptr) { uint8_t vk[] = { 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11 }; diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/inner_proof_data/inner_proof_data.test.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/inner_proof_data/inner_proof_data.test.cpp index daa08dd823f..4721089cdc9 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/inner_proof_data/inner_proof_data.test.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/inner_proof_data/inner_proof_data.test.cpp @@ -5,7 +5,7 @@ using namespace bb; using namespace bb::join_split_example::proofs; namespace { -auto& rand_engine = numeric::random::get_debug_engine(); +auto& rand_engine = numeric::get_debug_randomness(); } TEST(client_proofs_inner_proof_data, test_proof_to_data) diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp index 99db6944df5..5d110351dbb 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp @@ -29,7 +29,7 @@ using namespace bb; using namespace bb::stdlib; using namespace bb::stdlib::merkle_tree; using namespace bb::join_split_example::proofs::notes::native; -using key_pair = bb::join_split_example::fixtures::grumpkin_key_pair; +using key_pair = join_split_example::fixtures::grumpkin_key_pair; auto create_account_leaf_data(fr const& account_alias_hash, grumpkin::g1::affine_element const& owner_key, @@ -43,7 +43,7 @@ class join_split_tests : public ::testing::Test { static constexpr size_t ACCOUNT_INDEX = 14; static void SetUpTestCase() { - bb::srs::init_crs_factory("../srs_db/ignition"); + srs::init_crs_factory("../srs_db/ignition"); init_proving_key(false); auto crs_factory = std::make_unique>("../srs_db/ignition"); init_verification_key(); @@ -54,7 +54,7 @@ class join_split_tests : public ::testing::Test { { store = std::make_unique(); tree = std::make_unique>(*store, 32); - user = bb::join_split_example::fixtures::create_user_context(); + user = join_split_example::fixtures::create_user_context(); default_value_note = { .value = 100, .asset_id = asset_id, @@ -73,7 +73,7 @@ class join_split_tests : public ::testing::Test { value_notes[0].creator_pubkey = user.owner.public_key.x; value_notes[1].value = 50; - value_notes[1].creator_pubkey = bb::join_split_example::fixtures::create_key_pair(nullptr).public_key.x; + value_notes[1].creator_pubkey = join_split_example::fixtures::create_key_pair(nullptr).public_key.x; value_notes[2].value = 90; value_notes[2].account_required = true, @@ -254,7 +254,7 @@ class join_split_tests : public ::testing::Test { tx.output_note = { output_note1, output_note2 }; tx.partial_claim_note.input_nullifier = 0; tx.account_private_key = user.owner.private_key; - tx.alias_hash = bb::join_split_example::fixtures::generate_alias_hash("penguin"); + tx.alias_hash = join_split_example::fixtures::generate_alias_hash("penguin"); tx.account_required = false; tx.account_note_index = 0; tx.account_note_path = tree->get_hash_path(0); @@ -300,7 +300,7 @@ class join_split_tests : public ::testing::Test { return verify_logic(tx); } - bb::join_split_example::fixtures::user_context user; + join_split_example::fixtures::user_context user; std::unique_ptr store; std::unique_ptr> tree; bridge_call_data empty_bridge_call_data = { .bridge_address_id = 0, @@ -900,7 +900,7 @@ void assign_backward_link(join_split_tx& tx, size_t& indicator) tx.backward_link = tx.input_note[1].commit(); break; default: - tx.backward_link = bb::fr::random_element(); + tx.backward_link = fr::random_element(); } } @@ -1176,7 +1176,7 @@ TEST_F(join_split_tests, test_spend_registered_notes_with_owner_key_fails) TEST_F(join_split_tests, test_wrong_alias_hash_fails) { join_split_tx tx = simple_setup({ 2, 3 }, ACCOUNT_INDEX, 1); - tx.alias_hash = bb::join_split_example::fixtures::generate_alias_hash("derive_generators"); + tx.alias_hash = join_split_example::fixtures::generate_alias_hash("derive_generators"); auto result = sign_and_verify_logic(tx, user.owner); EXPECT_FALSE(result.valid); @@ -1186,7 +1186,7 @@ TEST_F(join_split_tests, test_wrong_alias_hash_fails) TEST_F(join_split_tests, test_nonregistered_signing_key_fails) { join_split_tx tx = simple_setup({ 2, 3 }, ACCOUNT_INDEX, 1); - auto keys = bb::join_split_example::fixtures::create_key_pair(nullptr); + auto keys = join_split_example::fixtures::create_key_pair(nullptr); tx.signing_pub_key = keys.public_key; auto result = sign_and_verify_logic(tx, user.owner); @@ -2197,7 +2197,7 @@ TEST_F(join_split_tests, test_incorrect_output_note_creator_pubkey_x) { join_split_tx tx = simple_setup(); tx.output_note[0].creator_pubkey = - bb::join_split_example::fixtures::create_key_pair(nullptr) + join_split_example::fixtures::create_key_pair(nullptr) .public_key.x; // setting creator to be different from sender (the owner of the input notes). auto result = sign_and_verify_logic(tx, user.owner); EXPECT_FALSE(result.valid); @@ -2206,7 +2206,7 @@ TEST_F(join_split_tests, test_incorrect_output_note_creator_pubkey_x) { join_split_tx tx = simple_setup(); tx.output_note[1].creator_pubkey = - bb::join_split_example::fixtures::create_key_pair(nullptr) + join_split_example::fixtures::create_key_pair(nullptr) .public_key.x; // setting creator to be different from sender (the owner of the input notes). auto result = sign_and_verify_logic(tx, user.owner); EXPECT_FALSE(result.valid); diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.cpp index 4d3fbdd110d..847e7d15cff 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.cpp @@ -13,7 +13,7 @@ namespace bb::join_split_example::proofs::join_split { using namespace bb::plonk; using namespace notes::circuit; using namespace bb::stdlib::merkle_tree; -using namespace bb::crypto::schnorr; +using namespace bb::crypto; /** * Check that the input note data, follows the given hash paths, to the publically given merkle root. @@ -286,7 +286,7 @@ void join_split_circuit(Builder& builder, join_split_tx const& tx) // many constraints on the bridge_call_data's format and the bit_config's format: .partial_claim_note = claim::partial_claim_note_witness_data(builder, tx.partial_claim_note), .signing_pub_key = group_ct::from_witness(&builder, tx.signing_pub_key), - .signature = stdlib::schnorr::convert_signature(&builder, tx.signature), + .signature = stdlib::schnorr_convert_signature(&builder, tx.signature), .merkle_root = witness_ct(&builder, tx.old_data_root), .input_path1 = stdlib::merkle_tree::create_witness_hash_path(builder, tx.input_path[0]), .input_path2 = stdlib::merkle_tree::create_witness_hash_path(builder, tx.input_path[1]), diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.hpp index 6d076829d68..799f0228bfd 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.hpp @@ -22,7 +22,7 @@ struct join_split_inputs { notes::circuit::value::witness_data output_note2; notes::circuit::claim::partial_claim_note_witness_data partial_claim_note; group_ct signing_pub_key; - schnorr::signature_bits signature; + schnorr_signature_bits signature; field_ct merkle_root; hash_path_ct input_path1; hash_path_ct input_path2; 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 e7cec1763d0..6754c48cbd0 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 @@ -14,7 +14,7 @@ using namespace bb; // using namespace bb::stdlib::types; using namespace bb::stdlib::merkle_tree; using namespace bb::join_split_example::proofs::notes::native; -using key_pair = bb::join_split_example::fixtures::grumpkin_key_pair; +using key_pair = join_split_example::fixtures::grumpkin_key_pair; /** * This test mirrors the test in join_split_prover.test.ts @@ -117,7 +117,7 @@ TEST_F(join_split_js_parity_tests, test_full_proof) tx.partial_claim_note.note_secret = 0; tx.partial_claim_note.input_nullifier = 0; tx.account_private_key = private_key; - tx.alias_hash = bb::join_split_example::fixtures::generate_alias_hash("penguin"); + tx.alias_hash = join_split_example::fixtures::generate_alias_hash("penguin"); tx.account_required = false; tx.account_note_index = 0; tx.account_note_path = tree->get_hash_path(0); diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.hpp index 71bf39d81ab..eb1282f0006 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.hpp @@ -31,7 +31,7 @@ struct join_split_tx { bb::fr backward_link; // 0: no link, otherwise: any commitment. uint32_t allow_chain; // 0: none, 1: output_note1, 2: output_note2 - crypto::schnorr::signature signature; + crypto::schnorr_signature signature; bool operator==(join_split_tx const&) const = default; }; diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.test.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.test.cpp index 38f7aa70280..758ae4c1a30 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.test.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.test.cpp @@ -14,7 +14,7 @@ using namespace bb; using namespace bb::join_split_example::proofs::join_split; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } TEST(client_proofs_join_split_tx, test_serialization) diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/sign_join_split_tx.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/sign_join_split_tx.cpp index e6b4ad0575e..f4ec6e2525d 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/sign_join_split_tx.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/sign_join_split_tx.cpp @@ -4,20 +4,20 @@ namespace bb::join_split_example::proofs::join_split { -using namespace bb::crypto::schnorr; +using namespace bb::crypto; -signature sign_join_split_tx(join_split_tx const& tx, key_pair const& keys) +schnorr_signature sign_join_split_tx(join_split_tx const& tx, schnorr_key_pair const& keys) { fr hashed = compute_signing_data(tx); std::vector message(sizeof(fr)); fr::serialize_to_buffer(hashed, &message[0]); - crypto::schnorr::signature signature = - crypto::schnorr::construct_signature( + crypto::schnorr_signature signature = + crypto::schnorr_construct_signature( std::string(message.begin(), message.end()), keys); - auto result = crypto::schnorr::verify_signature( + auto result = crypto::schnorr_verify_signature( std::string(message.begin(), message.end()), keys.public_key, signature); ASSERT(result == true); return signature; diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/sign_join_split_tx.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/sign_join_split_tx.hpp index b709c29cc73..a02a35f2f29 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/sign_join_split_tx.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/sign_join_split_tx.hpp @@ -5,7 +5,7 @@ namespace bb::join_split_example::proofs::join_split { -crypto::schnorr::signature sign_join_split_tx(proofs::join_split::join_split_tx const& tx, - crypto::schnorr::key_pair const& keys); +crypto::schnorr_signature sign_join_split_tx(proofs::join_split::join_split_tx const& tx, + crypto::schnorr_key_pair const& keys); } diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/verify_signature.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/verify_signature.hpp index 6fb148f3ae6..2b39536a135 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/verify_signature.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/verify_signature.hpp @@ -15,14 +15,14 @@ inline void verify_signature(field_ct const& public_value, group_ct const& owner_pub_key, field_ct const& backward_link, field_ct const& allow_chain, - schnorr::signature_bits const& signature) + schnorr_signature_bits const& signature) { std::vector to_compress = { public_value, public_owner, public_asset_id, output_note1_commitment, output_note2_commitment, nullifier1, nullifier2, backward_link, allow_chain, }; byte_array_ct message = pedersen_hash::hash(to_compress); - verify_signature(message, owner_pub_key, signature); + schnorr_verify_signature(message, owner_pub_key, signature); } } // namespace bb::join_split_example::proofs::join_split diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.test.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.test.cpp index 26738fc018e..adb6b5aed9e 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.test.cpp @@ -11,7 +11,7 @@ using namespace bb::join_split_example::proofs::notes; TEST(compute_nullifier_circuit, native_consistency) { - auto user = bb::join_split_example::fixtures::create_user_context(); + auto user = join_split_example::fixtures::create_user_context(); auto priv_key = uint256_t(user.owner.private_key); auto native_input_note = diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp index 4dfd44cfab0..1353b58e8d7 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp @@ -18,7 +18,7 @@ class ValueNote : public ::testing::Test { TEST_F(ValueNote, Commits) { - auto user = bb::join_split_example::fixtures::create_user_context(); + auto user = join_split_example::fixtures::create_user_context(); auto builder = Builder(); fr note_value = fr::random_element(); @@ -54,7 +54,7 @@ TEST_F(ValueNote, CommitsWith0Value) { auto builder = Builder(); - auto user = bb::join_split_example::fixtures::create_user_context(); + auto user = join_split_example::fixtures::create_user_context(); uint32_t asset_id_value = 0x2abbccddULL; // needs to be less than 30 bits @@ -91,7 +91,7 @@ TEST_F(ValueNote, CommitWithOversizedAssetIdFails) { auto builder = Builder(); - auto user = bb::join_split_example::fixtures::create_user_context(); + auto user = join_split_example::fixtures::create_user_context(); native::value::value_note note = { .value = 0, diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/native/value/compute_nullifier.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/native/value/compute_nullifier.cpp index 0a8365a2f42..92b7843902f 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/native/value/compute_nullifier.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/native/value/compute_nullifier.cpp @@ -26,7 +26,7 @@ fr compute_nullifier(grumpkin::fq const& note_commitment, }; auto hashed_inputs = crypto::pedersen_hash::hash(buf, GeneratorIndex::JOIN_SPLIT_NULLIFIER); - auto blake_result = blake2::blake2s(to_buffer(hashed_inputs)); + auto blake_result = bb::crypto::blake2s(to_buffer(hashed_inputs)); return from_buffer(blake_result); } diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/types.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/types.hpp index 8b6bedca204..68b0e79363d 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/types.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/types.hpp @@ -39,8 +39,6 @@ using bn254 = bb::stdlib::bn254; using hash_path_ct = bb::stdlib::merkle_tree::hash_path; -namespace schnorr { -using signature_bits = bb::stdlib::schnorr::signature_bits; -} // namespace schnorr +using schnorr_signature_bits = bb::stdlib::schnorr_signature_bits; -} // namespace bb::join_split_example \ No newline at end of file +} // namespace bb::join_split_example diff --git a/barretenberg/cpp/src/barretenberg/numeric/bitop/count_leading_zeros.hpp b/barretenberg/cpp/src/barretenberg/numeric/bitop/count_leading_zeros.hpp index c41877610c1..acf8179af94 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/bitop/count_leading_zeros.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/bitop/count_leading_zeros.hpp @@ -3,7 +3,7 @@ #include "../uint256/uint256.hpp" #include -namespace numeric { +namespace bb::numeric { /** * Returns the number of leading 0 bits for a given integer type. @@ -49,4 +49,4 @@ template <> constexpr inline size_t count_leading_zeros(uint256_t con return 256; } -} // namespace numeric +} // namespace bb::numeric diff --git a/barretenberg/cpp/src/barretenberg/numeric/bitop/count_leading_zeros.test.cpp b/barretenberg/cpp/src/barretenberg/numeric/bitop/count_leading_zeros.test.cpp index c482c7d0a75..0849a881d08 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/bitop/count_leading_zeros.test.cpp +++ b/barretenberg/cpp/src/barretenberg/numeric/bitop/count_leading_zeros.test.cpp @@ -1,6 +1,8 @@ #include "count_leading_zeros.hpp" #include +using namespace bb; + TEST(bitop, ClzUint3231) { uint32_t a = 0b00000000000000000000000000000001; diff --git a/barretenberg/cpp/src/barretenberg/numeric/bitop/get_msb.hpp b/barretenberg/cpp/src/barretenberg/numeric/bitop/get_msb.hpp index d3df553401b..fc456a68a8e 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/bitop/get_msb.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/bitop/get_msb.hpp @@ -2,7 +2,7 @@ #include #include #include -namespace numeric { +namespace bb::numeric { // from http://supertech.csail.mit.edu/papers/debruijn.pdf constexpr inline uint32_t get_msb32(const uint32_t in) @@ -43,4 +43,4 @@ template constexpr inline T get_msb(const T in) return (sizeof(T) <= 4) ? get_msb32(in) : get_msb64(in); } -} // namespace numeric \ No newline at end of file +} // namespace bb::numeric \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/numeric/bitop/get_msb.test.cpp b/barretenberg/cpp/src/barretenberg/numeric/bitop/get_msb.test.cpp index 044fb3bbfd9..3abdd73b155 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/bitop/get_msb.test.cpp +++ b/barretenberg/cpp/src/barretenberg/numeric/bitop/get_msb.test.cpp @@ -1,6 +1,8 @@ #include "get_msb.hpp" #include +using namespace bb; + TEST(bitop, GetMsbUint640Value) { uint64_t a = 0b00000000000000000000000000000000; diff --git a/barretenberg/cpp/src/barretenberg/numeric/bitop/keep_n_lsb.hpp b/barretenberg/cpp/src/barretenberg/numeric/bitop/keep_n_lsb.hpp index ee9859eecb6..c03a3154e37 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/bitop/keep_n_lsb.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/bitop/keep_n_lsb.hpp @@ -1,11 +1,11 @@ #pragma once #include -namespace numeric { +namespace bb::numeric { template inline T keep_n_lsb(T const& input, size_t num_bits) { return num_bits >= sizeof(T) * 8 ? input : input & ((T(1) << num_bits) - 1); } -} // namespace numeric +} // namespace bb::numeric diff --git a/barretenberg/cpp/src/barretenberg/numeric/bitop/pow.hpp b/barretenberg/cpp/src/barretenberg/numeric/bitop/pow.hpp index 295a5e5b4c7..2e67afffc9a 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/bitop/pow.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/bitop/pow.hpp @@ -3,7 +3,7 @@ #include "./get_msb.hpp" #include -namespace numeric { +namespace bb::numeric { constexpr uint64_t pow64(const uint64_t input, const uint64_t exponent) { if (input == 0) { @@ -31,4 +31,4 @@ constexpr bool is_power_of_two(uint64_t x) return (x != 0U) && ((x & (x - 1)) == 0U); } -} // namespace numeric \ No newline at end of file +} // namespace bb::numeric \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/numeric/bitop/rotate.hpp b/barretenberg/cpp/src/barretenberg/numeric/bitop/rotate.hpp index 1fc0cd1cfdd..5be15b96e38 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/bitop/rotate.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/bitop/rotate.hpp @@ -2,7 +2,7 @@ #include #include -namespace numeric { +namespace bb::numeric { constexpr inline uint64_t rotate64(const uint64_t value, const uint64_t rotation) { @@ -13,4 +13,4 @@ constexpr inline uint32_t rotate32(const uint32_t value, const uint32_t rotation { return rotation != 0U ? (value >> rotation) + (value << (32 - rotation)) : value; } -} // namespace numeric \ No newline at end of file +} // namespace bb::numeric \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/numeric/bitop/sparse_form.hpp b/barretenberg/cpp/src/barretenberg/numeric/bitop/sparse_form.hpp index dcc4a13315d..c2a17193831 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/bitop/sparse_form.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/bitop/sparse_form.hpp @@ -7,7 +7,7 @@ #include "../uint256/uint256.hpp" -namespace numeric { +namespace bb::numeric { inline std::vector slice_input(const uint256_t& input, const uint64_t base, const size_t num_slices) { @@ -154,4 +154,4 @@ template class sparse_int { uint64_t sparse_value; }; -} // namespace numeric +} // namespace bb::numeric diff --git a/barretenberg/cpp/src/barretenberg/numeric/random/engine.cpp b/barretenberg/cpp/src/barretenberg/numeric/random/engine.cpp index ff31c6136d8..e8b5c4a940a 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/random/engine.cpp +++ b/barretenberg/cpp/src/barretenberg/numeric/random/engine.cpp @@ -4,7 +4,7 @@ #include #include -namespace numeric::random { +namespace bb::numeric { namespace { auto generate_random_data() @@ -16,7 +16,7 @@ auto generate_random_data() } } // namespace -class RandomEngine : public Engine { +class RandomEngine : public RNG { public: uint8_t get_random_uint8() override { @@ -71,7 +71,7 @@ class RandomEngine : public Engine { } }; -class DebugEngine : public Engine { +class DebugEngine : public RNG { public: DebugEngine() // disable linting for this line: we want the DEBUG engine to produce predictable pseudorandom numbers! @@ -116,7 +116,7 @@ class DebugEngine : public Engine { /** * Used by tests to ensure consistent behavior. */ -Engine& get_debug_engine(bool reset) +RNG& get_debug_randomness(bool reset) { // static std::seed_seq seed({ 1, 2, 3, 4, 5 }); static DebugEngine debug_engine; @@ -129,11 +129,11 @@ Engine& get_debug_engine(bool reset) /** * Default engine. If wanting consistent proof construction, uncomment the line to return the debug engine. */ -Engine& get_engine() +RNG& get_randomness() { - // return get_debug_engine(); + // return get_debug_randomness(); static RandomEngine engine; return engine; } -} // namespace numeric::random +} // namespace bb::numeric diff --git a/barretenberg/cpp/src/barretenberg/numeric/random/engine.hpp b/barretenberg/cpp/src/barretenberg/numeric/random/engine.hpp index 9721f69886e..aad7932bbbf 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/random/engine.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/random/engine.hpp @@ -5,9 +5,9 @@ #include "unistd.h" #include -namespace numeric::random { +namespace bb::numeric { -class Engine { +class RNG { public: virtual uint8_t get_random_uint8() = 0; @@ -21,12 +21,12 @@ class Engine { virtual uint256_t get_random_uint256() = 0; - virtual ~Engine() = default; - Engine() noexcept = default; - Engine(const Engine& other) = default; - Engine(Engine&& other) = default; - Engine& operator=(const Engine& other) = default; - Engine& operator=(Engine&& other) = default; + virtual ~RNG() = default; + RNG() noexcept = default; + RNG(const RNG& other) = default; + RNG(RNG&& other) = default; + RNG& operator=(const RNG& other) = default; + RNG& operator=(RNG&& other) = default; uint512_t get_random_uint512() { @@ -45,7 +45,7 @@ class Engine { } }; -Engine& get_debug_engine(bool reset = false); -Engine& get_engine(); +RNG& get_debug_randomness(bool reset = false); +RNG& get_randomness(); -} // namespace numeric::random +} // namespace bb::numeric diff --git a/barretenberg/cpp/src/barretenberg/numeric/random/engine.test.cpp b/barretenberg/cpp/src/barretenberg/numeric/random/engine.test.cpp index 83c9c47f099..494246a07e8 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/random/engine.test.cpp +++ b/barretenberg/cpp/src/barretenberg/numeric/random/engine.test.cpp @@ -3,9 +3,11 @@ #include "barretenberg/common/streams.hpp" #include +using namespace bb; + TEST(engine, GetRandomUint64) { - auto& engine = numeric::random::get_engine(); + auto& engine = numeric::get_randomness(); auto a = engine.get_random_uint64(); auto b = engine.get_random_uint64(); EXPECT_NE(a, 0U); @@ -15,25 +17,25 @@ TEST(engine, GetRandomUint64) TEST(engine, ResetDebugEngine) { - auto& debug_engine = numeric::random::get_debug_engine(); + auto& debug_engine = numeric::get_debug_randomness(); auto a = debug_engine.get_random_uint64(); auto b = debug_engine.get_random_uint64(); EXPECT_NE(a, b); - debug_engine = numeric::random::get_debug_engine(true); + debug_engine = numeric::get_debug_randomness(true); auto c = debug_engine.get_random_uint64(); auto d = debug_engine.get_random_uint64(); EXPECT_EQ(a, c); EXPECT_EQ(b, d); - auto e = numeric::random::get_engine().get_random_uint64(); + auto e = numeric::get_randomness().get_random_uint64(); EXPECT_NE(a, e); } TEST(engine, GetExpectedDebugValue) { - auto& debug_engine = numeric::random::get_debug_engine(true); + auto& debug_engine = numeric::get_debug_randomness(true); auto a = debug_engine.get_random_uint1024(); auto expected = from_buffer(std::vector{ 0x69, 0x1f, 0x71, 0xcb, 0xcd, 0xdb, 0x45, 0x74, 0xe5, 0x17, 0x17, 0xa7, 0x29, 0x02, 0x21, 0x4a, diff --git a/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128.hpp b/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128.hpp index e229f9b7d23..363ee4f9a1b 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128.hpp @@ -7,7 +7,7 @@ #include "barretenberg/common/serialize.hpp" #include -namespace numeric { +namespace bb::numeric { class alignas(32) uint128_t { public: @@ -187,7 +187,7 @@ template inline void write(B& it, uint128_t const& value) write(it, value.data[0]); } -} // namespace numeric +} // namespace bb::numeric #include "./uint128_impl.hpp" diff --git a/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128.test.cpp b/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128.test.cpp index 14c4c843ce4..ecf457ad975 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128.test.cpp +++ b/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128.test.cpp @@ -2,12 +2,14 @@ #include "../random/engine.hpp" #include #ifdef __i386__ + +using namespace bb; +using namespace bb::numeric; + namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } -using namespace numeric; - TEST(uint128, GetBit) { constexpr uint128_t a{ 0b0110011001110010011001100, diff --git a/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128_impl.hpp b/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128_impl.hpp index 8fa503c95e3..5bc5f72c758 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128_impl.hpp @@ -3,7 +3,7 @@ #include "../bitop/get_msb.hpp" #include "./uint128.hpp" #include "barretenberg/common/assert.hpp" -namespace numeric { +namespace bb::numeric { constexpr std::pair uint128_t::mul_wide(const uint32_t a, const uint32_t b) { @@ -410,5 +410,5 @@ constexpr uint128_t uint128_t::operator<<(const uint128_t& other) const return result; } -} // namespace numeric +} // namespace bb::numeric #endif diff --git a/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256.hpp b/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256.hpp index 5ddaa9713ae..fe9e759adaa 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256.hpp @@ -20,7 +20,7 @@ #include #include -namespace numeric { +namespace bb::numeric { class alignas(32) uint256_t { public: @@ -242,10 +242,10 @@ template inline void write(B& it, uint256_t const& value) write(it, value.data[0]); } -} // namespace numeric +} // namespace bb::numeric #include "./uint256_impl.hpp" // disable linter errors; we want to expose a global uint256_t type to mimic uint64_t, uint32_t etc // NOLINTNEXTLINE(tidymisc-unused-using-decls, google-global-names-in-headers, misc-unused-using-decls) -using numeric::uint256_t; +using bb::numeric::uint256_t; diff --git a/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256.test.cpp b/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256.test.cpp index 28234d0c279..ae72524449c 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256.test.cpp +++ b/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256.test.cpp @@ -2,12 +2,12 @@ #include "../random/engine.hpp" #include +using namespace bb; +using namespace bb::numeric; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } -using namespace numeric; - TEST(uint256, TestStringConstructors) { std::string input = "9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789"; diff --git a/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256_impl.hpp b/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256_impl.hpp index 9f4d4daa33d..ee51adc763a 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256_impl.hpp @@ -2,7 +2,7 @@ #include "../bitop/get_msb.hpp" #include "./uint256.hpp" #include "barretenberg/common/assert.hpp" -namespace numeric { +namespace bb::numeric { constexpr std::pair uint256_t::mul_wide(const uint64_t a, const uint64_t b) { @@ -409,4 +409,4 @@ constexpr uint256_t uint256_t::operator<<(const uint256_t& other) const return result; } -} // namespace numeric +} // namespace bb::numeric diff --git a/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx.hpp b/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx.hpp index aa5fc07b097..2ac1b886604 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx.hpp @@ -18,7 +18,7 @@ #include #include -namespace numeric { +namespace bb::numeric { template class uintx { public: @@ -187,9 +187,9 @@ template inline std::ostream& operator<<(std::ostream& os, uin using uint512_t = uintx; using uint1024_t = uintx; -} // namespace numeric +} // namespace bb::numeric #include "./uintx_impl.hpp" -using numeric::uint1024_t; // NOLINT -using numeric::uint512_t; // NOLINT +using bb::numeric::uint1024_t; // NOLINT +using bb::numeric::uint512_t; // NOLINT diff --git a/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx.test.cpp b/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx.test.cpp index 32e5cc6da5f..036470ed975 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx.test.cpp +++ b/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx.test.cpp @@ -2,8 +2,10 @@ #include "../random/engine.hpp" #include +using namespace bb; + namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } // namespace TEST(uintx, GetBit) @@ -67,27 +69,27 @@ TEST(uintx, DivAndMod) TEST(uintx, DISABLEDMulmod) { /* - bb::fq a = bb::fq::random_element(); - bb::fq b = bb::fq::random_element(); - // bb::fq a_converted = a.from_montgomery_form(); - // bb::fq b_converted = b.from_montgomery_form(); + fq a = fq::random_element(); + fq b = fq::random_element(); + // fq a_converted = a.from_montgomery_form(); + // fq b_converted = b.from_montgomery_form(); uint256_t a_uint = uint256_t(a); // { a_converted.data[0], a_converted.data[1], a_converted.data[2], a_converted.data[3] }; uint256_t b_uint = uint256_t(b); // { b_converted.data[0], b_converted.data[1], b_converted.data[2], b_converted.data[3] }; uint256_t modulus_uint{ bb::Bn254FqParams::modulus_0, - bb::Bn254FqParams::modulus_1, - bb::Bn254FqParams::modulus_2, - bb::Bn254FqParams::modulus_3 }; + Bn254FqParams::modulus_1, + Bn254FqParams::modulus_2, + Bn254FqParams::modulus_3 }; uint1024_t a_uintx = uint1024_t(uint512_t(a_uint)); uint1024_t b_uintx = uint1024_t(uint512_t(b_uint)); uint1024_t modulus_uintx = uint1024_t(uint512_t(modulus_uint)); const auto [quotient, remainder] = (a_uintx * b_uintx).divmod(modulus_uintx); - // bb::fq expected_a = a_converted.to_montgomery_form(); - // bb::fq expected_b = b_converted.to_montgomery_form(); - bb::fq expected = (a * b).from_montgomery_form(); + // fq expected_a = a_converted.to_montgomery_form(); + // fq expected_b = b_converted.to_montgomery_form(); + fq expected = (a * b).from_montgomery_form(); EXPECT_EQ(remainder.lo.lo.data[0], expected.data[0]); EXPECT_EQ(remainder.lo.lo.data[1], expected.data[1]); diff --git a/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx_impl.hpp b/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx_impl.hpp index 314a754b6ae..91c6c9ea070 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx_impl.hpp @@ -2,7 +2,7 @@ #include "./uintx.hpp" #include "barretenberg/common/assert.hpp" -namespace numeric { +namespace bb::numeric { template constexpr std::pair, uintx> uintx::divmod(const uintx& b) const { @@ -336,4 +336,4 @@ template constexpr uintx uintx::operator } return result; } -} // namespace numeric \ No newline at end of file +} // namespace bb::numeric \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.test.cpp b/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.test.cpp index 6a201015921..952997d0e00 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.test.cpp @@ -9,7 +9,7 @@ using namespace bb; using namespace bb::plonk; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } class StandardPlonkComposer : public ::testing::Test { diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.test.cpp index 47305d32389..0fd5c17b8ac 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.test.cpp @@ -12,10 +12,8 @@ using namespace bb; using namespace bb::plonk; -namespace bb::plonk::test_ultra_plonk_composer { - namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } using plookup::ColumnIdx; @@ -65,10 +63,10 @@ TYPED_TEST_SUITE(ultra_plonk_composer, BooleanTypes); TYPED_TEST(ultra_plonk_composer, create_gates_from_plookup_accumulators) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto composer = UltraComposer(); - bb::fr input_value = fr::random_element(); + fr input_value = fr::random_element(); const fr input_lo = static_cast(input_value).slice(0, plookup::fixed_base::table::BITS_PER_LO_SCALAR); const auto input_lo_index = circuit_builder.add_variable(input_lo); @@ -646,7 +644,7 @@ TYPED_TEST(ultra_plonk_composer, non_native_field_multiplication) const auto q_indices = get_limb_witness_indices(split_into_limbs(uint256_t(q))); const auto r_indices = get_limb_witness_indices(split_into_limbs(uint256_t(r))); - bb::non_native_field_witnesses inputs{ + non_native_field_witnesses inputs{ a_indices, b_indices, q_indices, r_indices, modulus_limbs, fr(uint256_t(modulus)), }; const auto [lo_1_idx, hi_1_idx] = builder.evaluate_non_native_field_multiplication(inputs); @@ -822,5 +820,3 @@ TEST(ultra_plonk_composer, range_constraint_small_variable) bool result = verifier.verify_proof(proof); EXPECT_EQ(result, true); } - -} // namespace bb::plonk::test_ultra_plonk_composer diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/commitment_scheme.test.cpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/commitment_scheme.test.cpp index bd446e47c10..299b1f83e1b 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/commitment_scheme.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/commitment_scheme.test.cpp @@ -35,7 +35,7 @@ TEST(commitment_scheme, kate_open) transcript::StandardTranscript inp_tx = transcript::StandardTranscript(transcript::Manifest()); plonk::KateCommitmentScheme newKate; - // std::shared_ptr> crs_factory = (new + // std::shared_ptr> crs_factory = (new // FileReferenceStringFactory("../srs_db/ignition")); auto file_crs = std::make_shared>("../srs_db/ignition"); auto crs = file_crs->get_prover_crs(n); diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/prover.test.cpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/prover.test.cpp index f7b92b5bdaf..0e9dbb679ce 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/prover.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/prover/prover.test.cpp @@ -113,8 +113,7 @@ plonk::Prover generate_test_data(const size_t n) // even indices = mul gates, odd incides = add gates - auto reference_string = - std::make_shared>(n + 1, "../srs_db/ignition"); + auto reference_string = std::make_shared>(n + 1, "../srs_db/ignition"); std::shared_ptr key = std::make_shared(n, 0, reference_string, CircuitType::STANDARD); polynomial w_l(n); diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/proving_key/proving_key.test.cpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/proving_key/proving_key.test.cpp index 70a71190761..846d04951f1 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/proving_key/proving_key.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/proving_key/proving_key.test.cpp @@ -140,8 +140,8 @@ StandardComposer(); fr a = fr::one(); builder.add_public_variable(a); bool all_polys_are_equal{ true }; for (size_t i = 0; i < precomputed_poly_list.size(); ++i) { std::string poly_id = precomputed_poly_list[i]; - bb::polynomial& input_poly = p_key.polynomial_store.get(poly_id); - bb::polynomial& output_poly = pk_data.polynomial_store.get(poly_id); + polynomial& input_poly = p_key.polynomial_store.get(poly_id); + polynomial& output_poly = pk_data.polynomial_store.get(poly_id); all_polys_are_equal = all_polys_are_equal && (input_poly == output_poly); } diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/public_inputs/public_inputs.test.cpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/public_inputs/public_inputs.test.cpp index 9e9923a0220..c9e7fdeb57e 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/public_inputs/public_inputs.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/public_inputs/public_inputs.test.cpp @@ -138,7 +138,7 @@ TEST(test_public_inputs, compute_delta) for (size_t i = 0; i < num_public_inputs; ++i) { public_inputs.push_back(left[i]); } - fr target_delta = bb::plonk::compute_public_input_delta(public_inputs, beta, gamma, domain.root); + fr target_delta = plonk::compute_public_input_delta(public_inputs, beta, gamma, domain.root); EXPECT_EQ((modified_result == target_delta), true); } diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.test.cpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.test.cpp index 088d5142f56..caf2e4c4972 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.test.cpp @@ -3,14 +3,11 @@ #include "barretenberg/common/test.hpp" #include "barretenberg/numeric/random/engine.hpp" -namespace { -auto& engine = numeric::random::get_debug_engine(); -} // namespace - using namespace bb; using namespace bb::plonk; - -namespace bb::plonk::test_verification_key { +namespace { +auto& engine = numeric::get_debug_randomness(); +} // namespace /** * @brief generate a random vk data for use in tests @@ -154,4 +151,3 @@ TEST(VerificationKey, HashEqualityDifferentRecursiveProofPublicInputIndices) vk1_data.recursive_proof_public_input_indices.push_back(42); expect_hashes_eq(vk0_data, vk1_data); } -} // namespace bb::plonk::test_verification_key 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 13e997110c0..10a50a38edb 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 @@ -28,7 +28,7 @@ plonk::Verifier generate_verifier(std::shared_ptr circuit_proving_k poly_coefficients[6] = circuit_proving_key->polynomial_store.get("sigma_2").data(); poly_coefficients[7] = circuit_proving_key->polynomial_store.get("sigma_3").data(); - std::vector commitments; + std::vector commitments; scalar_multiplication::pippenger_runtime_state state(circuit_proving_key->circuit_size); commitments.resize(8); diff --git a/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.test.cpp b/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.test.cpp index 49f6bf9bee0..37ef74ff9a8 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/transcript/transcript.test.cpp @@ -5,6 +5,8 @@ #include #include +using namespace bb; + namespace { transcript::Manifest create_manifest(const size_t num_public_inputs) { @@ -135,8 +137,8 @@ TEST(transcript, univariate_serialization) constexpr size_t num_public_inputs = 0; constexpr size_t LENGTH = 8; - using Fr = bb::fr; - using Univariate = bb::Univariate; + using Fr = fr; + using Univariate = Univariate; using Transcript = transcript::StandardTranscript; std::vector g1_vector(64); diff --git a/barretenberg/cpp/src/barretenberg/polynomials/barycentric.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/barycentric.test.cpp index 10efc3916d7..a481f9fc64e 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/barycentric.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/barycentric.test.cpp @@ -2,7 +2,7 @@ #include "univariate.hpp" #include -namespace bb::test_barycentric { +using namespace bb; template class BarycentricDataTests : public testing::Test {}; @@ -86,5 +86,3 @@ TYPED_TEST(BarycentricDataTests, BarycentricData5to6) Univariate expected{ { 1, 3, 25, 109, 321, 751 } }; EXPECT_EQ(ext1, expected); } - -} // namespace bb::test_barycentric diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.test.cpp index 6e2cc6aab79..16281c3a650 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.test.cpp @@ -1043,7 +1043,7 @@ TYPED_TEST(PolynomialTests, evaluate_mle) using FF = TypeParam; auto test_case = [](size_t N) { - auto& engine = numeric::random::get_debug_engine(); + auto& engine = numeric::get_debug_randomness(); const size_t m = numeric::get_msb(N); EXPECT_EQ(N, 1 << m); Polynomial poly(N); diff --git a/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp index b6aeff91265..a9da061ba73 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp @@ -2,29 +2,27 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" #include -namespace bb::test_pow { - -using FF = bb::fr; +using namespace bb; TEST(PowPolynomial, FullPowConsistency) { constexpr size_t d = 5; - std::vector betas(d); + std::vector betas(d); for (auto& beta : betas) { - beta = FF::random_element(); + beta = fr::random_element(); } - PowPolynomial pow_polynomial(betas); - std::array variables{}; + PowPolynomial pow_polynomial(betas); + std::array variables{}; for (auto& u_i : variables) { - u_i = FF::random_element(); + u_i = fr::random_element(); pow_polynomial.partially_evaluate(u_i); } size_t beta_idx = 0; - FF expected_eval = 1; + fr expected_eval = 1; for (auto& u_i : variables) { - expected_eval *= FF(1) - u_i + u_i * pow_polynomial.betas[beta_idx]; + expected_eval *= fr(1) - u_i + u_i * pow_polynomial.betas[beta_idx]; beta_idx++; } @@ -33,10 +31,9 @@ TEST(PowPolynomial, FullPowConsistency) TEST(PowPolynomial, PowPolynomialsOnPowers) { - auto betas = std::vector{ 2, 4, 16 }; + auto betas = std::vector{ 2, 4, 16 }; auto pow = PowPolynomial(betas); pow.compute_values(); - auto expected_values = std::vector{ 1, 2, 4, 8, 16, 32, 64, 128 }; + auto expected_values = std::vector{ 1, 2, 4, 8, 16, 32, 64, 128 }; EXPECT_EQ(expected_values, pow.pow_betas); } -} // namespace bb::test_pow diff --git a/barretenberg/cpp/src/barretenberg/polynomials/univariate.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/univariate.test.cpp index 5b35de5e68a..10bcd0abb07 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/univariate.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/univariate.test.cpp @@ -2,30 +2,23 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" #include -namespace bb::test_univariate { +using namespace bb; template class UnivariateTest : public testing::Test { public: template using UnivariateView = UnivariateView; }; -using FieldTypes = testing::Types; +using FieldTypes = testing::Types; TYPED_TEST_SUITE(UnivariateTest, FieldTypes); -#define UNIVARIATE_TESTS_ALIASES using FF = TypeParam; -// IMPROVEMENT: Can't make alias for Univariate for some reason. -// Might be convenient to solve boilerplate or repeated type aliasing -// using this or some other means. - TYPED_TEST(UnivariateTest, Constructors) { - UNIVARIATE_TESTS_ALIASES - - FF a0 = FF::random_element(); - FF a1 = FF::random_element(); - FF a2 = FF::random_element(); + fr a0 = fr::random_element(); + fr a1 = fr::random_element(); + fr a2 = fr::random_element(); - Univariate uni({ a0, a1, a2 }); + Univariate uni({ a0, a1, a2 }); EXPECT_EQ(uni.value_at(0), a0); EXPECT_EQ(uni.value_at(1), a1); @@ -34,124 +27,111 @@ TYPED_TEST(UnivariateTest, Constructors) TYPED_TEST(UnivariateTest, Addition) { - UNIVARIATE_TESTS_ALIASES - - Univariate f1{ { 1, 2 } }; - Univariate f2{ { 3, 4 } }; + Univariate f1{ { 1, 2 } }; + Univariate f2{ { 3, 4 } }; // output should be {4, 6} - Univariate expected_result{ { 4, 6 } }; + Univariate expected_result{ { 4, 6 } }; auto f1f2 = f1 + f2; EXPECT_EQ(f1f2, expected_result); } TYPED_TEST(UnivariateTest, Multiplication) { - UNIVARIATE_TESTS_ALIASES - Univariate f1 = Univariate{ { 1, 2 } }.template extend_to<3>(); - Univariate f2 = Univariate{ { 3, 4 } }.template extend_to<3>(); + Univariate f1 = Univariate{ { 1, 2 } }.template extend_to<3>(); + Univariate f2 = Univariate{ { 3, 4 } }.template extend_to<3>(); // output should be {3, 8, 15} - Univariate expected_result{ { 3, 8, 15 } }; - Univariate f1f2 = f1 * f2; + Univariate expected_result{ { 3, 8, 15 } }; + Univariate f1f2 = f1 * f2; EXPECT_EQ(f1f2, expected_result); } TYPED_TEST(UnivariateTest, ConstructUnivariateViewFromUnivariate) { - UNIVARIATE_TESTS_ALIASES - Univariate f{ { 1, 2, 3 } }; - UnivariateView g(f); + Univariate f{ { 1, 2, 3 } }; + UnivariateView g(f); EXPECT_EQ(g.value_at(0), f.value_at(0)); EXPECT_EQ(g.value_at(1), f.value_at(1)); } TYPED_TEST(UnivariateTest, ConstructUnivariateFromUnivariateView) { - UNIVARIATE_TESTS_ALIASES - Univariate f{ { 1, 2, 3 } }; - UnivariateView g(f); - Univariate h(g); + Univariate f{ { 1, 2, 3 } }; + UnivariateView g(f); + Univariate h(g); EXPECT_EQ(h.value_at(0), g.value_at(0)); EXPECT_EQ(h.value_at(1), g.value_at(1)); } TYPED_TEST(UnivariateTest, UnivariateViewAddition) { - UNIVARIATE_TESTS_ALIASES + Univariate f1{ { 1, 2, 3 } }; + Univariate f2{ { 3, 4, 3 } }; - Univariate f1{ { 1, 2, 3 } }; - Univariate f2{ { 3, 4, 3 } }; + UnivariateView g1(f1); + UnivariateView g2(f2); - UnivariateView g1(f1); - UnivariateView g2(f2); - - Univariate expected_result{ { 4, 6 } }; - Univariate result = g1 + g2; + Univariate expected_result{ { 4, 6 } }; + Univariate result = g1 + g2; EXPECT_EQ(result, expected_result); - Univariate result2 = result + g1; - Univariate expected_result2{ { 5, 8 } }; + Univariate result2 = result + g1; + Univariate expected_result2{ { 5, 8 } }; EXPECT_EQ(result2, expected_result2); } TYPED_TEST(UnivariateTest, UnivariateViewSubtraction) { - UNIVARIATE_TESTS_ALIASES - - Univariate f1{ { 1, 2, 3 } }; - Univariate f2{ { 3, 4, 3 } }; + Univariate f1{ { 1, 2, 3 } }; + Univariate f2{ { 3, 4, 3 } }; - UnivariateView g1(f1); - UnivariateView g2(f2); + UnivariateView g1(f1); + UnivariateView g2(f2); - Univariate expected_result{ { -2, -2 } }; - Univariate result = g1 - g2; + Univariate expected_result{ { -2, -2 } }; + Univariate result = g1 - g2; EXPECT_EQ(result, expected_result); - Univariate result2 = result - g1; - Univariate expected_result2{ { -3, -4 } }; + Univariate result2 = result - g1; + Univariate expected_result2{ { -3, -4 } }; EXPECT_EQ(result2, expected_result2); } TYPED_TEST(UnivariateTest, UnivariateViewMultiplication) { - UNIVARIATE_TESTS_ALIASES + Univariate f1{ { 1, 2, 3 } }; + Univariate f2{ { 3, 4, 3 } }; - Univariate f1{ { 1, 2, 3 } }; - Univariate f2{ { 3, 4, 3 } }; + UnivariateView g1(f1); + UnivariateView g2(f2); - UnivariateView g1(f1); - UnivariateView g2(f2); - - Univariate expected_result{ { 3, 8 } }; - Univariate result = g1 * g2; + Univariate expected_result{ { 3, 8 } }; + Univariate result = g1 * g2; EXPECT_EQ(result, expected_result); - Univariate result2 = result * g1; - Univariate expected_result2{ { 3, 16 } }; + Univariate result2 = result * g1; + Univariate expected_result2{ { 3, 16 } }; EXPECT_EQ(result2, expected_result2); } TYPED_TEST(UnivariateTest, Serialization) { - UNIVARIATE_TESTS_ALIASES - const size_t LENGTH = 4; - std::array evaluations; + std::array evaluations; for (size_t i = 0; i < LENGTH; ++i) { - evaluations[i] = FF::random_element(); + evaluations[i] = fr::random_element(); } // Instantiate a Univariate from the evaluations - auto univariate = Univariate(evaluations); + auto univariate = Univariate(evaluations); // Serialize univariate to buffer std::vector buffer = univariate.to_buffer(); // Deserialize - auto deserialized_univariate = Univariate::serialize_from_buffer(&buffer[0]); + auto deserialized_univariate = Univariate::serialize_from_buffer(&buffer[0]); for (size_t i = 0; i < LENGTH; ++i) { EXPECT_EQ(univariate.value_at(i), deserialized_univariate.value_at(i)); @@ -160,17 +140,13 @@ TYPED_TEST(UnivariateTest, Serialization) TYPED_TEST(UnivariateTest, EvaluationCustomDomain) { - UNIVARIATE_TESTS_ALIASES - []() { - auto poly = Univariate(std::array{ 1, 2 }); - EXPECT_EQ(poly.evaluate(FF(5)), FF(5)); + auto poly = Univariate(std::array{ 1, 2 }); + EXPECT_EQ(poly.evaluate(fr(5)), fr(5)); }(); []() { - auto poly = Univariate(std::array{ 1, 11, 111, 1111, 11111 }); - EXPECT_EQ(poly.evaluate(FF(2)), FF(294330751)); + auto poly = Univariate(std::array{ 1, 11, 111, 1111, 11111 }); + EXPECT_EQ(poly.evaluate(fr(2)), fr(294330751)); }(); } - -} // namespace bb::test_univariate diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_builder_types.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_builder_types.hpp index d01d92ce5d6..99f7103afcf 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_builder_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_builder_types.hpp @@ -2,7 +2,7 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" -namespace bb_eccvm { +namespace bb::eccvm { static constexpr size_t NUM_SCALAR_BITS = 128; static constexpr size_t WNAF_SLICE_BITS = 4; @@ -44,4 +44,4 @@ template struct ScalarMul { template using MSM = std::vector>; -} // namespace bb_eccvm \ No newline at end of file +} // namespace bb::eccvm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp index b73b1889710..7569275796e 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp @@ -24,21 +24,21 @@ template class ECCVMCircuitBuilder { using Element = typename CycleGroup::element; using AffineElement = typename CycleGroup::affine_element; - static constexpr size_t NUM_SCALAR_BITS = bb_eccvm::NUM_SCALAR_BITS; - static constexpr size_t WNAF_SLICE_BITS = bb_eccvm::WNAF_SLICE_BITS; - static constexpr size_t NUM_WNAF_SLICES = bb_eccvm::NUM_WNAF_SLICES; - static constexpr uint64_t WNAF_MASK = bb_eccvm::WNAF_MASK; - static constexpr size_t POINT_TABLE_SIZE = bb_eccvm::POINT_TABLE_SIZE; - static constexpr size_t WNAF_SLICES_PER_ROW = bb_eccvm::WNAF_SLICES_PER_ROW; - static constexpr size_t ADDITIONS_PER_ROW = bb_eccvm::ADDITIONS_PER_ROW; + static constexpr size_t NUM_SCALAR_BITS = bb::eccvm::NUM_SCALAR_BITS; + static constexpr size_t WNAF_SLICE_BITS = bb::eccvm::WNAF_SLICE_BITS; + static constexpr size_t NUM_WNAF_SLICES = bb::eccvm::NUM_WNAF_SLICES; + static constexpr uint64_t WNAF_MASK = bb::eccvm::WNAF_MASK; + static constexpr size_t POINT_TABLE_SIZE = bb::eccvm::POINT_TABLE_SIZE; + static constexpr size_t WNAF_SLICES_PER_ROW = bb::eccvm::WNAF_SLICES_PER_ROW; + static constexpr size_t ADDITIONS_PER_ROW = bb::eccvm::ADDITIONS_PER_ROW; static constexpr size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; static constexpr size_t NUM_WIRES = Flavor::NUM_WIRES; - using MSM = bb_eccvm::MSM; - using VMOperation = bb_eccvm::VMOperation; + using MSM = bb::eccvm::MSM; + using VMOperation = bb::eccvm::VMOperation; std::shared_ptr op_queue; - using ScalarMul = bb_eccvm::ScalarMul; + using ScalarMul = bb::eccvm::ScalarMul; using ProverPolynomials = typename Flavor::ProverPolynomials; ECCVMCircuitBuilder() diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.test.cpp index 013e9a3c086..18bacda13ef 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.test.cpp @@ -6,11 +6,9 @@ using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } -namespace eccvm_circuit_builder_tests { - template class ECCVMCircuitBuilderTests : public ::testing::Test {}; using FlavorTypes = ::testing::Types; @@ -21,7 +19,7 @@ TYPED_TEST(ECCVMCircuitBuilderTests, BaseCase) using Flavor = TypeParam; using G1 = typename Flavor::CycleGroup; using Fr = typename G1::Fr; - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; auto generators = G1::derive_generators("test generators", 3); typename G1::element a = generators[0]; typename G1::element b = generators[1]; @@ -55,7 +53,7 @@ TYPED_TEST(ECCVMCircuitBuilderTests, Add) { using Flavor = TypeParam; using G1 = typename Flavor::CycleGroup; - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; auto generators = G1::derive_generators("test generators", 3); typename G1::element a = generators[0]; @@ -71,7 +69,7 @@ TYPED_TEST(ECCVMCircuitBuilderTests, Mul) using Flavor = TypeParam; using G1 = typename Flavor::CycleGroup; using Fr = typename G1::Fr; - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; auto generators = G1::derive_generators("test generators", 3); typename G1::element a = generators[0]; Fr x = Fr::random_element(&engine); @@ -87,7 +85,7 @@ TYPED_TEST(ECCVMCircuitBuilderTests, ShortMul) using Flavor = TypeParam; using G1 = typename Flavor::CycleGroup; using Fr = typename G1::Fr; - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; auto generators = G1::derive_generators("test generators", 3); typename G1::element a = generators[0]; @@ -109,7 +107,7 @@ TYPED_TEST(ECCVMCircuitBuilderTests, EqFails) using Flavor = TypeParam; using G1 = typename Flavor::CycleGroup; using Fr = typename G1::Fr; - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; auto generators = G1::derive_generators("test generators", 3); typename G1::element a = generators[0]; @@ -124,7 +122,7 @@ TYPED_TEST(ECCVMCircuitBuilderTests, EqFails) TYPED_TEST(ECCVMCircuitBuilderTests, EmptyRow) { using Flavor = TypeParam; - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; circuit.empty_row(); @@ -137,7 +135,7 @@ TYPED_TEST(ECCVMCircuitBuilderTests, EmptyRowBetweenOps) using Flavor = TypeParam; using G1 = typename Flavor::CycleGroup; using Fr = typename G1::Fr; - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; auto generators = G1::derive_generators("test generators", 3); typename G1::element a = generators[0]; @@ -158,7 +156,7 @@ TYPED_TEST(ECCVMCircuitBuilderTests, EndWithEq) using Flavor = TypeParam; using G1 = typename Flavor::CycleGroup; using Fr = typename G1::Fr; - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; auto generators = G1::derive_generators("test generators", 3); typename G1::element a = generators[0]; @@ -178,7 +176,7 @@ TYPED_TEST(ECCVMCircuitBuilderTests, EndWithAdd) using Flavor = TypeParam; using G1 = typename Flavor::CycleGroup; using Fr = typename G1::Fr; - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; auto generators = G1::derive_generators("test generators", 3); typename G1::element a = generators[0]; @@ -199,7 +197,7 @@ TYPED_TEST(ECCVMCircuitBuilderTests, EndWithMul) using Flavor = TypeParam; using G1 = typename Flavor::CycleGroup; using Fr = typename G1::Fr; - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; auto generators = G1::derive_generators("test generators", 3); typename G1::element a = generators[0]; @@ -218,7 +216,7 @@ TYPED_TEST(ECCVMCircuitBuilderTests, EndWithNoop) using Flavor = TypeParam; using G1 = typename Flavor::CycleGroup; using Fr = typename G1::Fr; - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; auto generators = G1::derive_generators("test generators", 3); typename G1::element a = generators[0]; @@ -257,17 +255,16 @@ TYPED_TEST(ECCVMCircuitBuilderTests, MSM) // single msms for (size_t j = 1; j < max_num_msms; ++j) { using Flavor = TypeParam; - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; try_msms(j, circuit); bool result = circuit.check_circuit(); EXPECT_EQ(result, true); } // chain msms - bb::ECCVMCircuitBuilder circuit; + ECCVMCircuitBuilder circuit; for (size_t j = 1; j < 9; ++j) { try_msms(j, circuit); } bool result = circuit.check_circuit(); EXPECT_EQ(result, true); } -} // namespace eccvm_circuit_builder_tests \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/msm_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/msm_builder.hpp index c47f818ff30..6f0c45e3744 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/msm_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/msm_builder.hpp @@ -13,9 +13,9 @@ template class ECCVMMSMMBuilder { using Element = typename CycleGroup::element; using AffineElement = typename CycleGroup::affine_element; - static constexpr size_t ADDITIONS_PER_ROW = bb_eccvm::ADDITIONS_PER_ROW; - static constexpr size_t NUM_SCALAR_BITS = bb_eccvm::NUM_SCALAR_BITS; - static constexpr size_t WNAF_SLICE_BITS = bb_eccvm::WNAF_SLICE_BITS; + static constexpr size_t ADDITIONS_PER_ROW = bb::eccvm::ADDITIONS_PER_ROW; + static constexpr size_t NUM_SCALAR_BITS = bb::eccvm::NUM_SCALAR_BITS; + static constexpr size_t WNAF_SLICE_BITS = bb::eccvm::WNAF_SLICE_BITS; struct MSMState { uint32_t pc = 0; @@ -53,7 +53,7 @@ template class ECCVMMSMMBuilder { * @param total_number_of_muls * @return std::vector */ - static std::vector compute_msm_state(const std::vector>& msms, + static std::vector compute_msm_state(const std::vector>& msms, std::array, 2>& point_table_read_counts, const uint32_t total_number_of_muls) { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/precomputed_tables_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/precomputed_tables_builder.hpp index ca583c8de41..1c7d2bb443e 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/precomputed_tables_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/precomputed_tables_builder.hpp @@ -11,9 +11,9 @@ template class ECCVMPrecomputedTablesBuilder { using Element = typename CycleGroup::element; using AffineElement = typename CycleGroup::affine_element; - static constexpr size_t NUM_WNAF_SLICES = bb_eccvm::NUM_WNAF_SLICES; - static constexpr size_t WNAF_SLICES_PER_ROW = bb_eccvm::WNAF_SLICES_PER_ROW; - static constexpr size_t WNAF_SLICE_BITS = bb_eccvm::WNAF_SLICE_BITS; + static constexpr size_t NUM_WNAF_SLICES = bb::eccvm::NUM_WNAF_SLICES; + static constexpr size_t WNAF_SLICES_PER_ROW = bb::eccvm::WNAF_SLICES_PER_ROW; + static constexpr size_t WNAF_SLICE_BITS = bb::eccvm::WNAF_SLICE_BITS; struct PrecomputeState { int s1 = 0; @@ -34,7 +34,7 @@ template class ECCVMPrecomputedTablesBuilder { }; static std::vector compute_precompute_state( - const std::vector>& ecc_muls) + const std::vector>& ecc_muls) { std::vector precompute_state; @@ -101,7 +101,7 @@ template class ECCVMPrecomputedTablesBuilder { row.precompute_double = d2; // fill accumulator in reverse order i.e. first row = 15[P], then 13[P], ..., 1[P] - row.precompute_accumulator = entry.precomputed_table[bb_eccvm::POINT_TABLE_SIZE - 1 - i]; + row.precompute_accumulator = entry.precomputed_table[bb::eccvm::POINT_TABLE_SIZE - 1 - i]; precompute_state.emplace_back(row); } } diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/transcript_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/transcript_builder.hpp index 5d0c693eac6..1ff3d8b4cba 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/transcript_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/transcript_builder.hpp @@ -58,7 +58,7 @@ template class ECCVMTranscriptBuilder { } }; static std::vector compute_transcript_state( - const std::vector>& vm_operations, const uint32_t total_number_of_muls) + const std::vector>& vm_operations, const uint32_t total_number_of_muls) { std::vector transcript_state; VMState state{ @@ -74,7 +74,7 @@ template class ECCVMTranscriptBuilder { transcript_state.emplace_back(TranscriptState{}); for (size_t i = 0; i < vm_operations.size(); ++i) { TranscriptState row; - const bb_eccvm::VMOperation& entry = vm_operations[i]; + const bb::eccvm::VMOperation& entry = vm_operations[i]; const bool is_mul = entry.mul; const bool z1_zero = (entry.mul) ? entry.z1 == 0 : true; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_translator_circuit_builder.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_translator_circuit_builder.test.cpp index acfdad1c165..e08938d1957 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_translator_circuit_builder.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_translator_circuit_builder.test.cpp @@ -7,10 +7,8 @@ using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } -namespace bb { - /** * @brief Check that a single accumulation gate is created correctly * @@ -78,9 +76,9 @@ TEST(GoblinTranslatorCircuitBuilder, CircuitBuilderBaseCase) */ TEST(GoblinTranslatorCircuitBuilder, SeveralOperationCorrectness) { - using point = bb::g1::affine_element; - using scalar = bb::fr; - using Fq = bb::fq; + using point = g1::affine_element; + using scalar = fr; + using Fq = fq; auto P1 = point::random_element(); auto P2 = point::random_element(); @@ -128,5 +126,4 @@ TEST(GoblinTranslatorCircuitBuilder, SeveralOperationCorrectness) EXPECT_TRUE(circuit_builder.check_circuit()); // Check the computation result is in line with what we've computed EXPECT_EQ(result, circuit_builder.get_computation_result()); -} -} // namespace bb \ No newline at end of file +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_translator_mini.fuzzer.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_translator_mini.fuzzer.cpp index ee34d21262b..f390dd0b8ef 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_translator_mini.fuzzer.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_translator_mini.fuzzer.cpp @@ -1,7 +1,10 @@ #include "barretenberg/numeric/uint256/uint256.hpp" #include "goblin_translator_circuit_builder.hpp" -using Fr = ::curve::BN254::ScalarField; -using Fq = ::curve::BN254::BaseField; + +using namespace bb; + +using Fr = curve::BN254::ScalarField; +using Fq = curve::BN254::BaseField; extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size) { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.test.cpp index 927f563626c..4e2b8566715 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.test.cpp @@ -4,7 +4,7 @@ using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } namespace bb { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/standard_circuit_builder.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/standard_circuit_builder.test.cpp index 7b3ab977ae4..aec2887e552 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/standard_circuit_builder.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/standard_circuit_builder.test.cpp @@ -6,11 +6,9 @@ using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } -namespace standard_circuit_constructor_tests { - TEST(standard_circuit_constructor, base_case) { StandardCircuitBuilder circuit_constructor = StandardCircuitBuilder(); @@ -467,5 +465,3 @@ TEST(standard_circuit_constructor, test_check_circuit_broken) bool result = circuit_constructor.check_circuit(); EXPECT_EQ(result, false); } - -} // namespace standard_circuit_constructor_tests diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp index 2049cf001a3..25e182c0a46 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/toy_avm/toy_avm_circuit_builder.test.cpp @@ -8,11 +8,9 @@ using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } -namespace toy_avm_circuit_builder_tests { - /** * @brief A test explaining the work of the permutations in Toy AVM * @@ -20,8 +18,8 @@ namespace toy_avm_circuit_builder_tests { TEST(ToyAVMCircuitBuilder, BaseCase) { - using FF = bb::honk::flavor::ToyFlavor::FF; - using Builder = bb::ToyCircuitBuilder; + using FF = honk::flavor::ToyFlavor::FF; + using Builder = ToyCircuitBuilder; using Row = Builder::Row; Builder circuit_builder; @@ -118,4 +116,3 @@ TEST(ToyAVMCircuitBuilder, BaseCase) circuit_builder.rows[2].toy_xor_a = tmp; EXPECT_EQ(circuit_builder.check_circuit(), true); } -} // namespace toy_avm_circuit_builder_tests \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.test.cpp index 8605db48b4a..16e1252712a 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.test.cpp @@ -5,7 +5,7 @@ using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } namespace bb { using plookup::ColumnIdx; @@ -44,7 +44,7 @@ TEST(ultra_circuit_constructor, create_gates_from_plookup_accumulators) UltraCircuitBuilder circuit_builder = UltraCircuitBuilder(); - bb::fr input_value = fr::random_element(); + fr input_value = fr::random_element(); const fr input_lo = static_cast(input_value).slice(0, plookup::fixed_base::table::BITS_PER_LO_SCALAR); const auto input_lo_index = circuit_builder.add_variable(input_lo); @@ -648,7 +648,7 @@ TEST(ultra_circuit_constructor, non_native_field_multiplication) const auto q_indices = get_limb_witness_indices(split_into_limbs(uint256_t(q))); const auto r_indices = get_limb_witness_indices(split_into_limbs(uint256_t(r))); - bb::non_native_field_witnesses inputs{ + non_native_field_witnesses inputs{ a_indices, b_indices, q_indices, r_indices, modulus_limbs, fr(uint256_t(modulus)), }; const auto [lo_1_idx, hi_1_idx] = circuit_constructor.evaluate_non_native_field_multiplication(inputs); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.test.cpp index 1f2aac2b46f..aad30452664 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.test.cpp @@ -6,7 +6,7 @@ #include #include -namespace bb::test_composer_lib { +using namespace bb; class ComposerLibTests : public ::testing::Test { protected: @@ -14,7 +14,7 @@ class ComposerLibTests : public ::testing::Test { using FF = typename Flavor::FF; Flavor::CircuitBuilder circuit_constructor; Flavor::ProvingKey proving_key = []() { - auto crs_factory = bb::srs::factories::CrsFactory(); + auto crs_factory = srs::factories::CrsFactory(); auto crs = crs_factory.get_prover_crs(4); return Flavor::ProvingKey(/*circuit_size=*/8, /*num_public_inputs=*/0); }(); @@ -59,5 +59,3 @@ TEST_F(ComposerLibTests, ConstructSelectors) EXPECT_EQ(proving_key.q_c[2 + offset], 19); EXPECT_EQ(proving_key.q_c[3 + offset], 20); } - -} // namespace bb::test_composer_lib diff --git a/barretenberg/cpp/src/barretenberg/proof_system/composer/permutation_lib.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/composer/permutation_lib.test.cpp index 0ebd08ea382..3fc4d2bcb3c 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/composer/permutation_lib.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/composer/permutation_lib.test.cpp @@ -6,7 +6,7 @@ #include #include -namespace bb::test_composer_lib { +using namespace bb; class PermutationHelperTests : public ::testing::Test { protected: @@ -14,7 +14,7 @@ class PermutationHelperTests : public ::testing::Test { using FF = typename Flavor::FF; using ProvingKey = Flavor::ProvingKey; Flavor::CircuitBuilder circuit_constructor; - bb::srs::factories::CrsFactory crs_factory = bb::srs::factories::CrsFactory(); + srs::factories::CrsFactory crs_factory = srs::factories::CrsFactory(); std::shared_ptr proving_key; virtual void SetUp() @@ -89,5 +89,3 @@ TEST_F(PermutationHelperTests, ComputeStandardAuxPolynomials) // TODO(#425) Flesh out these tests compute_first_and_last_lagrange_polynomials(proving_key); } - -} // namespace bb::test_composer_lib diff --git a/barretenberg/cpp/src/barretenberg/proof_system/library/grand_product_library.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/library/grand_product_library.test.cpp index e78684c82c7..7e78b77e3cd 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/library/grand_product_library.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/library/grand_product_library.test.cpp @@ -6,9 +6,8 @@ #include "barretenberg/srs/factories/file_crs_factory.hpp" #include - +using namespace bb; using namespace bb::honk; -namespace grand_product_library_tests { template class GrandProductTests : public testing::Test { @@ -81,7 +80,7 @@ template class GrandProductTests : public testing::Test { auto beta = FF::random_element(); auto gamma = FF::random_element(); - bb::RelationParameters params{ + RelationParameters params{ .eta = 0, .beta = beta, .gamma = gamma, @@ -91,8 +90,7 @@ template class GrandProductTests : public testing::Test { typename Flavor::ProverPolynomials prover_polynomials; for (auto [prover_poly, key_poly] : zip_view(prover_polynomials.get_unshifted(), proving_key->get_all())) { - ASSERT(bb::flavor_get_label(prover_polynomials, prover_poly) == - bb::flavor_get_label(*proving_key, key_poly)); + ASSERT(flavor_get_label(prover_polynomials, prover_poly) == flavor_get_label(*proving_key, key_poly)); prover_poly = key_poly.share(); } @@ -232,7 +230,7 @@ template class GrandProductTests : public testing::Test { auto gamma = FF::random_element(); auto eta = FF::random_element(); - bb::RelationParameters params{ + RelationParameters params{ .eta = eta, .beta = beta, .gamma = gamma, @@ -242,14 +240,13 @@ template class GrandProductTests : public testing::Test { typename Flavor::ProverPolynomials prover_polynomials; for (auto [prover_poly, key_poly] : zip_view(prover_polynomials.get_unshifted(), proving_key->get_all())) { - ASSERT(bb::flavor_get_label(prover_polynomials, prover_poly) == - bb::flavor_get_label(*proving_key, key_poly)); + ASSERT(flavor_get_label(prover_polynomials, prover_poly) == flavor_get_label(*proving_key, key_poly)); prover_poly = key_poly.share(); } for (auto [prover_poly, key_poly] : zip_view(prover_polynomials.get_shifted(), proving_key->get_to_be_shifted())) { - ASSERT(bb::flavor_get_label(prover_polynomials, prover_poly) == - bb::flavor_get_label(*proving_key, key_poly) + "_shift"); + ASSERT(flavor_get_label(prover_polynomials, prover_poly) == + flavor_get_label(*proving_key, key_poly) + "_shift"); prover_poly = key_poly.shifted(); } // Test a few assignments @@ -260,7 +257,7 @@ template class GrandProductTests : public testing::Test { // Method 1: Compute z_lookup using the prover library method constexpr size_t LOOKUP_RELATION_INDEX = 1; using LHS = typename std::tuple_element::type; - using RHS = bb::LookupRelation; + using RHS = LookupRelation; static_assert(std::same_as); grand_product_library::compute_grand_product( proving_key->circuit_size, prover_polynomials, params); @@ -351,5 +348,3 @@ TYPED_TEST(GrandProductTests, GrandProductLookup) { TestFixture::test_lookup_grand_product_construction(); } - -} // namespace grand_product_library_tests diff --git a/barretenberg/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp b/barretenberg/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp index 1caa057f858..a4d5d3642eb 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.hpp @@ -26,7 +26,7 @@ class ECCOpQueue { Point accumulator = point_at_infinity; public: - using ECCVMOperation = bb_eccvm::VMOperation; + using ECCVMOperation = bb::eccvm::VMOperation; std::vector raw_ops; std::array, 4> ultra_ops; // ops encoded in the width-4 Ultra format diff --git a/barretenberg/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.test.cpp index 2df97e0e810..7b13cce43f3 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/op_queue/ecc_op_queue.test.cpp @@ -1,7 +1,8 @@ #include "barretenberg/proof_system/op_queue/ecc_op_queue.hpp" #include -namespace bb::test_flavor { +using namespace bb; + TEST(ECCOpQueueTest, Basic) { ECCOpQueue op_queue; @@ -13,8 +14,8 @@ TEST(ECCOpQueueTest, Basic) TEST(ECCOpQueueTest, InternalAccumulatorCorrectness) { - using point = bb::g1::affine_element; - using scalar = bb::fr; + using point = g1::affine_element; + using scalar = fr; // Compute a simple point accumulation natively auto P1 = point::random_element(); @@ -36,5 +37,3 @@ TEST(ECCOpQueueTest, InternalAccumulatorCorrectness) // Adding an equality op should reset the accumulator to zero (the point at infinity) EXPECT_TRUE(op_queue.get_accumulator().is_point_at_infinity()); } - -} // namespace bb::test_flavor diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp index c1367e62414..132ba614498 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp @@ -6,13 +6,12 @@ #include "barretenberg/sumcheck/instance/instances.hpp" #include +using namespace bb; using namespace bb::honk; -namespace bb::test_protogalaxy_prover { -using Flavor = bb::honk::flavor::Ultra; + +using Flavor = honk::flavor::Ultra; using Polynomial = typename Flavor::Polynomial; using FF = typename Flavor::FF; -using RelationParameters = bb::RelationParameters; -using PowPolynomial = bb::PowPolynomial; // TODO(https://github.com/AztecProtocol/barretenberg/issues/780): Improve combiner tests to check more than the // arithmetic relation so we more than unit test folding relation parameters and alpha as well. @@ -43,7 +42,7 @@ TEST(Protogalaxy, CombinerOn2Instances) for (size_t idx = 0; idx < NUM_INSTANCES; idx++) { auto instance = std::make_shared(); - auto prover_polynomials = bb::honk::get_sequential_prover_polynomials( + auto prover_polynomials = honk::get_sequential_prover_polynomials( /*log_circuit_size=*/1, idx * 128); restrict_to_standard_arithmetic_relation(prover_polynomials); instance->prover_polynomials = std::move(prover_polynomials); @@ -52,22 +51,22 @@ TEST(Protogalaxy, CombinerOn2Instances) } ProverInstances instances{ instance_data }; - instances.alphas.fill(Univariate(FF(0))); // focus on the arithmetic relation only + instances.alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only auto pow_polynomial = PowPolynomial(std::vector{ 2 }); auto result = prover.compute_combiner(instances, pow_polynomial); - auto expected_result = bb::Univariate(std::array{ 87706, - 13644570, - 76451738, - 226257946, - static_cast(500811930), - static_cast(937862426), - static_cast(1575158170), - static_cast(2450447898), - static_cast(3601480346), - static_cast(5066004250), - static_cast(6881768346), - static_cast(9086521370), - static_cast(11718012058) }); + auto expected_result = Univariate(std::array{ 87706, + 13644570, + 76451738, + 226257946, + static_cast(500811930), + static_cast(937862426), + static_cast(1575158170), + static_cast(2450447898), + static_cast(3601480346), + static_cast(5066004250), + static_cast(6881768346), + static_cast(9086521370), + static_cast(11718012058) }); EXPECT_EQ(result, expected_result); } else { std::vector> instance_data(NUM_INSTANCES); @@ -75,7 +74,7 @@ TEST(Protogalaxy, CombinerOn2Instances) for (size_t idx = 0; idx < NUM_INSTANCES; idx++) { auto instance = std::make_shared(); - auto prover_polynomials = bb::honk::get_zero_prover_polynomials( + auto prover_polynomials = honk::get_zero_prover_polynomials( /*log_circuit_size=*/1); restrict_to_standard_arithmetic_relation(prover_polynomials); instance->prover_polynomials = std::move(prover_polynomials); @@ -84,7 +83,7 @@ TEST(Protogalaxy, CombinerOn2Instances) } ProverInstances instances{ instance_data }; - instances.alphas.fill(Univariate(FF(0))); // focus on the arithmetic relation only + instances.alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only const auto create_add_gate = [](auto& polys, const size_t idx, FF w_l, FF w_r) { polys.w_l[idx] = w_l; @@ -133,7 +132,7 @@ TEST(Protogalaxy, CombinerOn2Instances) auto pow_polynomial = PowPolynomial(std::vector{ 2 }); auto result = prover.compute_combiner(instances, pow_polynomial); auto expected_result = - bb::Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660, 792 }); + Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660, 792 }); EXPECT_EQ(result, expected_result); } @@ -166,7 +165,7 @@ TEST(Protogalaxy, CombinerOn4Instances) for (size_t idx = 0; idx < NUM_INSTANCES; idx++) { auto instance = std::make_shared(); - auto prover_polynomials = bb::honk::get_zero_prover_polynomials( + auto prover_polynomials = honk::get_zero_prover_polynomials( /*log_circuit_size=*/1); instance->prover_polynomials = std::move(prover_polynomials); instance->instance_size = 2; @@ -174,7 +173,7 @@ TEST(Protogalaxy, CombinerOn4Instances) } ProverInstances instances{ instance_data }; - instances.alphas.fill(Univariate(FF(0))); // focus on the arithmetic relation only + instances.alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only zero_all_selectors(instances[0]->prover_polynomials); zero_all_selectors(instances[1]->prover_polynomials); @@ -185,10 +184,8 @@ TEST(Protogalaxy, CombinerOn4Instances) auto result = prover.compute_combiner(instances, pow_polynomial); std::array zeroes; std::fill(zeroes.begin(), zeroes.end(), 0); - auto expected_result = bb::Univariate(zeroes); + auto expected_result = Univariate(zeroes); EXPECT_EQ(result, expected_result); }; run_test(); }; - -} // namespace bb::test_protogalaxy_prover \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/nested_containers.test.cpp b/barretenberg/cpp/src/barretenberg/relations/nested_containers.test.cpp index 6a6e08d0ddf..730125f0bc9 100644 --- a/barretenberg/cpp/src/barretenberg/relations/nested_containers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/nested_containers.test.cpp @@ -5,9 +5,7 @@ using namespace bb; -namespace bb::nested_contianers_tests { - -using FF = bb::fr; +using FF = fr; class NestedContainers : public testing::Test {}; @@ -15,12 +13,10 @@ TEST_F(NestedContainers, Univariate) { static constexpr std::array LENGTHS = { 0, 1, 2 }; static constexpr TupleOfUnivariates tuple; - static constexpr auto result0 = bb::Univariate(); - static constexpr auto result1 = bb::Univariate(); - static constexpr auto result2 = bb::Univariate(); + static constexpr auto result0 = Univariate(); + static constexpr auto result1 = Univariate(); + static constexpr auto result2 = Univariate(); EXPECT_EQ(std::get<0>(tuple), result0); EXPECT_EQ(std::get<1>(tuple), result1); EXPECT_EQ(std::get<2>(tuple), result2); } - -} // namespace bb::nested_contianers_tests diff --git a/barretenberg/cpp/src/barretenberg/relations/relation_manual.test.cpp b/barretenberg/cpp/src/barretenberg/relations/relation_manual.test.cpp index efe920903b9..099a7c3f25d 100644 --- a/barretenberg/cpp/src/barretenberg/relations/relation_manual.test.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/relation_manual.test.cpp @@ -4,16 +4,16 @@ #include "barretenberg/relations/relation_parameters.hpp" #include -namespace bb::relation_manual_tests { +using namespace bb; -using FF = bb::fr; +using FF = fr; class RelationManual : public testing::Test {}; TEST_F(RelationManual, Poseidon2ExternalRelationZeros) { using Accumulator = std::array; - using Relation = Poseidon2ExternalRelation; + using Relation = bb::Poseidon2ExternalRelation; Accumulator acc{ 0, 0, 0, 0 }; struct AllPoseidonValues { @@ -44,7 +44,7 @@ TEST_F(RelationManual, Poseidon2ExternalRelationZeros) TEST_F(RelationManual, Poseidon2ExternalRelationRandom) { using Accumulator = std::array; - using Relation = Poseidon2ExternalRelation; + using Relation = bb::Poseidon2ExternalRelation; Accumulator acc{ 0, 0, 0, 0 }; struct AllPoseidonValues { @@ -90,7 +90,7 @@ TEST_F(RelationManual, Poseidon2ExternalRelationRandom) TEST_F(RelationManual, Poseidon2InternalRelationZeros) { using Accumulator = std::array; - using Relation = Poseidon2InternalRelation; + using Relation = bb::Poseidon2InternalRelation; Accumulator acc{ 0, 0, 0, 0 }; struct AllPoseidonValues { @@ -121,7 +121,7 @@ TEST_F(RelationManual, Poseidon2InternalRelationZeros) TEST_F(RelationManual, Poseidon2InternalRelationRandom) { using Accumulator = std::array; - using Relation = Poseidon2InternalRelation; + using Relation = bb::Poseidon2InternalRelation; Accumulator acc{ 0, 0, 0, 0 }; struct AllPoseidonValues { @@ -164,5 +164,4 @@ TEST_F(RelationManual, Poseidon2InternalRelationRandom) EXPECT_EQ(acc[1], 0); EXPECT_EQ(acc[2], 0); EXPECT_EQ(acc[3], 0); -} -}; // namespace bb::relation_manual_tests \ No newline at end of file +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/goblin_translator_relation_consistency.test.cpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/goblin_translator_relation_consistency.test.cpp index 617a6b49e8c..4f8093f9ad8 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/goblin_translator_relation_consistency.test.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/goblin_translator_relation_consistency.test.cpp @@ -16,8 +16,6 @@ using namespace bb; -namespace bb::ultra_relation_consistency_tests { - using Flavor = honk::flavor::GoblinTranslator; using FF = typename Flavor::FF; using InputElements = typename Flavor::AllValues; @@ -947,5 +945,3 @@ TEST_F(GoblinTranslatorRelationConsistency, NonNativeFieldRelation) run_test(/*random_inputs=*/false); run_test(/*random_inputs=*/true); }; - -} // namespace bb::ultra_relation_consistency_tests diff --git a/barretenberg/cpp/src/barretenberg/relations/ultra_relation_consistency.test.cpp b/barretenberg/cpp/src/barretenberg/relations/ultra_relation_consistency.test.cpp index 8af4e374f34..731725d6ee2 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ultra_relation_consistency.test.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/ultra_relation_consistency.test.cpp @@ -26,9 +26,7 @@ using namespace bb; -namespace bb::ultra_relation_consistency_tests { - -using FF = bb::fr; +using FF = fr; struct InputElements { static constexpr size_t NUM_ELEMENTS = 45; std::array _data; @@ -680,5 +678,3 @@ TEST_F(UltraRelationConsistency, Poseidon2InternalRelation) run_test(/*random_inputs=*/false); run_test(/*random_inputs=*/true); }; - -} // namespace bb::ultra_relation_consistency_tests diff --git a/barretenberg/cpp/src/barretenberg/serialize/msgpack_schema.test.cpp b/barretenberg/cpp/src/barretenberg/serialize/msgpack_schema.test.cpp index 3979e8919be..33a8454dac3 100644 --- a/barretenberg/cpp/src/barretenberg/serialize/msgpack_schema.test.cpp +++ b/barretenberg/cpp/src/barretenberg/serialize/msgpack_schema.test.cpp @@ -3,37 +3,38 @@ #include +using namespace bb; + // Sanity checking for msgpack -// TODO eventually move to barretenberg struct GoodExample { - bb::fr a; - bb::fr b; + fr a; + fr b; MSGPACK_FIELDS(a, b); } good_example; struct BadExampleOverlap { - bb::fr a; - bb::fr b; + fr a; + fr b; MSGPACK_FIELDS(a, a); } bad_example_overlap; struct BadExampleIncomplete { - bb::fr a; - bb::fr b; + fr a; + fr b; MSGPACK_FIELDS(a); } bad_example_incomplete; struct BadExampleCompileTimeError { std::vector a; - bb::fr b; + fr b; MSGPACK_FIELDS(b); // Type mismatch, expect 'a', will catch at compile-time } bad_example_compile_time_error; struct BadExampleOutOfObject { - bb::fr a; - bb::fr b; + fr a; + fr b; void msgpack(auto ar) { BadExampleOutOfObject other_object; @@ -66,9 +67,9 @@ TEST(msgpack_tests, msgpack_sanity_sanity) } struct ComplicatedSchema { - std::vector> array; + std::vector> array; std::optional good_or_not; - bb::fr bare; + fr bare; std::variant huh; MSGPACK_FIELDS(array, good_or_not, bare, huh); } complicated_schema; diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/smt_bigfield.test.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/smt_bigfield.test.cpp index e40b9b0019a..1f1abe570e2 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/smt_bigfield.test.cpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/smt_bigfield.test.cpp @@ -30,9 +30,9 @@ using namespace smt_circuit; using namespace bb; using namespace bb::plonk; -using field_ct = bb::stdlib::field_t; -using witness_t = bb::stdlib::witness_t; -using pub_witness_t = bb::stdlib::public_witness_t; +using field_ct = stdlib::field_t; +using witness_t = stdlib::witness_t; +using pub_witness_t = stdlib::public_witness_t; using bn254 = stdlib::bn254; diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/smt_examples.test.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/smt_examples.test.cpp index 60babafb2d6..81e31bec0f9 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/smt_examples.test.cpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/smt_examples.test.cpp @@ -11,12 +11,12 @@ using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } -using field_t = bb::stdlib::field_t; -using witness_t = bb::stdlib::witness_t; -using pub_witness_t = bb::stdlib::public_witness_t; +using field_t = stdlib::field_t; +using witness_t = stdlib::witness_t; +using pub_witness_t = stdlib::public_witness_t; TEST(circuit_verification, multiplication_true) { diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/smt_polynomials.test.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/smt_polynomials.test.cpp index e24e469afcd..3e15583a71a 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/smt_polynomials.test.cpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/smt_polynomials.test.cpp @@ -16,13 +16,13 @@ using namespace bb; using namespace smt_circuit; -using field_ct = bb::stdlib::field_t; -using witness_t = bb::stdlib::witness_t; -using pub_witness_t = bb::stdlib::public_witness_t; +using field_ct = stdlib::field_t; +using witness_t = stdlib::witness_t; +using pub_witness_t = stdlib::public_witness_t; // TODO(alex): z1 = z2, s1=s2, but coefficients are not public namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } msgpack::sbuffer create_circuit(size_t n, bool pub_coeffs) 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 3b069e4a8a7..a20ab1c4bbe 100644 --- a/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/ecdsa_circuit.hpp +++ b/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/ecdsa_circuit.hpp @@ -12,10 +12,6 @@ #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/stdlib/primitives/witness/witness.hpp" -using namespace bb::plonk; -using namespace stdlib; -using numeric::uint256_t; - template class EcdsaCircuit { public: using field_ct = stdlib::field_t; @@ -47,18 +43,18 @@ template class EcdsaCircuit { } // UNCONSTRAINED: create a random keypair to sign with - crypto::ecdsa::key_pair account; + crypto::ecdsa_key_pair account; account.private_key = curve::fr::random_element(); 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( + crypto::ecdsa_verify_signature( message_string, account.public_key, signature); if (!dry_run) { throw_or_abort("[non circuit]: Sig verification failed"); @@ -72,16 +68,16 @@ template class EcdsaCircuit { uint8_t vv = signature.v; // IN CIRCUIT: create a witness with the sig in our circuit - stdlib::ecdsa::signature sig{ typename curve::byte_array_ct(&builder, rr), - typename curve::byte_array_ct(&builder, ss), - stdlib::uint8(&builder, vv) }; + stdlib::ecdsa_signature sig{ typename curve::byte_array_ct(&builder, rr), + typename curve::byte_array_ct(&builder, ss), + stdlib::uint8(&builder, vv) }; // IN CIRCUIT: verify the signature - typename curve::bool_ct signature_result = stdlib::ecdsa::verify_signature( + typename curve::bool_ct signature_result = stdlib::ecdsa_verify_signature( // input_buffer, public_key, sig); input_buffer, public_key, diff --git a/barretenberg/cpp/src/barretenberg/solidity_helpers/proof_gen.cpp b/barretenberg/cpp/src/barretenberg/solidity_helpers/proof_gen.cpp index 97e82644e88..10b54e88b7a 100644 --- a/barretenberg/cpp/src/barretenberg/solidity_helpers/proof_gen.cpp +++ b/barretenberg/cpp/src/barretenberg/solidity_helpers/proof_gen.cpp @@ -11,7 +11,7 @@ #include "circuits/recursive_circuit.hpp" #include "utils/utils.hpp" -using namespace numeric; +using namespace bb::numeric; using numeric::uint256_t; template typename Circuit> void generate_proof(uint256_t inputs[]) diff --git a/barretenberg/cpp/src/barretenberg/srs/factories/mem_crs_factory.test.cpp b/barretenberg/cpp/src/barretenberg/srs/factories/mem_crs_factory.test.cpp index 46dfdecc57a..bfdab78e996 100644 --- a/barretenberg/cpp/src/barretenberg/srs/factories/mem_crs_factory.test.cpp +++ b/barretenberg/cpp/src/barretenberg/srs/factories/mem_crs_factory.test.cpp @@ -9,7 +9,7 @@ using namespace bb; using namespace bb::srs::factories; -using namespace curve; +using namespace bb::curve; TEST(reference_string, mem_bn254_file_consistency) { @@ -41,7 +41,7 @@ TEST(reference_string, mem_bn254_file_consistency) EXPECT_EQ(memcmp(mem_verifier_crs->get_precomputed_g2_lines(), file_verifier_crs->get_precomputed_g2_lines(), - sizeof(bb::pairing::miller_lines) * 2), + sizeof(pairing::miller_lines) * 2), 0); } diff --git a/barretenberg/cpp/src/barretenberg/srs/factories/mem_grumpkin_crs_factory.cpp b/barretenberg/cpp/src/barretenberg/srs/factories/mem_grumpkin_crs_factory.cpp index d9ab3b28f59..1001c9519a4 100644 --- a/barretenberg/cpp/src/barretenberg/srs/factories/mem_grumpkin_crs_factory.cpp +++ b/barretenberg/cpp/src/barretenberg/srs/factories/mem_grumpkin_crs_factory.cpp @@ -7,7 +7,7 @@ namespace { -using namespace curve; +using namespace bb::curve; using namespace bb; using namespace bb::srs::factories; diff --git a/barretenberg/cpp/src/barretenberg/srs/global_crs.cpp b/barretenberg/cpp/src/barretenberg/srs/global_crs.cpp index 6bf83a86b44..f6ac2e05c71 100644 --- a/barretenberg/cpp/src/barretenberg/srs/global_crs.cpp +++ b/barretenberg/cpp/src/barretenberg/srs/global_crs.cpp @@ -6,8 +6,8 @@ namespace { // TODO(#637): As a PoC we have two global variables for the two CRS but this could be improved to avoid duplication. -std::shared_ptr> crs_factory; -std::shared_ptr> grumpkin_crs_factory; +std::shared_ptr> crs_factory; +std::shared_ptr> grumpkin_crs_factory; } // namespace namespace bb::srs { @@ -21,11 +21,11 @@ void init_crs_factory(std::vector const& points, g2::affine_ // Initializes crs from a file path this we use in the entire codebase void init_crs_factory(std::string crs_path) { - crs_factory = std::make_shared>(crs_path); + crs_factory = std::make_shared>(crs_path); } // Initializes the crs using the memory buffers -void init_grumpkin_crs_factory(std::vector const& points) +void init_grumpkin_crs_factory(std::vector const& points) { grumpkin_crs_factory = std::make_shared(points); } diff --git a/barretenberg/cpp/src/barretenberg/srs/scalar_multiplication.test.cpp b/barretenberg/cpp/src/barretenberg/srs/scalar_multiplication.test.cpp index b9805c7c7d1..9ed7c2e4048 100644 --- a/barretenberg/cpp/src/barretenberg/srs/scalar_multiplication.test.cpp +++ b/barretenberg/cpp/src/barretenberg/srs/scalar_multiplication.test.cpp @@ -20,12 +20,12 @@ #include #include +using namespace bb; + namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } -using namespace bb; - template class ScalarMultiplicationTests : public ::testing::Test { public: const std::string SRS_PATH = []() { @@ -231,14 +231,14 @@ TYPED_TEST(ScalarMultiplicationTests, ReduceBucketsSimple) std::array bucket_counts; std::array bit_offsets = { 0 }; - bb::scalar_multiplication::affine_product_runtime_state product_state{ + scalar_multiplication::affine_product_runtime_state product_state{ &monomials[0], &point_pairs[0], &output_buckets[0], &scratch_space[0], &bucket_counts[0], &bit_offsets[0], &point_schedule[0], num_points, 2, &bucket_empty_status[0] }; - AffineElement* output = bb::scalar_multiplication::reduce_buckets(product_state, true); + AffineElement* output = scalar_multiplication::reduce_buckets(product_state, true); for (size_t i = 0; i < product_state.num_buckets; ++i) { expected[i] = expected[i].normalize(); @@ -274,7 +274,7 @@ TYPED_TEST(ScalarMultiplicationTests, ReduceBuckets) TestFixture::read_transcript(monomials, num_initial_points, TestFixture::SRS_PATH); - bb::scalar_multiplication::generate_pippenger_point_table(monomials, monomials, num_initial_points); + scalar_multiplication::generate_pippenger_point_table(monomials, monomials, num_initial_points); Fr* scalars = (Fr*)(aligned_alloc(64, sizeof(Fr) * num_initial_points)); @@ -282,21 +282,21 @@ TYPED_TEST(ScalarMultiplicationTests, ReduceBuckets) scalars[i] = Fr::random_element(); } - bb::scalar_multiplication::pippenger_runtime_state state(num_initial_points); + scalar_multiplication::pippenger_runtime_state state(num_initial_points); std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); - bb::scalar_multiplication::compute_wnaf_states( + scalar_multiplication::compute_wnaf_states( state.point_schedule, state.skew_table, state.round_counts, scalars, num_initial_points); std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); std::chrono::milliseconds diff = std::chrono::duration_cast(end - start); std::cout << "wnaf time: " << diff.count() << "ms" << std::endl; start = std::chrono::steady_clock::now(); - bb::scalar_multiplication::organize_buckets(state.point_schedule, num_points); + scalar_multiplication::organize_buckets(state.point_schedule, num_points); end = std::chrono::steady_clock::now(); diff = std::chrono::duration_cast(end - start); std::cout << "organize bucket time: " << diff.count() << "ms" << std::endl; - const size_t max_num_buckets = bb::scalar_multiplication::get_num_buckets(num_points * 2); + const size_t max_num_buckets = scalar_multiplication::get_num_buckets(num_points * 2); uint32_t* bucket_counts = static_cast(aligned_alloc(64, max_num_buckets * 100 * sizeof(uint32_t))); memset((void*)bucket_counts, 0x00, max_num_buckets * sizeof(uint32_t)); @@ -312,19 +312,19 @@ TYPED_TEST(ScalarMultiplicationTests, ReduceBuckets) const size_t last_bucket = point_schedule_copy[num_points - 1] & 0x7fffffffULL; const size_t num_buckets = last_bucket - first_bucket + 1; - bb::scalar_multiplication::affine_product_runtime_state product_state{ monomials, - point_pairs, - scratch_points, - scratch_field, - bucket_counts, - &bit_offsets[0], - &state.point_schedule[num_points], - num_points, - static_cast(num_buckets), - bucket_empty_status }; + scalar_multiplication::affine_product_runtime_state product_state{ monomials, + point_pairs, + scratch_points, + scratch_field, + bucket_counts, + &bit_offsets[0], + &state.point_schedule[num_points], + num_points, + static_cast(num_buckets), + bucket_empty_status }; start = std::chrono::steady_clock::now(); - // bb::scalar_multiplication::scalar_multiplication_internal(state, monomials); + // scalar_multiplication::scalar_multiplication_internal(state, monomials); end = std::chrono::steady_clock::now(); diff = std::chrono::duration_cast(end - start); std::cout << "scalar mul: " << diff.count() << "ms" << std::endl; @@ -345,7 +345,7 @@ TYPED_TEST(ScalarMultiplicationTests, ReduceBuckets) size_t it = 0; - AffineElement* result_buckets = bb::scalar_multiplication::reduce_buckets(product_state, true); + AffineElement* result_buckets = scalar_multiplication::reduce_buckets(product_state, true); printf("num buckets = %zu \n", num_buckets); for (size_t i = 0; i < num_buckets; ++i) { @@ -401,22 +401,22 @@ TYPED_TEST(ScalarMultiplicationTests, DISABLED_ReduceBucketsBasic) Fr::__copy(source_scalar, scalars[i]); } - bb::scalar_multiplication::pippenger_runtime_state state(num_initial_points); - bb::scalar_multiplication::generate_pippenger_point_table(monomials, monomials, num_initial_points); + scalar_multiplication::pippenger_runtime_state state(num_initial_points); + scalar_multiplication::generate_pippenger_point_table(monomials, monomials, num_initial_points); std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); - bb::scalar_multiplication::compute_wnaf_states( + scalar_multiplication::compute_wnaf_states( state.point_schedule, state.skew_table, state.round_counts, scalars, num_initial_points); std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); std::chrono::milliseconds diff = std::chrono::duration_cast(end - start); std::cout << "wnaf time: " << diff.count() << "ms" << std::endl; start = std::chrono::steady_clock::now(); - bb::scalar_multiplication::organize_buckets(state.point_schedule, num_points); + scalar_multiplication::organize_buckets(state.point_schedule, num_points); end = std::chrono::steady_clock::now(); diff = std::chrono::duration_cast(end - start); std::cout << "organize bucket time: " << diff.count() << "ms" << std::endl; - const size_t max_num_buckets = bb::scalar_multiplication::get_num_buckets(num_points * 2); + const size_t max_num_buckets = scalar_multiplication::get_num_buckets(num_points * 2); uint32_t* bucket_counts = static_cast(aligned_alloc(64, max_num_buckets * sizeof(uint32_t))); memset((void*)bucket_counts, 0x00, max_num_buckets * sizeof(uint32_t)); @@ -425,20 +425,20 @@ TYPED_TEST(ScalarMultiplicationTests, DISABLED_ReduceBucketsBasic) const size_t last_bucket = state.point_schedule[num_points - 1] & 0x7fffffffULL; const size_t num_buckets = last_bucket - first_bucket + 1; - bb::scalar_multiplication::affine_product_runtime_state product_state{ monomials, - point_pairs, - scratch_points, - scratch_field, - bucket_counts, - &bit_offsets[0], - state.point_schedule, - (uint32_t)state.round_counts[0], - static_cast(num_buckets), - bucket_empty_status }; + scalar_multiplication::affine_product_runtime_state product_state{ monomials, + point_pairs, + scratch_points, + scratch_field, + bucket_counts, + &bit_offsets[0], + state.point_schedule, + (uint32_t)state.round_counts[0], + static_cast(num_buckets), + bucket_empty_status }; start = std::chrono::steady_clock::now(); - bb::scalar_multiplication::reduce_buckets(product_state, true); - // bb::scalar_multiplication::scalar_multiplication_internal(state, monomials); + scalar_multiplication::reduce_buckets(product_state, true); + // scalar_multiplication::scalar_multiplication_internal(state, monomials); end = std::chrono::steady_clock::now(); diff = std::chrono::duration_cast(end - start); std::cout << "scalar mul: " << diff.count() << "ms" << std::endl; @@ -478,7 +478,7 @@ TYPED_TEST(ScalarMultiplicationTests, AddAffinePoints) points_copy[count + 1] = points_copy[count + 1].normalize(); } - bb::scalar_multiplication::add_affine_points(points, num_points, scratch_space); + scalar_multiplication::add_affine_points(points, num_points, scratch_space); for (size_t i = num_points - 1; i > num_points - 1 - (num_points / 2); --i) { EXPECT_EQ((points[i].x == points_copy[i].x), true); EXPECT_EQ((points[i].y == points_copy[i].y), true); @@ -509,22 +509,22 @@ TYPED_TEST(ScalarMultiplicationTests, ConstructAdditionChains) Fr::__copy(source_scalar, scalars[i]); } - bb::scalar_multiplication::pippenger_runtime_state state(num_initial_points); - bb::scalar_multiplication::generate_pippenger_point_table(monomials, monomials, num_initial_points); + scalar_multiplication::pippenger_runtime_state state(num_initial_points); + scalar_multiplication::generate_pippenger_point_table(monomials, monomials, num_initial_points); std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); - bb::scalar_multiplication::compute_wnaf_states( + scalar_multiplication::compute_wnaf_states( state.point_schedule, state.skew_table, state.round_counts, scalars, num_initial_points); std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); std::chrono::milliseconds diff = std::chrono::duration_cast(end - start); std::cout << "wnaf time: " << diff.count() << "ms" << std::endl; start = std::chrono::steady_clock::now(); - bb::scalar_multiplication::organize_buckets(state.point_schedule, num_points); + scalar_multiplication::organize_buckets(state.point_schedule, num_points); end = std::chrono::steady_clock::now(); diff = std::chrono::duration_cast(end - start); std::cout << "organize bucket time: " << diff.count() << "ms" << std::endl; - const size_t max_num_buckets = bb::scalar_multiplication::get_num_buckets(num_points * 2); + const size_t max_num_buckets = scalar_multiplication::get_num_buckets(num_points * 2); bool* bucket_empty_status = static_cast(aligned_alloc(64, num_points * sizeof(bool))); uint32_t* bucket_counts = static_cast(aligned_alloc(64, max_num_buckets * sizeof(uint32_t))); memset((void*)bucket_counts, 0x00, max_num_buckets * sizeof(uint32_t)); @@ -533,20 +533,20 @@ TYPED_TEST(ScalarMultiplicationTests, ConstructAdditionChains) const size_t last_bucket = state.point_schedule[state.round_counts[0] - 1] & 0x7fffffffULL; const size_t num_buckets = last_bucket - first_bucket + 1; - bb::scalar_multiplication::affine_product_runtime_state product_state{ monomials, - monomials, - monomials, - nullptr, - bucket_counts, - &bit_offsets[0], - state.point_schedule, - static_cast( - state.round_counts[0]), - static_cast(num_buckets), - bucket_empty_status }; + scalar_multiplication::affine_product_runtime_state product_state{ monomials, + monomials, + monomials, + nullptr, + bucket_counts, + &bit_offsets[0], + state.point_schedule, + static_cast( + state.round_counts[0]), + static_cast(num_buckets), + bucket_empty_status }; start = std::chrono::steady_clock::now(); - bb::scalar_multiplication::construct_addition_chains(product_state, true); + scalar_multiplication::construct_addition_chains(product_state, true); end = std::chrono::steady_clock::now(); diff = std::chrono::duration_cast(end - start); info("construct addition chains: ", diff.count(), "ms"); @@ -608,7 +608,7 @@ TYPED_TEST(ScalarMultiplicationTests, RadixSort) // check that our radix sort correctly sorts! constexpr size_t target_degree = 1 << 8; - constexpr size_t num_rounds = bb::scalar_multiplication::get_num_rounds(target_degree * 2); + constexpr size_t num_rounds = scalar_multiplication::get_num_rounds(target_degree * 2); Fr* scalars = (Fr*)(aligned_alloc(64, sizeof(Fr) * target_degree)); Fr source_scalar = Fr::random_element(); @@ -617,14 +617,14 @@ TYPED_TEST(ScalarMultiplicationTests, RadixSort) Fr::__copy(source_scalar, scalars[i]); } - bb::scalar_multiplication::pippenger_runtime_state state(target_degree); - bb::scalar_multiplication::compute_wnaf_states( + scalar_multiplication::pippenger_runtime_state state(target_degree); + scalar_multiplication::compute_wnaf_states( state.point_schedule, state.skew_table, state.round_counts, scalars, target_degree); uint64_t* wnaf_copy = (uint64_t*)(aligned_alloc(64, sizeof(uint64_t) * target_degree * 2 * num_rounds)); memcpy((void*)wnaf_copy, (void*)state.point_schedule, sizeof(uint64_t) * target_degree * 2 * num_rounds); - bb::scalar_multiplication::organize_buckets(state.point_schedule, target_degree * 2); + scalar_multiplication::organize_buckets(state.point_schedule, target_degree * 2); for (size_t i = 0; i < num_rounds; ++i) { uint64_t* unsorted_wnaf = &wnaf_copy[i * target_degree * 2]; uint64_t* sorted_wnaf = &state.point_schedule[i * target_degree * 2]; @@ -668,7 +668,7 @@ TYPED_TEST(ScalarMultiplicationTests, OversizedInputs) memcpy((void*)(monomials + (2 * transcript_degree)), (void*)monomials, ((2 * target_degree - 2 * transcript_degree) * sizeof(AffineElement))); - bb::scalar_multiplication::generate_pippenger_point_table(monomials, monomials, target_degree); + scalar_multiplication::generate_pippenger_point_table(monomials, monomials, target_degree); Fr* scalars = (Fr*)(aligned_alloc(64, sizeof(Fr) * target_degree)); @@ -678,17 +678,17 @@ TYPED_TEST(ScalarMultiplicationTests, OversizedInputs) accumulator *= source_scalar; Fr::__copy(accumulator, scalars[i]); } - bb::scalar_multiplication::pippenger_runtime_state state(target_degree); + scalar_multiplication::pippenger_runtime_state state(target_degree); - Element first = bb::scalar_multiplication::pippenger(scalars, monomials, target_degree, state); + Element first = scalar_multiplication::pippenger(scalars, monomials, target_degree, state); first = first.normalize(); for (size_t i = 0; i < target_degree; ++i) { scalars[i].self_neg(); } - bb::scalar_multiplication::pippenger_runtime_state state_2(target_degree); + scalar_multiplication::pippenger_runtime_state state_2(target_degree); - Element second = bb::scalar_multiplication::pippenger(scalars, monomials, target_degree, state_2); + Element second = scalar_multiplication::pippenger(scalars, monomials, target_degree, state_2); second = second.normalize(); EXPECT_EQ((first.z == second.z), true); @@ -727,11 +727,11 @@ TYPED_TEST(ScalarMultiplicationTests, UndersizedInputs) expected += temp; } expected = expected.normalize(); - bb::scalar_multiplication::generate_pippenger_point_table(points, points, num_points); + scalar_multiplication::generate_pippenger_point_table(points, points, num_points); - bb::scalar_multiplication::pippenger_runtime_state state(num_points); + scalar_multiplication::pippenger_runtime_state state(num_points); - Element result = bb::scalar_multiplication::pippenger(scalars, points, num_points, state); + Element result = scalar_multiplication::pippenger(scalars, points, num_points, state); result = result.normalize(); aligned_free(scalars); @@ -765,10 +765,10 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerSmall) expected += temp; } expected = expected.normalize(); - bb::scalar_multiplication::generate_pippenger_point_table(points, points, num_points); - bb::scalar_multiplication::pippenger_runtime_state state(num_points); + scalar_multiplication::generate_pippenger_point_table(points, points, num_points); + scalar_multiplication::pippenger_runtime_state state(num_points); - Element result = bb::scalar_multiplication::pippenger(scalars, points, num_points, state); + Element result = scalar_multiplication::pippenger(scalars, points, num_points, state); result = result.normalize(); aligned_free(scalars); @@ -805,9 +805,9 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerEdgeCaseDbl) if (!expected.is_point_at_infinity()) { expected = expected.normalize(); } - bb::scalar_multiplication::generate_pippenger_point_table(points, points, num_points); - bb::scalar_multiplication::pippenger_runtime_state state(num_points); - Element result = bb::scalar_multiplication::pippenger(scalars, points, num_points, state); + scalar_multiplication::generate_pippenger_point_table(points, points, num_points); + scalar_multiplication::pippenger_runtime_state state(num_points); + Element result = scalar_multiplication::pippenger(scalars, points, num_points, state); result = result.normalize(); aligned_free(scalars); @@ -827,7 +827,7 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerShortInputs) Fr* scalars = (Fr*)aligned_alloc(32, sizeof(Fr) * num_points); - auto points = bb::scalar_multiplication::point_table_alloc(num_points); + auto points = scalar_multiplication::point_table_alloc(num_points); for (std::ptrdiff_t i = 0; i < (std::ptrdiff_t)num_points; ++i) { points[i] = AffineElement(Element::random_element()); @@ -862,10 +862,10 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerShortInputs) expected += temp; } expected = expected.normalize(); - bb::scalar_multiplication::generate_pippenger_point_table(points.get(), points.get(), num_points); - bb::scalar_multiplication::pippenger_runtime_state state(num_points); + scalar_multiplication::generate_pippenger_point_table(points.get(), points.get(), num_points); + scalar_multiplication::pippenger_runtime_state state(num_points); - Element result = bb::scalar_multiplication::pippenger(scalars, points.get(), num_points, state); + Element result = scalar_multiplication::pippenger(scalars, points.get(), num_points, state); result = result.normalize(); aligned_free(scalars); @@ -884,7 +884,7 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerUnsafe) Fr* scalars = (Fr*)aligned_alloc(32, sizeof(Fr) * num_points); - auto points = bb::scalar_multiplication::point_table_alloc(num_points); + auto points = scalar_multiplication::point_table_alloc(num_points); for (std::ptrdiff_t i = 0; i < (std::ptrdiff_t)num_points; ++i) { scalars[i] = Fr::random_element(); @@ -898,10 +898,10 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerUnsafe) expected += temp; } expected = expected.normalize(); - bb::scalar_multiplication::generate_pippenger_point_table(points.get(), points.get(), num_points); + scalar_multiplication::generate_pippenger_point_table(points.get(), points.get(), num_points); - bb::scalar_multiplication::pippenger_runtime_state state(num_points); - Element result = bb::scalar_multiplication::pippenger_unsafe(scalars, points.get(), num_points, state); + scalar_multiplication::pippenger_runtime_state state(num_points); + Element result = scalar_multiplication::pippenger_unsafe(scalars, points.get(), num_points, state); result = result.normalize(); aligned_free(scalars); @@ -955,10 +955,10 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerUnsafeShortInputs) expected += temp; } expected = expected.normalize(); - bb::scalar_multiplication::generate_pippenger_point_table(points, points, num_points); - bb::scalar_multiplication::pippenger_runtime_state state(num_points); + scalar_multiplication::generate_pippenger_point_table(points, points, num_points); + scalar_multiplication::pippenger_runtime_state state(num_points); - Element result = bb::scalar_multiplication::pippenger_unsafe(scalars, points, num_points, state); + Element result = scalar_multiplication::pippenger_unsafe(scalars, points, num_points, state); result = result.normalize(); aligned_free(scalars); @@ -992,10 +992,10 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerOne) expected += temp; } expected = expected.normalize(); - bb::scalar_multiplication::generate_pippenger_point_table(points, points, num_points); - bb::scalar_multiplication::pippenger_runtime_state state(num_points); + scalar_multiplication::generate_pippenger_point_table(points, points, num_points); + scalar_multiplication::pippenger_runtime_state state(num_points); - Element result = bb::scalar_multiplication::pippenger(scalars, points, num_points, state); + Element result = scalar_multiplication::pippenger(scalars, points, num_points, state); result = result.normalize(); aligned_free(scalars); @@ -1015,8 +1015,8 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerZeroPoints) AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * (2 + 1)); - bb::scalar_multiplication::pippenger_runtime_state state(0); - Element result = bb::scalar_multiplication::pippenger(scalars, points, 0, state); + scalar_multiplication::pippenger_runtime_state state(0); + Element result = scalar_multiplication::pippenger(scalars, points, 0, state); aligned_free(scalars); aligned_free(points); @@ -1038,10 +1038,10 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerMulByZero) scalars[0] = Fr::zero(); points[0] = Group::affine_one; - bb::scalar_multiplication::generate_pippenger_point_table(points, points, 1); + scalar_multiplication::generate_pippenger_point_table(points, points, 1); - bb::scalar_multiplication::pippenger_runtime_state state(1); - Element result = bb::scalar_multiplication::pippenger(scalars, points, 1, state); + scalar_multiplication::pippenger_runtime_state state(1); + Element result = scalar_multiplication::pippenger(scalars, points, 1, state); aligned_free(scalars); aligned_free(points); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp index 5e0f37f2dba..bced7a46256 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp @@ -6,10 +6,9 @@ #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "pedersen.hpp" -namespace test_StdlibPedersen { using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } template class StdlibPedersen : public testing::Test { @@ -61,7 +60,7 @@ template class StdlibPedersen : public testing::Test { { Builder builder; - std::vector inputs; + std::vector inputs; std::vector> witness_inputs; for (size_t i = 0; i < 8; ++i) { @@ -94,5 +93,3 @@ TYPED_TEST(StdlibPedersen, HashConstants) { TestFixture::test_hash_constants(); }; - -} // namespace test_StdlibPedersen diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.test.cpp index 743a1eb80be..76b52fbc27e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.test.cpp @@ -8,7 +8,7 @@ using namespace bb; TEST(stdlib_aes128, encrypt_64_bytes) { - typedef stdlib::field_t field_pt; + typedef stdlib::field_t field_pt; typedef stdlib::witness_t witness_pt; uint8_t key[16]{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; @@ -31,7 +31,7 @@ TEST(stdlib_aes128, encrypt_64_bytes) return converted; }; - auto builder = bb::UltraCircuitBuilder(); + auto builder = UltraCircuitBuilder(); std::vector in_field{ witness_pt(&builder, fr(convert_bytes(in))), diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp index ca4a212a866..1c2649ed1b3 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp @@ -4,42 +4,43 @@ #include "../../primitives/circuit_builders/circuit_builders_fwd.hpp" #include "../../primitives/uint/uint.hpp" #include "barretenberg/crypto/ecdsa/ecdsa.hpp" -namespace bb::stdlib::ecdsa { +namespace bb::stdlib { -template struct signature { +template struct ecdsa_signature { stdlib::byte_array r; stdlib::byte_array s; stdlib::uint8 v; }; template -bool_t verify_signature(const stdlib::byte_array& message, - const G1& public_key, - const signature& sig); +bool_t ecdsa_verify_signature(const stdlib::byte_array& message, + const G1& public_key, + const ecdsa_signature& sig); template -bool_t verify_signature_noassert(const stdlib::byte_array& message, - const G1& public_key, - const signature& sig); +bool_t ecdsa_verify_signature_noassert(const stdlib::byte_array& message, + const G1& public_key, + const ecdsa_signature& sig); template -bool_t verify_signature_prehashed_message_noassert(const stdlib::byte_array& hashed_message, - const G1& public_key, - const signature& sig); +bool_t ecdsa_verify_signature_prehashed_message_noassert(const stdlib::byte_array& hashed_message, + const G1& public_key, + const ecdsa_signature& sig); -template static signature from_witness(Builder* ctx, const crypto::ecdsa::signature& input) +template +static ecdsa_signature ecdsa_from_witness(Builder* ctx, const crypto::ecdsa_signature& input) { std::vector r_vec(std::begin(input.r), std::end(input.r)); std::vector s_vec(std::begin(input.s), std::end(input.s)); stdlib::byte_array r(ctx, r_vec); stdlib::byte_array s(ctx, s_vec); stdlib::uint8 v(ctx, input.v); - signature out; + ecdsa_signature out; out.r = r; out.s = s; out.v = v; return out; } -} // namespace bb::stdlib::ecdsa +} // namespace bb::stdlib #include "./ecdsa_impl.hpp" \ No newline at end of file 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 ca55a8af563..69aedf7e435 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.test.cpp @@ -8,9 +8,8 @@ using namespace bb; -namespace test_stdlib_ecdsa { -using Builder = bb::UltraCircuitBuilder; -using curve = stdlib::secp256k1; +using Builder = UltraCircuitBuilder; +using curve_ = stdlib::secp256k1; using curveR1 = stdlib::secp256r1; TEST(stdlib_ecdsa, verify_signature) @@ -20,31 +19,31 @@ TEST(stdlib_ecdsa, verify_signature) // whaaablaghaaglerijgeriij std::string message_string = "Instructions unclear, ask again later."; - crypto::ecdsa::key_pair account; - account.private_key = curve::fr::random_element(); - account.public_key = curve::g1::one * account.private_key; + crypto::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); + crypto::ecdsa_signature signature = + crypto::ecdsa_construct_signature(message_string, account); - bool first_result = crypto::ecdsa::verify_signature( + bool first_result = crypto::ecdsa_verify_signature( message_string, account.public_key, signature); EXPECT_EQ(first_result, true); - curve::g1_bigfr_ct public_key = curve::g1_bigfr_ct::from_witness(&builder, account.public_key); + curve_::g1_bigfr_ct public_key = curve_::g1_bigfr_ct::from_witness(&builder, account.public_key); std::vector rr(signature.r.begin(), signature.r.end()); std::vector ss(signature.s.begin(), signature.s.end()); uint8_t vv = signature.v; - stdlib::ecdsa::signature sig{ curve::byte_array_ct(&builder, rr), - curve::byte_array_ct(&builder, ss), - stdlib::uint8(&builder, vv) }; + stdlib::ecdsa_signature sig{ curve_::byte_array_ct(&builder, rr), + curve_::byte_array_ct(&builder, ss), + stdlib::uint8(&builder, vv) }; - curve::byte_array_ct message(&builder, message_string); + curve_::byte_array_ct message(&builder, message_string); - curve::bool_ct signature_result = - stdlib::ecdsa::verify_signature( + curve_::bool_ct signature_result = + stdlib::ecdsa_verify_signature( message, public_key, sig); EXPECT_EQ(signature_result.get_value(), true); @@ -61,15 +60,14 @@ TEST(stdlib_ecdsa, verify_r1_signature) std::string message_string = "Instructions unclear, ask again later."; - crypto::ecdsa::key_pair account; + crypto::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); + crypto::ecdsa_signature signature = + crypto::ecdsa_construct_signature(message_string, account); - bool first_result = crypto::ecdsa::verify_signature( + bool first_result = crypto::ecdsa_verify_signature( message_string, account.public_key, signature); EXPECT_EQ(first_result, true); @@ -79,14 +77,14 @@ TEST(stdlib_ecdsa, verify_r1_signature) std::vector ss(signature.s.begin(), signature.s.end()); uint8_t vv = signature.v; - stdlib::ecdsa::signature sig{ curveR1::byte_array_ct(&builder, rr), - curveR1::byte_array_ct(&builder, ss), - stdlib::uint8(&builder, vv) }; + stdlib::ecdsa_signature sig{ curveR1::byte_array_ct(&builder, rr), + curveR1::byte_array_ct(&builder, ss), + stdlib::uint8(&builder, vv) }; curveR1::byte_array_ct message(&builder, message_string); curveR1::bool_ct signature_result = - stdlib::ecdsa::verify_signature( + stdlib::ecdsa_verify_signature( message, public_key, sig); EXPECT_EQ(signature_result.get_value(), true); @@ -97,40 +95,40 @@ TEST(stdlib_ecdsa, verify_r1_signature) EXPECT_EQ(proof_result, true); } -TEST(stdlib_ecdsa, verify_signature_noassert_succeed) +TEST(stdlib_ecdsa, ecdsa_verify_signature_noassert_succeed) { Builder builder = Builder(); // whaaablaghaaglerijgeriij std::string message_string = "Instructions unclear, ask again later."; - crypto::ecdsa::key_pair account; - account.private_key = curve::fr::random_element(); - account.public_key = curve::g1::one * account.private_key; + crypto::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); + crypto::ecdsa_signature signature = + crypto::ecdsa_construct_signature(message_string, account); - bool first_result = crypto::ecdsa::verify_signature( + bool first_result = crypto::ecdsa_verify_signature( message_string, account.public_key, signature); EXPECT_EQ(first_result, true); - curve::g1_bigfr_ct public_key = curve::g1_bigfr_ct::from_witness(&builder, account.public_key); + curve_::g1_bigfr_ct public_key = curve_::g1_bigfr_ct::from_witness(&builder, account.public_key); std::vector rr(signature.r.begin(), signature.r.end()); std::vector ss(signature.s.begin(), signature.s.end()); uint8_t vv = signature.v; - stdlib::ecdsa::signature sig{ - curve::byte_array_ct(&builder, rr), - curve::byte_array_ct(&builder, ss), + stdlib::ecdsa_signature sig{ + curve_::byte_array_ct(&builder, rr), + curve_::byte_array_ct(&builder, ss), stdlib::uint8(&builder, vv), }; - curve::byte_array_ct message(&builder, message_string); + curve_::byte_array_ct message(&builder, message_string); - curve::bool_ct signature_result = - stdlib::ecdsa::verify_signature_noassert( + curve_::bool_ct signature_result = + stdlib::ecdsa_verify_signature_noassert( message, public_key, sig); EXPECT_EQ(signature_result.get_value(), true); @@ -141,38 +139,40 @@ TEST(stdlib_ecdsa, verify_signature_noassert_succeed) EXPECT_EQ(proof_result, true); } -TEST(stdlib_ecdsa, verify_signature_noassert_fail) +TEST(stdlib_ecdsa, ecdsa_verify_signature_noassert_fail) { Builder builder = Builder(); // whaaablaghaaglerijgeriij std::string message_string = "Instructions unclear, ask again later."; - crypto::ecdsa::key_pair account; - account.private_key = curve::fr::random_element(); - account.public_key = curve::g1::one * account.private_key; + crypto::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); + crypto::ecdsa_signature signature = + crypto::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 = crypto::ecdsa_verify_signature( message_string, account.public_key, signature); EXPECT_EQ(first_result, false); - curve::g1_bigfr_ct public_key = curve::g1_bigfr_ct::from_witness(&builder, account.public_key); + curve_::g1_bigfr_ct public_key = curve_::g1_bigfr_ct::from_witness(&builder, account.public_key); std::vector rr(signature.r.begin(), signature.r.end()); std::vector ss(signature.s.begin(), signature.s.end()); - stdlib::ecdsa::signature sig{ curve::byte_array_ct(&builder, rr), curve::byte_array_ct(&builder, ss), 27 }; + stdlib::ecdsa_signature sig{ curve_::byte_array_ct(&builder, rr), + curve_::byte_array_ct(&builder, ss), + 27 }; - curve::byte_array_ct message(&builder, message_string); + curve_::byte_array_ct message(&builder, message_string); - curve::bool_ct signature_result = - stdlib::ecdsa::verify_signature_noassert( + curve_::bool_ct signature_result = + stdlib::ecdsa_verify_signature_noassert( message, public_key, sig); EXPECT_EQ(signature_result.get_value(), false); @@ -182,4 +182,3 @@ TEST(stdlib_ecdsa, verify_signature_noassert_fail) bool proof_result = builder.check_circuit(); EXPECT_EQ(proof_result, true); } -} // namespace test_stdlib_ecdsa 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 5f7403fb2c1..fa67089fd4e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp @@ -4,7 +4,7 @@ #include "barretenberg/stdlib/hash/sha256/sha256.hpp" #include "barretenberg/stdlib/primitives//bit_array/bit_array.hpp" -namespace bb::stdlib::ecdsa { +namespace bb::stdlib { /** * @brief Verify ECDSA signature. Produces unsatisfiable constraints if signature fails @@ -20,9 +20,9 @@ namespace bb::stdlib::ecdsa { * @return bool_t */ template -bool_t verify_signature(const stdlib::byte_array& message, - const G1& public_key, - const signature& sig) +bool_t ecdsa_verify_signature(const stdlib::byte_array& message, + const G1& public_key, + const ecdsa_signature& sig) { Builder* ctx = message.get_context() ? message.get_context() : public_key.x.context; @@ -130,9 +130,9 @@ bool_t verify_signature(const stdlib::byte_array& message, * @return bool_t */ template -bool_t verify_signature_prehashed_message_noassert(const stdlib::byte_array& hashed_message, - const G1& public_key, - const signature& sig) +bool_t ecdsa_verify_signature_prehashed_message_noassert(const stdlib::byte_array& hashed_message, + const G1& public_key, + const ecdsa_signature& sig) { Builder* ctx = hashed_message.get_context() ? hashed_message.get_context() : public_key.x.context; @@ -210,14 +210,15 @@ bool_t verify_signature_prehashed_message_noassert(const stdlib::byte_a * @return bool_t */ template -bool_t verify_signature_noassert(const stdlib::byte_array& message, - const G1& public_key, - const signature& sig) +bool_t ecdsa_verify_signature_noassert(const stdlib::byte_array& message, + const G1& public_key, + const ecdsa_signature& sig) { stdlib::byte_array hashed_message = static_cast>(stdlib::sha256(message)); - return verify_signature_prehashed_message_noassert(hashed_message, public_key, sig); + return ecdsa_verify_signature_prehashed_message_noassert( + hashed_message, public_key, sig); } -} // namespace bb::stdlib::ecdsa \ No newline at end of file +} // namespace bb::stdlib \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.cpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.cpp index 2f73d0646c3..8c4c8e011c4 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.cpp @@ -7,13 +7,14 @@ #include "barretenberg/stdlib/primitives/group/cycle_group.hpp" #include -namespace bb::stdlib::schnorr { +namespace bb::stdlib { /** * @brief Instantiate a witness containing the signature (s, e) as a quadruple of * field_t elements (s_lo, s_hi, e_lo, e_hi). */ -template signature_bits convert_signature(C* context, const crypto::schnorr::signature& signature) +template +schnorr_signature_bits schnorr_convert_signature(C* context, const crypto::schnorr_signature& signature) { using cycle_scalar = typename cycle_group::cycle_scalar; @@ -23,8 +24,8 @@ template signature_bits convert_signature(C* context, const cryp const uint8_t* e_ptr = &signature.e[0]; numeric::read(s_ptr, s_bigint); numeric::read(e_ptr, e_bigint); - signature_bits sig{ .s = cycle_scalar::from_witness_bitstring(context, s_bigint, 256), - .e = cycle_scalar::from_witness_bitstring(context, e_bigint, 256) }; + schnorr_signature_bits sig{ .s = cycle_scalar::from_witness_bitstring(context, s_bigint, 256), + .e = cycle_scalar::from_witness_bitstring(context, e_bigint, 256) }; return sig; } @@ -37,9 +38,9 @@ template signature_bits convert_signature(C* context, const cryp * (~1,169k for fixed/variable_base_mul, ~4k for blake2s) for a string of length = 34. */ template -std::array, 2> verify_signature_internal(const byte_array& message, - const cycle_group& pub_key, - const signature_bits& sig) +std::array, 2> schnorr_verify_signature_internal(const byte_array& message, + const cycle_group& pub_key, + const schnorr_signature_bits& sig) { cycle_group g1(grumpkin::g1::one); // compute g1 * sig.s + key * sig,e @@ -66,9 +67,11 @@ std::array, 2> verify_signature_internal(const byte_array& message * e' == e is true. */ template -void verify_signature(const byte_array& message, const cycle_group& pub_key, const signature_bits& sig) +void schnorr_verify_signature(const byte_array& message, + const cycle_group& pub_key, + const schnorr_signature_bits& sig) { - auto [output_lo, output_hi] = verify_signature_internal(message, pub_key, sig); + auto [output_lo, output_hi] = schnorr_verify_signature_internal(message, pub_key, sig); output_lo.assert_equal(sig.e.lo, "verify signature failed"); output_hi.assert_equal(sig.e.hi, "verify signature failed"); } @@ -79,37 +82,42 @@ void verify_signature(const byte_array& message, const cycle_group& pub_ke * and return the boolean witness e' == e. */ template -bool_t signature_verification_result(const byte_array& message, - const cycle_group& pub_key, - const signature_bits& sig) +bool_t schnorr_signature_verification_result(const byte_array& message, + const cycle_group& pub_key, + const schnorr_signature_bits& sig) { - auto [output_lo, output_hi] = verify_signature_internal(message, pub_key, sig); + auto [output_lo, output_hi] = schnorr_verify_signature_internal(message, pub_key, sig); bool_t valid = (output_lo == sig.e.lo) && (output_hi == sig.e.hi); return valid; } #define VERIFY_SIGNATURE_INTERNAL(circuit_type) \ - template std::array, 2> verify_signature_internal( \ - const byte_array&, const cycle_group&, const signature_bits&) + template std::array, 2> schnorr_verify_signature_internal( \ + const byte_array&, \ + const cycle_group&, \ + const schnorr_signature_bits&) VERIFY_SIGNATURE_INTERNAL(bb::StandardCircuitBuilder); VERIFY_SIGNATURE_INTERNAL(bb::UltraCircuitBuilder); VERIFY_SIGNATURE_INTERNAL(bb::GoblinUltraCircuitBuilder); #define VERIFY_SIGNATURE(circuit_type) \ - template void verify_signature( \ - const byte_array&, const cycle_group&, const signature_bits&) + template void schnorr_verify_signature(const byte_array&, \ + const cycle_group&, \ + const schnorr_signature_bits&) VERIFY_SIGNATURE(bb::StandardCircuitBuilder); VERIFY_SIGNATURE(bb::UltraCircuitBuilder); VERIFY_SIGNATURE(bb::GoblinUltraCircuitBuilder); #define SIGNATURE_VERIFICATION_RESULT(circuit_type) \ - template bool_t signature_verification_result( \ - const byte_array&, const cycle_group&, const signature_bits&) + template bool_t schnorr_signature_verification_result( \ + const byte_array&, \ + const cycle_group&, \ + const schnorr_signature_bits&) SIGNATURE_VERIFICATION_RESULT(bb::StandardCircuitBuilder); SIGNATURE_VERIFICATION_RESULT(bb::UltraCircuitBuilder); SIGNATURE_VERIFICATION_RESULT(bb::GoblinUltraCircuitBuilder); #define CONVERT_SIGNATURE(circuit_type) \ - template signature_bits convert_signature(circuit_type*, \ - const crypto::schnorr::signature&) + template schnorr_signature_bits schnorr_convert_signature( \ + circuit_type*, const crypto::schnorr_signature&) CONVERT_SIGNATURE(bb::StandardCircuitBuilder); CONVERT_SIGNATURE(bb::UltraCircuitBuilder); CONVERT_SIGNATURE(bb::GoblinUltraCircuitBuilder); -} // namespace bb::stdlib::schnorr +} // namespace bb::stdlib diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.hpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.hpp index 26f2ef0784b..b9ea2e632a5 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.hpp @@ -6,26 +6,29 @@ #include "../../primitives/witness/witness.hpp" #include "barretenberg/crypto/schnorr/schnorr.hpp" -namespace bb::stdlib::schnorr { +namespace bb::stdlib { -template struct signature_bits { +template struct schnorr_signature_bits { typename cycle_group::cycle_scalar s; typename cycle_group::cycle_scalar e; }; -template signature_bits convert_signature(C* context, const crypto::schnorr::signature& sig); +template +schnorr_signature_bits schnorr_convert_signature(C* context, const crypto::schnorr_signature& sig); template -std::array, 2> verify_signature_internal(const byte_array& message, - const cycle_group& pub_key, - const signature_bits& sig); +std::array, 2> schnorr_verify_signature_internal(const byte_array& message, + const cycle_group& pub_key, + const schnorr_signature_bits& sig); template -void verify_signature(const byte_array& message, const cycle_group& pub_key, const signature_bits& sig); +void schnorr_verify_signature(const byte_array& message, + const cycle_group& pub_key, + const schnorr_signature_bits& sig); template -bool_t signature_verification_result(const byte_array& message, - const cycle_group& pub_key, - const signature_bits& sig); +bool_t schnorr_signature_verification_result(const byte_array& message, + const cycle_group& pub_key, + const schnorr_signature_bits& sig); -} // namespace bb::stdlib::schnorr +} // namespace bb::stdlib 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 0ae462195d5..6c5bfe9573f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp @@ -5,24 +5,21 @@ #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "schnorr.hpp" -namespace bb::test_stdlib_schnorr { - using namespace bb; using namespace bb::stdlib; -using namespace bb::stdlib::schnorr; -using Builder = bb::UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using bool_ct = bool_t; using byte_array_ct = byte_array; using field_ct = field_t; using witness_ct = witness_t; /** - * @test Test circuit verifying a Schnorr signature generated by \see{crypto::schnorr::verify_signature}. + * @test Test circuit verifying a Schnorr signature generated by \see{crypto::schnorr_verify_signature}. * We only test: messages signed and verified using Grumpkin and the BLAKE2s hash function. We test strings of lengths * 0, 1, ..., 33. */ -TEST(stdlib_schnorr, verify_signature) +TEST(stdlib_schnorr, schnorr_verify_signature) { std::string longer_string = "This is a test string of length 34"; @@ -31,24 +28,24 @@ TEST(stdlib_schnorr, verify_signature) Builder builder = Builder(); auto message_string = longer_string.substr(0, i); - crypto::schnorr::key_pair account; + crypto::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); + crypto::schnorr_signature signature = + crypto::schnorr_construct_signature(message_string, + account); - bool first_result = crypto::schnorr::verify_signature( + bool first_result = crypto::schnorr_verify_signature( message_string, account.public_key, signature); EXPECT_EQ(first_result, true); cycle_group pub_key{ witness_ct(&builder, account.public_key.x), witness_ct(&builder, account.public_key.y), false }; - signature_bits sig = convert_signature(&builder, signature); + schnorr_signature_bits sig = schnorr_convert_signature(&builder, signature); byte_array_ct message(&builder, message_string); - verify_signature(message, pub_key, sig); + schnorr_verify_signature(message, pub_key, sig); info("num gates = ", builder.get_num_gates()); bool result = builder.check_circuit(); @@ -66,22 +63,22 @@ 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; + crypto::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; + crypto::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); + crypto::schnorr_signature signature = + crypto::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 = crypto::schnorr_verify_signature( message_string, account2.public_key, signature); EXPECT_EQ(native_result, false); @@ -89,9 +86,9 @@ TEST(stdlib_schnorr, verify_signature_failure) cycle_group pub_key2_ct{ witness_ct(&builder, account2.public_key.x), witness_ct(&builder, account2.public_key.y), false }; - signature_bits sig = convert_signature(&builder, signature); + schnorr_signature_bits sig = schnorr_convert_signature(&builder, signature); byte_array_ct message(&builder, message_string); - verify_signature(message, pub_key2_ct, sig); + schnorr_verify_signature(message, pub_key2_ct, sig); info("num gates = ", builder.get_num_gates()); @@ -100,33 +97,33 @@ TEST(stdlib_schnorr, verify_signature_failure) } /** - * @test Like stdlib_schnorr.verify_signature, but we use the function signature_verification that produces a + * @test Like stdlib_schnorr.schnorr_verify_signature, but we use the function signature_verification that produces a * boolean witness and does not require the prover to provide a valid signature. */ -TEST(stdlib_schnorr, signature_verification_result) +TEST(stdlib_schnorr, schnorr_signature_verification_result) { std::string longer_string = "This is a test string of length 34"; Builder builder = Builder(); - crypto::schnorr::key_pair account; + crypto::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); + crypto::schnorr_signature signature = + crypto::schnorr_construct_signature(longer_string, + account); - bool first_result = crypto::schnorr::verify_signature( + bool first_result = crypto::schnorr_verify_signature( longer_string, account.public_key, signature); EXPECT_EQ(first_result, true); cycle_group pub_key{ witness_ct(&builder, account.public_key.x), witness_ct(&builder, account.public_key.y), false }; - signature_bits sig = convert_signature(&builder, signature); + schnorr_signature_bits sig = schnorr_convert_signature(&builder, signature); byte_array_ct message(&builder, longer_string); - bool_ct signature_result = signature_verification_result(message, pub_key, sig); + bool_ct signature_result = schnorr_signature_verification_result(message, pub_key, sig); EXPECT_EQ(signature_result.witness_bool, true); info("num gates = ", builder.get_num_gates()); @@ -145,22 +142,22 @@ 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; + crypto::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; + crypto::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); + crypto::schnorr_signature signature = + crypto::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 = crypto::schnorr_verify_signature( message_string, account2.public_key, signature); EXPECT_EQ(native_result, false); @@ -168,9 +165,9 @@ TEST(stdlib_schnorr, signature_verification_result_failure) cycle_group pub_key2_ct{ witness_ct(&builder, account2.public_key.x), witness_ct(&builder, account2.public_key.y), false }; - signature_bits sig = convert_signature(&builder, signature); + schnorr_signature_bits sig = schnorr_convert_signature(&builder, signature); byte_array_ct message(&builder, message_string); - bool_ct signature_result = signature_verification_result(message, pub_key2_ct, sig); + bool_ct signature_result = schnorr_signature_verification_result(message, pub_key2_ct, sig); EXPECT_EQ(signature_result.witness_bool, false); info("num gates = ", builder.get_num_gates()); @@ -178,5 +175,3 @@ TEST(stdlib_schnorr, signature_verification_result_failure) bool verification_result = builder.check_circuit(); EXPECT_EQ(verification_result, true); } - -} // namespace bb::test_stdlib_schnorr diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp index bf8be6de42f..f5a8b37f24d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp @@ -7,7 +7,7 @@ using namespace bb; using namespace bb::stdlib; -using Builder = bb::UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using field_ct = field_t; using witness_ct = witness_t; @@ -24,7 +24,7 @@ using public_witness_t = public_witness_t; // byte_array_ct input_arr(&builder, input_v); // byte_array_ct output = blake2s(input_arr); -// std::vector expected = blake2::blake2s(input_v); +// std::vector expected = crypto::blake2s(input_v); // EXPECT_EQ(output.get_value(), expected); @@ -43,7 +43,7 @@ TEST(stdlib_blake2s, test_single_block_plookup) byte_array_plookup input_arr(&builder, input_v); byte_array_plookup output = blake2s(input_arr); - auto expected = blake2::blake2s(input_v); + auto expected = crypto::blake2s(input_v); EXPECT_EQ(output.get_value(), std::vector(expected.begin(), expected.end())); @@ -62,7 +62,7 @@ TEST(stdlib_blake2s, test_single_block_plookup) // byte_array_ct input_arr(&builder, input_v); // byte_array_ct output = blake2s(input_arr); -// std::vector expected = blake2::blake2s(input_v); +// std::vector expected = crypto::blake2s(input_v); // EXPECT_EQ(output.get_value(), expected); @@ -81,7 +81,7 @@ TEST(stdlib_blake2s, test_double_block_plookup) byte_array_plookup input_arr(&builder, input_v); byte_array_plookup output = blake2s(input_arr); - auto expected = blake2::blake2s(input_v); + auto expected = crypto::blake2s(input_v); EXPECT_EQ(output.get_value(), std::vector(expected.begin(), expected.end())); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp index 69c5b7a7904..9e054605e3a 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp @@ -10,8 +10,8 @@ using byte_array = stdlib::byte_array; using public_witness_t = stdlib::public_witness_t; using byte_array_plookup = stdlib::byte_array; using public_witness_t_plookup = stdlib::public_witness_t; -using StandardBuilder = bb::StandardCircuitBuilder; -using UltraBuilder = bb::UltraCircuitBuilder; +using StandardBuilder = StandardCircuitBuilder; +using UltraBuilder = UltraCircuitBuilder; TEST(stdlib_blake3s, test_single_block) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.test.cpp index 3c414a26856..49409098b2f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.test.cpp @@ -6,7 +6,7 @@ using namespace bb; -typedef bb::UltraCircuitBuilder Builder; +typedef UltraCircuitBuilder Builder; typedef stdlib::byte_array byte_array; typedef stdlib::public_witness_t public_witness_t; typedef stdlib::field_t field_ct; @@ -14,7 +14,7 @@ typedef stdlib::witness_t witness_ct; typedef stdlib::uint32 uint32_ct; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } TEST(stdlib_keccak, keccak_format_input_table) @@ -67,7 +67,7 @@ TEST(stdlib_keccak, keccak_rho_output_table) { Builder builder = Builder(); - bb::constexpr_for<0, 25, 1>([&] { + constexpr_for<0, 25, 1>([&] { uint256_t extended_native = 0; uint256_t binary_native = 0; for (size_t j = 0; j < 64; ++j) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.test.cpp index e81aeae6bf5..71787e0a8de 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.test.cpp @@ -5,10 +5,9 @@ #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "pedersen.hpp" -namespace test_StdlibPedersen { using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } template class StdlibPedersen : public testing::Test { @@ -155,41 +154,41 @@ template class StdlibPedersen : public testing::Test { Builder builder; for (size_t i = 0; i < 7; ++i) { - std::vector inputs; + std::vector inputs; inputs.push_back(bb::fr::random_element()); inputs.push_back(bb::fr::random_element()); inputs.push_back(bb::fr::random_element()); inputs.push_back(bb::fr::random_element()); if (i == 1) { - inputs[0] = bb::fr(0); + inputs[0] = fr(0); } if (i == 2) { - inputs[1] = bb::fr(0); - inputs[2] = bb::fr(0); + inputs[1] = fr(0); + inputs[2] = fr(0); } if (i == 3) { - inputs[3] = bb::fr(0); + inputs[3] = fr(0); } if (i == 4) { - inputs[0] = bb::fr(0); - inputs[3] = bb::fr(0); + inputs[0] = fr(0); + inputs[3] = fr(0); } if (i == 5) { - inputs[0] = bb::fr(0); - inputs[1] = bb::fr(0); - inputs[2] = bb::fr(0); - inputs[3] = bb::fr(0); + inputs[0] = fr(0); + inputs[1] = fr(0); + inputs[2] = fr(0); + inputs[3] = fr(0); } if (i == 6) { - inputs[1] = bb::fr(1); + inputs[1] = fr(1); } std::vector witnesses; for (auto input : inputs) { witnesses.push_back(witness_ct(&builder, input)); } - bb::fr expected = crypto::pedersen_hash::hash(inputs); + fr expected = crypto::pedersen_hash::hash(inputs); fr_ct result = pedersen_hash::hash(witnesses); EXPECT_EQ(result.get_value(), expected); @@ -225,7 +224,7 @@ template class StdlibPedersen : public testing::Test { { Builder builder; - std::vector inputs; + std::vector inputs; std::vector> witness_inputs; for (size_t i = 0; i < 8; ++i) { @@ -237,7 +236,7 @@ template class StdlibPedersen : public testing::Test { } } - bb::fr expected = crypto::pedersen_hash::hash(inputs); + fr expected = crypto::pedersen_hash::hash(inputs); auto result = pedersen_hash::hash(witness_inputs); EXPECT_EQ(result.get_value(), expected); @@ -309,5 +308,3 @@ TYPED_TEST(StdlibPedersen, HashConstants) { TestFixture::test_hash_constants(); }; - -} // namespace test_StdlibPedersen diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.test.cpp index 428193f5c39..6d5e4bb1cdf 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.test.cpp @@ -4,10 +4,9 @@ #include "barretenberg/numeric/random/engine.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" -namespace test_StdlibPoseidon2 { using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } template class StdlibPoseidon2 : public testing::Test { @@ -128,7 +127,7 @@ template class StdlibPoseidon2 : public testing::Test { { Builder builder; - std::vector inputs; + std::vector inputs; std::vector> witness_inputs; for (size_t i = 0; i < 8; ++i) { @@ -140,7 +139,7 @@ template class StdlibPoseidon2 : public testing::Test { } } - bb::fr expected = native_poseidon2::hash(inputs); + fr expected = native_poseidon2::hash(inputs); auto result = poseidon2::hash(builder, witness_inputs); EXPECT_EQ(result.get_value(), expected); @@ -185,5 +184,3 @@ TYPED_TEST(StdlibPoseidon2, TestHashConstants) { TestFixture::test_hash_constants(); }; - -} // namespace test_StdlibPoseidon2 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 618dc52ef93..9d7e3299b61 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp @@ -9,16 +9,13 @@ #include "barretenberg/numeric/bitop/sparse_form.hpp" #include "barretenberg/numeric/random/engine.hpp" -namespace { -auto& engine = numeric::random::get_debug_engine(); -} - -namespace bb::test_stdlib_sha256 { - using namespace bb; using namespace bb::stdlib; -using Builder = bb::UltraCircuitBuilder; +namespace { +auto& engine = numeric::get_debug_randomness(); +} +using Builder = UltraCircuitBuilder; using byte_array_ct = byte_array; using packed_byte_array_ct = packed_byte_array; @@ -120,18 +117,18 @@ std::array inner_block(std::array& w) // auto builder = UltraPlonkBuilder(); // std::array w_inputs; -// std::array, 64> w_elements; +// std::array, 64> w_elements; // for (size_t i = 0; i < 64; ++i) { // w_inputs[i] = engine.get_random_uint32(); -// w_elements[i] = bb::stdlib::witness_t(&builder, -// bb::fr(w_inputs[i])); +// w_elements[i] = stdlib::witness_t(&builder, +// fr(w_inputs[i])); // } // const auto expected = inner_block(w_inputs); // const std::array, 8> result = -// bb::stdlib::sha256_inner_block(w_elements); +// stdlib::sha256_inner_block(w_elements); // for (size_t i = 0; i < 8; ++i) { // EXPECT_EQ(uint256_t(result[i].get_value()).data[0] & 0xffffffffUL, // uint256_t(expected[i]).data[0] & 0xffffffffUL); @@ -141,22 +138,22 @@ std::array inner_block(std::array& w) // auto prover = composer.create_prover(); // auto verifier = composer.create_verifier(); -// bb::plonk::proof proof = prover.construct_proof(); +// plonk::proof proof = prover.construct_proof(); // bool proof_result = builder.check_circuit(); // EXPECT_EQ(proof_result, true); // } TEST(stdlib_sha256, test_plookup_55_bytes) { - typedef bb::stdlib::field_t field_pt; - typedef bb::stdlib::packed_byte_array packed_byte_array_pt; + typedef stdlib::field_t field_pt; + typedef stdlib::packed_byte_array packed_byte_array_pt; // 55 bytes is the largest number of bytes that can be hashed in a single block, // accounting for the single padding bit, and the 64 size bits required by the SHA-256 standard. - auto builder = bb::UltraCircuitBuilder(); + auto builder = UltraCircuitBuilder(); packed_byte_array_pt input(&builder, "An 8 character password? Snow White and the 7 Dwarves.."); - packed_byte_array_pt output_bits = bb::stdlib::sha256(input); + packed_byte_array_pt output_bits = stdlib::sha256(input); std::vector output = output_bits.to_unverified_byte_slices(4); @@ -181,7 +178,7 @@ TEST(stdlib_sha256, test_55_bytes) auto builder = Builder(); packed_byte_array_ct input(&builder, "An 8 character password? Snow White and the 7 Dwarves.."); - packed_byte_array_ct output_bits = bb::stdlib::sha256(input); + packed_byte_array_ct output_bits = stdlib::sha256(input); std::vector output = output_bits.to_unverified_byte_slices(4); @@ -201,13 +198,13 @@ TEST(stdlib_sha256, test_55_bytes) TEST(stdlib_sha256, test_NIST_vector_one_packed_byte_array) { - typedef bb::stdlib::field_t field_pt; - typedef bb::stdlib::packed_byte_array packed_byte_array_pt; + typedef stdlib::field_t field_pt; + typedef stdlib::packed_byte_array packed_byte_array_pt; - auto builder = bb::UltraCircuitBuilder(); + auto builder = UltraCircuitBuilder(); packed_byte_array_pt input(&builder, "abc"); - packed_byte_array_pt output_bytes = bb::stdlib::sha256(input); + packed_byte_array_pt output_bytes = stdlib::sha256(input); std::vector output = output_bytes.to_unverified_byte_slices(4); EXPECT_EQ(uint256_t(output[0].get_value()).data[0], (uint64_t)0xBA7816BFU); EXPECT_EQ(uint256_t(output[1].get_value()).data[0], (uint64_t)0x8F01CFEAU); @@ -225,14 +222,14 @@ TEST(stdlib_sha256, test_NIST_vector_one_packed_byte_array) TEST(stdlib_sha256, test_NIST_vector_one) { - typedef bb::stdlib::field_t field_pt; - typedef bb::stdlib::packed_byte_array packed_byte_array_pt; + typedef stdlib::field_t field_pt; + typedef stdlib::packed_byte_array packed_byte_array_pt; - auto builder = bb::UltraCircuitBuilder(); + auto builder = UltraCircuitBuilder(); packed_byte_array_pt input(&builder, "abc"); - packed_byte_array_pt output_bits = bb::stdlib::sha256(input); + packed_byte_array_pt output_bits = stdlib::sha256(input); std::vector output = output_bits.to_unverified_byte_slices(4); @@ -256,7 +253,7 @@ TEST(stdlib_sha256, test_NIST_vector_two) byte_array_ct input(&builder, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"); - byte_array_ct output_bits = bb::stdlib::sha256(input); + byte_array_ct output_bits = stdlib::sha256(input); std::vector output = packed_byte_array_ct(output_bits).to_unverified_byte_slices(4); @@ -281,7 +278,7 @@ TEST(stdlib_sha256, test_NIST_vector_three) // one byte, 0xbd byte_array_ct input(&builder, std::vector{ 0xbd }); - byte_array_ct output_bits = bb::stdlib::sha256(input); + byte_array_ct output_bits = stdlib::sha256(input); std::vector output = packed_byte_array_ct(output_bits).to_unverified_byte_slices(4); @@ -306,7 +303,7 @@ TEST(stdlib_sha256, test_NIST_vector_four) // 4 bytes, 0xc98c8e55 byte_array_ct input(&builder, std::vector{ 0xc9, 0x8c, 0x8e, 0x55 }); - byte_array_ct output_bits = bb::stdlib::sha256(input); + byte_array_ct output_bits = stdlib::sha256(input); std::vector output = packed_byte_array_ct(output_bits).to_unverified_byte_slices(4); @@ -327,10 +324,10 @@ TEST(stdlib_sha256, test_NIST_vector_four) HEAVY_TEST(stdlib_sha256, test_NIST_vector_five) { - typedef bb::stdlib::field_t field_pt; - typedef bb::stdlib::packed_byte_array packed_byte_array_pt; + typedef stdlib::field_t field_pt; + typedef stdlib::packed_byte_array packed_byte_array_pt; - auto builder = bb::UltraCircuitBuilder(); + auto builder = UltraCircuitBuilder(); packed_byte_array_pt input( &builder, @@ -345,7 +342,7 @@ HEAVY_TEST(stdlib_sha256, test_NIST_vector_five) "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAA"); - packed_byte_array_pt output_bits = bb::stdlib::sha256(input); + packed_byte_array_pt output_bits = stdlib::sha256(input); std::vector output = output_bits.to_unverified_byte_slices(4); @@ -374,7 +371,7 @@ TEST(stdlib_sha256, test_input_len_multiple) auto input_buf = std::vector(inp, 1); byte_array_ct input(&builder, input_buf); - byte_array_ct output_bits = bb::stdlib::sha256(input); + byte_array_ct output_bits = stdlib::sha256(input); auto circuit_output = output_bits.get_value(); @@ -418,7 +415,7 @@ TEST(stdlib_sha256, test_input_str_len_multiple) auto input_buf = std::vector(input_str.begin(), input_str.end()); byte_array_ct input(&builder, input_buf); - byte_array_ct output_bits = bb::stdlib::sha256(input); + byte_array_ct output_bits = stdlib::sha256(input); auto circuit_output = output_bits.get_value(); @@ -427,5 +424,3 @@ TEST(stdlib_sha256, test_input_str_len_multiple) EXPECT_EQ(circuit_output, expected); } } - -} // namespace bb::test_stdlib_sha256 diff --git a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp index 8daf6b0ef38..2e420fb1538 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp @@ -5,12 +5,10 @@ #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "barretenberg/stdlib/merkle_tree/membership.hpp" -namespace bb::stdlib_merkle_tree_hash_test { - using namespace bb; using namespace bb::stdlib; -using Builder = bb::UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using field_ct = field_t; using witness_ct = witness_t; @@ -64,4 +62,3 @@ TEST(stdlib_merkle_tree_hash, compute_tree_native) } EXPECT_EQ(tree_vector.back(), mem_tree.root()); } -} // namespace bb::stdlib_merkle_tree_hash_test \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp index f559cf01085..1d8d06820e7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp @@ -7,17 +7,15 @@ #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" -namespace { -auto& engine = numeric::random::get_debug_engine(); -} - -namespace bb::stdlib_merkle_test { - using namespace bb; using namespace bb::stdlib::merkle_tree; using namespace bb::stdlib; -using Builder = bb::UltraCircuitBuilder; +namespace { +auto& engine = numeric::get_debug_randomness(); +} + +using Builder = UltraCircuitBuilder; using bool_ct = bool_t; using field_ct = field_t; @@ -247,4 +245,3 @@ TEST(stdlib_merkle_tree, test_update_memberships) bool result = builder.check_circuit(); EXPECT_EQ(result, true); } -} // namespace bb::stdlib_merkle_test \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.bench.cpp b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.bench.cpp index 94268b49bb1..49871e881e6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.bench.cpp @@ -8,7 +8,7 @@ using namespace benchmark; using namespace bb::stdlib::merkle_tree; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = bb::numeric::get_debug_randomness(); } constexpr size_t DEPTH = 256; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.test.cpp index ec80f169126..55bd530c216 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.test.cpp @@ -5,18 +5,16 @@ #include "memory_store.hpp" #include "memory_tree.hpp" -namespace bb::test_stdlib_merkle_tree { - using namespace bb::stdlib; using namespace bb::stdlib::merkle_tree; -using Builder = bb::UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using field_ct = field_t; using witness_ct = witness_t; namespace { -auto& engine = numeric::random::get_debug_engine(); -auto& random_engine = numeric::random::get_engine(); +auto& engine = numeric::get_debug_randomness(); +auto& random_engine = numeric::get_randomness(); } // namespace static std::vector VALUES = []() { @@ -184,4 +182,3 @@ TEST(stdlib_merkle_tree, test_get_sibling_path_layers) EXPECT_NE(before[2], after[2]); } } -} // namespace bb::test_stdlib_merkle_tree \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_tree.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_tree.test.cpp index de20b85ddbd..99a1eeeffde 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_tree.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_tree.test.cpp @@ -9,8 +9,8 @@ using namespace bb; using namespace bb::stdlib::merkle_tree; namespace { -auto& engine = numeric::random::get_debug_engine(); -auto& random_engine = numeric::random::get_engine(); +auto& engine = numeric::get_debug_randomness(); +auto& random_engine = numeric::get_randomness(); } // namespace static std::vector VALUES = []() { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp index e47278837ec..cc03446d73f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp @@ -18,7 +18,6 @@ #include #include -namespace test_stdlib_bigfield { using namespace bb; /* A note regarding Plookup: @@ -30,7 +29,7 @@ using namespace bb; */ namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } template class stdlib_bigfield : public testing::Test { @@ -827,18 +826,18 @@ template class stdlib_bigfield : public testing::Test { static void test_conditional_select_regression() { auto builder = Builder(); - bb::fq a(0); - bb::fq b(1); + fq a(0); + fq b(1); fq_ct a_ct(&builder, a); fq_ct b_ct(&builder, b); fq_ct selected = a_ct.conditional_select(b_ct, typename bn254::bool_ct(&builder, true)); - EXPECT_EQ(bb::fq((selected.get_value() % uint512_t(bb::fq::modulus)).lo), b); + EXPECT_EQ(fq((selected.get_value() % uint512_t(bb::fq::modulus)).lo), b); } static void test_division_context() { auto builder = Builder(); - bb::fq a(1); + fq a(1); fq_ct a_ct(&builder, a); fq_ct ret = fq_ct::div_check_denominator_nonzero({}, a_ct); EXPECT_NE(ret.get_context(), nullptr); @@ -943,15 +942,15 @@ TYPED_TEST(stdlib_bigfield, division_context) // fq_ct::NUM_LIMB_BITS * 2))), // witness_ct( // &builder, -// bb::fr(uint256_t(inputs[0]).slice(fq_ct::NUM_LIMB_BITS * 2, +// fr(uint256_t(inputs[0]).slice(fq_ct::NUM_LIMB_BITS * 2, // fq_ct::NUM_LIMB_BITS * 4)))); // fq_ct b1(&builder, uint256_t(inputs[1])); // fq_ct b2(&builder, uint256_t(inputs[2])); // fq_ct c = a / (b1 - b2); // // uint256_t modulus{ bb::Bn254FqParams::modulus_0, -// // bb::Bn254FqParams::modulus_1, -// // bb::Bn254FqParams::modulus_2, -// // bb::Bn254FqParams::modulus_3 }; +// // Bn254FqParams::modulus_1, +// // Bn254FqParams::modulus_2, +// // Bn254FqParams::modulus_3 }; // fq expected = (inputs[0] / (inputs[1] - inputs[2])); // std::cerr << "denominator = " << inputs[1] - inputs[2] << std::endl; @@ -978,20 +977,20 @@ TYPED_TEST(stdlib_bigfield, division_context) // // PLOOKUP TESTS // TEST(stdlib_bigfield_plookup, test_mul) // { -// plonk::UltraPlonkBuilder builder = bb::plonk::UltraPlonkBuilder(); +// plonk::UltraPlonkBuilder builder = plonk::UltraPlonkBuilder(); // size_t num_repetitions = 1; // for (size_t i = 0; i < num_repetitions; ++i) { // fq inputs[3]{ fq::random_element(), fq::random_element(), fq::random_element() }; // fq_ct a( // witness_ct(&builder, bb::fr(uint256_t(inputs[0]).slice(0, // fq_ct::NUM_LIMB_BITS * 2))), witness_ct(&builder, -// bb::fr( +// fr( // uint256_t(inputs[0]).slice(fq_ct::NUM_LIMB_BITS * 2, fq_ct::NUM_LIMB_BITS * // 4)))); // fq_ct b( // witness_ct(&builder, bb::fr(uint256_t(inputs[1]).slice(0, // fq_ct::NUM_LIMB_BITS * 2))), witness_ct(&builder, -// bb::fr( +// fr( // uint256_t(inputs[1]).slice(fq_ct::NUM_LIMB_BITS * 2, fq_ct::NUM_LIMB_BITS * // 4)))); // std::cerr << "starting mul" << std::endl; @@ -1025,14 +1024,14 @@ TYPED_TEST(stdlib_bigfield, division_context) // TEST(stdlib_bigfield_plookup, test_sqr) // { -// plonk::UltraPlonkBuilder builder = bb::plonk::UltraPlonkBuilder(); +// plonk::UltraPlonkBuilder builder = plonk::UltraPlonkBuilder(); // size_t num_repetitions = 10; // for (size_t i = 0; i < num_repetitions; ++i) { // fq inputs[3]{ fq::random_element(), fq::random_element(), fq::random_element() }; // fq_ct a( // witness_ct(&builder, bb::fr(uint256_t(inputs[0]).slice(0, // fq_ct::NUM_LIMB_BITS * 2))), witness_ct(&builder, -// bb::fr( +// fr( // uint256_t(inputs[0]).slice(fq_ct::NUM_LIMB_BITS * 2, fq_ct::NUM_LIMB_BITS * // 4)))); // uint64_t before = builder.get_num_gates(); @@ -1062,4 +1061,3 @@ TYPED_TEST(stdlib_bigfield, division_context) // bool result = verifier.verify_proof(proof); // EXPECT_EQ(result, true); // } -} // namespace test_stdlib_bigfield diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp index aaaa1a07506..1dad1d6a38c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp @@ -10,7 +10,7 @@ #include "barretenberg/stdlib/primitives/curves/secp256r1.hpp" namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } using namespace bb; @@ -906,7 +906,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, multiple_montgomery_ladder) HEAVY_TYPED_TEST(stdlib_biggroup, compute_naf) { // ULTRATODO: make this work for secp curves - if constexpr (TypeParam::Curve::type == bb::CurveType::BN254) { + if constexpr (TypeParam::Curve::type == CurveType::BN254) { size_t num_repetitions = 1; for (size_t i = 0; i < num_repetitions; i++) { TestFixture::test_compute_naf(); @@ -979,7 +979,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, wnaf_batch_4) /* The following tests are specific to BN254 and don't work when Fr is a bigfield */ HEAVY_TYPED_TEST(stdlib_biggroup, bn254_endo_batch_mul) { - if constexpr (TypeParam::Curve::type == bb::CurveType::BN254 && !TypeParam::use_bigfield) { + if constexpr (TypeParam::Curve::type == CurveType::BN254 && !TypeParam::use_bigfield) { if constexpr (HasGoblinBuilder) { GTEST_SKIP() << "https://github.com/AztecProtocol/barretenberg/issues/707"; } else { @@ -991,7 +991,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, bn254_endo_batch_mul) } HEAVY_TYPED_TEST(stdlib_biggroup, mixed_mul_bn254_endo) { - if constexpr (TypeParam::Curve::type == bb::CurveType::BN254 && !TypeParam::use_bigfield) { + if constexpr (TypeParam::Curve::type == CurveType::BN254 && !TypeParam::use_bigfield) { if constexpr (HasGoblinBuilder) { GTEST_SKIP() << "https://github.com/AztecProtocol/barretenberg/issues/707"; } else { @@ -1005,7 +1005,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, mixed_mul_bn254_endo) /* The following tests are specific to SECP256k1 */ HEAVY_TYPED_TEST(stdlib_biggroup, wnaf_secp256k1) { - if constexpr (TypeParam::Curve::type == bb::CurveType::SECP256K1) { + if constexpr (TypeParam::Curve::type == CurveType::SECP256K1) { TestFixture::test_wnaf_secp256k1(); } else { GTEST_SKIP(); @@ -1013,7 +1013,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, wnaf_secp256k1) } HEAVY_TYPED_TEST(stdlib_biggroup, wnaf_8bit_secp256k1) { - if constexpr (TypeParam::Curve::type == bb::CurveType::SECP256K1) { + if constexpr (TypeParam::Curve::type == CurveType::SECP256K1) { TestFixture::test_wnaf_8bit_secp256k1(); } else { GTEST_SKIP(); @@ -1021,7 +1021,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, wnaf_8bit_secp256k1) } HEAVY_TYPED_TEST(stdlib_biggroup, ecdsa_mul_secp256k1) { - if constexpr (TypeParam::Curve::type == bb::CurveType::SECP256K1) { + if constexpr (TypeParam::Curve::type == CurveType::SECP256K1) { TestFixture::test_ecdsa_mul_secp256k1(); } else { GTEST_SKIP(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin.test.cpp index a88c0b5c82c..1753d04de84 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin.test.cpp @@ -10,7 +10,7 @@ #include namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } using namespace bb; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.test.cpp index 8db4db895f2..7f002085da0 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.test.cpp @@ -17,12 +17,10 @@ using bit_array_ct = stdlib::bit_array; \ using bool_ct = stdlib::bool_t; -namespace test_stdlib_bit_array { - using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } template class BitArrayTest : public ::testing::Test {}; @@ -129,4 +127,3 @@ TYPED_TEST(BitArrayTest, test_uint32_vector_constructor) static_cast(test_bit_array_2).get_value(); } -} // namespace test_stdlib_bit_array diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp index e3d4dfc7159..d9f87cd59ab 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp @@ -8,11 +8,10 @@ using witness_ct = stdlib::witness_t; \ using bool_ct = stdlib::bool_t; -namespace test_stdlib_bool { using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } template class BoolTest : public ::testing::Test {}; @@ -528,4 +527,3 @@ TYPED_TEST(BoolTest, Normalize) bool result = builder.check_circuit(); EXPECT_EQ(result, true); } -} // namespace test_stdlib_bool \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp index 3f1ec92fb3a..0985b61aad5 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp @@ -7,7 +7,6 @@ #pragma GCC diagnostic ignored "-Wunused-local-typedefs" -namespace test_stdlib_byte_array { using namespace bb; using namespace bb::stdlib; @@ -138,5 +137,3 @@ TYPED_TEST(ByteArrayTest, set_bit) bool proof_result = builder.check_circuit(); EXPECT_EQ(proof_result, true); } - -} // namespace test_stdlib_byte_array diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/secp256k1.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/secp256k1.hpp index c771f3e1f7f..9ab05338b66 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/secp256k1.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/secp256k1.hpp @@ -11,21 +11,21 @@ namespace bb::stdlib { template struct secp256k1 { static constexpr bb::CurveType type = bb::CurveType::SECP256K1; - typedef ::secp256k1::fq fq; - typedef ::secp256k1::fr fr; - typedef ::secp256k1::g1 g1; + using fq = ::secp256k1::fq; + using fr = ::secp256k1::fr; + using g1 = ::secp256k1::g1; - typedef CircuitType Builder; - typedef witness_t witness_ct; - typedef public_witness_t public_witness_ct; - typedef field_t fr_ct; - typedef byte_array byte_array_ct; - typedef bool_t bool_ct; - typedef stdlib::uint32 uint32_ct; + using Builder = CircuitType; + using witness_ct = witness_t; + using public_witness_ct = public_witness_t; + using fr_ct = field_t; + using byte_array_ct = byte_array; + using bool_ct = bool_t; + using uint32_ct = stdlib::uint32; - typedef bigfield fq_ct; - typedef bigfield bigfr_ct; - typedef element g1_ct; - typedef element g1_bigfr_ct; + using fq_ct = bigfield; + using bigfr_ct = bigfield; + using g1_ct = element; + using g1_bigfr_ct = element; }; } // namespace bb::stdlib diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp index bb4602e33b6..70b7e8fee18 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp @@ -6,16 +6,14 @@ #include #include -namespace test_stdlib_array { +using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } template void ignore_unused(T&) {} // use to ignore unused variables in lambdas -using namespace bb; - template class stdlib_array : public testing::Test { typedef stdlib::bool_t bool_ct; typedef stdlib::field_t field_ct; @@ -695,4 +693,3 @@ TYPED_TEST(stdlib_array, test_pata_nonzero_after_zero_target_fails_2) { TestFixture::test_pata_nonzero_after_zero_target_fails_2(); } -} // namespace test_stdlib_array \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp index 444364e4b3f..6977453e34a 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp @@ -10,10 +10,8 @@ using namespace bb; -namespace test_stdlib_field { - namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } template void ignore_unused(T&) {} // use to ignore unused variables in lambdas @@ -193,12 +191,12 @@ template class stdlib_field : public testing::Test { Builder builder = Builder(); field_ct a = witness_ct(&builder, bb::fr::random_element()); - a *= bb::fr::random_element(); - a += bb::fr::random_element(); + a *= fr::random_element(); + a += fr::random_element(); field_ct b = witness_ct(&builder, bb::fr::random_element()); - b *= bb::fr::random_element(); - b += bb::fr::random_element(); + b *= fr::random_element(); + b += fr::random_element(); // numerator constant field_ct out = field_ct(&builder, b.get_value()) / a; @@ -618,11 +616,11 @@ template class stdlib_field : public testing::Test { constexpr uint256_t modulus_minus_one = fr::modulus - 1; const fr p_lo = modulus_minus_one.slice(0, 130); - std::vector test_elements = { bb::fr::random_element(), - 0, - -1, - bb::fr(static_cast(engine.get_random_uint8())), - bb::fr((static_cast(1) << 130) + 1 + p_lo) }; + std::vector test_elements = { bb::fr::random_element(), + 0, + -1, + fr(static_cast(engine.get_random_uint8())), + fr((static_cast(1) << 130) + 1 + p_lo) }; for (auto a_expected : test_elements) { field_ct a = witness_ct(&builder, a_expected); @@ -713,13 +711,13 @@ template class stdlib_field : public testing::Test { { Builder builder = Builder(); - bb::fr base_val(engine.get_random_uint256()); + fr base_val(engine.get_random_uint256()); uint32_t exponent_val = engine.get_random_uint32(); field_ct base = witness_ct(&builder, base_val); field_ct exponent = witness_ct(&builder, exponent_val); field_ct result = base.pow(exponent); - bb::fr expected = base_val.pow(exponent_val); + fr expected = base_val.pow(exponent_val); EXPECT_EQ(result.get_value(), expected); @@ -732,7 +730,7 @@ template class stdlib_field : public testing::Test { { Builder builder = Builder(); - bb::fr base_val(engine.get_random_uint256()); + fr base_val(engine.get_random_uint256()); uint32_t exponent_val = 0; field_ct base = witness_ct(&builder, base_val); @@ -750,7 +748,7 @@ template class stdlib_field : public testing::Test { { Builder builder = Builder(); - bb::fr base_val(engine.get_random_uint256()); + fr base_val(engine.get_random_uint256()); uint32_t exponent_val = 1; field_ct base = witness_ct(&builder, base_val); @@ -770,13 +768,13 @@ template class stdlib_field : public testing::Test { const size_t num_gates_start = builder.num_gates; - bb::fr base_val(engine.get_random_uint256()); + fr base_val(engine.get_random_uint256()); uint32_t exponent_val = engine.get_random_uint32(); field_ct base(&builder, base_val); field_ct exponent(&builder, exponent_val); field_ct result = base.pow(exponent); - bb::fr expected = base_val.pow(exponent_val); + fr expected = base_val.pow(exponent_val); EXPECT_EQ(result.get_value(), expected); @@ -788,13 +786,13 @@ template class stdlib_field : public testing::Test { { Builder builder = Builder(); - bb::fr base_val(engine.get_random_uint256()); + fr base_val(engine.get_random_uint256()); uint32_t exponent_val = engine.get_random_uint32(); field_ct base(&builder, base_val); field_ct exponent = witness_ct(&builder, exponent_val); field_ct result = base.pow(exponent); - bb::fr expected = base_val.pow(exponent_val); + fr expected = base_val.pow(exponent_val); EXPECT_EQ(result.get_value(), expected); @@ -807,13 +805,13 @@ template class stdlib_field : public testing::Test { { Builder builder = Builder(); - bb::fr base_val(engine.get_random_uint256()); + fr base_val(engine.get_random_uint256()); uint32_t exponent_val = engine.get_random_uint32(); field_ct base = witness_ct(&builder, base_val); field_ct exponent(&builder, exponent_val); field_ct result = base.pow(exponent); - bb::fr expected = base_val.pow(exponent_val); + fr expected = base_val.pow(exponent_val); EXPECT_EQ(result.get_value(), expected); info("num gates = ", builder.get_num_gates()); @@ -826,14 +824,14 @@ template class stdlib_field : public testing::Test { { Builder builder = Builder(); - bb::fr base_val(engine.get_random_uint256()); + fr base_val(engine.get_random_uint256()); uint64_t exponent_val = engine.get_random_uint32(); exponent_val += (uint64_t(1) << 32); field_ct base = witness_ct(&builder, base_val); field_ct exponent = witness_ct(&builder, exponent_val); field_ct result = base.pow(exponent); - bb::fr expected = base_val.pow(exponent_val); + fr expected = base_val.pow(exponent_val); EXPECT_NE(result.get_value(), expected); EXPECT_EQ(builder.failed(), true); @@ -844,7 +842,7 @@ template class stdlib_field : public testing::Test { { Builder builder = Builder(); - bb::fr value(engine.get_random_uint256()); + fr value(engine.get_random_uint256()); field_ct value_ct = witness_ct(&builder, value); field_ct first_copy = witness_ct(&builder, value_ct.get_value()); @@ -1035,5 +1033,3 @@ TYPED_TEST(stdlib_field, test_ranged_less_than) { TestFixture::test_ranged_less_than(); } - -} // namespace test_stdlib_field diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp index c321120d4c5..9a4fcd32c85 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.test.cpp @@ -17,11 +17,10 @@ using bool_ct = stdlib::bool_t; \ using witness_ct = stdlib::witness_t; -namespace stdlib_cycle_group_tests { using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-local-typedefs" @@ -567,5 +566,3 @@ TYPED_TEST(CycleGroupTest, TestMul) EXPECT_EQ(proof_result, true); } #pragma GCC diagnostic pop - -} // namespace stdlib_cycle_group_tests diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp index a8d88e0f9be..d0ac7d4f1b2 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp @@ -15,17 +15,14 @@ using field_ct = stdlib::field_t; \ using bool_ct = stdlib::bool_t; \ using public_witness_ct = stdlib::public_witness_t; - -namespace test_stdlib_logic { +using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } template void ignore_unused(T&) {} // use to ignore unused variables in lambdas -using namespace bb; - template class LogicTest : public testing::Test {}; using CircuitTypes = ::testing::Types; @@ -147,5 +144,3 @@ TYPED_TEST(LogicTest, DifferentWitnessSameResult) EXPECT_EQ(result, false); } } - -} // namespace test_stdlib_logic \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.test.cpp index 07525e2cd17..ff419207d4f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.test.cpp @@ -7,15 +7,14 @@ #include "../bool/bool.hpp" #include "../circuit_builders/circuit_builders.hpp" -namespace test_stdlib_dynamic_array { using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } // Defining ultra-specific types for local testing. -using Builder = bb::UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using bool_ct = stdlib::bool_t; using field_ct = stdlib::field_t; using witness_ct = stdlib::witness_t; @@ -63,5 +62,3 @@ TEST(DynamicArray, DynamicArrayReadWriteConsistency) bool verified = builder.check_circuit(); EXPECT_EQ(verified, true); } - -} // namespace test_stdlib_dynamic_array \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.test.cpp index 0f471c3a4ca..4c58de3300b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.test.cpp @@ -4,17 +4,15 @@ #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "ram_table.hpp" -namespace test_stdlib_ram_table { - using namespace bb; // Defining ultra-specific types for local testing. -using Builder = bb::UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using field_ct = stdlib::field_t; using witness_ct = stdlib::witness_t; using ram_table_ct = stdlib::ram_table; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } TEST(ram_table, ram_table_init_read_consistency) @@ -30,7 +28,7 @@ TEST(ram_table, ram_table_init_read_consistency) ram_table_ct table(table_values); field_ct result(0); - bb::fr expected(0); + fr expected(0); for (size_t i = 0; i < 10; ++i) { field_ct index(witness_ct(&builder, (uint64_t)i)); @@ -56,7 +54,7 @@ TEST(ram_table, ram_table_read_write_consistency) Builder builder; const size_t table_size = 10; - std::vector table_values(table_size); + std::vector table_values(table_size); ram_table_ct table(&builder, table_size); @@ -64,12 +62,12 @@ TEST(ram_table, ram_table_read_write_consistency) table.write(i, 0); } field_ct result(0); - bb::fr expected(0); + fr expected(0); const auto update = [&]() { for (size_t i = 0; i < table_size / 2; ++i) { - table_values[2 * i] = bb::fr::random_element(); - table_values[2 * i + 1] = bb::fr::random_element(); + table_values[2 * i] = fr::random_element(); + table_values[2 * i + 1] = fr::random_element(); // init with both constant and variable values table.write(2 * i, table_values[2 * i]); @@ -100,4 +98,3 @@ TEST(ram_table, ram_table_read_write_consistency) bool verified = builder.check_circuit(); EXPECT_EQ(verified, true); } -} // namespace test_stdlib_ram_table \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.test.cpp index 9fdd7ffe021..dbbb9b09937 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.test.cpp @@ -5,17 +5,16 @@ #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "rom_table.hpp" -namespace test_stdlib_rom_array { using namespace bb; // Defining ultra-specific types for local testing. -using Builder = bb::UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using field_ct = stdlib::field_t; using witness_ct = stdlib::witness_t; using rom_table_ct = stdlib::rom_table; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } TEST(rom_table, rom_table_read_write_consistency) @@ -31,7 +30,7 @@ TEST(rom_table, rom_table_read_write_consistency) rom_table_ct table(table_values); field_ct result(0); - bb::fr expected(0); + fr expected(0); for (size_t i = 0; i < 10; ++i) { field_ct index(witness_ct(&builder, (uint64_t)i)); @@ -62,5 +61,3 @@ TEST(rom_table, rom_table_read_write_consistency) bool verified = builder.check_circuit(); EXPECT_EQ(verified, true); } - -} // namespace test_stdlib_rom_array diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp index 2eca3f8ff12..81552258c9b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp @@ -7,11 +7,10 @@ #pragma GCC diagnostic ignored "-Wunused-local-typedefs" -namespace test_stdlib_packed_byte_array { using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } #define STDLIB_TYPE_ALIASES \ using Builder = TypeParam; \ @@ -194,5 +193,3 @@ TYPED_TEST(PackedByteArrayTest, TestAppendUint32) EXPECT_TRUE(builder.check_circuit()); } - -} // namespace test_stdlib_packed_byte_array diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.test.cpp index f09630c53c7..00d2b6846ee 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.test.cpp @@ -13,12 +13,12 @@ using namespace bb; using namespace bb::plookup; // Defining ultra-specific types for local testing. -using Builder = bb::UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using field_ct = stdlib::field_t; using witness_ct = stdlib::witness_t; -using plookup_read = bb::stdlib::plookup_read; +using plookup_read = stdlib::plookup_read; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } // TODO FIX FIX @@ -26,15 +26,15 @@ auto& engine = numeric::random::get_debug_engine(); // { // Builder builder = Builder(); -// bb::fr input_value = fr::random_element(); +// fr input_value = fr::random_element(); // field_ct input_hi = witness_ct(&builder, uint256_t(input_value).slice(126, 256)); // field_ct input_lo = witness_ct(&builder, uint256_t(input_value).slice(0, 126)); // const auto lookup_hi = plookup_read::get_lookup_accumulators(MultiTableId::PEDERSEN_LEFT_HI, input_hi); // const auto lookup_lo = plookup_read::get_lookup_accumulators(MultiTableId::PEDERSEN_LEFT_LO, input_lo); -// std::vector expected_x; -// std::vector expected_y; +// std::vector expected_x; +// std::vector expected_y; // const size_t num_lookups_hi = // (128 + crypto::pedersen_hash::lookup::BITS_PER_TABLE) / crypto::pedersen_hash::lookup::BITS_PER_TABLE; @@ -44,7 +44,7 @@ auto& engine = numeric::random::get_debug_engine(); // EXPECT_EQ(num_lookups_lo, lookup_lo[ColumnIdx::C1].size()); // const size_t num_lookups = num_lookups_hi + num_lookups_lo; -// std::vector expected_scalars; +// std::vector expected_scalars; // expected_x.resize(num_lookups); // expected_y.resize(num_lookups); // expected_scalars.resize(num_lookups); @@ -103,15 +103,15 @@ auto& engine = numeric::random::get_debug_engine(); // { // Builder builder = Builder(); -// bb::fr input_value = fr::random_element(); +// fr input_value = fr::random_element(); // field_ct input_hi = witness_ct(&builder, uint256_t(input_value).slice(126, 256)); // field_ct input_lo = witness_ct(&builder, uint256_t(input_value).slice(0, 126)); // const auto lookup_hi = plookup_read::get_lookup_accumulators(MultiTableId::PEDERSEN_RIGHT_HI, input_hi); // const auto lookup_lo = plookup_read::get_lookup_accumulators(MultiTableId::PEDERSEN_RIGHT_LO, input_lo); -// std::vector expected_x; -// std::vector expected_y; +// std::vector expected_x; +// std::vector expected_y; // const size_t num_lookups_hi = // (128 + crypto::pedersen_hash::lookup::BITS_PER_TABLE) / crypto::pedersen_hash::lookup::BITS_PER_TABLE; @@ -121,7 +121,7 @@ auto& engine = numeric::random::get_debug_engine(); // EXPECT_EQ(num_lookups_lo, lookup_lo[ColumnIdx::C1].size()); // const size_t num_lookups = num_lookups_hi + num_lookups_lo; -// std::vector expected_scalars; +// std::vector expected_scalars; // expected_x.resize(num_lookups); // expected_y.resize(num_lookups); // expected_scalars.resize(num_lookups); @@ -237,9 +237,9 @@ TEST(stdlib_plookup, blake2s_xor_rotate_16) const auto left_slices = numeric::slice_input(left_value, 1 << 6, num_lookups); const auto right_slices = numeric::slice_input(right_value, 1 << 6, num_lookups); - std::vector out_expected(num_lookups); - std::vector left_expected(num_lookups); - std::vector right_expected(num_lookups); + std::vector out_expected(num_lookups); + std::vector left_expected(num_lookups); + std::vector right_expected(num_lookups); for (size_t i = 0; i < left_slices.size(); ++i) { if (i == 2) { @@ -260,7 +260,7 @@ TEST(stdlib_plookup, blake2s_xor_rotate_16) * out_coefficients must be (a5/a4, a4/a3, a3/a2, a2/a1, a1/a0). Note that these are stored in reverse orde * for simplicity. */ - std::vector out_coefficients{ (1 << 6), (bb::fr(1) / bb::fr(1 << 22)), (1 << 2), (1 << 6), (1 << 6) }; + std::vector out_coefficients{ (1 << 6), (bb::fr(1) / bb::fr(1 << 22)), (1 << 2), (1 << 6), (1 << 6) }; for (size_t i = num_lookups - 2; i < num_lookups; --i) { out_expected[i] += out_expected[i + 1] * out_coefficients[i]; @@ -279,10 +279,10 @@ TEST(stdlib_plookup, blake2s_xor_rotate_16) * while defining the table we had set the coefficient of s0 to 1, so to correct that, we need to multiply by a * constant. */ - auto mul_constant = bb::fr(1 << 16); - bb::fr lookup_output = lookup[ColumnIdx::C3][0].get_value() * mul_constant; + auto mul_constant = fr(1 << 16); + fr lookup_output = lookup[ColumnIdx::C3][0].get_value() * mul_constant; uint32_t xor_rotate_output = numeric::rotate32(uint32_t(left_value) ^ uint32_t(right_value), 16); - EXPECT_EQ(bb::fr(uint256_t(xor_rotate_output)), lookup_output); + EXPECT_EQ(fr(uint256_t(xor_rotate_output)), lookup_output); bool result = builder.check_circuit(); @@ -306,9 +306,9 @@ TEST(stdlib_plookup, blake2s_xor_rotate_8) const auto left_slices = numeric::slice_input(left_value, 1 << 6, num_lookups); const auto right_slices = numeric::slice_input(right_value, 1 << 6, num_lookups); - std::vector out_expected(num_lookups); - std::vector left_expected(num_lookups); - std::vector right_expected(num_lookups); + std::vector out_expected(num_lookups); + std::vector left_expected(num_lookups); + std::vector right_expected(num_lookups); for (size_t i = 0; i < left_slices.size(); ++i) { if (i == 1) { @@ -323,8 +323,8 @@ TEST(stdlib_plookup, blake2s_xor_rotate_8) right_expected[i] = right_slices[i]; } - auto mul_constant = bb::fr(1 << 24); - std::vector out_coefficients{ (bb::fr(1) / mul_constant), (1 << 4), (1 << 6), (1 << 6), (1 << 6) }; + auto mul_constant = fr(1 << 24); + std::vector out_coefficients{ (bb::fr(1) / mul_constant), (1 << 4), (1 << 6), (1 << 6), (1 << 6) }; for (size_t i = num_lookups - 2; i < num_lookups; --i) { out_expected[i] += out_expected[i + 1] * out_coefficients[i]; @@ -338,9 +338,9 @@ TEST(stdlib_plookup, blake2s_xor_rotate_8) EXPECT_EQ(lookup[ColumnIdx::C3][i].get_value(), out_expected[i]); } - bb::fr lookup_output = lookup[ColumnIdx::C3][0].get_value() * mul_constant; + fr lookup_output = lookup[ColumnIdx::C3][0].get_value() * mul_constant; uint32_t xor_rotate_output = numeric::rotate32(uint32_t(left_value) ^ uint32_t(right_value), 8); - EXPECT_EQ(bb::fr(uint256_t(xor_rotate_output)), lookup_output); + EXPECT_EQ(fr(uint256_t(xor_rotate_output)), lookup_output); bool result = builder.check_circuit(); @@ -364,9 +364,9 @@ TEST(stdlib_plookup, blake2s_xor_rotate_7) const auto left_slices = numeric::slice_input(left_value, 1 << 6, num_lookups); const auto right_slices = numeric::slice_input(right_value, 1 << 6, num_lookups); - std::vector out_expected(num_lookups); - std::vector left_expected(num_lookups); - std::vector right_expected(num_lookups); + std::vector out_expected(num_lookups); + std::vector left_expected(num_lookups); + std::vector right_expected(num_lookups); for (size_t i = 0; i < left_slices.size(); ++i) { if (i == 1) { @@ -381,8 +381,8 @@ TEST(stdlib_plookup, blake2s_xor_rotate_7) right_expected[i] = right_slices[i]; } - auto mul_constant = bb::fr(1 << 25); - std::vector out_coefficients{ (bb::fr(1) / mul_constant), (1 << 5), (1 << 6), (1 << 6), (1 << 6) }; + auto mul_constant = fr(1 << 25); + std::vector out_coefficients{ (bb::fr(1) / mul_constant), (1 << 5), (1 << 6), (1 << 6), (1 << 6) }; for (size_t i = num_lookups - 2; i < num_lookups; --i) { out_expected[i] += out_expected[i + 1] * out_coefficients[i]; @@ -396,9 +396,9 @@ TEST(stdlib_plookup, blake2s_xor_rotate_7) EXPECT_EQ(lookup[ColumnIdx::C3][i].get_value(), out_expected[i]); } - bb::fr lookup_output = lookup[ColumnIdx::C3][0].get_value() * mul_constant; + fr lookup_output = lookup[ColumnIdx::C3][0].get_value() * mul_constant; uint32_t xor_rotate_output = numeric::rotate32(uint32_t(left_value) ^ uint32_t(right_value), 7); - EXPECT_EQ(bb::fr(uint256_t(xor_rotate_output)), lookup_output); + EXPECT_EQ(fr(uint256_t(xor_rotate_output)), lookup_output); bool result = builder.check_circuit(); @@ -441,9 +441,9 @@ TEST(stdlib_plookup, blake2s_xor) // t5 = a5 // // output = (t0 - 2^12 t2) * 2^{32 - 12} + t2 - bb::fr lookup_output = lookup[ColumnIdx::C3][2].get_value(); - bb::fr t2_term = bb::fr(1 << 12) * lookup[ColumnIdx::C3][2].get_value(); - lookup_output += bb::fr(1 << 20) * (lookup[ColumnIdx::C3][0].get_value() - t2_term); + fr lookup_output = lookup[ColumnIdx::C3][2].get_value(); + fr t2_term = fr(1 << 12) * lookup[ColumnIdx::C3][2].get_value(); + lookup_output += fr(1 << 20) * (lookup[ColumnIdx::C3][0].get_value() - t2_term); for (size_t i = num_lookups - 2; i < num_lookups; --i) { out_expected[i] += out_expected[i + 1] * (1 << 6); @@ -455,7 +455,7 @@ TEST(stdlib_plookup, blake2s_xor) // The following checks if the xor output rotated by 12 can be computed correctly from basic blake2s_xor. // auto xor_rotate_output = numeric::rotate32(uint32_t(left_value) ^ uint32_t(right_value), 12); - EXPECT_EQ(bb::fr(uint256_t(xor_rotate_output)), lookup_output); + EXPECT_EQ(fr(uint256_t(xor_rotate_output)), lookup_output); for (size_t i = 0; i < num_lookups; ++i) { EXPECT_EQ(lookup[ColumnIdx::C1][i].get_value(), bb::fr(left_expected[i])); @@ -519,7 +519,7 @@ TEST(stdlib_plookup, secp256k1_generator) uint64_t wnaf_entries[18] = { 0 }; bool skew = false; - bb::wnaf::fixed_wnaf<129, 1, 8>(&input_value.data[0], &wnaf_entries[0], skew, 0); + wnaf::fixed_wnaf<129, 1, 8>(&input_value.data[0], &wnaf_entries[0], skew, 0); std::vector naf_values; for (size_t i = 0; i < 17; ++i) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.test.cpp index 7afc1b71f1b..93c167cbde6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.test.cpp @@ -7,6 +7,8 @@ #include #include +using namespace bb; + #pragma GCC diagnostic ignored "-Wunused-local-typedefs" #define STDLIB_TYPE_ALIASES \ @@ -19,10 +21,9 @@ using public_witness_ct = stdlib::public_witness_t; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } -namespace test_stdlib_safe_uint { using namespace bb; template void ignore_unused(T&) {} // use to ignore unused variables in lambdas @@ -706,4 +707,3 @@ TYPED_TEST(SafeUintTest, TestByteArrayConversion) arr.write(static_cast(safe)); EXPECT_EQ(arr.get_string(), expected); } -} // namespace test_stdlib_safe_uint diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.test.cpp index 4e89a42c0cb..73a4ac6c6dd 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.test.cpp @@ -6,7 +6,7 @@ using namespace bb; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } // NOTE: We only test width 32, but widths 8, 16, 32 and 64 can all be tested. @@ -15,7 +15,7 @@ auto& engine = numeric::random::get_debug_engine(); // test_xor_special, test_xor_more_constants, test_and_constants, test_and_special, test_or_special, // test_ror_special, test_hash_rounds, test_and, test_xor, test_or. // They fail with 'C++ exception with description"Last key slice greater than 64" thrown in the test body."' -namespace test_stdlib_uint { + typedef uint32_t uint_native; size_t uint_native_width = 8 * sizeof(uint_native); uint_native uint_native_max = static_cast((static_cast(1) << uint_native_width) - 1); @@ -1914,10 +1914,10 @@ TYPED_TEST(stdlib_uint, test_at) // There was one plookup-specific test in the ./plookup/uint_plookup.test.cpp TEST(stdlib_uint32, test_accumulators_plookup_uint32) { - using uint32_ct = bb::stdlib::uint32; - using witness_ct = bb::stdlib::witness_t; + using uint32_ct = stdlib::uint32; + using witness_ct = stdlib::witness_t; - bb::UltraCircuitBuilder builder; + UltraCircuitBuilder builder; uint32_t a_val = engine.get_random_uint32(); uint32_t b_val = engine.get_random_uint32(); @@ -1939,4 +1939,3 @@ TEST(stdlib_uint32, test_accumulators_plookup_uint32) bool proof_result = builder.check_circuit(); EXPECT_EQ(proof_result, true); } -} // namespace test_stdlib_uint diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.test.cpp index 4d8386ada5c..307e388e368 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/transcript/transcript.test.cpp @@ -13,7 +13,7 @@ namespace bb::stdlib::recursion::honk { using Builder = UltraCircuitBuilder; using UltraFlavor = ::bb::honk::flavor::Ultra; using UltraRecursiveFlavor = ::bb::honk::flavor::UltraRecursive_; -using FF = bb::fr; +using FF = fr; using BaseTranscript = ::bb::honk::BaseTranscript; /** @@ -124,8 +124,8 @@ TEST(RecursiveHonkTranscript, InterfacesMatch) */ TEST(RecursiveHonkTranscript, ReturnValuesMatch) { - using FF = bb::fr; - using Commitment = bb::g1::affine_element; + using FF = fr; + using Commitment = g1::affine_element; using field_ct = field_t; using fq_ct = bigfield; 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 6d370e4cbd5..7f6b856a253 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.test.cpp @@ -56,9 +56,9 @@ transcript::Manifest create_manifest(const size_t num_public_inputs) } // namespace struct TestData { - std::vector g1_elements; - std::vector fr_elements; - std::vector public_input_elements; + std::vector g1_elements; + std::vector fr_elements; + std::vector public_input_elements; size_t num_public_inputs; }; @@ -69,8 +69,8 @@ TestData get_test_data() data.g1_elements.push_back(bb::g1::affine_element(bb::g1::element::random_element())); data.fr_elements.push_back(bb::fr::random_element()); } - data.fr_elements[2] = bb::fr(0); - data.fr_elements[3] = bb::fr(0); + data.fr_elements[2] = fr(0); + data.fr_elements[3] = fr(0); data.num_public_inputs = 13; for (size_t i = 0; i < data.num_public_inputs; ++i) { data.public_input_elements.push_back(bb::fr::random_element()); @@ -191,8 +191,7 @@ TEST(stdlib_transcript, validate_transcript) const auto check_challenge = [&normal_transcript, &recursive_transcript](const std::string& challenge_name, const size_t challenge_idx = 0) { field_t result = recursive_transcript.get_challenge_field_element(challenge_name, challenge_idx); - bb::fr expected = - bb::fr::serialize_from_buffer(&normal_transcript.get_challenge(challenge_name, challenge_idx)[0]); + fr expected = fr::serialize_from_buffer(&normal_transcript.get_challenge(challenge_name, challenge_idx)[0]); EXPECT_EQ(result.get_value(), expected); }; @@ -209,21 +208,21 @@ TEST(stdlib_transcript, validate_transcript) const auto check_field_element = [&normal_transcript, &recursive_transcript](const std::string& element_name) { field_t result = recursive_transcript.get_field_element(element_name); - bb::fr expected = bb::fr::serialize_from_buffer(&normal_transcript.get_element(element_name)[0]); + fr expected = fr::serialize_from_buffer(&normal_transcript.get_element(element_name)[0]); EXPECT_EQ(result.get_value(), expected); }; const auto check_group_element = [&normal_transcript, &recursive_transcript](const std::string& element_name) { group_t recursive_value = recursive_transcript.get_circuit_group_element(element_name); - bb::g1::affine_element expected = - bb::g1::affine_element::serialize_from_buffer(&normal_transcript.get_element(element_name)[0]); - bb::g1::affine_element result{ recursive_value.x.get_value().lo, recursive_value.y.get_value().lo }; + g1::affine_element expected = + g1::affine_element::serialize_from_buffer(&normal_transcript.get_element(element_name)[0]); + g1::affine_element result{ recursive_value.x.get_value().lo, recursive_value.y.get_value().lo }; EXPECT_EQ(result, expected); }; const auto check_public_inputs = [&normal_transcript, &recursive_transcript]() { std::vector result = recursive_transcript.get_field_element_vector("public_inputs"); - std::vector expected = many_from_buffer(normal_transcript.get_element("public_inputs")); + std::vector expected = many_from_buffer(normal_transcript.get_element("public_inputs")); EXPECT_EQ(result.size(), expected.size()); for (size_t i = 0; i < result.size(); ++i) { EXPECT_EQ(result[i].get_value(), expected[i]); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.test.cpp index a6e60ec4e74..b579681391c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.test.cpp @@ -7,7 +7,7 @@ #include "barretenberg/srs/factories/file_crs_factory.hpp" namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } // namespace using namespace bb::plonk; @@ -20,8 +20,8 @@ using namespace bb::plonk; */ template class VerificationKeyFixture : public testing::Test { public: - using Curve = bb::stdlib::bn254; - using RecursVk = bb::stdlib::recursion::verification_key; + using Curve = stdlib::bn254; + using RecursVk = stdlib::recursion::verification_key; static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } 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 97a2933c32d..b3d9cadc6ce 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.test.cpp @@ -16,7 +16,7 @@ namespace bb::stdlib { template class stdlib_verifier : public testing::Test { - using InnerComposer = bb::plonk::UltraComposer; + using InnerComposer = plonk::UltraComposer; using InnerBuilder = typename InnerComposer::CircuitBuilder; using OuterBuilder = typename OuterComposer::CircuitBuilder; @@ -36,7 +36,7 @@ template class stdlib_verifier : public testing::Test { using inner_scalar_field = typename inner_curve::ScalarFieldNative; using outer_scalar_field = typename outer_curve::BaseFieldNative; - using pairing_target_field = bb::fq12; + using pairing_target_field = fq12; // These constexpr definitions are to allow for the following: An Ultra Pedersen hash evaluates to a // different value from the Standard version of the Pedersen hash. Therefore, the fiat-shamir @@ -212,7 +212,7 @@ template class stdlib_verifier : public testing::Test { plonk::proof proof_to_recursively_verify_b = prover.construct_proof(); - auto output = bb::stdlib::recursion::verify_proof( + auto output = stdlib::recursion::verify_proof( &outer_circuit, verification_key_b, recursive_manifest, proof_to_recursively_verify_b, previous_output); verification_key_b->hash(); @@ -265,8 +265,8 @@ template class stdlib_verifier : public testing::Test { transcript::Manifest recursive_manifest = InnerComposer::create_manifest(prover_a.key->num_public_inputs); - bb::stdlib::recursion::aggregation_state output = - bb::stdlib::recursion::verify_proof( + stdlib::recursion::aggregation_state output = + stdlib::recursion::verify_proof( &outer_circuit, verification_key, recursive_manifest, recursive_proof); return { output, verification_key }; @@ -320,7 +320,7 @@ template class stdlib_verifier : public testing::Test { { x1, y1 }, }; - pairing_target_field result = bb::pairing::reduced_ate_pairing_batch_precomputed(P_affine, lines, 2); + pairing_target_field result = pairing::reduced_ate_pairing_batch_precomputed(P_affine, lines, 2); return (result == pairing_target_field::one()); } @@ -332,13 +332,13 @@ template class stdlib_verifier : public testing::Test { static void check_pairing(const circuit_outputs& circuit_output) { - auto g2_lines = bb::srs::get_crs_factory()->get_verifier_crs()->get_precomputed_g2_lines(); + auto g2_lines = srs::get_crs_factory()->get_verifier_crs()->get_precomputed_g2_lines(); g1::affine_element P[2]; P[0].x = outer_scalar_field(circuit_output.aggregation_state.P0.x.get_value().lo); P[0].y = outer_scalar_field(circuit_output.aggregation_state.P0.y.get_value().lo); P[1].x = outer_scalar_field(circuit_output.aggregation_state.P1.x.get_value().lo); P[1].y = outer_scalar_field(circuit_output.aggregation_state.P1.y.get_value().lo); - pairing_target_field inner_proof_result = bb::pairing::reduced_ate_pairing_batch_precomputed(P, g2_lines, 2); + pairing_target_field inner_proof_result = pairing::reduced_ate_pairing_batch_precomputed(P, g2_lines, 2); EXPECT_EQ(inner_proof_result, pairing_target_field::one()); } @@ -347,7 +347,7 @@ template class stdlib_verifier : public testing::Test { info("number of gates in recursive verification circuit = ", outer_circuit.get_num_gates()); bool result = outer_circuit.check_circuit(); EXPECT_EQ(result, expected_result); - auto g2_lines = bb::srs::get_crs_factory()->get_verifier_crs()->get_precomputed_g2_lines(); + auto g2_lines = srs::get_crs_factory()->get_verifier_crs()->get_precomputed_g2_lines(); EXPECT_EQ(check_recursive_proof_public_inputs(outer_circuit, g2_lines), true); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/types/ultra.hpp b/barretenberg/cpp/src/barretenberg/stdlib/types/ultra.hpp index 555d3f2975e..96bf0d2b203 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/types/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/types/ultra.hpp @@ -57,9 +57,7 @@ using namespace stdlib::merkle_tree; using hash_path = stdlib::merkle_tree::hash_path; } // namespace merkle_tree -namespace schnorr { -using signature_bits = stdlib::schnorr::signature_bits; -} // namespace schnorr +using schnorr_signature_bits = stdlib::schnorr_signature_bits; // Ultra-composer specific types using rom_table_ct = stdlib::rom_table; diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.test.cpp index 9de85a37604..86c51e5ed1c 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.test.cpp @@ -5,9 +5,8 @@ #include "barretenberg/proof_system/library/grand_product_library.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" #include - +using namespace bb; using namespace bb::honk; -namespace instance_tests { template class InstanceTests : public testing::Test { using FF = typename Flavor::FF; @@ -89,5 +88,3 @@ TYPED_TEST(InstanceTests, SortedListAccumulator) { TestFixture::test_sorted_list_accumulator_construction(); } - -} // namespace instance_tests \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index c0df47b4861..83c5084988a 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp @@ -4,7 +4,6 @@ #include using namespace bb::honk::sumcheck; -namespace test_sumcheck_polynomials { template class PartialEvaluationTests : public testing::Test {}; @@ -317,5 +316,3 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) EXPECT_EQ((polynomial_get_all[i])[0], expected_val[i]); } } - -} // namespace test_sumcheck_polynomials diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp index 7d385c5947e..81a58a3f169 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp @@ -11,18 +11,16 @@ #include "barretenberg/ultra_honk/ultra_composer.hpp" #include - +using namespace bb; using namespace bb::honk; using namespace bb::honk::sumcheck; -using Flavor = bb::honk::flavor::Ultra; +using Flavor = honk::flavor::Ultra; using FF = typename Flavor::FF; using ProverPolynomials = typename Flavor::ProverPolynomials; using RelationSeparator = Flavor::RelationSeparator; const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; -namespace test_sumcheck_round { - -bb::Polynomial random_poly(size_t size) +Polynomial random_poly(size_t size) { auto poly = bb::Polynomial(size); for (auto& coeff : poly) { @@ -53,7 +51,7 @@ TEST_F(SumcheckTests, PolynomialNormalization) // Randomly construct the prover polynomials that are input to Sumcheck. // Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory. - std::array, NUM_POLYNOMIALS> random_polynomials; + std::array, NUM_POLYNOMIALS> random_polynomials; for (auto& poly : random_polynomials) { poly = random_poly(multivariate_n); } @@ -116,7 +114,7 @@ TEST_F(SumcheckTests, PolynomialNormalization) // full polynomials at challenge u via the evaluate_mle() function std::vector u_challenge = { u_0, u_1, u_2 }; for (auto [full_poly, claimed_eval] : zip_view(full_polynomials.get_all(), output.claimed_evaluations.get_all())) { - bb::Polynomial poly(full_poly); + Polynomial poly(full_poly); auto v_expected = poly.evaluate_mle(u_challenge); EXPECT_EQ(v_expected, claimed_eval); } @@ -129,7 +127,7 @@ TEST_F(SumcheckTests, Prover) // Randomly construct the prover polynomials that are input to Sumcheck. // Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory. - std::array, NUM_POLYNOMIALS> random_polynomials; + std::array, NUM_POLYNOMIALS> random_polynomials; for (auto& poly : random_polynomials) { poly = random_poly(multivariate_n); } @@ -176,9 +174,9 @@ TEST_F(SumcheckTests, ProverAndVerifierSimple) // Construct prover polynomials where each is the zero polynomial. // Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory. - std::array, NUM_POLYNOMIALS> zero_polynomials; + std::array, NUM_POLYNOMIALS> zero_polynomials; for (auto& poly : zero_polynomials) { - poly = bb::Polynomial(multivariate_n); + poly = Polynomial(multivariate_n); } auto full_polynomials = construct_ultra_full_polynomials(zero_polynomials); @@ -213,7 +211,7 @@ TEST_F(SumcheckTests, ProverAndVerifierSimple) full_polynomials.q_arith = q_arith; // Set aribitrary random relation parameters - bb::RelationParameters relation_parameters{ + RelationParameters relation_parameters{ .beta = FF::random_element(), .gamma = FF::random_element(), .public_input_delta = FF::one(), @@ -255,5 +253,3 @@ TEST_F(SumcheckTests, ProverAndVerifierSimple) run_test(/* expect_verified=*/true); run_test(/* expect_verified=*/false); } - -} // namespace test_sumcheck_round diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.test.cpp index bb33dc4ef7f..5091717988e 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.test.cpp @@ -3,7 +3,7 @@ #include "barretenberg/relations/utils.hpp" #include - +using namespace bb; using namespace bb::honk; using namespace bb::honk::sumcheck; @@ -12,9 +12,7 @@ using bb::Univariate; using Flavor = flavor::Ultra; using FF = typename Flavor::FF; -using Utils = bb::RelationUtils; - -namespace test_sumcheck_round { +using Utils = RelationUtils; /** * @brief Test SumcheckRound functions for operations on tuples (and tuples of tuples) of Univariates @@ -22,7 +20,7 @@ namespace test_sumcheck_round { */ TEST(SumcheckRound, SumcheckTupleOfTuplesOfUnivariates) { - using Flavor = bb::honk::flavor::Ultra; + using Flavor = honk::flavor::Ultra; using FF = typename Flavor::FF; using RelationSeparator = typename Flavor::RelationSeparator; @@ -43,7 +41,7 @@ TEST(SumcheckRound, SumcheckTupleOfTuplesOfUnivariates) Utils::scale_univariates(tuple_of_tuples, challenge, running_challenge); // Use extend_and_batch_univariates to extend to MAX_LENGTH then accumulate - bb::PowPolynomial pow_polynomial({ 1 }); + PowPolynomial pow_polynomial({ 1 }); auto result = Univariate(); SumcheckProverRound::extend_and_batch_univariates(tuple_of_tuples, result, pow_polynomial); @@ -73,8 +71,8 @@ TEST(SumcheckRound, SumcheckTupleOfTuplesOfUnivariates) */ TEST(SumcheckRound, TuplesOfEvaluationArrays) { - using Flavor = bb::honk::flavor::Ultra; - using Utils = bb::RelationUtils; + using Flavor = honk::flavor::Ultra; + using Utils = RelationUtils; using FF = typename Flavor::FF; using RelationSeparator = typename Flavor::RelationSeparator; @@ -113,7 +111,7 @@ TEST(SumcheckRound, TuplesOfEvaluationArrays) */ TEST(SumcheckRound, AddTuplesOfTuplesOfUnivariates) { - using Flavor = bb::honk::flavor::Ultra; + using Flavor = honk::flavor::Ultra; using FF = typename Flavor::FF; // Define some arbitrary univariates @@ -141,5 +139,3 @@ TEST(SumcheckRound, AddTuplesOfTuplesOfUnivariates) EXPECT_EQ(std::get<0>(std::get<1>(tuple_of_tuples_1)), expected_sum_2); EXPECT_EQ(std::get<1>(std::get<1>(tuple_of_tuples_1)), expected_sum_3); } - -} // namespace test_sumcheck_round diff --git a/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp b/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp index b62cc960a2a..f9698f1a6c8 100644 --- a/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp @@ -1,12 +1,12 @@ #include "barretenberg/transcript/transcript.hpp" #include -namespace bb::honk_transcript_tests { +using namespace bb; -using FF = bb::fr; -using Fr = bb::fr; -using Fq = bb::fq; -using Transcript = bb::honk::BaseTranscript; +using FF = fr; +using Fr = fr; +using Fq = fq; +using Transcript = honk::BaseTranscript; /** * @brief Test sending, receiving, and exporting proofs @@ -47,5 +47,3 @@ TEST(BaseTranscript, TwoProversTwoFields) EXPECT_STATE(verifier_transcript, 0, 64, 64); EXPECT_EQ(received_b, elt_b); } - -} // namespace bb::honk_transcript_tests diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.test.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.test.cpp index f6bcffd50bd..7221bab8ff5 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.test.cpp @@ -7,16 +7,14 @@ #include "barretenberg/translator_vm/goblin_translator_prover.hpp" #include - +using namespace bb; using namespace bb::honk; using CircuitBuilder = flavor::GoblinTranslator::CircuitBuilder; using Transcript = flavor::GoblinTranslator::Transcript; -using OpQueue = bb::ECCOpQueue; - -namespace test_goblin_translator_composer { +using OpQueue = ECCOpQueue; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } std::vector add_variables(auto& circuit_constructor, std::vector variables) @@ -48,9 +46,9 @@ class GoblinTranslatorComposerTests : public ::testing::Test { */ TEST_F(GoblinTranslatorComposerTests, Basic) { - using G1 = bb::g1::affine_element; - using Fr = bb::fr; - using Fq = bb::fq; + using G1 = g1::affine_element; + using Fr = fr; + using Fq = fq; auto P1 = G1::random_element(); auto P2 = G1::random_element(); @@ -81,5 +79,3 @@ TEST_F(GoblinTranslatorComposerTests, Basic) bool verified = verifier.verify_proof(proof); EXPECT_TRUE(verified); } - -} // namespace test_goblin_translator_composer diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/databus_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/databus_composer.test.cpp index 654834bd151..6dcc73e1f7f 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/databus_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/databus_composer.test.cpp @@ -9,13 +9,11 @@ #include "barretenberg/proof_system/instance_inspector.hpp" #include "barretenberg/ultra_honk/ultra_composer.hpp" #include "barretenberg/ultra_honk/ultra_prover.hpp" - +using namespace bb; using namespace bb::honk; -namespace test_ultra_honk_composer { - namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } class DataBusComposerTests : public ::testing::Test { @@ -54,7 +52,7 @@ TEST_F(DataBusComposerTests, CallDataRead) // Add mock data to op queue to simulate interaction with a previous circuit op_queue->populate_with_mock_initital_data(); - auto builder = bb::GoblinUltraCircuitBuilder{ op_queue }; + auto builder = GoblinUltraCircuitBuilder{ op_queue }; // Create a general test circuit generate_test_circuit(builder); @@ -95,5 +93,3 @@ TEST_F(DataBusComposerTests, CallDataRead) bool verified = verifier.verify_proof(proof); EXPECT_TRUE(verified); } - -} // namespace test_ultra_honk_composer diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp index 96512d75f10..ff5d21488c3 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp @@ -7,13 +7,11 @@ #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "barretenberg/ultra_honk/ultra_composer.hpp" #include "barretenberg/ultra_honk/ultra_prover.hpp" - +using namespace bb; using namespace bb::honk; -namespace test_ultra_honk_composer { - namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } class GoblinUltraHonkComposerTests : public ::testing::Test { @@ -99,7 +97,7 @@ TEST_F(GoblinUltraHonkComposerTests, SingleCircuit) // Add mock data to op queue to simulate interaction with a previous circuit op_queue->populate_with_mock_initital_data(); - auto builder = bb::GoblinUltraCircuitBuilder{ op_queue }; + auto builder = GoblinUltraCircuitBuilder{ op_queue }; generate_test_circuit(builder); @@ -130,7 +128,7 @@ TEST_F(GoblinUltraHonkComposerTests, MultipleCircuitsMergeOnly) // Construct multiple test circuits that share an ECC op queue. Generate and verify a proof for each. size_t NUM_CIRCUITS = 3; for (size_t i = 0; i < NUM_CIRCUITS; ++i) { - auto builder = bb::GoblinUltraCircuitBuilder{ op_queue }; + auto builder = GoblinUltraCircuitBuilder{ op_queue }; generate_test_circuit(builder); @@ -158,7 +156,7 @@ TEST_F(GoblinUltraHonkComposerTests, MultipleCircuitsHonkOnly) // Construct multiple test circuits that share an ECC op queue. Generate and verify a proof for each. size_t NUM_CIRCUITS = 3; for (size_t i = 0; i < NUM_CIRCUITS; ++i) { - auto builder = bb::GoblinUltraCircuitBuilder{ op_queue }; + auto builder = GoblinUltraCircuitBuilder{ op_queue }; generate_test_circuit(builder); @@ -186,7 +184,7 @@ TEST_F(GoblinUltraHonkComposerTests, MultipleCircuitsHonkAndMerge) // Construct multiple test circuits that share an ECC op queue. Generate and verify a proof for each. size_t NUM_CIRCUITS = 3; for (size_t i = 0; i < NUM_CIRCUITS; ++i) { - auto builder = bb::GoblinUltraCircuitBuilder{ op_queue }; + auto builder = GoblinUltraCircuitBuilder{ op_queue }; generate_test_circuit(builder); @@ -212,5 +210,3 @@ TEST_F(GoblinUltraHonkComposerTests, MultipleCircuitsHonkAndMerge) EXPECT_EQ(result, expected); } } - -} // namespace test_ultra_honk_composer diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp index 3eceba80cf3..0865eff99bb 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp @@ -6,13 +6,14 @@ #include "barretenberg/ultra_honk/ultra_composer.hpp" #include +using namespace bb; using namespace bb::honk; class GoblinUltraTranscriptTests : public ::testing::Test { public: static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } - using Flavor = bb::honk::flavor::GoblinUltra; + using Flavor = honk::flavor::GoblinUltra; using FF = Flavor::FF; /** diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp index 4651a5b7e6a..ab2e65df40a 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/protogalaxy.test.cpp @@ -2,7 +2,7 @@ #include "barretenberg/protogalaxy/protogalaxy_prover.hpp" #include "barretenberg/ultra_honk/ultra_composer.hpp" #include - +using namespace bb; using namespace bb::honk; using Flavor = flavor::Ultra; @@ -14,21 +14,18 @@ using FF = Flavor::FF; using Affine = Flavor::Commitment; using Projective = Flavor::GroupElement; using Builder = Flavor::CircuitBuilder; -using Polynomial = typename Flavor::Polynomial; using ProverPolynomials = Flavor::ProverPolynomials; -using RelationParameters = bb::RelationParameters; using WitnessCommitments = typename Flavor::WitnessCommitments; using CommitmentKey = Flavor::CommitmentKey; -using PowPolynomial = bb::PowPolynomial; const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } // TODO(https://github.com/AztecProtocol/barretenberg/issues/744): make testing utility with functionality shared // amongst test files in the proof system -bb::Polynomial get_random_polynomial(size_t size) +Polynomial get_random_polynomial(size_t size) { auto poly = bb::Polynomial(size); for (auto& coeff : poly) { @@ -143,12 +140,12 @@ TEST_F(ProtoGalaxyTests, PerturbatorPolynomial) const size_t log_instance_size(3); const size_t instance_size(1 << log_instance_size); - std::array, NUM_POLYNOMIALS> random_polynomials; + std::array, NUM_POLYNOMIALS> random_polynomials; for (auto& poly : random_polynomials) { poly = get_random_polynomial(instance_size); } auto full_polynomials = construct_ultra_full_polynomials(random_polynomials); - auto relation_parameters = bb::RelationParameters::get_random(); + auto relation_parameters = RelationParameters::get_random(); RelationSeparator alphas; for (auto& alpha : alphas) { alpha = FF::random_element(); @@ -188,12 +185,12 @@ TEST_F(ProtoGalaxyTests, PerturbatorPolynomial) TEST_F(ProtoGalaxyTests, CombinerQuotient) { auto compressed_perturbator = FF(2); // F(\alpha) in the paper - auto combiner = bb::Univariate(std::array{ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 }); + auto combiner = Univariate(std::array{ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 }); auto combiner_quotient = ProtoGalaxyProver::compute_combiner_quotient(compressed_perturbator, combiner); // K(i) = (G(i) - ( L_0(i) * F(\alpha)) / Z(i), i = {2,.., 13} for ProverInstances::NUM = 2 // K(i) = (G(i) - (1 - i) * F(\alpha)) / i * (i - 1) - auto expected_evals = bb::Univariate(std::array{ + auto expected_evals = Univariate(std::array{ (FF(22) - (FF(1) - FF(2)) * compressed_perturbator) / (FF(2) * FF(2 - 1)), (FF(23) - (FF(1) - FF(3)) * compressed_perturbator) / (FF(3) * FF(3 - 1)), (FF(24) - (FF(1) - FF(4)) * compressed_perturbator) / (FF(4) * FF(4 - 1)), @@ -229,7 +226,7 @@ TEST_F(ProtoGalaxyTests, CombineRelationParameters) Instances instances{ { instance1, instance2 } }; ProtoGalaxyProver::combine_relation_parameters(instances); - bb::Univariate expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 } }; + Univariate expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 } }; EXPECT_EQ(instances.relation_parameters.eta, expected_eta); } @@ -250,7 +247,7 @@ TEST_F(ProtoGalaxyTests, CombineAlpha) Instances instances{ { instance1, instance2 } }; ProtoGalaxyProver::combine_alpha(instances); - bb::Univariate expected_alpha{ { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26 } }; + Univariate expected_alpha{ { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26 } }; for (const auto& alpha : instances.alphas) { EXPECT_EQ(alpha, expected_alpha); } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp index 28e780ca913..bbecb252bf6 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp @@ -11,7 +11,7 @@ #include "barretenberg/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/ultra_honk/ultra_composer.hpp" #include - +using namespace bb; using namespace bb::honk; void ensure_non_zero(auto& polynomial) @@ -125,23 +125,23 @@ template void create_some_lookup_gates(auto& circuit_builder) using FF = typename Flavor::FF; // Add some lookup gates (related to pedersen hashing) auto pedersen_input_value = FF::random_element(); - const auto input_hi = uint256_t(pedersen_input_value) - .slice(bb::plookup::fixed_base::table::BITS_PER_LO_SCALAR, - bb::plookup::fixed_base::table::BITS_PER_LO_SCALAR + - bb::plookup::fixed_base::table::BITS_PER_HI_SCALAR); + const auto input_hi = + uint256_t(pedersen_input_value) + .slice(plookup::fixed_base::table::BITS_PER_LO_SCALAR, + plookup::fixed_base::table::BITS_PER_LO_SCALAR + plookup::fixed_base::table::BITS_PER_HI_SCALAR); const auto input_lo = uint256_t(pedersen_input_value).slice(0, bb::plookup::fixed_base::table::BITS_PER_LO_SCALAR); const auto input_hi_index = circuit_builder.add_variable(input_hi); const auto input_lo_index = circuit_builder.add_variable(input_lo); const auto sequence_data_hi = - bb::plookup::get_lookup_accumulators(bb::plookup::MultiTableId::FIXED_BASE_LEFT_HI, input_hi); + plookup::get_lookup_accumulators(bb::plookup::MultiTableId::FIXED_BASE_LEFT_HI, input_hi); const auto sequence_data_lo = - bb::plookup::get_lookup_accumulators(bb::plookup::MultiTableId::FIXED_BASE_LEFT_LO, input_lo); + plookup::get_lookup_accumulators(bb::plookup::MultiTableId::FIXED_BASE_LEFT_LO, input_lo); circuit_builder.create_gates_from_plookup_accumulators( - bb::plookup::MultiTableId::FIXED_BASE_LEFT_HI, sequence_data_hi, input_hi_index); + plookup::MultiTableId::FIXED_BASE_LEFT_HI, sequence_data_hi, input_hi_index); circuit_builder.create_gates_from_plookup_accumulators( - bb::plookup::MultiTableId::FIXED_BASE_LEFT_LO, sequence_data_lo, input_lo_index); + plookup::MultiTableId::FIXED_BASE_LEFT_LO, sequence_data_lo, input_lo_index); } template void create_some_genperm_sort_gates(auto& circuit_builder) @@ -226,7 +226,7 @@ template void create_some_ecc_op_queue_gates(auto& circuit_bui { using G1 = typename Flavor::Curve::Group; using FF = typename Flavor::FF; - static_assert(bb::IsGoblinFlavor); + static_assert(IsGoblinFlavor); const size_t num_ecc_operations = 10; // arbitrary for (size_t i = 0; i < num_ecc_operations; ++i) { auto point = G1::affine_one * FF::random_element(); @@ -258,7 +258,7 @@ TEST_F(RelationCorrectnessTests, UltraRelationCorrectness) // Create a composer and then add an assortment of gates designed to ensure that the constraint(s) represented // by each relation are non-trivially exercised. - auto builder = bb::UltraCircuitBuilder(); + auto builder = UltraCircuitBuilder(); // Create an assortment of representative gates create_some_add_gates(builder); @@ -310,7 +310,7 @@ TEST_F(RelationCorrectnessTests, GoblinUltraRelationCorrectness) // Create a composer and then add an assortment of gates designed to ensure that the constraint(s) represented // by each relation are non-trivially exercised. - auto builder = bb::GoblinUltraCircuitBuilder(); + auto builder = GoblinUltraCircuitBuilder(); // Create an assortment of representative gates create_some_add_gates(builder); @@ -378,14 +378,14 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorPermutationRelationCorrectness) using ProverPolynomials = typename Flavor::ProverPolynomials; using Polynomial = bb::Polynomial; using namespace bb::honk::permutation_library; - auto& engine = numeric::random::get_debug_engine(); + auto& engine = numeric::get_debug_randomness(); auto circuit_size = Flavor::MINI_CIRCUIT_SIZE * Flavor::CONCATENATION_INDEX; // We only need gamma, because permutationr elation only uses gamma FF gamma = FF::random_element(); // Fill relation parameters - bb::RelationParameters params; + RelationParameters params; params.gamma = gamma; // Create storage for polynomials @@ -495,14 +495,14 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorGenPermSortRelationCorrectness) using FF = typename Flavor::FF; using ProverPolynomials = typename Flavor::ProverPolynomials; using Polynomial = bb::Polynomial; - auto& engine = numeric::random::get_debug_engine(); + auto& engine = numeric::get_debug_randomness(); const auto circuit_size = Flavor::FULL_CIRCUIT_SIZE; const auto sort_step = Flavor::SORT_STEP; const auto max_value = (1 << Flavor::MICRO_LIMB_BITS) - 1; // No relation parameters are used in this relation - bb::RelationParameters params; + RelationParameters params; ProverPolynomials prover_polynomials; // Allocate polynomials @@ -577,13 +577,13 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) using ProverPolynomialIds = typename Flavor::ProverPolynomialIds; using Polynomial = bb::Polynomial; - auto& engine = numeric::random::get_debug_engine(); + auto& engine = numeric::get_debug_randomness(); auto circuit_size = Flavor::FULL_CIRCUIT_SIZE; auto mini_circuit_size = Flavor::MINI_CIRCUIT_SIZE; // We only use accumulated_result from relation parameters in this relation - bb::RelationParameters params; + RelationParameters params; params.accumulated_result = { FF::random_element(), FF::random_element(), FF::random_element(), FF::random_element() }; @@ -679,12 +679,12 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes using ProverPolynomials = typename Flavor::ProverPolynomials; using ProverPolynomialIds = typename Flavor::ProverPolynomialIds; using Polynomial = bb::Polynomial; - auto& engine = numeric::random::get_debug_engine(); + auto& engine = numeric::get_debug_randomness(); auto circuit_size = Flavor::FULL_CIRCUIT_SIZE; // Decomposition relation doesn't use any relation parameters - bb::RelationParameters params; + RelationParameters params; // Create storage for polynomials ProverPolynomials prover_polynomials; @@ -1058,7 +1058,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) constexpr auto circuit_size = Flavor::FULL_CIRCUIT_SIZE; constexpr auto mini_circuit_size = Flavor::MINI_CIRCUIT_SIZE; - auto& engine = numeric::random::get_debug_engine(); + auto& engine = numeric::get_debug_randomness(); auto op_queue = std::make_shared(); @@ -1083,10 +1083,10 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) const auto evaluation_input_x = BF::random_element(&engine); // Generating all the values is pretty tedious, so just use CircuitBuilder - auto circuit_builder = bb::GoblinTranslatorCircuitBuilder(batching_challenge_v, evaluation_input_x, op_queue); + auto circuit_builder = GoblinTranslatorCircuitBuilder(batching_challenge_v, evaluation_input_x, op_queue); // The non-native field relation uses limbs of evaluation_input_x and powers of batching_challenge_v as inputs - bb::RelationParameters params; + RelationParameters params; auto v_power = BF::one(); for (size_t i = 0; i < 4 /*Number of powers of v that we need {1,2,3,4}*/; i++) { v_power *= batching_challenge_v; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp index 5036322b497..fe0fede946c 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp @@ -14,10 +14,11 @@ #include +using namespace bb; using namespace bb::honk; using namespace bb::honk::sumcheck; -using Flavor = bb::honk::flavor::Ultra; +using Flavor = honk::flavor::Ultra; using FF = typename Flavor::FF; class SumcheckTestsRealCircuit : public ::testing::Test { @@ -37,7 +38,7 @@ TEST_F(SumcheckTestsRealCircuit, Ultra) using RelationSeparator = typename Flavor::RelationSeparator; // Create a composer and a dummy circuit with a few gates - auto builder = bb::UltraCircuitBuilder(); + auto builder = UltraCircuitBuilder(); FF a = FF::one(); // Add some basic add gates, with a public input for good measure @@ -63,23 +64,23 @@ TEST_F(SumcheckTestsRealCircuit, Ultra) // Add some lookup gates (related to pedersen hashing) auto pedersen_input_value = FF::random_element(); - const FF input_hi = uint256_t(pedersen_input_value) - .slice(bb::plookup::fixed_base::table::BITS_PER_LO_SCALAR, - bb::plookup::fixed_base::table::BITS_PER_LO_SCALAR + - bb::plookup::fixed_base::table::BITS_PER_HI_SCALAR); + const FF input_hi = + uint256_t(pedersen_input_value) + .slice(plookup::fixed_base::table::BITS_PER_LO_SCALAR, + plookup::fixed_base::table::BITS_PER_LO_SCALAR + plookup::fixed_base::table::BITS_PER_HI_SCALAR); const FF input_lo = uint256_t(pedersen_input_value).slice(0, bb::plookup::fixed_base::table::BITS_PER_LO_SCALAR); const auto input_hi_index = builder.add_variable(input_hi); const auto input_lo_index = builder.add_variable(input_lo); const auto sequence_data_hi = - bb::plookup::get_lookup_accumulators(bb::plookup::MultiTableId::FIXED_BASE_LEFT_HI, input_hi); + plookup::get_lookup_accumulators(bb::plookup::MultiTableId::FIXED_BASE_LEFT_HI, input_hi); const auto sequence_data_lo = - bb::plookup::get_lookup_accumulators(bb::plookup::MultiTableId::FIXED_BASE_LEFT_LO, input_lo); + plookup::get_lookup_accumulators(bb::plookup::MultiTableId::FIXED_BASE_LEFT_LO, input_lo); builder.create_gates_from_plookup_accumulators( - bb::plookup::MultiTableId::FIXED_BASE_LEFT_HI, sequence_data_hi, input_hi_index); + plookup::MultiTableId::FIXED_BASE_LEFT_HI, sequence_data_hi, input_hi_index); builder.create_gates_from_plookup_accumulators( - bb::plookup::MultiTableId::FIXED_BASE_LEFT_LO, sequence_data_lo, input_lo_index); + plookup::MultiTableId::FIXED_BASE_LEFT_LO, sequence_data_lo, input_lo_index); // Add a sort gate (simply checks that consecutive inputs have a difference of < 4) a_idx = builder.add_variable(FF(0)); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp index fed8e874026..09a1bdb72f3 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp @@ -20,7 +20,7 @@ using namespace bb; using namespace bb::honk; namespace { -auto& engine = numeric::random::get_debug_engine(); +auto& engine = numeric::get_debug_randomness(); } std::vector add_variables(auto& circuit_builder, std::vector variables) @@ -52,9 +52,6 @@ void ensure_non_zero(auto& polynomial) } class UltraHonkComposerTests : public ::testing::Test { - public: - using fr = bb::fr; - protected: static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } }; @@ -68,7 +65,7 @@ class UltraHonkComposerTests : public ::testing::Test { */ TEST_F(UltraHonkComposerTests, ANonZeroPolynomialIsAGoodPolynomial) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto composer = UltraComposer(); auto instance = composer.create_instance(circuit_builder); @@ -95,7 +92,7 @@ TEST_F(UltraHonkComposerTests, ANonZeroPolynomialIsAGoodPolynomial) */ TEST_F(UltraHonkComposerTests, PublicInputs) { - auto builder = bb::UltraCircuitBuilder(); + auto builder = UltraCircuitBuilder(); size_t num_gates = 10; // Add some arbitrary arithmetic gates that utilize public inputs @@ -119,7 +116,7 @@ TEST_F(UltraHonkComposerTests, PublicInputs) TEST_F(UltraHonkComposerTests, XorConstraint) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); uint32_t left_value = engine.get_random_uint32(); uint32_t right_value = engine.get_random_uint32(); @@ -147,9 +144,9 @@ TEST_F(UltraHonkComposerTests, XorConstraint) TEST_F(UltraHonkComposerTests, create_gates_from_plookup_accumulators) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); - bb::fr input_value = fr::random_element(); + fr input_value = fr::random_element(); const fr input_lo = static_cast(input_value).slice(0, plookup::fixed_base::table::BITS_PER_LO_SCALAR); const auto input_lo_index = circuit_builder.add_variable(input_lo); @@ -214,7 +211,7 @@ TEST_F(UltraHonkComposerTests, create_gates_from_plookup_accumulators) TEST_F(UltraHonkComposerTests, test_no_lookup_proof) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); for (size_t i = 0; i < 16; ++i) { for (size_t j = 0; j < 16; ++j) { @@ -239,7 +236,7 @@ TEST_F(UltraHonkComposerTests, test_elliptic_gate) { typedef grumpkin::g1::affine_element affine_element; typedef grumpkin::g1::element element; - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); affine_element p1 = affine_element::random_element(); affine_element p2 = affine_element::random_element(); @@ -271,7 +268,7 @@ TEST_F(UltraHonkComposerTests, test_elliptic_gate) TEST_F(UltraHonkComposerTests, non_trivial_tag_permutation) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); fr a = fr::random_element(); fr b = -a; @@ -299,7 +296,7 @@ TEST_F(UltraHonkComposerTests, non_trivial_tag_permutation) TEST_F(UltraHonkComposerTests, non_trivial_tag_permutation_and_cycles) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); fr a = fr::random_element(); fr c = -a; @@ -338,7 +335,7 @@ TEST_F(UltraHonkComposerTests, non_trivial_tag_permutation_and_cycles) TEST_F(UltraHonkComposerTests, bad_tag_permutation) { { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); fr a = fr::random_element(); fr b = -a; @@ -363,7 +360,7 @@ TEST_F(UltraHonkComposerTests, bad_tag_permutation) } // Same as above but without tag creation to check reason of failure is really tag mismatch { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); fr a = fr::random_element(); fr b = -a; @@ -383,7 +380,7 @@ TEST_F(UltraHonkComposerTests, bad_tag_permutation) TEST_F(UltraHonkComposerTests, sort_widget) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); fr a = fr::one(); fr b = fr(2); fr c = fr(3); @@ -411,7 +408,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) fr h = fr(8); { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto a_idx = circuit_builder.add_variable(a); auto b_idx = circuit_builder.add_variable(b); auto c_idx = circuit_builder.add_variable(c); @@ -428,7 +425,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) } { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto a_idx = circuit_builder.add_variable(a); auto b_idx = circuit_builder.add_variable(b); auto c_idx = circuit_builder.add_variable(c); @@ -444,7 +441,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) prove_and_verify(circuit_builder, composer, /*expected_result=*/false); } { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto a_idx = circuit_builder.add_variable(a); auto b_idx = circuit_builder.add_variable(b); auto c_idx = circuit_builder.add_variable(c); @@ -460,7 +457,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) prove_and_verify(circuit_builder, composer, /*expected_result=*/false); } { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto a_idx = circuit_builder.add_variable(a); auto c_idx = circuit_builder.add_variable(c); auto d_idx = circuit_builder.add_variable(d); @@ -476,7 +473,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) prove_and_verify(circuit_builder, composer, /*expected_result=*/false); } { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto idx = add_variables(circuit_builder, { 1, 2, 5, 6, 7, 10, 11, 13, 16, 17, 20, 22, 22, 25, 26, 29, 29, 32, 32, 33, 35, 38, 39, 39, 42, 42, 43, 45 }); circuit_builder.create_sort_constraint_with_edges(idx, 1, 45); @@ -485,7 +482,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) prove_and_verify(circuit_builder, composer, /*expected_result=*/true); } { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto idx = add_variables(circuit_builder, { 1, 2, 5, 6, 7, 10, 11, 13, 16, 17, 20, 22, 22, 25, 26, 29, 29, 32, 32, 33, 35, 38, 39, 39, 42, 42, 43, 45 }); circuit_builder.create_sort_constraint_with_edges(idx, 1, 29); @@ -498,7 +495,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) TEST_F(UltraHonkComposerTests, range_constraint) { { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto indices = add_variables(circuit_builder, { 1, 2, 3, 4, 5, 6, 7, 8 }); for (size_t i = 0; i < indices.size(); i++) { circuit_builder.create_new_range_constraint(indices[i], 8); @@ -510,7 +507,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) prove_and_verify(circuit_builder, composer, /*expected_result=*/true); } { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto indices = add_variables(circuit_builder, { 3 }); for (size_t i = 0; i < indices.size(); i++) { circuit_builder.create_new_range_constraint(indices[i], 3); @@ -522,7 +519,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) prove_and_verify(circuit_builder, composer, /*expected_result=*/true); } { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto indices = add_variables(circuit_builder, { 1, 2, 3, 4, 5, 6, 8, 25 }); for (size_t i = 0; i < indices.size(); i++) { circuit_builder.create_new_range_constraint(indices[i], 8); @@ -533,7 +530,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) prove_and_verify(circuit_builder, composer, /*expected_result=*/false); } { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto indices = add_variables(circuit_builder, { 1, 2, 3, 4, 5, 6, 10, 8, 15, 11, 32, 21, 42, 79, 16, 10, 3, 26, 19, 51 }); for (size_t i = 0; i < indices.size(); i++) { @@ -545,7 +542,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) prove_and_verify(circuit_builder, composer, /*expected_result=*/true); } { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto indices = add_variables(circuit_builder, { 1, 2, 3, 80, 5, 6, 29, 8, 15, 11, 32, 21, 42, 79, 16, 10, 3, 26, 13, 14 }); for (size_t i = 0; i < indices.size(); i++) { @@ -557,7 +554,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) prove_and_verify(circuit_builder, composer, /*expected_result=*/false); } { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto indices = add_variables(circuit_builder, { 1, 0, 3, 80, 5, 6, 29, 8, 15, 11, 32, 21, 42, 79, 16, 10, 3, 26, 13, 14 }); for (size_t i = 0; i < indices.size(); i++) { @@ -572,7 +569,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) TEST_F(UltraHonkComposerTests, range_with_gates) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto idx = add_variables(circuit_builder, { 1, 2, 3, 4, 5, 6, 7, 8 }); for (size_t i = 0; i < idx.size(); i++) { circuit_builder.create_new_range_constraint(idx[i], 8); @@ -591,7 +588,7 @@ TEST_F(UltraHonkComposerTests, range_with_gates) TEST_F(UltraHonkComposerTests, range_with_gates_where_range_is_not_a_power_of_two) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto idx = add_variables(circuit_builder, { 1, 2, 3, 4, 5, 6, 7, 8 }); for (size_t i = 0; i < idx.size(); i++) { circuit_builder.create_new_range_constraint(idx[i], 12); @@ -612,7 +609,7 @@ TEST_F(UltraHonkComposerTests, sort_widget_complex) { { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); std::vector a = { 1, 3, 4, 7, 7, 8, 11, 14, 15, 15, 18, 19, 21, 21, 24, 25, 26, 27, 30, 32 }; std::vector ind; for (size_t i = 0; i < a.size(); i++) @@ -624,7 +621,7 @@ TEST_F(UltraHonkComposerTests, sort_widget_complex) } { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); std::vector a = { 1, 3, 4, 7, 7, 8, 16, 14, 15, 15, 18, 19, 21, 21, 24, 25, 26, 27, 30, 32 }; std::vector ind; for (size_t i = 0; i < a.size(); i++) @@ -638,7 +635,7 @@ TEST_F(UltraHonkComposerTests, sort_widget_complex) TEST_F(UltraHonkComposerTests, sort_widget_neg) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); fr a = fr::one(); fr b = fr(2); fr c = fr(3); @@ -656,7 +653,7 @@ TEST_F(UltraHonkComposerTests, sort_widget_neg) TEST_F(UltraHonkComposerTests, composed_range_constraint) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); auto c = fr::random_element(); auto d = uint256_t(c).slice(0, 133); auto e = fr(d); @@ -670,8 +667,8 @@ TEST_F(UltraHonkComposerTests, composed_range_constraint) TEST_F(UltraHonkComposerTests, non_native_field_multiplication) { - using fq = bb::fq; - auto circuit_builder = bb::UltraCircuitBuilder(); + using fq = fq; + auto circuit_builder = UltraCircuitBuilder(); fq a = fq::random_element(); fq b = fq::random_element(); @@ -715,7 +712,7 @@ TEST_F(UltraHonkComposerTests, non_native_field_multiplication) const auto q_indices = get_limb_witness_indices(split_into_limbs(uint256_t(q))); const auto r_indices = get_limb_witness_indices(split_into_limbs(uint256_t(r))); - bb::non_native_field_witnesses inputs{ + non_native_field_witnesses inputs{ a_indices, b_indices, q_indices, r_indices, modulus_limbs, fr(uint256_t(modulus)), }; const auto [lo_1_idx, hi_1_idx] = circuit_builder.evaluate_non_native_field_multiplication(inputs); @@ -727,7 +724,7 @@ TEST_F(UltraHonkComposerTests, non_native_field_multiplication) TEST_F(UltraHonkComposerTests, rom) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); uint32_t rom_values[8]{ circuit_builder.add_variable(fr::random_element()), circuit_builder.add_variable(fr::random_element()), @@ -769,7 +766,7 @@ TEST_F(UltraHonkComposerTests, rom) TEST_F(UltraHonkComposerTests, ram) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); uint32_t ram_values[8]{ circuit_builder.add_variable(fr::random_element()), circuit_builder.add_variable(fr::random_element()), @@ -833,7 +830,7 @@ TEST_F(UltraHonkComposerTests, ram) TEST_F(UltraHonkComposerTests, range_checks_on_duplicates) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); uint32_t a = circuit_builder.add_variable(100); uint32_t b = circuit_builder.add_variable(100); @@ -873,7 +870,7 @@ TEST_F(UltraHonkComposerTests, range_checks_on_duplicates) // before range constraints are applied to it. TEST_F(UltraHonkComposerTests, range_constraint_small_variable) { - auto circuit_builder = bb::UltraCircuitBuilder(); + auto circuit_builder = UltraCircuitBuilder(); uint16_t mask = (1 << 8) - 1; int a = engine.get_random_uint16() & mask; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp index 2c5c6ccb1dc..9fe521be717 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp @@ -6,13 +6,14 @@ #include "barretenberg/ultra_honk/ultra_composer.hpp" #include +using namespace bb; using namespace bb::honk; class UltraTranscriptTests : public ::testing::Test { public: static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } - using Flavor = bb::honk::flavor::Ultra; + using Flavor = honk::flavor::Ultra; using FF = Flavor::FF; /** diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp index 57060f411e1..15f4e0a37ee 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_arithmetic.test.cpp @@ -3,6 +3,7 @@ #include "barretenberg/numeric/uint128/uint128.hpp" using namespace numeric; +using namespace tests_avm; namespace { void common_validate_arithmetic_op(Row const& main_row, @@ -140,7 +141,7 @@ std::vector gen_mutated_trace_add(FF const& a, FF const& b, FF const& c_mut auto trace = trace_builder.finalize(); auto select_row = [](Row r) { return r.avmMini_sel_op_add == FF(1); }; - tests_avm::mutate_ic_in_trace(trace, select_row, c_mutated, true); + mutate_ic_in_trace(trace, select_row, c_mutated, true); return trace; } @@ -158,7 +159,7 @@ std::vector gen_mutated_trace_sub(FF const& a, FF const& b, FF const& c_mut auto trace = trace_builder.finalize(); auto select_row = [](Row r) { return r.avmMini_sel_op_sub == FF(1); }; - tests_avm::mutate_ic_in_trace(trace, select_row, c_mutated, true); + mutate_ic_in_trace(trace, select_row, c_mutated, true); return trace; } @@ -176,16 +177,14 @@ std::vector gen_mutated_trace_mul(FF const& a, FF const& b, FF const& c_mut auto trace = trace_builder.finalize(); auto select_row = [](Row r) { return r.avmMini_sel_op_mul == FF(1); }; - tests_avm::mutate_ic_in_trace(trace, select_row, c_mutated, true); + mutate_ic_in_trace(trace, select_row, c_mutated, true); return trace; } } // anonymous namespace -namespace tests_avm { using namespace avm_trace; - class AvmMiniArithmeticTests : public ::testing::Test { public: AvmMiniTraceBuilder trace_builder; @@ -194,7 +193,7 @@ class AvmMiniArithmeticTests : public ::testing::Test { // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialised for every test. void SetUp() override { - bb::srs::init_crs_factory("../srs_db/ignition"); + srs::init_crs_factory("../srs_db/ignition"); trace_builder = AvmMiniTraceBuilder(); // Clean instance for every run. }; }; @@ -1676,6 +1675,4 @@ TEST_F(AvmMiniArithmeticNegativeTestsU128, multiplication) FF{ uint256_t::from_uint128(c) }, AvmMemoryTag::U128); EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "ALU_MULTIPLICATION_OUT_U128"); -} - -} // namespace tests_avm \ No newline at end of file +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_control_flow.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_control_flow.test.cpp index b1712c08b81..657ae8e25b1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_control_flow.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_control_flow.test.cpp @@ -1,7 +1,7 @@ #include "AvmMini_common.test.hpp" -namespace tests_avm { using namespace avm_trace; +using namespace tests_avm; class AvmMiniControlFlowTests : public ::testing::Test { public: @@ -11,7 +11,7 @@ class AvmMiniControlFlowTests : public ::testing::Test { // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialised for every test. void SetUp() override { - bb::srs::init_crs_factory("../srs_db/ignition"); + srs::init_crs_factory("../srs_db/ignition"); trace_builder = AvmMiniTraceBuilder(); // Clean instance for every run. }; }; @@ -285,4 +285,3 @@ TEST_F(AvmMiniControlFlowTests, multipleCallsAndReturns) validate_trace_proof(std::move(trace)); } -} // namespace tests_avm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp index 0f709e6ba20..a5ccfd1076a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/AvmMini_memory.test.cpp @@ -1,8 +1,7 @@ #include "AvmMini_common.test.hpp" -namespace tests_avm { +using namespace tests_avm; using namespace avm_trace; - class AvmMiniMemoryTests : public ::testing::Test { public: AvmMiniTraceBuilder trace_builder; @@ -11,7 +10,7 @@ class AvmMiniMemoryTests : public ::testing::Test { // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialised for every test. void SetUp() override { - bb::srs::init_crs_factory("../srs_db/ignition"); + srs::init_crs_factory("../srs_db/ignition"); trace_builder = AvmMiniTraceBuilder(); // Clean instance for every run. }; }; @@ -237,4 +236,3 @@ TEST_F(AvmMiniMemoryTests, consistentTagNoErrorViolation) EXPECT_THROW_WITH_MESSAGE(validate_trace_proof(std::move(trace)), "MEM_IN_TAG_CONSISTENCY_1"); } -} // namespace tests_avm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp index 8948c17d18b..8377eba5ff8 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp @@ -1,8 +1,8 @@ #include "AvmMini_common.test.hpp" -namespace tests_avm { -using namespace avm_trace; +using namespace bb; +namespace tests_avm { /** * @brief Helper routine proving and verifying a proof based on the supplied trace * @@ -10,12 +10,12 @@ using namespace avm_trace; */ void validate_trace_proof(std::vector&& trace) { - auto circuit_builder = bb::AvmMiniCircuitBuilder(); + auto circuit_builder = AvmMiniCircuitBuilder(); circuit_builder.set_trace(std::move(trace)); EXPECT_TRUE(circuit_builder.check_circuit()); - auto composer = bb::honk::AvmMiniComposer(); + auto composer = honk::AvmMiniComposer(); auto prover = composer.create_prover(circuit_builder); auto proof = prover.construct_proof(); @@ -23,7 +23,7 @@ void validate_trace_proof(std::vector&& trace) bool verified = verifier.verify_proof(proof); if (!verified) { - log_avmMini_trace(circuit_builder.rows, 0, 10); + avm_trace::log_avmMini_trace(circuit_builder.rows, 0, 10); } }; @@ -70,5 +70,4 @@ void mutate_ic_in_trace(std::vector& trace, std::function&& sele EXPECT_TRUE(mem_row != trace.end()); mem_row->memTrace_m_val = newValue; }; - } // namespace tests_avm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp index 10debc85891..430c1cce45b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp @@ -10,9 +10,7 @@ std::string message = e.what(); \ EXPECT_TRUE(message.find(expectedMessage) != std::string::npos); \ } - namespace tests_avm { - void validate_trace_proof(std::vector&& trace); void mutate_ic_in_trace(std::vector& trace, std::function&& selectRow, diff --git a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp index 3f312600c4b..e9bc1fc610e 100644 --- a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp +++ b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp @@ -94,4 +94,4 @@ template struct CircuitTypes { static byte_array blake2s(const byte_array& input) { return plonk::stdlib::blake2s(input); } }; -} // namespace aztec3::utils::types \ No newline at end of file +} // namespace aztec3::utils::types