diff --git a/barretenberg/cpp/src/barretenberg/api/api_client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/api/api_client_ivc.test.cpp index 12af7213f0be..80f0ae003f63 100644 --- a/barretenberg/cpp/src/barretenberg/api/api_client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/api/api_client_ivc.test.cpp @@ -147,7 +147,7 @@ TEST_F(ClientIVCAPITests, ProveAndVerifyFileBasedFlow) auto verify_vk_equivalence = [&](const std::filesystem::path& vk1_path, const ClientIVC::MegaVerificationKey& vk2) { auto vk1_data = read_file(vk1_path); auto vk1 = from_buffer(vk1_data); - ASSERT(msgpack::msgpack_check_eq(vk1, vk2, "VK from prove should match VK from write_vk")); + ASSERT_TRUE(msgpack::msgpack_check_eq(vk1, vk2, "VK from prove should match VK from write_vk")); }; // Helper lambda to verify proof 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 84ed8d495145..b0884efabb01 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/ipa.bench.cpp @@ -1,4 +1,5 @@ #include "barretenberg/commitment_schemes/ipa/ipa.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_circuits.hpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_circuits.hpp index ed3b8e7816c0..b8292445cb10 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_circuits.hpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_circuits.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include "barretenberg/common/assert.hpp" #include "barretenberg/crypto/merkle_tree/membership.hpp" #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp" @@ -39,9 +40,9 @@ template void generate_basic_arithmetic_circuit(Builder& buil } size_t est_gate_count = builder.get_estimated_num_finalized_gates(); - ASSERT(est_gate_count <= - (1UL << log2_num_gates) - - GATE_COUNT_BUFFER); // Check that the finalized gate count won't exceed the desired gate count. + BB_ASSERT_LTE(est_gate_count, + (1UL << log2_num_gates) - GATE_COUNT_BUFFER, + "Check that the finalized gate count won't exceed the desired gate count."); } template diff --git a/barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph.cpp b/barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph.cpp index 05a46940dcc2..667dddddbf88 100644 --- a/barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph.cpp +++ b/barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph.cpp @@ -1,4 +1,5 @@ #include "./graph.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" #include #include @@ -430,7 +431,7 @@ inline std::vector StaticAnalyzer_::get_rom_table_connected_compon bb::UltraCircuitBuilder& ultra_builder, const bb::RomTranscript& rom_array) { size_t block_index = find_block_index(ultra_builder, ultra_builder.blocks.aux); - ASSERT(block_index == 5); + BB_ASSERT_EQ(block_index, 5U); // Every RomTranscript data structure has 2 main components that are interested for static analyzer: // 1) records contains values that were put in the gate, we can use them to create connections between variables @@ -491,7 +492,7 @@ inline std::vector StaticAnalyzer_::get_ram_table_connected_compon bb::UltraCircuitBuilder& ultra_builder, const bb::RamTranscript& ram_array) { size_t block_index = find_block_index(ultra_builder, ultra_builder.blocks.aux); - ASSERT(block_index == 5); + BB_ASSERT_EQ(block_index, 5U); std::vector ram_table_variables; for (const auto& record : ram_array.records) { std::vector gate_variables; @@ -1115,12 +1116,12 @@ inline void StaticAnalyzer_::remove_record_witness_variables(bb::UltraCircui auto block_data = ultra_builder.blocks.get(); size_t blk_idx = find_block_index(ultra_builder, ultra_builder.blocks.aux); std::vector to_remove; - ASSERT(blk_idx == 5); + BB_ASSERT_EQ(blk_idx, 5U); for (const auto& var_idx : variables_in_one_gate) { KeyPair key = { var_idx, blk_idx }; if (auto search = variable_gates.find(key); search != variable_gates.end()) { std::vector gate_indexes = variable_gates[key]; - ASSERT(gate_indexes.size() == 1); + BB_ASSERT_EQ(gate_indexes.size(), 1U); size_t gate_idx = gate_indexes[0]; auto q_1 = block_data[blk_idx].q_1()[gate_idx]; auto q_2 = block_data[blk_idx].q_2()[gate_idx]; @@ -1269,7 +1270,7 @@ void StaticAnalyzer_::print_variable_in_one_gate(bb::UltraCircuitBuilder& ul const auto& block_data = ultra_builder.blocks.get(); for (const auto& [key, gates] : variable_gates) { if (key.first == real_idx) { - ASSERT(gates.size() == 1); + BB_ASSERT_EQ(gates.size(), 1U); size_t gate_index = gates[0]; UltraBlock block = block_data[key.second]; info("---- printing variables in this gate"); diff --git a/barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph_description_goblin.test.cpp b/barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph_description_goblin.test.cpp index 0fffaf172146..78beadc6d642 100644 --- a/barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph_description_goblin.test.cpp +++ b/barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph_description_goblin.test.cpp @@ -102,7 +102,7 @@ TEST_F(BoomerangGoblinRecursiveVerifierTests, graph_description_basic) auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); - ASSERT(verified); + ASSERT_TRUE(verified); } auto translator_pairing_points = output.points_accumulator; translator_pairing_points.P0.x.fix_witness(); diff --git a/barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_checker.cpp b/barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_checker.cpp index 673bc3c60c09..0f3ec604f52a 100644 --- a/barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_checker.cpp +++ b/barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_checker.cpp @@ -1,4 +1,5 @@ #include "ultra_circuit_checker.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/flavor/mega_flavor.hpp" #include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index 8a5ea11cbd29..22725c73c808 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -1,6 +1,7 @@ #include "barretenberg/client_ivc/client_ivc.hpp" #include "barretenberg/client_ivc/mock_circuit_producer.hpp" #include "barretenberg/client_ivc/test_bench_shared.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/mem.hpp" #include "barretenberg/common/test.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" @@ -299,7 +300,7 @@ TEST_F(ClientIVCTests, WrongProofComponentFailure) tampered_proof.goblin_proof.merge_proof = civc_proof_2.goblin_proof.merge_proof; - EXPECT_DEATH(ClientIVC::verify(tampered_proof, civc_vk_1), ".*IPA verification fails.*"); + EXPECT_THROW_OR_ABORT(ClientIVC::verify(tampered_proof, civc_vk_1), ".*IPA verification fails.*"); } { @@ -308,7 +309,7 @@ TEST_F(ClientIVCTests, WrongProofComponentFailure) tampered_proof.mega_proof = civc_proof_2.mega_proof; - EXPECT_DEATH(ClientIVC::verify(tampered_proof, civc_vk_1), ".*IPA verification fails.*"); + EXPECT_THROW_OR_ABORT(ClientIVC::verify(tampered_proof, civc_vk_1), ".*IPA verification fails.*"); } { @@ -317,7 +318,7 @@ TEST_F(ClientIVCTests, WrongProofComponentFailure) tampered_proof.goblin_proof.eccvm_proof = civc_proof_2.goblin_proof.eccvm_proof; - EXPECT_DEATH(ClientIVC::verify(tampered_proof, civc_vk_1), ".*IPA verification fails.*"); + EXPECT_THROW_OR_ABORT(ClientIVC::verify(tampered_proof, civc_vk_1), ".*IPA verification fails.*"); } { diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.fuzzer.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.fuzzer.cpp index 9acb932d4881..d5bd3da29531 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.fuzzer.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/ipa/ipa.fuzzer.cpp @@ -4,6 +4,7 @@ // external_2: { status: not started, auditors: [], date: YYYY-MM-DD } // ===================== +#include "barretenberg/common/assert.hpp" #include "barretenberg/srs/global_crs.hpp" #define IPA_FUZZ_TEST #include "./mock_transcript.hpp" @@ -75,7 +76,7 @@ extern "C" void LLVMFuzzerInitialize(int*, char***) // Don't use dereference casts, since the data may be not aligned and it causes segfault uint256_t read_uint256(const uint8_t* data, size_t buffer_size = 32) { - ASSERT(buffer_size <= 32); + BB_ASSERT_LTE(buffer_size, 32U); uint64_t parts[4] = { 0, 0, 0, 0 }; 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 f2b29ebf2d95..1966907ac9cf 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/kzg/kzg.test.cpp @@ -85,7 +85,7 @@ TEST_F(KZGTest, ZeroPolynomial) } // Sanity check - ASSERT(zero.is_zero()); + ASSERT_TRUE(zero.is_zero()); const Fr challenge = Fr::random_element(); const Fr evaluation = zero.evaluate(challenge); diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.hpp index bd126810043c..f1e5b6541e6b 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.hpp @@ -8,6 +8,7 @@ #include "barretenberg/commitment_schemes/claim.hpp" #include "barretenberg/commitment_schemes/commitment_key.hpp" #include "barretenberg/commitment_schemes/verification_key.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/transcript/transcript.hpp" @@ -373,7 +374,7 @@ template class ShplonkVerifier_ { , commitments({ quotient }) , scalars{ Fr{ 1 } } { - ASSERT(num_claims > 1, "Using Shplonk with just one claim. Should use batch reduction."); + BB_ASSERT_GT(num_claims, 1U, "Using Shplonk with just one claim. Should use batch reduction."); const size_t num_commitments = commitments.size(); commitments.reserve(num_commitments); scalars.reserve(num_commitments); diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp index bb27dd0835fb..1435648e0d6d 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplonk.test.cpp @@ -127,7 +127,7 @@ TYPED_TEST(ShplonkTest, ExportBatchClaimAndVerify) // KZG verifier auto final_proof_points = KZG::reduce_verify_batch_opening_claim(batched_verifier_claim, verifier_transcript); - ASSERT(this->vk().pairing_check(final_proof_points[0], final_proof_points[1])); + ASSERT_TRUE(this->vk().pairing_check(final_proof_points[0], final_proof_points[1])); } else { // Verify IPA proof auto vk = create_verifier_commitment_key>(); diff --git a/barretenberg/cpp/src/barretenberg/common/assert.hpp b/barretenberg/cpp/src/barretenberg/common/assert.hpp index 31d97f7d0502..1db883c1459f 100644 --- a/barretenberg/cpp/src/barretenberg/common/assert.hpp +++ b/barretenberg/cpp/src/barretenberg/common/assert.hpp @@ -1,5 +1,8 @@ #pragma once +#include "barretenberg/common/throw_or_abort.hpp" +#include + // NOLINTBEGIN #if NDEBUG // Compiler should optimize this out in release builds, without triggering unused-variable warnings. @@ -9,13 +12,7 @@ } // All assertion macros accept an optional message but do nothing in release. -#define ASSERT(expression, ...) DONT_EVALUATE((expression)) - -#define BB_ASSERT_EQ(actual, expected, ...) DONT_EVALUATE((actual) == (expected)) -#define BB_ASSERT_GT(left, right, ...) DONT_EVALUATE((left) > (right)) -#define BB_ASSERT_GTE(left, right, ...) DONT_EVALUATE((left) >= (right)) -#define BB_ASSERT_LT(left, right, ...) DONT_EVALUATE((left) < (right)) -#define BB_ASSERT_LTE(left, right, ...) DONT_EVALUATE((left) <= (right)) +#define ASSERT_DEBUG_ONLY(expression, ...) DONT_EVALUATE((expression)) #else #include "barretenberg/common/log.hpp" @@ -25,12 +22,25 @@ #include // Basic assert with optional error message -#define ASSERT(expression, ...) \ +#define ASSERT_DEBUG(expression, ...) ASSERT(expression, __VA_ARGS__) +#endif // NDEBUG + +#define ASSERT_IN_CONSTEXPR(expression, ...) \ do { \ if (!(expression)) { \ info("Assertion failed: (" #expression ")"); \ __VA_OPT__(info("Reason : ", __VA_ARGS__);) \ - std::abort(); \ + throw_or_abort(""); \ + } \ + } while (0) + +#define ASSERT(expression, ...) \ + do { \ + if (!(expression)) { \ + std::ostringstream oss; \ + oss << "Assertion failed: (" #expression ")"; \ + __VA_OPT__(oss << " | Reason: " << __VA_ARGS__;) \ + throw_or_abort(oss.str()); \ } \ } while (0) @@ -39,11 +49,12 @@ auto _actual = (actual); \ auto _expected = (expected); \ if (!(_actual == _expected)) { \ - info("Assertion failed: (" #actual " == " #expected ")"); \ - info(" Actual : ", _actual); \ - info(" Expected: ", _expected); \ - __VA_OPT__(info(" Reason : ", __VA_ARGS__);) \ - std::abort(); \ + std::ostringstream oss; \ + oss << "Assertion failed: (" #actual " == " #expected ")\n"; \ + oss << " Actual : " << _actual << "\n"; \ + oss << " Expected: " << _expected; \ + __VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \ + throw_or_abort(oss.str()); \ } \ } while (0) @@ -52,11 +63,12 @@ auto _left = (left); \ auto _right = (right); \ if (!(_left > _right)) { \ - info("Assertion failed: (" #left " > " #right ")"); \ - info(" Left : ", _left); \ - info(" Right : ", _right); \ - __VA_OPT__(info(" Reason : ", __VA_ARGS__);) \ - std::abort(); \ + std::ostringstream oss; \ + oss << "Assertion failed: (" #left " > " #right ")\n"; \ + oss << " Left : " << _left << "\n"; \ + oss << " Right : " << _right; \ + __VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \ + throw_or_abort(oss.str()); \ } \ } while (0) @@ -65,11 +77,12 @@ auto _left = (left); \ auto _right = (right); \ if (!(_left >= _right)) { \ - info("Assertion failed: (" #left " >= " #right ")"); \ - info(" Left : ", _left); \ - info(" Right : ", _right); \ - __VA_OPT__(info(" Reason : ", __VA_ARGS__);) \ - std::abort(); \ + std::ostringstream oss; \ + oss << "Assertion failed: (" #left " >= " #right ")\n"; \ + oss << " Left : " << _left << "\n"; \ + oss << " Right : " << _right; \ + __VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \ + throw_or_abort(oss.str()); \ } \ } while (0) @@ -78,11 +91,12 @@ auto _left = (left); \ auto _right = (right); \ if (!(_left < _right)) { \ - info("Assertion failed: (" #left " < " #right ")"); \ - info(" Left : ", _left); \ - info(" Right : ", _right); \ - __VA_OPT__(info(" Reason : ", __VA_ARGS__);) \ - std::abort(); \ + std::ostringstream oss; \ + oss << "Assertion failed: (" #left " < " #right ")\n"; \ + oss << " Left : " << _left << "\n"; \ + oss << " Right : " << _right; \ + __VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \ + throw_or_abort(oss.str()); \ } \ } while (0) @@ -91,14 +105,22 @@ auto _left = (left); \ auto _right = (right); \ if (!(_left <= _right)) { \ - info("Assertion failed: (" #left " <= " #right ")"); \ - info(" Left : ", _left); \ - info(" Right : ", _right); \ - __VA_OPT__(info(" Reason : ", __VA_ARGS__);) \ - std::abort(); \ + std::ostringstream oss; \ + oss << "Assertion failed: (" #left " <= " #right ")\n"; \ + oss << " Left : " << _left << "\n"; \ + oss << " Right : " << _right; \ + __VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \ + throw_or_abort(oss.str()); \ } \ } while (0) -#endif // NDEBUG +// These are used in tests. +#ifdef BB_NO_EXCEPTIONS +#define ASSERT_THROW_OR_ABORT(statement, matcher) ASSERT_DEATH(statement, matcher) +#define EXPECT_THROW_OR_ABORT(statement, matcher) EXPECT_DEATH(statement, matcher) +#else +#define ASSERT_THROW_OR_ABORT(statement, matcher) ASSERT_THROW(statement, std::runtime_error) +#define EXPECT_THROW_OR_ABORT(statement, matcher) EXPECT_THROW(statement, std::runtime_error) +#endif -// NOLINTEND \ No newline at end of file +// NOLINTEND diff --git a/barretenberg/cpp/src/barretenberg/common/fuzzer.hpp b/barretenberg/cpp/src/barretenberg/common/fuzzer.hpp index 10bd8a6a9446..818fd71e4931 100644 --- a/barretenberg/cpp/src/barretenberg/common/fuzzer.hpp +++ b/barretenberg/cpp/src/barretenberg/common/fuzzer.hpp @@ -1,5 +1,6 @@ #pragma once #include "barretenberg/circuit_checker/circuit_checker.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" // NOLINTBEGIN(cppcoreguidelines-macro-usage, google-runtime-int) @@ -104,7 +105,7 @@ template static inline uint256_t fast_log_distributed_uint256(T& rn // Don't use dereference casts, since the data may be not aligned and it causes segfault uint256_t read_uint256(const uint8_t* data, size_t buffer_size = 32) { - ASSERT(buffer_size <= 32); + BB_ASSERT_LTE(buffer_size, 32U); uint64_t parts[4] = { 0, 0, 0, 0 }; diff --git a/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.tcc b/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.tcc index 3444028b8c87..b0cbd5c06ff4 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.tcc +++ b/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.tcc @@ -241,7 +241,8 @@ constexpr void blake3_hasher_finalize(const blake3_hasher* self, uint8_t* out) std::vector blake3s(std::vector const& input) { - ASSERT(input.size() <= 1024, "Barretenberg does not support blake3s with input lengths greater than 1024 bytes."); + BB_ASSERT_LTE( + input.size(), 1024U, "Barretenberg does not support blake3s with input lengths greater than 1024 bytes."); blake3_hasher hasher; blake3_hasher_init(&hasher); diff --git a/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.test.cpp index be0a8d896d29..7bfa9a430ee6 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.test.cpp @@ -2,6 +2,7 @@ #include +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/constexpr_utils.hpp" #include #include @@ -418,5 +419,5 @@ TEST(MiscBlake3s, TestVectors) TEST(MiscBlake3s, TooLargeInputTest) { std::vector input(1025, 0); - EXPECT_DEATH(blake3::blake3s(input), "Assertion failed"); + EXPECT_THROW_OR_ABORT(blake3::blake3s(input), "Assertion failed"); } diff --git a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/hash.hpp b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/hash.hpp index f87a9c1dc003..bfbdde908f01 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/hash.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/hash.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/net.hpp" #include "barretenberg/crypto/blake2s/blake2s.hpp" #include "barretenberg/crypto/pedersen_commitment/pedersen.hpp" @@ -55,9 +56,7 @@ inline bb::fr hash_native(std::vector const& inputs) */ inline bb::fr compute_tree_root_native(std::vector const& input) { - // Check if the input vector size is a power of 2. - BB_ASSERT_GT(input.size(), static_cast(0)); - ASSERT(numeric::is_power_of_two(input.size())); + ASSERT(numeric::is_power_of_two(input.size()), "Check if the input vector size is a power of 2."); auto layer = input; while (layer.size() > 1) { std::vector next_layer(layer.size() / 2); @@ -73,9 +72,7 @@ inline bb::fr compute_tree_root_native(std::vector const& input) // TODO write test inline std::vector compute_tree_native(std::vector const& input) { - // Check if the input vector size is a power of 2. - BB_ASSERT_GT(input.size(), static_cast(0)); - ASSERT(numeric::is_power_of_two(input.size())); + ASSERT(numeric::is_power_of_two(input.size()), "Check if the input vector size is a power of 2."); auto layer = input; std::vector tree(input); while (layer.size() > 1) { diff --git a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/membership.hpp b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/membership.hpp index 73183b0ebfa0..3be5b3740658 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/membership.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/membership.hpp @@ -5,8 +5,10 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/crypto/merkle_tree/memory_store.hpp" #include "barretenberg/crypto/merkle_tree/merkle_tree.hpp" +#include "barretenberg/numeric/bitop/pow.hpp" #include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" @@ -256,9 +258,7 @@ void update_subtree_membership(field_t const& new_root, */ template field_t compute_tree_root(std::vector> const& input) { - // Check if the input vector size is a power of 2. - ASSERT(input.size() > 0); - ASSERT(!(input.size() & (input.size() - 1)) == true); + ASSERT(numeric::is_power_of_two(input.size()), "Check if the input vector size is a power of 2."); auto layer = input; while (layer.size() > 1) { std::vector> next_layer(layer.size() / 2); @@ -363,4 +363,4 @@ template static void generate_merkle_membership_test_circuit( idx_ct); } } -} // namespace bb::stdlib \ No newline at end of file +} // namespace bb::stdlib diff --git a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/memory_tree.hpp b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/memory_tree.hpp index aa9d3fe5f41a..447359b32edf 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/memory_tree.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/memory_tree.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "hash_path.hpp" namespace bb::crypto::merkle_tree { @@ -52,7 +53,8 @@ MemoryTree::MemoryTree(size_t depth) : depth_(depth) { - ASSERT(depth_ >= 1 && depth <= 20); + BB_ASSERT_GTE(depth_, 1U); + BB_ASSERT_LTE(depth, 20U); total_size_ = 1UL << depth_; hashes_.resize(total_size_ * 2 - 2); diff --git a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/merkle_tree.hpp b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/merkle_tree.hpp index 322f6a6f534f..af77bc2bfed1 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/merkle_tree.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/merkle_tree.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/net.hpp" #include "barretenberg/numeric/bitop/count_leading_zeros.hpp" #include "barretenberg/numeric/bitop/keep_n_lsb.hpp" @@ -121,7 +122,8 @@ MerkleTree::MerkleTree(Store& store, size_t depth, uint8_t , depth_(depth) , tree_id_(tree_id) { - ASSERT(depth_ >= 1 && depth <= 256); + BB_ASSERT_GTE(depth_, 1U); + BB_ASSERT_LTE(depth, 256U); zero_hashes_.resize(depth); // Compute the zero values at each layer. @@ -184,8 +186,9 @@ fr_hash_path MerkleTree::get_hash_path(index_t index) status = store_.get(std::vector(it, it + 32), data); } else { // This is a stump. The hash path can be fully restored from this node. - // In case of a stump, we store: [key : (value, local_index, true)], i.e. 65-byte data. - ASSERT(data.size() == STUMP_NODE_SIZE); + BB_ASSERT_EQ(data.size(), + STUMP_NODE_SIZE, + "We store: [key : (value, local_index, true)], i.e. 65-byte data, in a thump."); fr current = from_buffer(data, 0); index_t element_index = from_buffer(data, 32); index_t subtree_index = numeric::keep_n_lsb(index, i + 1); @@ -256,7 +259,7 @@ fr_sibling_path MerkleTree::get_sibling_path(index_t index } else { // This is a stump. The sibling path can be fully restored from this node. // In case of a stump, we store: [key : (value, local_index, true)], i.e. 65-byte data. - ASSERT(data.size() == STUMP_NODE_SIZE); + BB_ASSERT_EQ(data.size(), STUMP_NODE_SIZE); fr current = from_buffer(data, 0); index_t element_index = from_buffer(data, 32); index_t subtree_index = numeric::keep_n_lsb(index, i + 1); @@ -383,8 +386,7 @@ fr MerkleTree::update_element(fr const& root, fr const& va return fork_stump(existing_value, existing_index, value, index, height, common_height); } else { - // If its not a stump, the data size must be 64 bytes. - ASSERT(data.size() == REGULAR_NODE_SIZE); + BB_ASSERT_EQ(data.size(), REGULAR_NODE_SIZE, "If it's not a stump, the data size must be 64 bytes."); bool is_right = bit_set(index, height - 1); fr subtree_root = from_buffer(data, is_right ? 32 : 0); fr subtree_root_copy = subtree_root; diff --git a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp index cf3c187869e5..e1fb7c249de2 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp @@ -7,6 +7,7 @@ #pragma once #include "../hash.hpp" #include "../memory_tree.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/crypto/merkle_tree/hash_path.hpp" #include "nullifier_leaf.hpp" @@ -102,8 +103,9 @@ template NullifierMemoryTree::NullifierMemoryTree(size_t depth, size_t initial_size) : MemoryTree(depth) { - ASSERT(depth_ >= 1 && depth <= 32); - ASSERT(initial_size > 0); + BB_ASSERT_GTE(depth_, 1U); + BB_ASSERT_LTE(depth, 32U); + BB_ASSERT_GT(initial_size, 0U); total_size_ = 1UL << depth_; hashes_.resize(total_size_ * 2 - 2); @@ -181,4 +183,4 @@ template fr_sibling_path NullifierMemoryTree NullifierTree::NullifierTree(Store& store, size_t depth, size_t initial_size, uint8_t tree_id) : MerkleTree(store, depth, tree_id) { - ASSERT(depth_ >= 1 && depth <= 256); - ASSERT(initial_size > 0); + BB_ASSERT_GTE(depth_, 1U); + BB_ASSERT_LTE(depth, 256U); + BB_ASSERT_GT(initial_size, 0U); zero_hashes_.resize(depth); // Create the zero hashes for the tree diff --git a/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.cpp b/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.cpp index 808b0f1ad6b0..969dd8949245 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/sha256/sha256.cpp @@ -5,6 +5,7 @@ // ===================== #include "./sha256.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/net.hpp" #include #include @@ -114,7 +115,7 @@ std::array sha256_block(const std::array& h_init, cons Sha256Hash sha256_block(const std::vector& input) { - ASSERT(input.size() == 64); + BB_ASSERT_EQ(input.size(), 64U); std::array result; prepare_constants(result); std::array hash_input; 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 cda541998554..a3191a9b145d 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -6,6 +6,7 @@ #include "acir_format.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/log.hpp" #include "barretenberg/common/op_count.hpp" #include "barretenberg/common/throw_or_abort.hpp" @@ -264,8 +265,8 @@ void build_constraints(Builder& builder, AcirProgram& program, const ProgramMeta } // We shouldn't have both honk recursion constraints and ivc recursion constraints. - ASSERT((constraint_system.honk_recursion_constraints.empty() || - constraint_system.ivc_recursion_constraints.empty()) && + ASSERT(constraint_system.honk_recursion_constraints.empty() || + constraint_system.ivc_recursion_constraints.empty(), "Invalid circuit: both honk and ivc recursion constraints present."); // If its an app circuit that has no recursion constraints, add default pairing points to public inputs. if (constraint_system.honk_recursion_constraints.empty() && @@ -344,7 +345,7 @@ void handle_IPA_accumulation(Builder& builder, OpeningClaim> final_ipa_claim; HonkProof final_ipa_proof; if (is_root_rollup) { - ASSERT(nested_ipa_claims.size() == 2 && "Root rollup must have two nested IPA claims."); + BB_ASSERT_EQ(nested_ipa_claims.size(), 2U, "Root rollup must have two nested IPA claims."); } if (nested_ipa_claims.size() == 2) { // If we have two claims, accumulate. @@ -456,7 +457,7 @@ process_honk_recursion_constraints(Builder& builder, gate_counter.track_diff(constraint_system.gates_per_opcode, constraint_system.original_opcode_indices.honk_recursion_constraints.at(idx++)); } - ASSERT(!(output.is_root_rollup && output.nested_ipa_claims.size() != 2) && + ASSERT(!(output.is_root_rollup && output.nested_ipa_claims.size() != 2), "Root rollup must accumulate two IPA proofs."); return output; } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_integration.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_integration.test.cpp index b31f4eb73f1b..0fb2b57910b3 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_integration.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_integration.test.cpp @@ -405,9 +405,9 @@ TEST_F(AcirIntegrationTest, DISABLED_DatabusTwoCalldata) const auto& secondary_calldata = builder.get_secondary_calldata(); const auto& return_data = builder.get_return_data(); - BB_ASSERT_EQ(calldata.size(), static_cast(4)); - BB_ASSERT_EQ(secondary_calldata.size(), static_cast(3)); - BB_ASSERT_EQ(return_data.size(), static_cast(4)); + ASSERT_EQ(calldata.size(), static_cast(4)); + ASSERT_EQ(secondary_calldata.size(), static_cast(3)); + ASSERT_EQ(return_data.size(), static_cast(4)); // Check that return data was computed from the two calldata inputs as expected ASSERT_EQ(builder.get_variable(calldata[0]) + builder.get_variable(secondary_calldata[0]), diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index a39dc9e2067a..18fc0a9e748f 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -13,8 +13,10 @@ #include #include "barretenberg/api/get_bytecode.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/container.hpp" #include "barretenberg/common/map.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/dsl/acir_format/recursion_constraint.hpp" #include "barretenberg/honk/execution_trace/gate_data.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" @@ -151,7 +153,7 @@ poly_triple serialize_arithmetic_gate(Acir::Expression const& arg) bool c_set = false; // If necessary, set values for quadratic term (q_m * w_l * w_r) - ASSERT(arg.mul_terms.size() <= 1); // We can only accommodate 1 quadratic term + BB_ASSERT_LTE(arg.mul_terms.size(), 1U, "We can only accommodate 1 quadratic term"); // Note: mul_terms are tuples of the form {selector_value, witness_idx_1, witness_idx_2} if (!arg.mul_terms.empty()) { const auto& mul_term = arg.mul_terms[0]; @@ -163,7 +165,7 @@ poly_triple serialize_arithmetic_gate(Acir::Expression const& arg) } // If necessary, set values for linears terms q_l * w_l, q_r * w_r and q_o * w_o - ASSERT(arg.linear_combinations.size() <= 3); // We can only accommodate 3 linear terms + BB_ASSERT_LTE(arg.linear_combinations.size(), 3U, "We can only accommodate 3 linear terms"); for (const auto& linear_term : arg.linear_combinations) { fr selector_value(uint256_t(std::get<0>(linear_term))); uint32_t witness_idx = std::get<1>(linear_term).value; @@ -233,7 +235,7 @@ void assign_linear_term(mul_quad_& gate, int index, uint32_t witness_index, gate.d_scaling = scaling; break; default: - ASSERT(false); + throw_or_abort("Unexpected index"); } } @@ -357,7 +359,7 @@ mul_quad_ serialize_mul_quad_gate(Acir::Expression const& arg) bool b_set = false; bool c_set = false; bool d_set = false; - ASSERT(arg.mul_terms.size() <= 1); // We can only accommodate 1 quadratic term + BB_ASSERT_LTE(arg.mul_terms.size(), 1U, "We can only accommodate 1 quadratic term"); // Note: mul_terms are tuples of the form {selector_value, witness_idx_1, witness_idx_2} if (!arg.mul_terms.empty()) { const auto& mul_term = arg.mul_terms[0]; @@ -542,7 +544,7 @@ WitnessOrConstant parse_input(Acir::FunctionInput input) .is_constant = true, }; } else { - ASSERT(false); + throw_or_abort("Unrecognized Acir::ConstantOrWitnessEnum variant."); } return WitnessOrConstant{ .index = 0, @@ -755,8 +757,7 @@ void handle_blackbox_func_call(Acir::Opcode::BlackBoxFuncCall const& arg, AcirFo af.original_opcode_indices.avm_recursion_constraints.push_back(opcode_index); break; default: - info("Invalid PROOF_TYPE in RecursionConstraint!"); - ASSERT(false); + throw_or_abort("Invalid PROOF_TYPE in RecursionConstraint!"); } } else if constexpr (std::is_same_v) { af.bigint_from_le_bytes_constraints.push_back(BigIntFromLeBytes{ diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.cpp index 024b64895ec9..13bb2ab2aedc 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.cpp @@ -111,7 +111,7 @@ void create_bigint_addition_constraint(const BigIntOperation& input, DSLBigInts< break; } default: { - ASSERT(false); + throw_or_abort("Unexpected Modulus ID"); } } } @@ -157,7 +157,7 @@ void create_bigint_sub_constraint(const BigIntOperation& input, DSLBigInts class DSLBigInts { } big_bn254_fr bn254_fr(uint32_t bigint_id) { - if (this->m_bn254_fr.contains(bigint_id)) { - return this->m_bn254_fr[bigint_id]; - } - ASSERT(false); - return { 0 }; + ASSERT(this->m_bn254_fr.contains(bigint_id)); + return this->m_bn254_fr[bigint_id]; } void set_bn254_fr(const big_bn254_fr& bigint, uint32_t bigint_id) { this->m_bn254_fr[bigint_id] = bigint; } big_bn254_fq bn254_fq(uint32_t bigint_id) { - if (this->m_bn254_fq.contains(bigint_id)) { - return this->m_bn254_fq[bigint_id]; - } - ASSERT(false); - return { 0 }; + ASSERT(this->m_bn254_fq.contains(bigint_id)); + return this->m_bn254_fq[bigint_id]; } void set_bn254_fq(const big_bn254_fq& bigint, uint32_t bigint_id) { this->m_bn254_fq[bigint_id] = bigint; } big_secp256r1_fq secp256r1_fq(uint32_t bigint_id) { - if (this->m_secp256r1_fq.contains(bigint_id)) { - return this->m_secp256r1_fq[bigint_id]; - } - ASSERT(false); - return { 0 }; + ASSERT(this->m_secp256r1_fq.contains(bigint_id)); + return this->m_secp256r1_fq[bigint_id]; } void set_secp256r1_fq(const big_secp256r1_fq& bigint, uint32_t bigint_id) @@ -212,11 +204,8 @@ template class DSLBigInts { big_secp256r1_fr secp256r1_fr(uint32_t bigint_id) { - if (this->m_secp256r1_fr.contains(bigint_id)) { - return this->m_secp256r1_fr[bigint_id]; - } - ASSERT(false); - return { 0 }; + ASSERT(this->m_secp256r1_fr.contains(bigint_id)); + return this->m_secp256r1_fr[bigint_id]; } void set_secp256r1_fr(const big_secp256r1_fr& bigint, uint32_t bigint_id) @@ -226,11 +215,8 @@ template class DSLBigInts { big_secp256k1_fq secp256k1_fq(uint32_t bigint_id) { - if (this->m_secp256k1_fq.contains(bigint_id)) { - return this->m_secp256k1_fq[bigint_id]; - } - ASSERT(false); - return { 0 }; + ASSERT(this->m_secp256k1_fq.contains(bigint_id)); + return this->m_secp256k1_fq[bigint_id]; } void set_secp256k1_fq(const big_secp256k1_fq& bigint, uint32_t bigint_id) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp index 16407db507ec..73e9fe855341 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp @@ -2,6 +2,7 @@ #include "acir_format.hpp" #include "acir_format_mocks.hpp" #include "barretenberg/circuit_checker/circuit_checker.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" #include @@ -65,7 +66,7 @@ generate_big_int_op_constraint_with_modulus( value = witness_values[lhs_id] / witness_values[rhs_id]; break; default: - ASSERT(false); + throw_or_abort("Unexpected BigIntOperationType."); break; } @@ -148,7 +149,7 @@ std::tuple generate_big_int_op_constraint_with value = witness_values[lhs_id] / witness_values[rhs_id]; break; default: - ASSERT(false); + throw_or_abort("Unexpected BigIntOperationType."); break; } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake3_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake3_constraint.cpp index 54256420d6d5..c5d55c36732a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake3_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake3_constraint.cpp @@ -5,6 +5,7 @@ // ===================== #include "blake3_constraint.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/stdlib/hash/blake3s/blake3s.hpp" #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" #include "round.hpp" @@ -27,7 +28,7 @@ template void create_blake3_constraints(Builder& builder, con // XXX: The implementation requires us to truncate the element to the nearest byte and not bit auto num_bytes = round_to_nearest_byte(num_bits); - ASSERT(num_bytes <= 1024, "barretenberg does not support blake3 inputs with more than 1024 bytes"); + BB_ASSERT_LTE(num_bytes, 1024U, "barretenberg does not support blake3 inputs with more than 1024 bytes"); field_ct element = to_field_ct(witness_index, builder); byte_array_ct element_bytes(element, num_bytes); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp index bce8a1a210ae..fc069279eafc 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp @@ -5,6 +5,8 @@ // ===================== #include "block_constraint.hpp" +#include "barretenberg/common/assert.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/stdlib/primitives/databus/databus.hpp" #include "barretenberg/stdlib/primitives/memory/ram_table.hpp" #include "barretenberg/stdlib/primitives/memory/rom_table.hpp" @@ -17,9 +19,9 @@ template stdlib::field_t poly_to_field_ct(const poly { using field_ct = stdlib::field_t; - ASSERT(poly.q_m == 0); - ASSERT(poly.q_r == 0); - ASSERT(poly.q_o == 0); + BB_ASSERT_EQ(poly.q_m, 0); + BB_ASSERT_EQ(poly.q_r, 0); + BB_ASSERT_EQ(poly.q_o, 0); if (poly.q_l == 0) { return field_ct(poly.q_c); } @@ -58,7 +60,7 @@ void create_block_constraints(UltraCircuitBuilder& builder, process_RAM_operations(builder, constraint, has_valid_witness_assignments, init); } break; default: - ASSERT(false); + throw_or_abort("Unexpected block constraint type."); break; } } @@ -94,7 +96,7 @@ void create_block_constraints(MegaCircuitBuilder& builder, process_return_data_operations(constraint, init); } break; default: - ASSERT(false); + throw_or_abort("Unexpected block constraint type."); break; } } @@ -110,7 +112,7 @@ void process_ROM_operations(Builder& builder, rom_table_ct table(init); for (auto& op : constraint.trace) { - ASSERT(op.access_type == 0); + BB_ASSERT_EQ(op.access_type, 0); field_ct value = poly_to_field_ct(op.value, builder); field_ct index = poly_to_field_ct(op.index, builder); // For a ROM table, constant read should be optimized out: @@ -152,7 +154,7 @@ void process_RAM_operations(Builder& builder, if (op.access_type == 0) { value.assert_equal(table.read(index)); } else { - ASSERT(op.access_type == 1); + BB_ASSERT_EQ(op.access_type, 1); table.write(index, value); } } @@ -174,7 +176,7 @@ void process_call_data_operations(Builder& builder, calldata_array.set_values(init); // Initialize the data in the bus array for (const auto& op : constraint.trace) { - ASSERT(op.access_type == 0); + BB_ASSERT_EQ(op.access_type, 0); field_ct value = poly_to_field_ct(op.value, builder); field_ct index = poly_to_field_ct(op.index, builder); fr w_value = 0; @@ -194,8 +196,7 @@ void process_call_data_operations(Builder& builder, } else if (constraint.calldata_id == 1) { process_calldata(databus.secondary_calldata); } else { - info("Databus only supports two calldata arrays."); - ASSERT(false); + throw_or_abort("Databus only supports two calldata arrays."); } } @@ -215,7 +216,7 @@ void process_return_data_operations(const BlockConstraint& constraint, std::vect value.assert_equal(databus.return_data[c]); c++; } - ASSERT(constraint.trace.size() == 0); + BB_ASSERT_EQ(constraint.trace.size(), 0U); } } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp index f99d51116669..8fcc98eacc7d 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp @@ -5,6 +5,7 @@ // ===================== #include "honk_recursion_constraint.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/constants.hpp" #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/flavor/ultra_recursive_flavor.hpp" @@ -222,7 +223,7 @@ HonkRecursionConstraintOutput create_honk_recur using RecursiveVerifier = bb::stdlib::recursion::honk::UltraRecursiveVerifier_; ASSERT(input.proof_type == HONK || input.proof_type == HONK_ZK || HasIPAAccumulator); - ASSERT((input.proof_type == ROLLUP_HONK || input.proof_type == ROOT_ROLLUP_HONK) == HasIPAAccumulator); + BB_ASSERT_EQ(input.proof_type == ROLLUP_HONK || input.proof_type == ROOT_ROLLUP_HONK, HasIPAAccumulator); // Construct an in-circuit representation of the verification key. // For now, the v-key is a circuit constant and is fixed for the circuit. diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.cpp index 96f90112fa7d..9680f8189cc2 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.cpp @@ -5,6 +5,8 @@ // ===================== #include "ivc_recursion_constraint.hpp" +#include "barretenberg/common/assert.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/dsl/acir_format/mock_verifier_inputs.hpp" #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/flavor/ultra_recursive_flavor.hpp" @@ -61,14 +63,15 @@ std::shared_ptr create_mock_ivc_from_constraints(const std::vectorverifier_accumulator = create_mock_decider_vk(); mock_ivc_accumulation(ivc, ClientIVC::QUEUE_TYPE::PG, /*is_kernel=*/true); mock_ivc_accumulation(ivc, ClientIVC::QUEUE_TYPE::PG, /*is_kernel=*/false); return ivc; } - ASSERT(false && "WARNING: Invalid set of IVC recursion constraints!"); + throw_or_abort("Invalid set of IVC recursion constraints!"); return ivc; } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.cpp index 5f2bfd23bbc1..caca2c4cead3 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.cpp @@ -50,4 +50,4 @@ template void create_poseidon2_permutations(UltraCircuitBui template void create_poseidon2_permutations(MegaCircuitBuilder& builder, const Poseidon2Constraint& constraint); -} // namespace acir_format \ No newline at end of file +} // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp b/barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp index 24509e905b60..12049bc7d154 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp @@ -5,6 +5,8 @@ // ===================== #include "barretenberg/ecc/batched_affine_addition/batched_affine_addition.hpp" +#include "barretenberg/common/assert.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/common/zip_view.hpp" #include #include @@ -59,8 +61,7 @@ typename BatchedAffineAddition::ThreadData BatchedAffineAddition:: } if (points.size() != total_count) { - info("Number of input points does not match sequence counts!"); - ASSERT(false); + throw_or_abort("Number of input points does not match sequence counts!"); } // Determine the optimal number of threads for parallelization @@ -119,8 +120,7 @@ typename BatchedAffineAddition::ThreadData BatchedAffineAddition:: } if (thread_sequence_counts.size() != thread_points.size()) { - info("Mismatch in sequence count construction!"); - ASSERT(false); + throw_or_abort("Mismatch in sequence count construction!"); } // Construct the addition sequences for each thread @@ -147,7 +147,7 @@ std::span::Fq> BatchedAffineAddition< } // Define scratch space for batched inverse computations and eventual storage of denominators - ASSERT(add_sequences.scratch_space.size() >= 2 * total_num_pairs); + BB_ASSERT_GTE(add_sequences.scratch_space.size(), 2 * total_num_pairs); std::span denominators = add_sequences.scratch_space.subspan(0, total_num_pairs); std::span differences = add_sequences.scratch_space.subspan(total_num_pairs, 2 * total_num_pairs); @@ -158,7 +158,7 @@ std::span::Fq> BatchedAffineAddition< for (auto& count : sequence_counts) { const auto num_pairs = count >> 1; for (size_t j = 0; j < num_pairs; ++j) { - ASSERT(pair_idx < total_num_pairs); + BB_ASSERT_LT(pair_idx, total_num_pairs); const auto& x1 = points[point_idx++].x; const auto& x2 = points[point_idx++].x; diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/fq.test.cpp b/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/fq.test.cpp index eb7c91434544..3e571de9334f 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/fq.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/fq.test.cpp @@ -121,7 +121,7 @@ TEST(fq, MulShortIntegers) uint256_t prod_expected = (uint512_t(a_original) * uint512_t(b_original) % uint512_t(fq::modulus)).lo; fq const_expected = prod_expected; constexpr fq const_result = a * b; - ASSERT(const_result == const_expected); + ASSERT_EQ(const_result, const_expected); fq c; fq d; diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field_conversion.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field_conversion.hpp index d28fce9565dc..e7189d972563 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field_conversion.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field_conversion.hpp @@ -6,6 +6,7 @@ #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/curves/bn254/bn254.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp index c676cca9a7bc..1a5241c30b9a 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp @@ -137,7 +137,7 @@ template struct alignas(32) field { constexpr explicit operator bool() const { field out = from_montgomery_form(); - ASSERT(out.data[0] == 0 || out.data[0] == 1); + ASSERT_IN_CONSTEXPR(out.data[0] == 0 || out.data[0] == 1); return static_cast(out.data[0]); } @@ -280,9 +280,9 @@ template struct alignas(32) field { return result; } - static constexpr field coset_generator(const size_t idx) + template static constexpr field coset_generator() { - ASSERT(idx < 7); + static_assert(idx < 7); #if defined(__SIZEOF_INT128__) && !defined(__wasm__) const field result{ Params::coset_generators_0[idx], diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp index fc1f43a35683..6759ffa76216 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/op_count.hpp" #include "barretenberg/common/slab_allocator.hpp" #include "barretenberg/common/throw_or_abort.hpp" @@ -501,8 +502,8 @@ template constexpr field field::tonelli_shanks_sqrt() const noex return 0; } - constexpr field g = coset_generator(0).pow(Q); - constexpr field g_inv = coset_generator(0).pow(modulus - 1 - Q); + constexpr field g = coset_generator<0>().pow(Q); + constexpr field g_inv = coset_generator<0>().pow(modulus - 1 - Q); constexpr size_t root_bits = primitive_root_log_size(); constexpr size_t table_bits = 6; constexpr size_t num_tables = root_bits / table_bits + (root_bits % table_bits != 0 ? 1 : 0); @@ -590,7 +591,7 @@ template constexpr field field::tonelli_shanks_sqrt() const noex } } - ASSERT(count != table_size); + ASSERT_IN_CONSTEXPR(count != table_size); e_slices[table_index] = count; } diff --git a/barretenberg/cpp/src/barretenberg/ecc/groups/element_impl.hpp b/barretenberg/cpp/src/barretenberg/ecc/groups/element_impl.hpp index cb19babee9e6..d9d834367380 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/groups/element_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/groups/element_impl.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/op_count.hpp" #include "barretenberg/common/thread.hpp" #include "barretenberg/ecc/groups/element.hpp" @@ -726,7 +727,7 @@ void element::batch_affine_add(const std::span affine_element; const size_t num_points = first_group.size(); - ASSERT(second_group.size() == first_group.size()); + BB_ASSERT_EQ(second_group.size(), first_group.size()); // Space for temporary values std::vector scratch_space(num_points); diff --git a/barretenberg/cpp/src/barretenberg/ecc/groups/group_impl_asm.tcc b/barretenberg/cpp/src/barretenberg/ecc/groups/group_impl_asm.tcc index ad2d8b34d995..2177ba1ad37a 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/groups/group_impl_asm.tcc +++ b/barretenberg/cpp/src/barretenberg/ecc/groups/group_impl_asm.tcc @@ -71,8 +71,8 @@ inline void group::conditional_negate_affine(const affine_elemen if constexpr (Params::small_elements) { #if defined __AVX__ && defined USE_AVX - ASSERT((((uintptr_t)src & 0x1f) == 0)); - ASSERT((((uintptr_t)dest & 0x1f) == 0)); + BB_ASSERT_EQ(((uintptr_t)src & 0x1f, 0)); + BB_ASSERT_EQ(((uintptr_t)dest & 0x1f, 0)); __asm__ __volatile__("xorq %%r8, %%r8 \n\t" "movq 32(%0), %%r8 \n\t" "movq 40(%0), %%r9 \n\t" diff --git a/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/bitvector.hpp b/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/bitvector.hpp index c132d78db268..e9c6b624c1b3 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/bitvector.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/bitvector.hpp @@ -21,7 +21,7 @@ class BitVector { BB_INLINE void set(size_t index, bool value) noexcept { - ASSERT(index < num_bits_); + BB_ASSERT_LT(index, num_bits_); const size_t word = index >> 6; const size_t bit = index & 63; @@ -35,7 +35,7 @@ class BitVector { BB_INLINE bool get(size_t index) const noexcept { - ASSERT(index < num_bits_); + BB_ASSERT_LT(index, num_bits_); const uint64_t word = index >> 6; const uint64_t bit = index & 63; return ((data_[static_cast(word)] >> bit) & 1) == 1; diff --git a/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.cpp b/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.cpp index c480c0e1673e..d65f93b7a8ab 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.cpp @@ -3,6 +3,7 @@ // external_1: { status: not started, auditors: [], date: YYYY-MM-DD } // external_2: { status: not started, auditors: [], date: YYYY-MM-DD } // ===================== +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/groups/precomputed_generators_bn254_impl.hpp" #include "barretenberg/ecc/groups/precomputed_generators_grumpkin_impl.hpp" @@ -764,7 +765,7 @@ std::vector MSM::batch_multi_scalar_mul( std::vector>& scalars, bool handle_edge_cases) noexcept { - ASSERT(points.size() == scalars.size()); + BB_ASSERT_EQ(points.size(), scalars.size()); const size_t num_msms = points.size(); std::vector> msm_scalar_indices; diff --git a/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.test.cpp b/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.test.cpp index 9af2e896c7dc..c7bb07aebcf7 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.test.cpp @@ -65,7 +65,7 @@ template class ScalarMultiplicationTest : public ::testing::Test { } }); for (size_t i = 0; i < num_points - 1; ++i) { - BB_ASSERT_EQ(generators[i].x == generators[i + 1].x, false); + ASSERT_EQ(generators[i].x == generators[i + 1].x, false); } }; }; @@ -315,7 +315,7 @@ TYPED_TEST(ScalarMultiplicationTest, EvaluatePippengerRound) Element previous_round_output; previous_round_output.self_set_infinity(); for (auto x : indices) { - BB_ASSERT_LT(x, num_points); + ASSERT_LT(x, num_points); } std::vector point_schedule(scalars.size()); typename scalar_multiplication::MSM::MSMData msm_data( @@ -369,7 +369,7 @@ TYPED_TEST(ScalarMultiplicationTest, BatchMultiScalarMul) for (size_t k = 0; k < num_msms; ++k) { const size_t num_points = static_cast(engine.get_random_uint16()) % 400; - BB_ASSERT_LT(vector_offset + num_points, TestFixture::num_points); + ASSERT_LT(vector_offset + num_points, TestFixture::num_points); std::span batch_scalars(&TestFixture::scalars[vector_offset], num_points); std::span batch_points(&TestFixture::generators[vector_offset], num_points); diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp index 61e7e6ee6644..bdcc69cd888f 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_circuit_builder.hpp @@ -10,6 +10,7 @@ #include "./msm_builder.hpp" #include "./precomputed_tables_builder.hpp" #include "./transcript_builder.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/constants.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" @@ -105,7 +106,7 @@ class ECCVMCircuitBuilder { scalar = scalar >> NUM_WNAF_DIGIT_BITS; } - ASSERT(scalar == 0); + BB_ASSERT_EQ(scalar, 0U); output[0] = previous_slice; @@ -151,8 +152,8 @@ class ECCVMCircuitBuilder { const auto& op = eccvm_ops[msm_opqueue_index[i]]; auto [msm_index, mul_index] = msm_mul_index[i]; if (op.z1 != 0 && !op.base_point.is_point_at_infinity()) { - ASSERT(result.size() > msm_index); - ASSERT(result[msm_index].size() > mul_index); + BB_ASSERT_GT(result.size(), msm_index); + BB_ASSERT_GT(result[msm_index].size(), mul_index); result[msm_index][mul_index] = (ScalarMul{ .pc = 0, .scalar = op.z1, @@ -164,8 +165,8 @@ class ECCVMCircuitBuilder { mul_index++; } if (op.z2 != 0 && !op.base_point.is_point_at_infinity()) { - ASSERT(result.size() > msm_index); - ASSERT(result[msm_index].size() > mul_index); + BB_ASSERT_GT(result.size(), msm_index); + BB_ASSERT_GT(result[msm_index].size(), mul_index); auto endo_point = AffineElement{ op.base_point.x * FF::cube_root_of_unity(), -op.base_point.y }; result[msm_index][mul_index] = (ScalarMul{ .pc = 0, @@ -195,7 +196,7 @@ class ECCVMCircuitBuilder { } } - ASSERT(pc == 0); + BB_ASSERT_EQ(pc, 0U); return result; } diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp index ebd8808c16b2..89e262554155 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp @@ -6,6 +6,7 @@ #pragma once #include "barretenberg/commitment_schemes/ipa/ipa.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/std_array.hpp" #include "barretenberg/ecc/curves/bn254/bn254.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" @@ -1048,7 +1049,7 @@ class ECCVMFlavor { serialize_to_buffer(ipa_G_0_eval, proof_data); serialize_to_buffer(ipa_a_0_eval, proof_data); - ASSERT(NativeTranscript::proof_data.size() == old_proof_length); + BB_ASSERT_EQ(NativeTranscript::proof_data.size(), old_proof_length); } }; }; diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_transcript.test.cpp index 1168044052d0..fa7c15a4f72e 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_transcript.test.cpp @@ -300,7 +300,7 @@ TEST_F(ECCVMTranscriptTests, ProverManifestConsistency) auto prover_manifest = prover.transcript->get_manifest(); // Note: a manifest can be printed using manifest.print() - ASSERT(manifest_expected.size() > 0); + ASSERT_GT(manifest_expected.size(), 0); for (size_t round = 0; round < manifest_expected.size(); ++round) { ASSERT_EQ(prover_manifest[round], manifest_expected[round]) << "Prover manifest discrepency in round " << round; } @@ -309,7 +309,7 @@ TEST_F(ECCVMTranscriptTests, ProverManifestConsistency) auto prover_ipa_manifest = prover.ipa_transcript->get_manifest(); // Note: a manifest can be printed using manifest.print() - ASSERT(ipa_manifest_expected.size() > 0); + ASSERT_GT(ipa_manifest_expected.size(), 0); for (size_t round = 0; round < ipa_manifest_expected.size(); ++round) { ASSERT_EQ(prover_ipa_manifest[round], ipa_manifest_expected[round]) << "IPA prover manifest discrepency in round " << round; @@ -348,7 +348,7 @@ TEST_F(ECCVMTranscriptTests, VerifierManifestConsistency) // The last challenge generated by the ECCVM Prover is the translation univariate batching challenge and, on the // verifier side, is only generated in the translator verifier hence the ECCVM prover's manifest will have one extra // challenge - ASSERT(prover_manifest.size() > 0); + ASSERT_GT(prover_manifest.size(), 0); for (size_t round = 0; round < prover_manifest.size() - 1; ++round) { ASSERT_EQ(prover_manifest[round], verifier_manifest[round]) << "Prover/Verifier manifest discrepency in round " << round; @@ -357,7 +357,7 @@ TEST_F(ECCVMTranscriptTests, VerifierManifestConsistency) // Check consistency of IPA transcripts auto prover_ipa_manifest = prover.ipa_transcript->get_manifest(); auto verifier_ipa_manifest = verifier.ipa_transcript->get_manifest(); - ASSERT(prover_ipa_manifest.size() > 0); + ASSERT_GT(prover_ipa_manifest.size(), 0); for (size_t round = 0; round < prover_ipa_manifest.size(); ++round) { ASSERT_EQ(prover_ipa_manifest[round], verifier_ipa_manifest[round]) << "Prover/Verifier IPA manifest discrepency in round " << round; @@ -387,4 +387,4 @@ TEST_F(ECCVMTranscriptTests, ChallengeGenerationTest) ASSERT_NE(a, 0) << "Challenge a is 0"; ASSERT_NE(b, 0) << "Challenge b is 0"; ASSERT_NE(c, 0) << "Challenge c is 0"; -} \ No newline at end of file +} diff --git a/barretenberg/cpp/src/barretenberg/eccvm/msm_builder.hpp b/barretenberg/cpp/src/barretenberg/eccvm/msm_builder.hpp index ed10c53e421c..d2d63362153b 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/msm_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/msm_builder.hpp @@ -9,6 +9,7 @@ #include #include "./eccvm_builder_types.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/groups/precomputed_generators_bn254_impl.hpp" #include "barretenberg/op_queue/ecc_op_queue.hpp" @@ -135,7 +136,7 @@ class ECCVMMSMMBuilder { msm_row_counts.push_back(msm_row_counts.back() + num_rows_required); pc_values.push_back(pc_values.back() - msm.size()); } - ASSERT(pc_values.back() == 0); + BB_ASSERT_EQ(pc_values.back(), 0U); // compute the MSM rows @@ -383,7 +384,7 @@ class ECCVMMSMMBuilder { for (size_t row_idx = 0; row_idx < num_rows_per_digit; ++row_idx) { auto& row = msm_rows[msm_row_index]; const Element& normalized_accumulator = accumulator_trace[accumulator_index]; - ASSERT(normalized_accumulator.is_point_at_infinity() == 0); + BB_ASSERT_EQ(normalized_accumulator.is_point_at_infinity(), 0); row.accumulator_x = normalized_accumulator.x; row.accumulator_y = normalized_accumulator.y; for (size_t point_idx = 0; point_idx < ADDITIONS_PER_ROW; ++point_idx) { @@ -420,7 +421,7 @@ class ECCVMMSMMBuilder { for (size_t row_idx = 0; row_idx < num_rows_per_digit; ++row_idx) { MSMRow& row = msm_rows[msm_row_index]; const Element& normalized_accumulator = accumulator_trace[accumulator_index]; - ASSERT(normalized_accumulator.is_point_at_infinity() == 0); + BB_ASSERT_EQ(normalized_accumulator.is_point_at_infinity(), 0); const size_t offset = row_idx * ADDITIONS_PER_ROW; row.accumulator_x = normalized_accumulator.x; row.accumulator_y = normalized_accumulator.y; diff --git a/barretenberg/cpp/src/barretenberg/eccvm/precomputed_tables_builder.hpp b/barretenberg/cpp/src/barretenberg/eccvm/precomputed_tables_builder.hpp index a8b92d3caf49..cf1cf7239f9f 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/precomputed_tables_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/precomputed_tables_builder.hpp @@ -7,6 +7,7 @@ #pragma once #include "./eccvm_builder_types.hpp" +#include "barretenberg/common/assert.hpp" namespace bb { @@ -102,7 +103,7 @@ class ECCVMPointTablePrecomputationBuilder { row.pc = entry.pc; if (last_row) { - ASSERT(scalar_sum - entry.wnaf_skew == entry.scalar); + ASSERT(scalar_sum - entry.wnaf_skew, entry.scalar); } row.precompute_double = entry.precomputed_table[bb::eccvm::POINT_TABLE_SIZE]; @@ -115,4 +116,4 @@ class ECCVMPointTablePrecomputationBuilder { return precompute_state; } }; -} // namespace bb \ No newline at end of file +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/ext/starknet/flavor/ultra_starknet_zk_flavor.hpp b/barretenberg/cpp/src/barretenberg/ext/starknet/flavor/ultra_starknet_zk_flavor.hpp index 8fe463bef473..31ed20ad5d17 100644 --- a/barretenberg/cpp/src/barretenberg/ext/starknet/flavor/ultra_starknet_zk_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/ext/starknet/flavor/ultra_starknet_zk_flavor.hpp @@ -148,7 +148,7 @@ class UltraStarknetZKFlavor : public UltraKeccakZKFlavor { Base::template serialize_to_buffer(this->shplonk_q_comm, proof_data); Base::template serialize_to_buffer(this->kzg_w_comm, proof_data); - ASSERT(proof_data.size() == old_proof_length); + BB_ASSERT_EQ(proof_data.size(), old_proof_length); } }; }; diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 7729811a8b10..85261fce212e 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -70,6 +70,7 @@ */ #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/ref_vector.hpp" #include "barretenberg/common/std_array.hpp" #include "barretenberg/common/std_vector.hpp" @@ -102,7 +103,7 @@ namespace bb { struct ActiveRegionData { void add_range(const size_t start, const size_t end) { - ASSERT(start >= current_end); // ranges should be non-overlapping and increasing + BB_ASSERT_GTE(start, current_end, "Ranges should be non-overlapping and increasing."); ranges.emplace_back(start, end); for (size_t i = start; i < end; ++i) { idxs.push_back(i); diff --git a/barretenberg/cpp/src/barretenberg/flavor/grand_product_library.test.cpp b/barretenberg/cpp/src/barretenberg/flavor/grand_product_library.test.cpp index ce4307dba358..d7b860df4030 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/grand_product_library.test.cpp +++ b/barretenberg/cpp/src/barretenberg/flavor/grand_product_library.test.cpp @@ -1,4 +1,3 @@ - #include "barretenberg/honk/library/grand_product_library.hpp" #include "barretenberg/ecc/curves/bn254/bn254.hpp" #include "barretenberg/flavor/ultra_flavor.hpp" @@ -15,7 +14,7 @@ template class GrandProductTests : public testing::Test { static void populate_span(auto& polynomial_view, const auto& polynomial) { - ASSERT(polynomial_view.size() <= polynomial.size()); + ASSERT_LE(polynomial_view.size(), polynomial.size()); for (size_t idx = 0; idx < polynomial.size(); idx++) { polynomial_view[idx] = polynomial[idx]; } diff --git a/barretenberg/cpp/src/barretenberg/flavor/mega_recursive_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/mega_recursive_flavor.hpp index 44ec55f925f1..f98527748879 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/mega_recursive_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/mega_recursive_flavor.hpp @@ -7,6 +7,7 @@ #pragma once #include "barretenberg/commitment_schemes/commitment_key.hpp" #include "barretenberg/commitment_schemes/kzg/kzg.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/flavor/flavor_macros.hpp" @@ -157,8 +158,7 @@ template class MegaRecursiveFlavor_ { } if (num_frs_read != elements.size()) { - info("Warning: Invalid buffer length in VerificationKey constuctor from fields!"); - ASSERT(false); + throw_or_abort("Invalid buffer length in VerificationKey constuctor from fields!"); } } diff --git a/barretenberg/cpp/src/barretenberg/flavor/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/ultra_flavor.hpp index 637b307ec7e2..98a1ddd757c8 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra_flavor.hpp @@ -6,6 +6,7 @@ #pragma once #include "barretenberg/commitment_schemes/kzg/kzg.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/flavor/flavor_macros.hpp" @@ -450,7 +451,7 @@ class UltraFlavor { Base::template serialize_to_buffer(kzg_w_comm, proof_data); // sanity check to make sure we generate the same length of proof as before. - ASSERT(proof_data.size() == old_proof_length); + BB_ASSERT_EQ(proof_data.size(), old_proof_length); } }; diff --git a/barretenberg/cpp/src/barretenberg/flavor/ultra_keccak_zk_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/ultra_keccak_zk_flavor.hpp index 06680d77c015..1d2750dfa2a3 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra_keccak_zk_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra_keccak_zk_flavor.hpp @@ -6,6 +6,7 @@ #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/flavor/ultra_keccak_flavor.hpp" namespace bb { @@ -180,7 +181,7 @@ class UltraKeccakZKFlavor : public UltraKeccakFlavor { Base::template serialize_to_buffer(this->shplonk_q_comm, proof_data); Base::template serialize_to_buffer(this->kzg_w_comm, proof_data); - ASSERT(proof_data.size() == old_proof_length); + BB_ASSERT_EQ(proof_data.size(), old_proof_length); } }; }; diff --git a/barretenberg/cpp/src/barretenberg/flavor/ultra_zk_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/ultra_zk_flavor.hpp index 768eb821bc7a..780ec6de3dd8 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra_zk_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra_zk_flavor.hpp @@ -6,6 +6,7 @@ #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/flavor/ultra_flavor.hpp" namespace bb { @@ -190,7 +191,7 @@ class UltraZKFlavor : public UltraFlavor { Base::template serialize_to_buffer(this->shplonk_q_comm, proof_data); Base::template serialize_to_buffer(this->kzg_w_comm, proof_data); - ASSERT(proof_data.size() == old_proof_length); + BB_ASSERT_EQ(proof_data.size(), old_proof_length); } }; using Transcript = Transcript_; diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.cpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.cpp index 01e6af5696df..23fefa3815ea 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.cpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.cpp @@ -6,6 +6,7 @@ #include "goblin.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/eccvm/eccvm_verifier.hpp" #include "barretenberg/translator_vm/translator_prover.hpp" #include "barretenberg/translator_vm/translator_proving_key.hpp" @@ -53,8 +54,9 @@ GoblinProof Goblin::prove() info("Constructing a Goblin proof with num ultra ops = ", op_queue->get_ultra_ops_table_num_rows()); prove_merge(transcript); // Use shared transcript for merge proving - ASSERT(merge_verification_queue.size() == 1, - "Goblin::prove: merge_verification_queue should contain only a single proof at this stage."); + BB_ASSERT_EQ(merge_verification_queue.size(), + 1U, + "Goblin::prove: merge_verification_queue should contain only a single proof at this stage."); goblin_proof.merge_proof = merge_verification_queue.back(); { diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/honk/composer/composer_lib.hpp index 49d5d4d482d9..c2dff52f3b31 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/composer_lib.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/ref_array.hpp" #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/polynomials/polynomial_store.hpp" @@ -29,7 +30,7 @@ void construct_lookup_table_polynomials(const RefArray tables_size + additional_offset); + BB_ASSERT_GT(dyadic_circuit_size, tables_size + additional_offset); size_t offset = circuit.blocks.lookup.trace_offset(); for (const auto& table : circuit.lookup_tables) { diff --git a/barretenberg/cpp/src/barretenberg/honk/execution_trace/execution_trace_block.hpp b/barretenberg/cpp/src/barretenberg/honk/execution_trace/execution_trace_block.hpp index 4c62669f4f23..ae1551de4995 100644 --- a/barretenberg/cpp/src/barretenberg/honk/execution_trace/execution_trace_block.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/execution_trace/execution_trace_block.hpp @@ -5,9 +5,11 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/mem.hpp" #include "barretenberg/common/ref_array.hpp" #include "barretenberg/common/slab_allocator.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include #ifdef CHECK_CIRCUIT_STACKTRACES diff --git a/barretenberg/cpp/src/barretenberg/honk/execution_trace/ultra_execution_trace.hpp b/barretenberg/cpp/src/barretenberg/honk/execution_trace/ultra_execution_trace.hpp index f6609b1e4620..cae6a9a5e518 100644 --- a/barretenberg/cpp/src/barretenberg/honk/execution_trace/ultra_execution_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/execution_trace/ultra_execution_trace.hpp @@ -7,6 +7,7 @@ #pragma once #include "barretenberg/common/ref_vector.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/honk/execution_trace/execution_trace_block.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" @@ -109,8 +110,7 @@ class UltraExecutionTraceBlocks : public UltraTraceBlockData { void compute_offsets(bool is_structured) { if (is_structured) { - info("Trace is structuring not implemented for UltraHonk"); - ASSERT(false); + throw_or_abort("Trace is structuring not implemented for UltraHonk"); } uint32_t offset = 1; // start at 1 because the 0th row is unused for selectors for Honk for (auto& block : this->get()) { diff --git a/barretenberg/cpp/src/barretenberg/honk/library/grand_product_library.hpp b/barretenberg/cpp/src/barretenberg/honk/library/grand_product_library.hpp index 6b394033b6ae..6ce4274920b4 100644 --- a/barretenberg/cpp/src/barretenberg/honk/library/grand_product_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/library/grand_product_library.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/common/debug_log.hpp" #include "barretenberg/common/thread.hpp" @@ -179,7 +180,7 @@ void compute_grand_product(typename Flavor::ProverPolynomials& full_polynomials, // Step (3) Compute z_perm[i] = numerator[i] / denominator[i] auto& grand_product_polynomial = GrandProdRelation::get_grand_product_polynomial(full_polynomials); // We have a 'virtual' 0 at the start (as this is a to-be-shifted polynomial) - ASSERT(grand_product_polynomial.start_index() == 1); + BB_ASSERT_EQ(grand_product_polynomial.start_index(), 1U); // For Ultra/Mega, the first row is an inactive zero row thus the grand prod takes value 1 at both i = 0 and i = 1 if constexpr (IsUltraOrMegaHonk) { diff --git a/barretenberg/cpp/src/barretenberg/honk/relation_checker.hpp b/barretenberg/cpp/src/barretenberg/honk/relation_checker.hpp index 17fac043dbc7..67f014deb341 100644 --- a/barretenberg/cpp/src/barretenberg/honk/relation_checker.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/relation_checker.hpp @@ -50,25 +50,17 @@ template class RelationChecker { for (auto& element : result) { if constexpr (has_linearly_dependent) { if (element != 0 && Relation::SUBRELATION_LINEARLY_INDEPENDENT[subrelation_idx]) { - info("RelationChecker: ", - label, - " relation (subrelation idx: ", - subrelation_idx, - ") failed at row idx: ", - i, - "."); - ASSERT(false); + std::ostringstream oss; + oss << "RelationChecker: " << label << " relation (subrelation idx: " << subrelation_idx + << ") failed at row idx: " << i << "."; + throw_or_abort(oss.str()); } } else { if (element != 0) { - info("RelationChecker: ", - label, - " relation (subrelation idx: ", - subrelation_idx, - ") failed at row idx: ", - i, - "."); - ASSERT(false); + std::ostringstream oss; + oss << "RelationChecker: " << label << " relation (subrelation idx: " << subrelation_idx + << ") failed at row idx: " << i << "."; + throw_or_abort(oss.str()); } } subrelation_idx++; @@ -80,12 +72,10 @@ template class RelationChecker { for (auto& element : result) { // Check that linearly dependent subrelation result is 0 over the entire execution trace if (element != 0 && Relation::SUBRELATION_LINEARLY_INDEPENDENT[subrelation_idx]) { - info("RelationChecker: ", - label, - " linearly dependent subrelation idx: ", - subrelation_idx, - " failed."); - ASSERT(false); + std::ostringstream oss; + oss << "RelationChecker: " << label << " linearly dependent subrelation idx: " << subrelation_idx + << ") failed."; + throw_or_abort(oss.str()); } subrelation_idx++; } @@ -133,4 +123,4 @@ template <> class RelationChecker : public RelationChecker { }; } // namespace bb -// namespace bb \ No newline at end of file +// namespace bb diff --git a/barretenberg/cpp/src/barretenberg/numeric/general/general.hpp b/barretenberg/cpp/src/barretenberg/numeric/general/general.hpp index c77855b4b7dc..c92b4ce83be9 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/general/general.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/general/general.hpp @@ -6,6 +6,7 @@ #pragma once +#include "barretenberg/common/assert.hpp" #include namespace bb::numeric { @@ -21,7 +22,7 @@ namespace bb::numeric { */ template constexpr T ceil_div(const T& numerator, const T& denominator) { - ASSERT(denominator > 0, "Denominator must be greater than zero."); + ASSERT_IN_CONSTEXPR(denominator > 0, "Denominator must be greater than zero."); static_assert(std::is_integral_v, "Type must be an integral type."); return (numerator + denominator - 1) / denominator; } diff --git a/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128_impl.hpp b/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128_impl.hpp index 445cba509a31..e41ce888f2fc 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/uint128/uint128_impl.hpp @@ -190,7 +190,7 @@ constexpr uint128_t uint128_t::pow(const uint128_t& exponent) const constexpr bool uint128_t::get_bit(const uint64_t bit_index) const { - ASSERT(bit_index < 128); + ASSERT_IN_CONSTEXPR(bit_index < 128); if (bit_index > 127) { return false; } diff --git a/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256_impl.hpp b/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256_impl.hpp index 85ae78bdb7ce..72bb884e6a8f 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/uint256/uint256_impl.hpp @@ -317,7 +317,7 @@ constexpr uint256_t uint256_t::pow(const uint256_t& exponent) const constexpr bool uint256_t::get_bit(const uint64_t bit_index) const { - ASSERT(bit_index < 256); + ASSERT_IN_CONSTEXPR(bit_index < 256); if (bit_index > 255) { return static_cast(0); } diff --git a/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx_impl.hpp b/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx_impl.hpp index 197a53bdcb40..9f3906c06fa5 100644 --- a/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/numeric/uintx/uintx_impl.hpp @@ -308,7 +308,7 @@ std::pair, uintx> uintx::barrett_reductio // TODO(https://github.com/AztecProtocol/barretenberg/issues/1051): investigate, why) size_t i = 0; while (remainder >= uintx(modulus)) { - ASSERT(i < 4); + BB_ASSERT_LT(i, 4U); remainder = remainder - modulus; quotient = quotient + 1; i++; diff --git a/barretenberg/cpp/src/barretenberg/op_queue/ecc_ops_table.hpp b/barretenberg/cpp/src/barretenberg/op_queue/ecc_ops_table.hpp index 712a48437fba..e7b1476156b4 100644 --- a/barretenberg/cpp/src/barretenberg/op_queue/ecc_ops_table.hpp +++ b/barretenberg/cpp/src/barretenberg/op_queue/ecc_ops_table.hpp @@ -6,6 +6,7 @@ #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/curves/bn254/bn254.hpp" #include "barretenberg/eccvm/eccvm_builder_types.hpp" #include "barretenberg/polynomials/polynomial.hpp" @@ -139,7 +140,7 @@ template class EccOpsTable { // const version of operator[] const OpFormat& operator[](size_t index) const { - ASSERT(index < size()); + BB_ASSERT_LT(index, size()); // simple linear search to find the correct subtable for (const auto& subtable : table) { if (index < subtable.size()) { diff --git a/barretenberg/cpp/src/barretenberg/op_queue/ecc_ops_table.test.cpp b/barretenberg/cpp/src/barretenberg/op_queue/ecc_ops_table.test.cpp index 1e4f011a0d7d..00cb81e4eb9e 100644 --- a/barretenberg/cpp/src/barretenberg/op_queue/ecc_ops_table.test.cpp +++ b/barretenberg/cpp/src/barretenberg/op_queue/ecc_ops_table.test.cpp @@ -1,4 +1,5 @@ #include "barretenberg/op_queue/ecc_ops_table.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/zip_view.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include @@ -17,7 +18,7 @@ class EccOpsTableTest : public ::testing::Test { virtual Op generate_random_op() const = 0; std::vector> generate_subtables(size_t num_subtables, std::vector ops_per_table) { - ASSERT(num_subtables == ops_per_table.size()); + BB_ASSERT_EQ(num_subtables, ops_per_table.size()); std::vector> subtables; subtables.reserve(num_subtables); for (size_t i = 0; i < num_subtables; ++i) { diff --git a/barretenberg/cpp/src/barretenberg/polynomials/evaluation_domain.cpp b/barretenberg/cpp/src/barretenberg/polynomials/evaluation_domain.cpp index c6f7ca4836a1..0e29f26bb488 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/evaluation_domain.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/evaluation_domain.cpp @@ -66,8 +66,8 @@ EvaluationDomain::EvaluationDomain(const size_t domain_size, const size_t ta , generator_size(target_generator_size ? target_generator_size : domain_size) , domain(Fr{ size, 0, 0, 0 }.to_montgomery_form()) , domain_inverse(domain.invert()) - , generator(Fr::coset_generator(0)) - , generator_inverse(Fr::coset_generator(0).invert()) + , generator(Fr::template coset_generator<0>()) + , generator_inverse(Fr::template coset_generator<0>().invert()) , four_inverse(Fr(4).invert()) , roots(nullptr) { @@ -175,7 +175,7 @@ template EvaluationDomain::~EvaluationDomain() {} template void EvaluationDomain::compute_lookup_table() { - ASSERT(roots == nullptr); + BB_ASSERT_EQ(roots, nullptr); // roots = (Fr*)(aligned_alloc(32, sizeof(Fr) * size * 2)); roots = std::static_pointer_cast(get_mem_slab(sizeof(Fr) * size * 2)); compute_lookup_table_single(root, size, roots.get(), round_roots); diff --git a/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.cpp b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.cpp index 12f28ed11b06..73bc6214b229 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.cpp @@ -96,7 +96,7 @@ template LegacyPolynomial::LegacyPolynomial(std::span interpolation_points, std::span evaluations) : LegacyPolynomial(interpolation_points.size()) { - ASSERT(size_ > 0); + BB_ASSERT_GT(size_, 0U); polynomial_arithmetic::compute_efficient_interpolation( evaluations.data(), coefficients_, interpolation_points.data(), size_); @@ -188,7 +188,7 @@ template bool LegacyPolynomial::operator==(LegacyPolynomial co template void LegacyPolynomial::zero_memory_beyond(const size_t start_position) { size_t end = capacity(); - ASSERT(end >= start_position); + BB_ASSERT_GTE(end, start_position); size_t delta = end - start_position; if (delta > 0) { @@ -321,7 +321,7 @@ Fr LegacyPolynomial::evaluate_from_fft(const EvaluationDomain& large_dom template LegacyPolynomial LegacyPolynomial::shifted() const { - ASSERT(size_ > 0); + BB_ASSERT_GT(size_, 0U); ASSERT(coefficients_[0].is_zero()); ASSERT(coefficients_[size_].is_zero()); // relies on MAXIMUM_COEFFICIENT_SHIFT >= 1 LegacyPolynomial p; @@ -340,10 +340,10 @@ template void LegacyPolynomial::set_to_right_shifted(std::span ASSERT(coefficients_ != coeffs_in.data()); auto size_in = coeffs_in.size(); - ASSERT(size_in > 0); + BB_ASSERT_GT(size_in, 0U); // Ensure that the last shift_size-many input coefficients are zero to ensure no information is lost in the shift. - ASSERT(shift_size <= size_in); + BB_ASSERT_LTE(shift_size, size_in); for (size_t i = 0; i < shift_size; ++i) { size_t idx = size_in - shift_size - 1; ASSERT(coeffs_in[idx].is_zero()); @@ -441,7 +441,7 @@ template Fr LegacyPolynomial::evaluate_mle(std::span const size_t m = evaluation_points.size(); // To simplify handling of edge cases, we assume that size_ is always a power of 2 - ASSERT(size_ == static_cast(1 << m)); + BB_ASSERT_EQ(size_, static_cast(1 << m)); // we do m rounds l = 0,...,m-1. // in round l, n_l is the size of the buffer containing the polynomial partially evaluated @@ -456,7 +456,7 @@ template Fr LegacyPolynomial::evaluate_mle(std::span Fr* prev = coefficients_; if (shift) { - ASSERT(prev[0] == Fr::zero()); + BB_ASSERT_EQ(prev[0], Fr::zero()); prev++; } @@ -485,7 +485,7 @@ LegacyPolynomial LegacyPolynomial::partial_evaluate_mle(std::span= static_cast(1 << m)); + BB_ASSERT_GTE(size_, static_cast(1 << m)); size_t n = numeric::get_msb(size_); // Partial evaluation is done in m rounds l = 0,...,m-1. At the end of round l, the polynomial has been partially @@ -523,4 +523,4 @@ LegacyPolynomial LegacyPolynomial::partial_evaluate_mle(std::span; template class LegacyPolynomial; -} // namespace bb \ No newline at end of file +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.hpp b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.hpp index db351264cb7d..a7bb5c248072 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/legacy_polynomial.hpp @@ -5,7 +5,9 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/mem.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/crypto/sha256/sha256.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" // for PolynomialSpan @@ -95,8 +97,7 @@ template class LegacyPolynomial { bool is_zero() { if (is_empty()) { - ASSERT(false); - info("Checking is_zero on an empty Polynomial!"); + throw_or_abort("Checking is_zero on an empty Polynomial!"); } for (size_t i = 0; i < size(); i++) { if (coefficients_[i] != 0) { @@ -116,14 +117,14 @@ template class LegacyPolynomial { // For compatibility with Polynomial (which needs a special mutable accessor) Fr const& at(const size_t i) const { - ASSERT(i < capacity()); + BB_ASSERT_LT(i, capacity()); return coefficients_[i]; } // For compatibility with Polynomial (which needs a special mutable accessor) Fr& at(const size_t i) { - ASSERT(i < capacity()); + BB_ASSERT_LT(i, capacity()); return coefficients_[i]; } diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp index 2a2382f83508..15d7ec560c67 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp @@ -5,8 +5,10 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/mem.hpp" #include "barretenberg/common/op_count.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/common/zip_view.hpp" #include "barretenberg/constants.hpp" #include "barretenberg/crypto/sha256/sha256.hpp" @@ -141,8 +143,7 @@ template class Polynomial { bool is_zero() const { if (is_empty()) { - ASSERT(false); - info("Checking is_zero on an empty Polynomial!"); + throw_or_abort("Checking is_zero on an empty Polynomial!"); } for (size_t i = 0; i < size(); i++) { if (coefficients_.data()[i] != 0) { @@ -557,7 +558,13 @@ template auto zip_polys(Poly&& poly, Polys&&. { // Ensure all polys have the same start_index() and end_index() as poly // Use fold expression to check all polys exactly match our size - ASSERT((poly.start_index() == polys.start_index() && poly.end_index() == polys.end_index()) && ...); + // Wrap BB_ASSERT_EQ_RELEASE in a lambda to make it usable in a fold expression + auto check_indices = [&](const auto& other) { + BB_ASSERT_EQ(poly.start_index(), other.start_index()); + BB_ASSERT_EQ(poly.end_index(), other.end_index()); + }; + // Apply the lambda to each poly in the parameter pack + (check_indices(polys), ...); return zip_view(poly.indices(), poly.coeffs(), polys.coeffs()...); } } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp index d1f376236956..1f1b76a094c6 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.test.cpp @@ -1,6 +1,7 @@ #include #include +#include "barretenberg/common/assert.hpp" #include "barretenberg/polynomials/polynomial.hpp" // Simple test/demonstration of shifted functionality @@ -143,13 +144,13 @@ TEST(Polynomial, AddScaledEdgeConditions) auto poly = bb::Polynomial::random(4, /*start index*/ 1); poly.add_scaled(bb::Polynomial::random(4, /*start index*/ 0), 1); }; - ASSERT_DEATH(test_subset_bad1(), ".*start_index.*other.start_index.*"); + ASSERT_THROW_OR_ABORT(test_subset_bad1(), ".*start_index.*other.start_index.*"); auto test_subset_bad2 = []() { // Not contained within poly auto poly = bb::Polynomial::random(4, /*start index*/ 0); poly.add_scaled(bb::Polynomial::random(5, /*start index*/ 0), 1); }; - ASSERT_DEATH(test_subset_bad2(), ".*end_index.*other.end_index.*"); + ASSERT_THROW_OR_ABORT(test_subset_bad2(), ".*end_index.*other.end_index.*"); } TEST(Polynomial, OperatorAddEdgeConditions) @@ -168,13 +169,13 @@ TEST(Polynomial, OperatorAddEdgeConditions) auto poly = bb::Polynomial::random(4, /*start index*/ 1); poly += bb::Polynomial::random(4, /*start index*/ 0); }; - ASSERT_DEATH(test_subset_bad1(), ".*start_index.*other.start_index.*"); + ASSERT_THROW_OR_ABORT(test_subset_bad1(), ".*start_index.*other.start_index.*"); auto test_subset_bad2 = []() { // Not contained within poly auto poly = bb::Polynomial::random(4, /*start index*/ 0); poly += bb::Polynomial::random(5, /*start index*/ 0); }; - ASSERT_DEATH(test_subset_bad2(), ".*end_index.*other.end_index.*"); + ASSERT_THROW_OR_ABORT(test_subset_bad2(), ".*end_index.*other.end_index.*"); } TEST(Polynomial, OperatorSubtractEdgeConditions) @@ -193,13 +194,13 @@ TEST(Polynomial, OperatorSubtractEdgeConditions) auto poly = bb::Polynomial::random(4, /*start index*/ 1); poly -= bb::Polynomial::random(4, /*start index*/ 0); }; - ASSERT_DEATH(test_subset_bad1(), ".*start_index.*other.start_index.*"); + ASSERT_THROW_OR_ABORT(test_subset_bad1(), ".*start_index.*other.start_index.*"); auto test_subset_bad2 = []() { // Not contained within poly auto poly = bb::Polynomial::random(4, /*start index*/ 0); poly -= bb::Polynomial::random(5, /*start index*/ 0); }; - ASSERT_DEATH(test_subset_bad2(), ".*end_index.*other.end_index.*"); + ASSERT_THROW_OR_ABORT(test_subset_bad2(), ".*end_index.*other.end_index.*"); } // Makes a vector fully of the virtual_size aka degree + 1 @@ -219,7 +220,7 @@ TEST(Polynomial, Full) auto poly = bb::Polynomial::random(1, degree_plus_1, /*start index*/ degree_plus_1 - 1); poly -= bb::Polynomial::random(degree_plus_1, /*start index*/ 0); }; - ASSERT_DEATH(no_full_bad(), ".*start_index.*other.start_index.*"); + ASSERT_THROW_OR_ABORT(no_full_bad(), ".*start_index.*other.start_index.*"); } // TODO(https://github.com/AztecProtocol/barretenberg/issues/1113): Optimizing based on actual sizes would involve using @@ -243,21 +244,21 @@ TEST(Polynomial, Expand) // Expand beyond virtual size poly.expand(1, 11); }; - ASSERT_DEATH(test_subset_bad1(), ".*new_end_index.*virtual_size.*"); + ASSERT_THROW_OR_ABORT(test_subset_bad1(), ".*new_end_index.*virtual_size.*"); auto test_subset_bad2 = []() { auto poly = bb::Polynomial::random(5, 10, /*start index*/ 1); // Expand illegally on start_index poly.expand(2, 7); }; - ASSERT_DEATH(test_subset_bad2(), ".*new_start_index.*start_index.*"); + ASSERT_THROW_OR_ABORT(test_subset_bad2(), ".*new_start_index.*start_index.*"); auto test_subset_bad3 = []() { auto poly = bb::Polynomial::random(5, 10, /*start_index*/ 1); // Expand illegally on end_index poly.expand(1, 3); }; - ASSERT_DEATH(test_subset_bad3(), ".*new_end_index.*end_index.*"); + ASSERT_THROW_OR_ABORT(test_subset_bad3(), ".*new_end_index.*end_index.*"); } #endif diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.cpp index 608295ede8aa..738b737dd675 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.cpp @@ -884,7 +884,7 @@ void compute_lagrange_polynomial_fft(Fr* l_1_coefficients, // First compute X_i^n (which forms a multiplicative subgroup of order k) size_t log2_subgroup_size = target_domain.log2_size - src_domain.log2_size; // log_2(k) size_t subgroup_size = 1UL << log2_subgroup_size; // k - ASSERT(target_domain.log2_size >= src_domain.log2_size); + BB_ASSERT_GTE(target_domain.log2_size, src_domain.log2_size); Fr subgroup_roots[subgroup_size]; compute_multiplicative_subgroup(log2_subgroup_size, src_domain, &subgroup_roots[0]); @@ -951,7 +951,7 @@ void divide_by_pseudo_vanishing_polynomial(std::vector coeffs, // i.e. the 4th roots of unity size_t log2_subgroup_size = target_domain.log2_size - src_domain.log2_size; size_t subgroup_size = 1UL << log2_subgroup_size; - ASSERT(target_domain.log2_size >= src_domain.log2_size); + BB_ASSERT_GTE(target_domain.log2_size, src_domain.log2_size); Fr* subgroup_roots = new Fr[subgroup_size]; compute_multiplicative_subgroup(log2_subgroup_size, src_domain, &subgroup_roots[0]); @@ -1176,7 +1176,7 @@ void compress_fft(const Fr* src, Fr* dest, const size_t cur_size, const size_t c { // iterate from top to bottom, allows `dest` to overlap with `src` size_t log2_compress_factor = (size_t)numeric::get_msb(compress_factor); - ASSERT(1UL << log2_compress_factor == compress_factor); + BB_ASSERT_EQ(1UL << log2_compress_factor, compress_factor); size_t new_size = cur_size >> log2_compress_factor; for (size_t i = 0; i < new_size; ++i) { Fr::__copy(src[i << log2_compress_factor], dest[i]); diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.hpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.hpp index 987ac651578c..a5ce5a77b432 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_arithmetic.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "evaluation_domain.hpp" namespace bb::polynomial_arithmetic { @@ -22,7 +23,7 @@ using lagrange_evaluations = LagrangeEvaluations; template Fr evaluate(const Fr* coeffs, const Fr& z, const size_t n); template Fr evaluate(std::span coeffs, const Fr& z, const size_t n) { - ASSERT(n <= coeffs.size()); + BB_ASSERT_LTE(n, coeffs.size()); return evaluate(coeffs.data(), z, n); }; template Fr evaluate(std::span coeffs, const Fr& z) @@ -293,7 +294,7 @@ template void factor_roots(std::span polynomial, std::span minus_root_inverses; diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.cpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.cpp index b115e83c589e..560a0ab8cc6d 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial_store.cpp @@ -79,4 +79,4 @@ template void PolynomialStore::print() template class PolynomialStore; -} // namespace bb \ No newline at end of file +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp index 9c0640eeac22..b22de58e59a0 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp @@ -333,7 +333,7 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) // relation. if (is_random_input) { std::vector> keys_data(NUM_KEYS); - ASSERT(NUM_KEYS == 2); // Don't want to handle more here + ASSERT_EQ(NUM_KEYS, 2U); // Don't want to handle more here for (size_t idx = 0; idx < NUM_KEYS; idx++) { auto key = std::make_shared(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/eccvm_verifier/eccvm_recursive_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/eccvm_verifier/eccvm_recursive_verifier.test.cpp index 2ed5365757a7..688e37f1fb3f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/eccvm_verifier/eccvm_recursive_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/eccvm_verifier/eccvm_recursive_verifier.test.cpp @@ -110,7 +110,7 @@ class ECCVMRecursiveTests : public ::testing::Test { auto recursive_manifest = verifier.transcript->get_manifest(); auto native_manifest = native_verifier.transcript->get_manifest(); - ASSERT(recursive_manifest.size() > 0); + ASSERT_GT(recursive_manifest.size(), 0); for (size_t i = 0; i < recursive_manifest.size(); ++i) { EXPECT_EQ(recursive_manifest[i], native_manifest[i]) << "Recursive Verifier/Verifier manifest discrepency in round " << i; @@ -134,7 +134,7 @@ class ECCVMRecursiveTests : public ::testing::Test { auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); - ASSERT(verified); + ASSERT_TRUE(verified); } } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/goblin_verifier/goblin_recursive_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/goblin_verifier/goblin_recursive_verifier.test.cpp index 7ac0cc04bc33..a99c8a943bc5 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/goblin_verifier/goblin_recursive_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/goblin_verifier/goblin_recursive_verifier.test.cpp @@ -1,5 +1,6 @@ #include "barretenberg/stdlib/goblin_verifier/goblin_recursive_verifier.hpp" #include "barretenberg/circuit_checker/circuit_checker.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/test.hpp" #include "barretenberg/goblin/goblin.hpp" #include "barretenberg/goblin/mock_circuits.hpp" @@ -124,7 +125,7 @@ TEST_F(GoblinRecursiveVerifierTests, Basic) auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); - ASSERT(verified); + ASSERT_TRUE(verified); } } @@ -193,7 +194,7 @@ TEST_F(GoblinRecursiveVerifierTests, ECCVMFailure) auto native_ipa_proof = goblin_rec_verifier_output.ipa_proof.get_value(); native_ipa_transcript->load_proof(native_ipa_proof); - EXPECT_DEATH( + EXPECT_THROW_OR_ABORT( IPA::reduce_verify(grumpkin_verifier_commitment_key, native_claim, native_ipa_transcript), ".*IPA verification fails.*"); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.cpp index ab54c0a8b784..8d989bfd2fa7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.cpp @@ -5,6 +5,7 @@ // ===================== #include "blake2s.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "blake2s_plookup.hpp" #include "blake_util.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.cpp index df9a388feaec..1d003ba2476f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.cpp @@ -6,6 +6,7 @@ #include "blake3s.hpp" #include "../blake2s/blake_util.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "blake3s_plookup.hpp" @@ -246,7 +247,8 @@ using namespace blake3_internal; template byte_array blake3s(const byte_array& input) { - ASSERT(input.size() <= 1024, "Barretenberg does not support blake3s with input lengths greater than 1024 bytes."); + BB_ASSERT_LTE( + input.size(), 1024U, "Barretenberg does not support blake3s with input lengths greater than 1024 bytes."); if constexpr (HasPlookup) { return blake3s_plookup::blake3s(input); 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 5bc7da4869fd..8e6863772b7f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp @@ -1,5 +1,6 @@ #include "barretenberg/crypto/blake3s/blake3s.hpp" #include "barretenberg/circuit_checker/circuit_checker.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/streams.hpp" #include "blake3s.hpp" #include "blake3s_plookup.hpp" @@ -56,6 +57,6 @@ TEST(stdlib_blake3s, test_too_large_input_plookup) std::vector input_v(1025, 0); byte_array_plookup input_arr(&builder, input_v); - EXPECT_DEATH(stdlib::blake3s(input_arr), - "Barretenberg does not support blake3s with input lengths greater than 1024 bytes."); + EXPECT_THROW_OR_ABORT(stdlib::blake3s(input_arr), + "Barretenberg does not support blake3s with input lengths greater than 1024 bytes."); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp index 698cf1d89569..49e35aca480c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp @@ -5,6 +5,7 @@ // ===================== #include "keccak.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/numeric/bitop/sparse_form.hpp" #include "barretenberg/stdlib/primitives/logic/logic.hpp" @@ -343,7 +344,7 @@ template void keccak::theta(keccak_state& internal) // prevents an extra range table from being created constexpr uint256_t maximum = BASE.pow(64 % plookup::keccak_tables::Theta::TABLE_BITS); const field_ct target = -most_significant_slice + maximum; - ASSERT(((uint256_t(1) << Builder::DEFAULT_PLOOKUP_RANGE_BITNUM) - 1) > maximum); + BB_ASSERT_GT((uint256_t(1) << Builder::DEFAULT_PLOOKUP_RANGE_BITNUM) - 1, maximum); target.create_range_constraint(Builder::DEFAULT_PLOOKUP_RANGE_BITNUM, "input to KECCAK_THETA_OUTPUT too large!"); } @@ -589,7 +590,7 @@ std::vector> keccak::format_input_lanes(byte_array_ct& // We require that `num_bytes` does not exceed the size of our input byte array. // (can be less if the hash size is not known at circuit-compile time, only the maximum) - ASSERT(input.size() >= static_cast(num_bytes.get_value())); + BB_ASSERT_GTE(input.size(), static_cast(num_bytes.get_value())); field_ct(num_bytes > uint32_ct(static_cast(input.size()))).assert_equal(0); const size_t input_size = input.size(); // max_blocks_length = maximum number of bytes to hash @@ -685,7 +686,7 @@ std::vector> keccak::format_input_lanes(byte_array_ct& // validate the number of lanes is less than the default plookup size (we use the default size to do a cheap `<` // check later on. Should be fine as this translates to ~2MB of input data) - ASSERT(uint256_t(sliced_buffer.size()) < (uint256_t(1ULL) << Builder::DEFAULT_PLOOKUP_RANGE_BITNUM)); + BB_ASSERT_LT(uint256_t(sliced_buffer.size()), uint256_t(1ULL) << Builder::DEFAULT_PLOOKUP_RANGE_BITNUM); // If the terminating input byte index matches the terminating block byte index, we set the byte to 0x80. // If we trigger this case, set `terminating_index_limb_addition` to 0 so that we do not write `0x01 + 0x80` @@ -792,7 +793,7 @@ stdlib::byte_array keccak::hash_using_permutation_opcode(byte_ { auto ctx = input.get_context(); - ASSERT(uint256_t(num_bytes.get_value()) == input.size()); + BB_ASSERT_EQ(uint256_t(num_bytes.get_value()), input.size()); if (ctx == nullptr) { // if buffer is constant compute hash and return w/o creating constraints @@ -822,7 +823,7 @@ stdlib::byte_array keccak::hash(byte_array_ct& input, const ui { auto ctx = input.get_context(); - ASSERT(uint256_t(num_bytes.get_value()) <= input.size()); + BB_ASSERT_LTE(uint256_t(num_bytes.get_value()), input.size()); const auto constant_case = [&] { // if buffer is constant, compute hash and return w/o creating constraints byte_array_ct output(nullptr, 32); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.cpp index def4e9e318da..a25548a3909b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.cpp @@ -5,6 +5,7 @@ // ===================== #include "sha256.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" #include "sha256_plookup.hpp" @@ -120,7 +121,7 @@ template byte_array sha256_block(const byte_array uint32; - ASSERT(input.size() == 64); + BB_ASSERT_EQ(input.size(), 64U); std::array hash; prepare_constants(hash); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.test.cpp index 9c7d4667d37a..7a1a87381284 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.test.cpp @@ -258,19 +258,18 @@ template class RecursiveVerifierTest : public testing if constexpr (HasIPAAccumulator) { VerifierCommitmentKey ipa_verification_key = (1 << CONST_ECCVM_LOG_N); OuterVerifier verifier(verification_key, ipa_verification_key); - ASSERT(verifier.verify_proof(proof, proving_key->ipa_proof)); + ASSERT_TRUE(verifier.verify_proof(proof, proving_key->ipa_proof)); } else { OuterVerifier verifier(verification_key); - ASSERT(verifier.verify_proof(proof)); + ASSERT_TRUE(verifier.verify_proof(proof)); } } // Check the size of the recursive verifier if constexpr (std::same_as>) { uint32_t NUM_GATES_EXPECTED = 870522; - BB_ASSERT_EQ(static_cast(outer_circuit.get_num_finalized_gates()), - NUM_GATES_EXPECTED, - "MegaZKHonk Recursive verifier changed in Ultra gate count! Update this value if you " - "are sure this is expected."); + ASSERT_EQ(static_cast(outer_circuit.get_num_finalized_gates()), NUM_GATES_EXPECTED) + << "MegaZKHonk Recursive verifier changed in Ultra gate count! Update this value if you " + "are sure this is expected."; } } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/pairing_points.hpp b/barretenberg/cpp/src/barretenberg/stdlib/pairing_points.hpp index 04046205a539..9bc6042f744d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/pairing_points.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/pairing_points.hpp @@ -6,6 +6,7 @@ #pragma once #include "barretenberg/circuit_checker/circuit_checker.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/honk/types/aggregation_object_type.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" @@ -59,7 +60,7 @@ template struct PairingPoints { // aggregation rather than individually aggregating 1 object at a time. void aggregate(PairingPoints const& other) { - ASSERT(other.has_data && "Cannot aggregate null pairing points."); + ASSERT(other.has_data, "Cannot aggregate null pairing points."); // If LHS is empty, simply set it equal to the incoming pairing points if (!this->has_data && other.has_data) { @@ -98,7 +99,7 @@ template struct PairingPoints { */ uint32_t set_public() { - ASSERT(this->has_data && "Calling set_public on empty pairing points."); + ASSERT(this->has_data, "Calling set_public on empty pairing points."); uint32_t start_idx = P0.set_public(); P1.set_public(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.fuzzer.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.fuzzer.hpp index 047f64783ba9..58893d6f59d9 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.fuzzer.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.fuzzer.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/curves/bn254/fq.hpp" #include "barretenberg/numeric/random/engine.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" @@ -920,7 +921,7 @@ template class BigFieldBase { numerators.push_back(bigfield_t(this->bigfield.context, bb::fq(add))); v += add; } - ASSERT(v == this->base); + BB_ASSERT_EQ(v, this->base); return ExecutionHandler(this->base / divisor, /* Multi-numerator division */ diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.hpp index 64e177aa500b..2506b7c40ae2 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.hpp @@ -48,7 +48,7 @@ template class bigfield { { if (input.is_constant()) { maximum_value = uint256_t(input.additive_constant); - ASSERT(maximum_value <= max); + BB_ASSERT_LTE(maximum_value, max); } else { maximum_value = max; } @@ -160,8 +160,9 @@ template class bigfield { const field_t& d, const bool can_overflow = false) { - ASSERT(a.is_constant() == b.is_constant() && b.is_constant() == c.is_constant() && - c.is_constant() == d.is_constant()); + BB_ASSERT_EQ(a.is_constant(), b.is_constant()); + BB_ASSERT_EQ(b.is_constant(), c.is_constant()); + BB_ASSERT_EQ(c.is_constant(), d.is_constant()); bigfield result; result.context = a.context; result.binary_basis_limbs[0] = Limb(field_t(a)); @@ -187,8 +188,9 @@ template class bigfield { const field_t& d, const bool can_overflow = false) { - ASSERT(a.is_constant() == b.is_constant() && b.is_constant() == c.is_constant() && - c.is_constant() == d.is_constant()); + BB_ASSERT_EQ(a.is_constant(), b.is_constant()); + BB_ASSERT_EQ(b.is_constant(), c.is_constant()); + BB_ASSERT_EQ(c.is_constant(), d.is_constant()); bigfield result; auto ctx = a.context; result.context = a.context; @@ -232,8 +234,10 @@ template class bigfield { const field_t& prime_limb, const bool can_overflow = false) { - ASSERT(a.is_constant() == b.is_constant() && b.is_constant() == c.is_constant() && - c.is_constant() == d.is_constant() && d.is_constant() == prime_limb.is_constant()); + BB_ASSERT_EQ(a.is_constant(), b.is_constant()); + BB_ASSERT_EQ(b.is_constant(), c.is_constant()); + BB_ASSERT_EQ(c.is_constant(), d.is_constant()); + BB_ASSERT_EQ(d.is_constant(), prime_limb.is_constant()); bigfield result; result.context = a.context; result.binary_basis_limbs[0] = Limb(field_t(a)); @@ -370,7 +374,7 @@ template class bigfield { // `lo` and `hi` to `byte_array` each containing ((NUM_LIMB_BITS * 2) / 8) bytes. // Therefore, it is necessary for (NUM_LIMB_BITS * 2) to be divisible by 8 for correctly // converting `lo` and `hi` to `byte_array`s. - ASSERT((NUM_LIMB_BITS * 2 / 8) * 8 == NUM_LIMB_BITS * 2); + BB_ASSERT_EQ((NUM_LIMB_BITS * 2 / 8) * 8, NUM_LIMB_BITS * 2); result.write(byte_array(hi, 32 - (NUM_LIMB_BITS / 4))); result.write(byte_array(lo, (NUM_LIMB_BITS / 4))); return result; @@ -615,8 +619,10 @@ template class bigfield { bool is_limb_2_constant = binary_basis_limbs[2].element.is_constant(); bool is_limb_3_constant = binary_basis_limbs[3].element.is_constant(); bool is_prime_limb_constant = prime_basis_limb.is_constant(); - ASSERT(is_limb_0_constant == is_limb_1_constant && is_limb_1_constant == is_limb_2_constant && - is_limb_2_constant == is_limb_3_constant && is_limb_3_constant == is_prime_limb_constant); + BB_ASSERT_EQ(is_limb_0_constant, is_limb_1_constant); + BB_ASSERT_EQ(is_limb_1_constant, is_limb_2_constant); + BB_ASSERT_EQ(is_limb_2_constant, is_limb_3_constant); + BB_ASSERT_EQ(is_limb_3_constant, is_prime_limb_constant); return is_prime_limb_constant; } @@ -851,7 +857,7 @@ template class bigfield { // check that the add terms alone cannot overflow the crt modulus. v. unlikely so just forbid circuits that // trigger this case - ASSERT(add_term + maximum_default_bigint < get_maximum_crt_product()); + BB_ASSERT_LT(add_term + maximum_default_bigint, get_maximum_crt_product()); return ((product + add_term) >= get_maximum_crt_product()); } @@ -869,7 +875,7 @@ template class bigfield { const std::vector& to_add) { std::vector products; - ASSERT(as_max.size() == bs_max.size()); + BB_ASSERT_EQ(as_max.size(), bs_max.size()); // Computing individual products uint1024_t product_sum = 0; uint1024_t add_term = 0; @@ -883,7 +889,7 @@ template class bigfield { // check that the add terms alone cannot overflow the crt modulus. v. unlikely so just forbid circuits that // trigger this case - ASSERT(add_term + maximum_default_bigint < get_maximum_crt_product()); + BB_ASSERT_LT(add_term + maximum_default_bigint, get_maximum_crt_product()); return ((product_sum + add_term) >= get_maximum_crt_product()); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield_impl.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield_impl.hpp index 4d853ee46ca2..50cc34b44e5f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield_impl.hpp @@ -37,7 +37,7 @@ bigfield::bigfield(Builder* parent_context, const uint256_t& value) Limb(bb::fr(value.slice(NUM_LIMB_BITS * 3, NUM_LIMB_BITS * 4))) } , prime_basis_limb(context, value) { - ASSERT(value < modulus); + BB_ASSERT_LT(value, modulus); } template @@ -46,13 +46,13 @@ bigfield::bigfield(const field_t& low_bits_in, const bool can_overflow, const size_t maximum_bitlength) { - ASSERT(low_bits_in.is_constant() == high_bits_in.is_constant()); + BB_ASSERT_EQ(low_bits_in.is_constant(), high_bits_in.is_constant()); ASSERT((can_overflow == true && maximum_bitlength == 0) || (can_overflow == false && (maximum_bitlength == 0 || maximum_bitlength > (3 * NUM_LIMB_BITS)))); // Check that the values of two parts are within specified bounds - ASSERT(uint256_t(low_bits_in.get_value()) < (uint256_t(1) << (NUM_LIMB_BITS * 2))); - ASSERT(uint256_t(high_bits_in.get_value()) < (uint256_t(1) << (NUM_LIMB_BITS * 2))); + BB_ASSERT_LT(uint256_t(low_bits_in.get_value()), uint256_t(1) << (NUM_LIMB_BITS * 2)); + BB_ASSERT_LT(uint256_t(high_bits_in.get_value()), uint256_t(1) << (NUM_LIMB_BITS * 2)); context = low_bits_in.context == nullptr ? high_bits_in.context : low_bits_in.context; field_t limb_0(context); @@ -80,7 +80,7 @@ bigfield::bigfield(const field_t& low_bits_in, // if maximum_bitlength is set, this supercedes can_overflow if (maximum_bitlength > 0) { - ASSERT(maximum_bitlength > 3 * NUM_LIMB_BITS); + BB_ASSERT_GT(maximum_bitlength, 3 * NUM_LIMB_BITS); num_last_limb_bits = maximum_bitlength - (3 * NUM_LIMB_BITS); } // We create the high limb values similar to the low limb ones above @@ -186,7 +186,7 @@ bigfield bigfield::create_from_u512_as_witness(Builder* // if maximum_bitlength is set, this supercedes can_overflow if (maximum_bitlength > 0) { - ASSERT(maximum_bitlength > 3 * NUM_LIMB_BITS); + BB_ASSERT_GT(maximum_bitlength, 3 * NUM_LIMB_BITS); num_last_limb_bits = maximum_bitlength - (3 * NUM_LIMB_BITS); uint256_t max_limb_value = (uint256_t(1) << num_last_limb_bits) - 1; result.binary_basis_limbs[3].maximum_value = max_limb_value; @@ -209,7 +209,7 @@ bigfield bigfield::create_from_u512_as_witness(Builder* template bigfield::bigfield(const byte_array& bytes) { - ASSERT(bytes.size() == 32); // we treat input as a 256-bit big integer + BB_ASSERT_EQ(bytes.size(), 32U); // we treat input as a 256-bit big integer const auto split_byte_into_nibbles = [](Builder* ctx, const field_t& split_byte) { const uint64_t byte_val = uint256_t(split_byte.get_value()).data[0]; const uint64_t lo_nibble_val = byte_val & 15ULL; @@ -316,8 +316,8 @@ bigfield bigfield::add_to_lower_limb(const field_t bigfield::operator/(const bigfield& other) cons template bigfield bigfield::sum(const std::vector& terms) { - ASSERT(terms.size() > 0); + BB_ASSERT_GT(terms.size(), 0U); if (terms.size() == 1) { return terms[0]; @@ -795,7 +795,7 @@ bigfield bigfield::internal_div(const std::vector(denominator.get_context(), uint256_t(0)); } @@ -933,7 +933,7 @@ template bigfield bigfield bigfield bigfield::sqradd(const std::vector& to_add) const { - ASSERT(to_add.size() <= MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(to_add.size(), MAXIMUM_SUMMAND_COUNT); reduction_check(); Builder* ctx = context; @@ -1057,7 +1057,7 @@ template bigfield bigfield bigfield bigfield::madd(const bigfield& to_mul, const std::vector& to_add) const { - ASSERT(to_add.size() <= MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(to_add.size(), MAXIMUM_SUMMAND_COUNT); Builder* ctx = context ? context : to_mul.context; reduction_check(); to_mul.reduction_check(); @@ -1134,9 +1134,9 @@ void bigfield::perform_reductions_for_mult_madd(std::vector& mul_right, const std::vector& to_add) { - ASSERT(mul_left.size() == mul_right.size()); - ASSERT(to_add.size() <= MAXIMUM_SUMMAND_COUNT); - ASSERT(mul_left.size() <= MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_EQ(mul_left.size(), mul_right.size()); + BB_ASSERT_LTE(to_add.size(), MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(mul_left.size(), MAXIMUM_SUMMAND_COUNT); const size_t number_of_products = mul_left.size(); // Get the maximum values of elements @@ -1266,9 +1266,9 @@ bigfield bigfield::mult_madd(const std::vector const std::vector& to_add, bool fix_remainder_to_zero) { - ASSERT(mul_left.size() == mul_right.size()); - ASSERT(mul_left.size() <= MAXIMUM_SUMMAND_COUNT); - ASSERT(to_add.size() <= MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_EQ(mul_left.size(), mul_right.size()); + BB_ASSERT_LTE(mul_left.size(), MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(to_add.size(), MAXIMUM_SUMMAND_COUNT); std::vector mutable_mul_left(mul_left); std::vector mutable_mul_right(mul_right); @@ -1396,7 +1396,7 @@ bigfield bigfield::mult_madd(const std::vector uint1024_t(DEFAULT_MAXIMUM_REMAINDER); // Check that we can actually reduce the products enough, this assert will probably never get triggered - ASSERT((worst_case_product_sum + add_right_maximum) < get_maximum_crt_product()); + BB_ASSERT_LT(worst_case_product_sum + add_right_maximum, get_maximum_crt_product()); // We've collapsed all constants, checked if we can compute the sum of products in the worst case, time to check // if we need to reduce something @@ -1416,7 +1416,7 @@ bigfield bigfield::mult_madd(const std::vector if (fix_remainder_to_zero) { // This is not the only check. Circuit check is coming later :) - ASSERT(remainder_1024.lo == uint512_t(0)); + BB_ASSERT_EQ(remainder_1024.lo, uint512_t(0)); } const uint512_t quotient_value = quotient_1024.lo; const uint512_t remainder_value = remainder_1024.lo; @@ -1456,7 +1456,7 @@ bigfield bigfield::dual_madd(const bigfield& left_a, const bigfield& right_b, const std::vector& to_add) { - ASSERT(to_add.size() <= MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(to_add.size(), MAXIMUM_SUMMAND_COUNT); left_a.reduction_check(); right_a.reduction_check(); left_b.reduction_check(); @@ -1494,7 +1494,7 @@ bigfield bigfield::msub_div(const std::vector& bool enable_divisor_nz_check) { // Check the basics - ASSERT(mul_left.size() == mul_right.size()); + BB_ASSERT_EQ(mul_left.size(), mul_right.size()); ASSERT(divisor.get_value() != 0); OriginTag new_tag = divisor.get_origin_tag(); @@ -1598,7 +1598,7 @@ bigfield bigfield::conditional_negate(const bool_t void bigfield::assert_less_t // Warning: this assumes we have run circuit construction at least once in debug mode where large non reduced // constants are NOT allowed via ASSERT if (is_constant()) { - ASSERT(get_value() < static_cast(upper_limit)); + BB_ASSERT_LT(get_value(), static_cast(upper_limit)); return; } @@ -1891,7 +1891,7 @@ template void bigfield::assert_equal( (void)OriginTag(get_origin_tag(), other.get_origin_tag()); if (is_constant() && other.is_constant()) { std::cerr << "bigfield: calling assert equal on 2 CONSTANT bigfield elements...is this intended?" << std::endl; - ASSERT(get_value() == other.get_value()); // We expect constants to be less than the target modulus + BB_ASSERT_EQ(get_value(), other.get_value(), "We expect constants to be less than the target modulus"); return; } else if (other.is_constant()) { // NOTE(https://github.com/AztecProtocol/barretenberg/issues/998): This can lead to a situation where @@ -1901,7 +1901,7 @@ template void bigfield::assert_equal( // because the limb-differences would not be 0 mod r. Therefore, an honest prover needs to make sure that // `this` is reduced before calling this method. Also `other` should never be greater than the modulus by // design. As a precaution, we assert that the circuit-constant `other` is less than the modulus. - ASSERT(other.get_value() < modulus_u512); + BB_ASSERT_LT(other.get_value(), modulus_u512); field_t t0 = (binary_basis_limbs[0].element - other.binary_basis_limbs[0].element); field_t t1 = (binary_basis_limbs[1].element - other.binary_basis_limbs[1].element); field_t t2 = (binary_basis_limbs[2].element - other.binary_basis_limbs[2].element); @@ -2005,14 +2005,14 @@ template void bigfield::self_reduce() ++maximum_quotient_bits; } - ASSERT(maximum_quotient_bits <= NUM_LIMB_BITS); + BB_ASSERT_LTE(maximum_quotient_bits, NUM_LIMB_BITS); uint32_t quotient_limb_index = context->add_variable(bb::fr(quotient_value.lo)); field_t quotient_limb = field_t::from_witness_index(context, quotient_limb_index); context->decompose_into_default_range(quotient_limb.get_normalized_witness_index(), static_cast(maximum_quotient_bits)); - ASSERT((uint1024_t(1) << maximum_quotient_bits) * uint1024_t(modulus_u512) + DEFAULT_MAXIMUM_REMAINDER < - get_maximum_crt_product()); + BB_ASSERT_LT((uint1024_t(1) << maximum_quotient_bits) * uint1024_t(modulus_u512) + DEFAULT_MAXIMUM_REMAINDER, + get_maximum_crt_product()); quotient.binary_basis_limbs[0] = Limb(quotient_limb, uint256_t(1) << maximum_quotient_bits); quotient.binary_basis_limbs[1] = Limb(field_t::from_witness_index(context, context->zero_idx), 0); quotient.binary_basis_limbs[2] = Limb(field_t::from_witness_index(context, context->zero_idx), 0); @@ -2041,8 +2041,8 @@ void bigfield::unsafe_evaluate_multiply_add(const bigfield& input_le const std::vector& input_remainders) { - ASSERT(to_add.size() <= MAXIMUM_SUMMAND_COUNT); - ASSERT(input_remainders.size() <= MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(to_add.size(), MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(input_remainders.size(), MAXIMUM_SUMMAND_COUNT); // Sanity checks input_left.sanity_check(); input_to_mul.sanity_check(); @@ -2248,12 +2248,13 @@ void bigfield::unsafe_evaluate_multiple_multiply_add(const std::vect const bigfield& input_quotient, const std::vector& input_remainders) { - ASSERT(input_left.size() == input_right.size()); - ASSERT(input_left.size() <= MAXIMUM_SUMMAND_COUNT); - ASSERT(to_add.size() <= MAXIMUM_SUMMAND_COUNT); - ASSERT(input_remainders.size() <= MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_EQ(input_left.size(), input_right.size()); + BB_ASSERT_LTE(input_left.size(), MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(to_add.size(), MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(input_remainders.size(), MAXIMUM_SUMMAND_COUNT); - ASSERT(input_left.size() == input_right.size() && input_left.size() < 1024); + BB_ASSERT_EQ(input_left.size(), input_right.size()); + BB_ASSERT_LT(input_left.size(), 1024U); // Sanity checks bool is_left_constant = true; for (auto& el : input_left) { @@ -2545,7 +2546,7 @@ void bigfield::unsafe_evaluate_square_add(const bigfield& left, const bigfield& quotient, const bigfield& remainder) { - ASSERT(to_add.size() <= MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(to_add.size(), MAXIMUM_SUMMAND_COUNT); // Suppose input is: // x = (x3 || x2 || x1 || x0) @@ -2567,7 +2568,7 @@ template std::pair bigfield::compute_quotient_remainder_values( const bigfield& a, const bigfield& b, const std::vector& to_add) { - ASSERT(to_add.size() <= MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(to_add.size(), MAXIMUM_SUMMAND_COUNT); uint512_t add_values(0); for (const auto& add_element : to_add) { @@ -2590,8 +2591,8 @@ uint512_t bigfield::compute_maximum_quotient_value(const std::vector const std::vector& bs, const std::vector& to_add) { - ASSERT(as.size() == bs.size()); - ASSERT(to_add.size() <= MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_EQ(as.size(), bs.size()); + BB_ASSERT_LTE(to_add.size(), MAXIMUM_SUMMAND_COUNT); uint512_t add_values(0); for (const auto& add_element : to_add) { @@ -2614,11 +2615,11 @@ std::pair bigfield::get_quotient_reduction_info(const const std::vector& to_add, const std::vector& remainders_max) { - ASSERT(as_max.size() == bs_max.size()); + BB_ASSERT_EQ(as_max.size(), bs_max.size()); - ASSERT(to_add.size() <= MAXIMUM_SUMMAND_COUNT); - ASSERT(as_max.size() <= MAXIMUM_SUMMAND_COUNT); - ASSERT(remainders_max.size() <= MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(to_add.size(), MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(as_max.size(), MAXIMUM_SUMMAND_COUNT); + BB_ASSERT_LTE(remainders_max.size(), MAXIMUM_SUMMAND_COUNT); // Check if the product sum can overflow CRT modulus if (mul_product_overflows_crt_modulus(as_max, bs_max, to_add)) { 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 99fe36335556..f6e682867599 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp @@ -874,7 +874,7 @@ template class stdlib_biggroup : public testing::Test { } Builder builder; - ASSERT(points.size() == scalars.size()); + ASSERT_EQ(points.size(), scalars.size()); std::vector circuit_points; std::vector circuit_scalars; @@ -933,7 +933,7 @@ template class stdlib_biggroup : public testing::Test { scalars.push_back(1); Builder builder; - ASSERT(points.size() == scalars.size()); + ASSERT_EQ(points.size(), scalars.size()); const size_t num_points = points.size(); std::vector circuit_points; @@ -982,7 +982,7 @@ template class stdlib_biggroup : public testing::Test { scalars.push_back(1); Builder builder; - ASSERT(points.size() == scalars.size()); + ASSERT_EQ(points.size(), scalars.size()); const size_t num_points = points.size(); std::vector circuit_points; @@ -1185,7 +1185,7 @@ template class stdlib_biggroup : public testing::Test { scalars.push_back(1); Builder builder; - ASSERT(points.size() == scalars.size()); + ASSERT_EQ(points.size(), scalars.size()); const size_t num_points = points.size(); std::vector circuit_points; @@ -1230,7 +1230,7 @@ template class stdlib_biggroup : public testing::Test { scalars.push_back(1); Builder builder; - ASSERT(points.size() == scalars.size()); + ASSERT_EQ(points.size(), scalars.size()); const size_t num_points = points.size(); std::vector circuit_points; @@ -1274,7 +1274,7 @@ template class stdlib_biggroup : public testing::Test { scalars.push_back(1); Builder builder; - ASSERT(points.size() == scalars.size()); + ASSERT_EQ(points.size(), scalars.size()); const size_t num_points = points.size(); std::vector circuit_points; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_batch_mul.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_batch_mul.hpp index 9891b8a56355..1a315214374f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_batch_mul.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_batch_mul.hpp @@ -6,6 +6,7 @@ #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/stdlib/primitives/biggroup/biggroup_edgecase_handling.hpp" #include namespace bb::stdlib::element_default { @@ -21,7 +22,7 @@ element element::wnaf_batch_mul(const std::vector& _scalars) { constexpr size_t WNAF_SIZE = 4; - ASSERT(_points.size() == _scalars.size()); + BB_ASSERT_EQ(_points.size(), _scalars.size()); const auto [points, scalars] = handle_points_at_infinity(_points, _scalars); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_bn254.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_bn254.hpp index da843960e10e..c57ac9884f3b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_bn254.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_bn254.hpp @@ -13,6 +13,7 @@ * We use a special case algorithm to split bn254 scalar multipliers into endomorphism scalars * **/ +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/groups/precomputed_generators_bn254_impl.hpp" #include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" #include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" @@ -221,7 +222,7 @@ element element::bn254_endo_batch_mul(const std::vec const size_t max_num_small_bits) { - ASSERT(max_num_small_bits % 2 == 0); + BB_ASSERT_EQ(max_num_small_bits % 2, 0U); const size_t num_big_points = big_points.size(); const size_t num_small_points = small_points.size(); @@ -298,8 +299,8 @@ element element::bn254_endo_batch_mul(const std::vec points[i].set_origin_tag(OriginTag()); scalars[i].set_origin_tag(OriginTag()); } - ASSERT(big_scalars.size() == num_big_points); - ASSERT(small_scalars.size() == num_small_points); + BB_ASSERT_EQ(big_scalars.size(), num_big_points); + BB_ASSERT_EQ(small_scalars.size(), num_small_points); /** * Compute batch_lookup_table diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_edgecase_handling.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_edgecase_handling.hpp index 877f591e3516..78a5eb813474 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_edgecase_handling.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_edgecase_handling.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/groups/precomputed_generators_bn254_impl.hpp" #include "barretenberg/ecc/groups/precomputed_generators_secp256r1_impl.hpp" #include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" @@ -42,7 +43,7 @@ std::pair>, std::vector> element points; std::vector scalars; - ASSERT(_points.size() == _scalars.size()); + BB_ASSERT_EQ(_points.size(), _scalars.size()); using NativeFr = typename Fr::native; auto running_scalar = NativeFr::one(); // Get the offset generator G_offset in native and in-circuit form diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin.hpp index 8fa26b9cd13b..1b28af93b62c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin.hpp @@ -13,6 +13,7 @@ #include "../field/field.hpp" #include "../memory/rom_table.hpp" #include "../memory/twin_rom_table.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/ecc/curves/secp256k1/secp256k1.hpp" #include "barretenberg/ecc/curves/secp256r1/secp256r1.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin_impl.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin_impl.hpp index 2a0ae041a275..b4bd87ef3733 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin_impl.hpp @@ -6,6 +6,7 @@ #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/stdlib/primitives/biggroup/biggroup_goblin.hpp" #include "barretenberg/transcript/origin_tag.hpp" namespace bb::stdlib::element_goblin { @@ -74,8 +75,8 @@ goblin_element goblin_element::batch_mul(const std:: // Note: These constraints do not assume or enforce that the coordinates of the original point have been // asserted to be in the field, only that they are less than the smallest power of 2 greater than the field // modulus (a la the bigfield(lo, hi) constructor with can_overflow == false). - ASSERT(uint1024_t(point.x.get_maximum_value()) <= Fq::DEFAULT_MAXIMUM_REMAINDER); - ASSERT(uint1024_t(point.y.get_maximum_value()) <= Fq::DEFAULT_MAXIMUM_REMAINDER); + BB_ASSERT_LTE(uint1024_t(point.x.get_maximum_value()), Fq::DEFAULT_MAXIMUM_REMAINDER); + BB_ASSERT_LTE(uint1024_t(point.y.get_maximum_value()), Fq::DEFAULT_MAXIMUM_REMAINDER); x_lo.assert_equal(point.x.limbs[0]); x_hi.assert_equal(point.x.limbs[1]); y_lo.assert_equal(point.y.limbs[0]); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_impl.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_impl.hpp index 914188c850bf..0992cb1cb1a4 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_impl.hpp @@ -8,6 +8,7 @@ #include "../circuit_builders/circuit_builders.hpp" #include "../plookup/plookup.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/groups/precomputed_generators.hpp" #include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" #include "barretenberg/transcript/origin_tag.hpp" @@ -515,7 +516,7 @@ element element::quadruple_and_add(const std::vector x_1 = minus_lambda_dbl.sqradd({ -(two_x) }); } - ASSERT(to_add.size() > 0); + BB_ASSERT_GT(to_add.size(), 0); to_add[0].x.assert_is_not_equal(x_1); const Fq x_minus_x_1 = x - x_1; @@ -796,7 +797,7 @@ element element::batch_mul(const std::vector */ element element::scalar_mul(const Fr& scalar, const size_t max_num_bits) const { - ASSERT(max_num_bits % 2 == 0); + BB_ASSERT_EQ(max_num_bits % 2, 0U); /** * * Let's say we have some curve E defined over a field Fq. The order of E is p, which is prime. diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_nafs.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_nafs.hpp index 355bfcc0b0c3..7d99846b8094 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_nafs.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_nafs.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/curves/secp256k1/secp256k1.hpp" #include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" @@ -454,7 +455,7 @@ std::vector> element::compute_wnaf(const Fr& scalar) for (size_t i = 0; i < (num_rounds - midpoint); ++i) { negative_lo += uint256_t(15) * (uint256_t(1) << (i * 4)); } - ASSERT((num_rounds - midpoint) * 4 == 136); + BB_ASSERT_EQ((num_rounds - midpoint) * 4, 136U); // If skew == 1 lo_offset = 0, else = 0xf...f field_t lo_offset = (-field_t(bb::fr(negative_lo))) .madd(wnaf_entries[wnaf_entries.size() - 1], field_t(bb::fr(negative_lo))) @@ -478,7 +479,7 @@ template std::vector> element::compute_naf(const Fr& scalar, const size_t max_num_bits) { // We are not handling the case of odd bit lengths here. - ASSERT(max_num_bits % 2 == 0); + BB_ASSERT_EQ(max_num_bits % 2, 0U); C* ctx = scalar.context; uint512_t scalar_multiplier_512 = uint512_t(uint256_t(scalar.get_value()) % Fr::modulus); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.cpp index 5bd05826fede..ecccb5e2c7a3 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.cpp @@ -6,6 +6,7 @@ #include "bool.hpp" #include "../circuit_builders/circuit_builders.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/transcript/origin_tag.hpp" using namespace bb; @@ -239,7 +240,7 @@ template bool_t bool_t::operator|(const boo context->create_poly_gate( { witness_index, other.witness_index, result.witness_index, q_m, q_l, q_r, q_o, q_c }); } else if (!is_constant() && other.is_constant()) { - ASSERT(other.witness_inverted == false); + BB_ASSERT_EQ(other.witness_inverted, false); // If we are computing a | b and b is a constant `true`, the result is a constant `true` that does not // depend on `a`. @@ -248,7 +249,7 @@ template bool_t bool_t::operator|(const boo } else if (is_constant() && !other.is_constant()) { // If we are computing a | b and `a` is a constant `true`, the result is a constant `true` that does not // depend on `b`. - ASSERT(witness_inverted == false); + BB_ASSERT_EQ(witness_inverted, false); result = witness_bool ? *this : other; } result.tag = OriginTag(tag, other.tag); @@ -295,11 +296,11 @@ template bool_t bool_t::operator^(const boo { witness_index, other.witness_index, result.witness_index, q_m, q_l, q_r, q_o, q_c }); } else if (!is_constant() && other.is_constant()) { // witness ^ 1 = !witness - ASSERT(other.witness_inverted == false); + BB_ASSERT_EQ(other.witness_inverted, false); result = other.witness_bool ? !*this : *this; } else if (is_constant() && !other.is_constant()) { - ASSERT(witness_inverted == false); + BB_ASSERT_EQ(witness_inverted, false); result = witness_bool ? !other : other; } result.tag = OriginTag(tag, other.tag); @@ -360,11 +361,11 @@ template bool_t bool_t::operator==(const bo } else if (!is_constant() && (other.is_constant())) { // Compare *this with a constant other. If other == true, then we're checking *this == true. In this case we // propagate *this without adding extra constraints, otherwise (if other = false), we propagate !*this. - ASSERT(other.witness_inverted == false); + BB_ASSERT_EQ(other.witness_inverted, false); result = other.witness_bool ? *this : !(*this); } else if (is_constant() && !other.is_constant()) { // Completely analogous to the previous case. - ASSERT(witness_inverted == false); + BB_ASSERT_EQ(witness_inverted, false); result = witness_bool ? other : !other; } @@ -398,7 +399,7 @@ template void bool_t::assert_equal(const bool_t& rhs Builder* ctx = lhs.get_context() ? lhs.get_context() : rhs.get_context(); (void)OriginTag(get_origin_tag(), rhs.get_origin_tag()); if (lhs.is_constant() && rhs.is_constant()) { - ASSERT(lhs.get_value() == rhs.get_value()); + BB_ASSERT_EQ(lhs.get_value(), rhs.get_value()); } else if (lhs.is_constant()) { ASSERT(!lhs.witness_inverted); // if rhs is inverted, flip the value of the lhs constant 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 fdbd6ade42f4..9b18091623c1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp @@ -1,5 +1,6 @@ #include "bool.hpp" #include "barretenberg/circuit_checker/circuit_checker.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" #include "barretenberg/transcript/origin_tag.hpp" #include @@ -121,16 +122,14 @@ template class BoolTest : public ::testing::Test { EXPECT_TRUE(builder.get_estimated_num_finalized_gates() - num_gates_start == 2); EXPECT_TRUE(CircuitChecker::check(builder)); -#ifndef NDEBUG // Test failure bool_ct a_incorrect; uint256_t random_value(engine.get_random_uint256()); if (random_value * random_value - random_value != 0) { - EXPECT_DEATH(a_incorrect = witness_ct(&builder, random_value), - "((other.witness == bb::fr::one()) || (other.witness == bb::fr::zero()))"); + EXPECT_THROW_OR_ABORT(a_incorrect = witness_ct(&builder, random_value), + "((other.witness == bb::fr::one()) || (other.witness == bb::fr::zero()))"); }; -#endif } void test_AND() { @@ -189,9 +188,7 @@ template class BoolTest : public ::testing::Test { bool_ct b = create_bool_ct(rhs, &builder); if (a.is_constant() && b.is_constant() && !(!a.get_value() || b.get_value())) { -#ifndef NDEBUG - EXPECT_DEATH(a.must_imply(b), R"(\(lhs\.get_value\(\) == rhs\.get_value\(\)\))"); -#endif + EXPECT_THROW_OR_ABORT(a.must_imply(b), R"(\(lhs\.get_value\(\) == rhs\.get_value\(\)\))"); } else { bool result_is_constant = (!a || b).is_constant(); @@ -317,9 +314,7 @@ template class BoolTest : public ::testing::Test { EXPECT_EQ(CircuitChecker::check(builder), !failed); } else { if (failed) { -#ifndef NDEBUG - EXPECT_DEATH(a.assert_equal(b), R"(\(lhs\.get_value\(\) == rhs\.get_value\(\)\))"); -#endif + EXPECT_THROW_OR_ABORT(a.assert_equal(b), R"(\(lhs\.get_value\(\) == rhs\.get_value\(\)\))"); } } } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.cpp index 6fa1c99e8f42..98e763e74ef1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.cpp @@ -9,6 +9,7 @@ #include #include "../circuit_builders/circuit_builders.hpp" +#include "barretenberg/common/assert.hpp" using namespace bb; @@ -99,7 +100,7 @@ byte_array::byte_array(Builder* parent_context, std::vector co */ template byte_array::byte_array(const field_t& input, const size_t num_bytes) { - ASSERT(num_bytes <= 32); + BB_ASSERT_LTE(num_bytes, 32U); uint256_t value = input.get_value(); values.resize(num_bytes); context = input.get_context(); @@ -242,7 +243,7 @@ template byte_array& byte_array::write(byte template byte_array& byte_array::write_at(byte_array const& other, size_t index) { - ASSERT(index + other.values.size() <= values.size()); + BB_ASSERT_LTE(index + other.values.size(), values.size()); for (size_t i = 0; i < other.values.size(); i++) { values[i + index] = other.values[i]; } @@ -251,7 +252,7 @@ template byte_array& byte_array::write_at(b template byte_array byte_array::slice(size_t offset) const { - ASSERT(offset < values.size()); + BB_ASSERT_LT(offset, values.size()); return byte_array(context, bytes_t(values.begin() + (long)(offset), values.end())); } @@ -261,9 +262,9 @@ template byte_array byte_array::slice(size_ **/ template byte_array byte_array::slice(size_t offset, size_t length) const { - ASSERT(offset < values.size()); + BB_ASSERT_LT(offset, values.size()); // it's <= cause vector constructor doesn't include end point - ASSERT(length <= values.size() - offset); + BB_ASSERT_LTE(length, values.size() - offset); auto start = values.begin() + (long)(offset); auto end = values.begin() + (long)((offset + length)); return byte_array(context, bytes_t(start, end)); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.hpp index 0d832cef2257..4c174663508a 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.hpp @@ -9,6 +9,7 @@ #include "../circuit_builders/circuit_builders_fwd.hpp" #include "../field/field.hpp" #include "../safe_uint/safe_uint.hpp" +#include "barretenberg/common/assert.hpp" namespace bb::stdlib { template class byte_array { @@ -65,13 +66,13 @@ template class byte_array { void set_byte(size_t index, const field_t& byte_val) { - ASSERT(index < values.size()); + BB_ASSERT_LT(index, values.size()); values[index] = byte_val; } void set_context(Builder* ctx) { - ASSERT(context == nullptr); + BB_ASSERT_EQ(context, nullptr); context = ctx; } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/databus/databus.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/databus/databus.cpp index 88683ff813f9..1d03dcbdaab9 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/databus/databus.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/databus/databus.cpp @@ -6,6 +6,7 @@ #include "databus.hpp" #include "../circuit_builders/circuit_builders.hpp" +#include "barretenberg/common/assert.hpp" namespace bb::stdlib { @@ -61,4 +62,4 @@ field_t databus::bus_vector::operator[](const field_pt& index) } template class databus; -} // namespace bb::stdlib \ No newline at end of file +} // namespace bb::stdlib diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.cpp index 342ed4dd18a2..ade5679ea085 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.cpp @@ -7,6 +7,7 @@ #include "field.hpp" #include "../bool/bool.hpp" #include "../circuit_builders/circuit_builders.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include @@ -454,7 +455,7 @@ template field_t field_t::pow(const uint32_ template field_t field_t::pow(const field_t& exponent) const { uint256_t exponent_value = exponent.get_value(); - ASSERT(exponent_value.get_msb() < 32); + BB_ASSERT_LT(exponent_value.get_msb(), 32U); if (is_constant() && exponent.is_constant()) { return field_t(get_value().pow(exponent_value)); @@ -817,7 +818,7 @@ template bb::fr field_t::get_value() const ASSERT(context); return (multiplicative_constant * context->get_variable(witness_index)) + additive_constant; } - ASSERT(multiplicative_constant == bb::fr::one()); + BB_ASSERT_EQ(multiplicative_constant, bb::fr::one()); // A constant field_t's value is tracked wholly by its additive_constant member. return additive_constant; } @@ -898,7 +899,7 @@ void field_t::create_range_constraint(const size_t num_bits, std::strin assert_is_zero("0-bit range_constraint on non-zero field_t."); } else { if (is_constant()) { - ASSERT(uint256_t(get_value()).get_msb() < num_bits); + BB_ASSERT_LT(uint256_t(get_value()).get_msb(), num_bits); } else { context->decompose_into_default_range( get_normalized_witness_index(), num_bits, bb::UltraCircuitBuilder::DEFAULT_PLOOKUP_RANGE_BITNUM, msg); @@ -919,7 +920,7 @@ template void field_t::assert_equal(const field_t& r Builder* ctx = lhs.get_context() ? lhs.get_context() : rhs.get_context(); (void)OriginTag(get_origin_tag(), rhs.get_origin_tag()); if (lhs.is_constant() && rhs.is_constant()) { - ASSERT(lhs.get_value() == rhs.get_value()); + BB_ASSERT_EQ(lhs.get_value(), rhs.get_value()); } else if (lhs.is_constant()) { field_t right = rhs.normalize(); ctx->assert_equal_constant(right.witness_index, lhs.get_value(), msg); @@ -1053,7 +1054,7 @@ void field_t::evaluate_linear_identity(const field_t& a, const field_t& Builder* ctx = first_non_null(a.context, b.context, c.context, d.context); if (a.is_constant() && b.is_constant() && c.is_constant() && d.is_constant()) { - ASSERT(a.get_value() + b.get_value() + c.get_value() + d.get_value() == 0); + BB_ASSERT_EQ(a.get_value() + b.get_value() + c.get_value() + d.get_value(), 0); return; } @@ -1247,8 +1248,8 @@ template field_t field_t::accumulate(const template std::array, 3> field_t::slice(const uint8_t msb, const uint8_t lsb) const { - ASSERT(msb >= lsb); - ASSERT(msb < grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH); + BB_ASSERT_GTE(msb, lsb); + BB_ASSERT_LT(msb, grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH); Builder* ctx = get_context(); const uint256_t one(1); @@ -1341,7 +1342,7 @@ std::vector> field_t::decompose_into_bits( size_t num_bits, const std::function(Builder*, uint64_t, uint256_t)> get_bit) const { static constexpr size_t max_num_bits = 256; - ASSERT(num_bits <= max_num_bits); + BB_ASSERT_LTE(num_bits, max_num_bits); const size_t midpoint = max_num_bits / 2; std::vector> result(num_bits); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.hpp index 0e0cdfcf1cbf..295dfe6997cc 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.hpp @@ -353,7 +353,8 @@ template class field_t { */ void convert_constant_to_fixed_witness(Builder* ctx) { - ASSERT(is_constant() && ctx); + ASSERT(is_constant()); + ASSERT(ctx); context = ctx; (*this) = field_t(witness_t(context, get_value())); context->fix_witness(witness_index, get_value()); 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 e6caa122a39e..4ab429965782 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp @@ -36,7 +36,7 @@ template class stdlib_field : public testing::Test { field_ct c = a + b; EXPECT_TRUE(c.witness_index == a.witness_index); EXPECT_TRUE(builder.get_estimated_num_finalized_gates() == num_gates); - field_ct d(&builder, fr::coset_generator(0)); // like b, d is just a constant and not a wire value + field_ct d(&builder, fr::coset_generator<0>()); // like b, d is just a constant and not a wire value // by this point, we shouldn't have added any constraints in our circuit for (size_t i = 0; i < 17; ++i) { @@ -166,17 +166,16 @@ template class stdlib_field : public testing::Test { EXPECT_TRUE(converted.witness_index == field_elt.witness_index); } } -#ifndef NDEBUG // Check that the conversion aborts in the case of random field elements. bool_ct invalid_bool; // Case 4: Invalid constant conversion - EXPECT_DEATH(invalid_bool = bool_ct(field_ct(input_array.back())), - "Assertion failed: (additive_constant == bb::fr::one() || additive_constant == bb::fr::zero())"); + EXPECT_THROW_OR_ABORT( + invalid_bool = bool_ct(field_ct(input_array.back())), + "Assertion failed: (additive_constant == bb::fr::one() || additive_constant == bb::fr::zero())"); // Case 5: Invalid witness conversion Builder builder = Builder(); - EXPECT_DEATH(invalid_bool = bool_ct(field_ct(witness_ct(&builder, input_array.back()))), - "Assertion failed: ((witness == bb::fr::zero()) || (witness == bb::fr::one()) == true)"); -#endif + EXPECT_THROW_OR_ABORT(invalid_bool = bool_ct(field_ct(witness_ct(&builder, input_array.back()))), + "Assertion failed: ((witness == bb::fr::zero()) || (witness == bb::fr::one()) == true)"); } /** * @brief Test that bool is converted correctly @@ -409,19 +408,17 @@ template class stdlib_field : public testing::Test { EXPECT_TRUE(q.is_constant()); EXPECT_EQ(a.get_value() / b.get_value(), q.get_value()); -#ifndef NDEBUG { // Case 1. Numerator = const, denominator = const 0. Check that the division is aborted b = 0; - EXPECT_DEATH(a / b, ".*"); + EXPECT_THROW_OR_ABORT(a / b, ".*"); } { // Case 2. Numerator != const, denominator = const 0. Check that the division is aborted Builder builder = Builder(); field_ct a = witness_ct(&builder, bb::fr::random_element()); b = 0; - EXPECT_DEATH(a / b, ".*"); + EXPECT_THROW_OR_ABORT(a / b, ".*"); } -#endif { // Case 3. Numerator != const, denominator = witness 0 . Check that the circuit fails. Builder builder = Builder(); @@ -682,9 +679,7 @@ template class stdlib_field : public testing::Test { } { // a is a const 0 a = field_ct(0); -#ifndef NDEBUG - EXPECT_DEATH(a.assert_is_not_zero(), "assert_is_not_zero"); -#endif + EXPECT_THROW_OR_ABORT(a.assert_is_not_zero(), "assert_is_not_zero"); } } @@ -1068,14 +1063,10 @@ template class stdlib_field : public testing::Test { [[maybe_unused]] field_ct base = witness_ct(&builder, base_val); field_ct exponent = witness_ct(&builder, exponent_val); -#ifndef NDEBUG - EXPECT_DEATH(base.pow(exponent), "Assertion failed: \\(exponent_value.get_msb\\(\\) < 32\\)"); -#endif + EXPECT_THROW_OR_ABORT(base.pow(exponent), "Assertion failed: \\(exponent_value.get_msb\\(\\) < 32\\)"); exponent = field_ct(exponent_val); -#ifndef NDEBUG - EXPECT_DEATH(base.pow(exponent), "Assertion failed: \\(exponent_value.get_msb\\(\\) < 32\\)"); -#endif + EXPECT_THROW_OR_ABORT(base.pow(exponent), "Assertion failed: \\(exponent_value.get_msb\\(\\) < 32\\)"); }; static void test_copy_as_new_witness() @@ -1107,12 +1098,10 @@ template class stdlib_field : public testing::Test { elt.assert_is_zero(); // If we apply `assert_is_zero()` to a non-zero constant, we hit an ASSERT failure elt = bb::fr::random_element(); -#ifndef NDEBUG if (elt.get_value() != 0) { - EXPECT_DEATH(elt.assert_is_zero(), "field_t::assert_is_zero"); + EXPECT_THROW_OR_ABORT(elt.assert_is_zero(), "field_t::assert_is_zero"); } -#endif // Create a witness 0 Builder builder = Builder(); elt = witness_ct(&builder, bb::fr::zero()); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field_conversion.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field_conversion.cpp index 9350907dd624..aff68d9169e0 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field_conversion.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field_conversion.cpp @@ -5,6 +5,7 @@ // ===================== #include "barretenberg/stdlib/primitives/field/field_conversion.hpp" +#include "barretenberg/common/assert.hpp" namespace bb::stdlib::field_conversion { @@ -37,7 +38,7 @@ template fq convert_to_grumpkin_fr(Builder& builder, builder.create_range_constraint(low.witness_index, NUM_BITS_IN_TWO_LIMBS, "create_range_constraint"); builder.create_range_constraint(hi.witness_index, UPPER_TWO_LIMB_BITS, "create_range_constraint"); - ASSERT(static_cast(low_val) + (static_cast(hi_val) << NUM_BITS_IN_TWO_LIMBS) == value); + BB_ASSERT_EQ(static_cast(low_val) + (static_cast(hi_val) << NUM_BITS_IN_TWO_LIMBS), value); // checks this decomposition low + hi * 2^64 = value with an assert_equal auto sum = low + hi * shift; builder.assert_equal(f.witness_index, sum.witness_index, "assert_equal"); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field_conversion.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field_conversion.hpp index 8c87c46271ec..928b92eef815 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field_conversion.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field_conversion.hpp @@ -6,6 +6,7 @@ #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" #include "barretenberg/stdlib/primitives/bigfield/goblin_field.hpp" @@ -93,20 +94,20 @@ template constexpr size_t calc_num_bn254_frs() template T convert_from_bn254_frs(Builder& builder, std::span> fr_vec) { if constexpr (IsAnyOf>) { - ASSERT(fr_vec.size() == 1); + BB_ASSERT_EQ(fr_vec.size(), 1U); return fr_vec[0]; } else if constexpr (IsAnyOf>) { - ASSERT(fr_vec.size() == 2); + BB_ASSERT_EQ(fr_vec.size(), 2U); fq result(fr_vec[0], fr_vec[1]); return result; } else if constexpr (IsAnyOf>) { - ASSERT(fr_vec.size() == 2); + BB_ASSERT_EQ(fr_vec.size(), 2U); goblin_field result(fr_vec[0], fr_vec[1]); return result; } else if constexpr (IsAnyOf>) { using BaseField = bn254_element::BaseField; constexpr size_t BASE_FIELD_SCALAR_SIZE = calc_num_bn254_frs(); - ASSERT(fr_vec.size() == 2 * BASE_FIELD_SCALAR_SIZE); + BB_ASSERT_EQ(fr_vec.size(), 2 * BASE_FIELD_SCALAR_SIZE); bn254_element result; result.x = convert_from_bn254_frs(builder, fr_vec.subspan(0, BASE_FIELD_SCALAR_SIZE)); @@ -125,7 +126,7 @@ template T convert_from_bn254_frs(Builder& builde } else if constexpr (IsAnyOf>) { using BaseField = fr; constexpr size_t BASE_FIELD_SCALAR_SIZE = calc_num_bn254_frs(); - ASSERT(fr_vec.size() == 2 * BASE_FIELD_SCALAR_SIZE); + BB_ASSERT_EQ(fr_vec.size(), 2 * BASE_FIELD_SCALAR_SIZE); fr x = convert_from_bn254_frs>(builder, fr_vec.subspan(0, BASE_FIELD_SCALAR_SIZE)); fr y = convert_from_bn254_frs>( @@ -136,7 +137,7 @@ template T convert_from_bn254_frs(Builder& builde // Array or Univariate T val; constexpr size_t FieldScalarSize = calc_num_bn254_frs(); - ASSERT(fr_vec.size() == FieldScalarSize * std::tuple_size::value); + BB_ASSERT_EQ(fr_vec.size(), FieldScalarSize * std::tuple_size::value); size_t i = 0; for (auto& x : val) { x = convert_from_bn254_frs( @@ -209,4 +210,4 @@ TargetType deserialize_from_frs(Builder& builder, std::span> element return result; } -} // namespace bb::stdlib::field_conversion \ No newline at end of file +} // namespace bb::stdlib::field_conversion diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.cpp index 10194ef49cb8..04d85bebc461 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/cycle_group.cpp @@ -5,6 +5,7 @@ // ===================== #include "../field/field.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/zip_view.hpp" #include "barretenberg/crypto/pedersen_commitment/pedersen.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" @@ -252,7 +253,8 @@ template cycle_group cycle_group::get_stand */ template void cycle_group::set_point_at_infinity(const bool_t& is_infinity) { - ASSERT((this->x.is_constant() && this->y.is_constant() && this->_is_infinity.is_constant()) == this->_is_constant); + BB_ASSERT_EQ(this->x.is_constant() && this->y.is_constant() && this->_is_infinity.is_constant(), + this->_is_constant); this->_is_standard = true; @@ -297,7 +299,8 @@ template void cycle_group::set_point_at_infinity(con this->y = field_t::conditional_assign(is_infinity, 0, this->y); // We won't bump into the case where we end up with non constant coordinates - ASSERT(!this->x.is_constant() && !this->y.is_constant()); + ASSERT(!this->x.is_constant()); + ASSERT(!this->y.is_constant()); this->_is_constant = false; // We have to check this to avoid the situation, where we change the infinity @@ -318,9 +321,11 @@ template void cycle_group::set_point_at_infinity(con */ template void cycle_group::standardize() { - ASSERT((this->x.is_constant() && this->y.is_constant() && this->_is_infinity.is_constant()) == this->_is_constant); + BB_ASSERT_EQ(this->x.is_constant() && this->y.is_constant() && this->_is_infinity.is_constant(), + this->_is_constant); if (this->_is_infinity.is_constant() && this->_is_infinity.get_value()) { - ASSERT(this->_is_constant && this->_is_standard); + ASSERT(this->_is_constant); + ASSERT(this->_is_standard); } if (this->_is_standard) { @@ -898,7 +903,7 @@ template typename cycle_group::cycle_scalar cycle_group::cycle_scalar::from_witness_bitstring( Builder* context, const uint256_t& bitstring, const size_t num_bits) { - ASSERT(bitstring.get_msb() < num_bits); + BB_ASSERT_LT(bitstring.get_msb(), num_bits); const uint256_t lo_v = bitstring.slice(0, LO_BITS); const uint256_t hi_v = bitstring.slice(LO_BITS, HI_BITS); field_t lo = witness_t(context, lo_v); @@ -1020,7 +1025,8 @@ template cycle_group::cycle_scalar::cycle_scalar(Big } // sanity check that limb[1] is the limb that contributs both to *this.lo and *this.hi - ASSERT((BigScalarField::NUM_LIMB_BITS * 2 > LO_BITS) && (BigScalarField::NUM_LIMB_BITS < LO_BITS)); + BB_ASSERT_GT(BigScalarField::NUM_LIMB_BITS * 2, LO_BITS); + BB_ASSERT_LT(BigScalarField::NUM_LIMB_BITS, LO_BITS); // limb1 is the tricky one as it contributs to both *this.lo and *this.hi // By this point, we know that limb1 fits in the range `1 << BigScalarField::NUM_LIMB_BITS to (1 << @@ -1363,7 +1369,7 @@ cycle_group::straus_lookup_table::straus_lookup_table(Builder* context, std::array{ point_table[i].x.get_witness_index(), point_table[i].y.get_witness_index() }); } } else { - ASSERT(table_bits == 1); + BB_ASSERT_EQ(table_bits, 1U); } } @@ -1432,7 +1438,7 @@ typename cycle_group::batch_mul_internal_output cycle_group::_ const std::span offset_generators, const bool unconditional_add) { - ASSERT(scalars.size() == base_points.size()); + BB_ASSERT_EQ(scalars.size(), base_points.size()); Builder* context = nullptr; for (auto& scalar : scalars) { @@ -1562,7 +1568,7 @@ typename cycle_group::batch_mul_internal_output cycle_group::_ const std::optional scalar_slice = scalar_slices[j].read(num_rounds - i - 1); // if we are doing a batch mul over scalars of different bit-lengths, we may not have a bit slice // for a given round and a given scalar - ASSERT(scalar_slice.value().get_value() == scalar_slices[j].slices_native[num_rounds - i - 1]); + BB_ASSERT_EQ(scalar_slice.value().get_value(), scalar_slices[j].slices_native[num_rounds - i - 1]); if (scalar_slice.has_value()) { const auto& point = points_to_add[point_counter++]; if (!unconditional_add) { @@ -1613,7 +1619,7 @@ typename cycle_group::batch_mul_internal_output cycle_group::_ const std::span /*unused*/) requires IsUltraArithmetic { - ASSERT(scalars.size() == base_points.size()); + BB_ASSERT_EQ(scalars.size(), base_points.size()); const size_t num_points = base_points.size(); using MultiTableId = plookup::MultiTableId; @@ -1713,7 +1719,7 @@ typename cycle_group::batch_mul_internal_output cycle_group::_ requires IsNotUltraArithmetic { - ASSERT(scalars.size() == base_points.size()); + BB_ASSERT_EQ(scalars.size(), base_points.size()); static_assert(TABLE_BITS == 1); Builder* context = nullptr; @@ -1819,7 +1825,7 @@ cycle_group cycle_group::batch_mul(const std::vector& scalars, const GeneratorContext context) { - ASSERT(scalars.size() == base_points.size()); + BB_ASSERT_EQ(scalars.size(), base_points.size()); std::vector variable_base_scalars; std::vector variable_base_points; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp index 3e0a59dc3090..1597f2b572f1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp @@ -37,8 +37,8 @@ field_t logic::create_logic_constraint( const std::function(uint256_t, uint256_t, size_t)>& get_chunk) { // ensure the number of bits doesn't exceed field size and is not negatove - ASSERT(num_bits < 254); - ASSERT(num_bits > 0); + BB_ASSERT_LT(num_bits, 254U); + BB_ASSERT_GT(num_bits, 0U); if (a.is_constant() && !b.is_constant()) { Builder* ctx = b.get_context(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.cpp index 6a3d276e2c1c..52b3e401f413 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.cpp @@ -8,6 +8,7 @@ #include "../bool/bool.hpp" #include "../circuit_builders/circuit_builders.hpp" +#include "barretenberg/common/assert.hpp" namespace bb::stdlib { @@ -110,7 +111,7 @@ template void DynamicArray::resize(const field_pt& n // 1: assert new_length < max_size field_pt max_bounds_check = (field_pt(_max_size) - new_length - 1); if (max_bounds_check.is_constant()) { - ASSERT(uint256_t(new_length.get_value()) <= _max_size); + BB_ASSERT_LTE(uint256_t(new_length.get_value()), _max_size); } else { _context->create_new_range_constraint(max_bounds_check.normalize().get_witness_index(), _max_size); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.cpp index 63dea45b192f..f0e1c5986f68 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.cpp @@ -7,6 +7,7 @@ #include "ram_table.hpp" #include "../circuit_builders/circuit_builders.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" #include "barretenberg/transcript/origin_tag.hpp" #include @@ -291,4 +292,4 @@ template void ram_table::write(const field_pt& index template class ram_table; template class ram_table; -} // namespace bb::stdlib \ No newline at end of file +} // namespace bb::stdlib diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.cpp index 6ece7fb316b9..786324a978b0 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.cpp @@ -7,6 +7,7 @@ #include "rom_table.hpp" #include "../circuit_builders/circuit_builders.hpp" +#include "barretenberg/common/assert.hpp" using namespace bb; @@ -158,4 +159,4 @@ template field_t rom_table::operator[](cons template class rom_table; template class rom_table; -} // namespace bb::stdlib \ No newline at end of file +} // namespace bb::stdlib diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/twin_rom_table.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/twin_rom_table.cpp index d369ea7c06d0..f1fc00f13205 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/twin_rom_table.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/twin_rom_table.cpp @@ -7,6 +7,7 @@ #include "twin_rom_table.hpp" #include "../circuit_builders/circuit_builders.hpp" +#include "barretenberg/common/assert.hpp" using namespace bb; @@ -172,4 +173,4 @@ std::array, 2> twin_rom_table::operator[](const field_ template class twin_rom_table; template class twin_rom_table; -} // namespace bb::stdlib \ No newline at end of file +} // namespace bb::stdlib diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.cpp index 67048a2e4162..1fb4acaaec5c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.cpp @@ -7,6 +7,7 @@ #include "packed_byte_array.hpp" #include "../circuit_builders/circuit_builders.hpp" +#include "barretenberg/common/assert.hpp" using namespace bb; @@ -38,7 +39,7 @@ packed_byte_array::packed_byte_array(const std::vector& input : context(get_context_from_fields(input)) , num_bytes(bytes_per_input * input.size()) { - ASSERT(bytes_per_input <= BYTES_PER_ELEMENT); + BB_ASSERT_LTE(bytes_per_input, BYTES_PER_ELEMENT); if (bytes_per_input > BYTES_PER_ELEMENT) { context->failure("packed_byte_array: called `packed_byte_array` constructor with `bytes_per_input > 16 bytes"); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/public_input_component/public_input_component.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/public_input_component/public_input_component.hpp index 7f745317569a..785ada96f696 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/public_input_component/public_input_component.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/public_input_component/public_input_component.hpp @@ -6,6 +6,7 @@ #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" #include namespace bb::stdlib { @@ -60,12 +61,13 @@ class PublicInputComponent { { // Ensure that the key has been set if (!key.is_set()) { - ASSERT(false && "ERROR: Trying to construct a PublicInputComponent from an invalid key!"); + throw_or_abort("ERROR: Trying to construct a PublicInputComponent from an invalid key!"); } // Use the provided key to extract the limbs of the component from the public inputs then reconstruct it - ASSERT(key.start_idx + COMPONENT_SIZE <= public_inputs.size() && - "PublicInputComponent cannot be reconstructed - PublicInputComponentKey start_idx out of bounds"); + BB_ASSERT_LTE(key.start_idx + COMPONENT_SIZE, + public_inputs.size(), + "PublicInputComponent cannot be reconstructed - PublicInputComponentKey start_idx out of bounds"); std::span limbs{ public_inputs.data() + key.start_idx, COMPONENT_SIZE }; return ComponentType::reconstruct_from_public(limbs); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.cpp index eea5639df06b..f0bcd7968164 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.cpp @@ -7,6 +7,7 @@ #include "safe_uint.hpp" #include "../bool/bool.hpp" #include "../circuit_builders/circuit_builders.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" namespace bb::stdlib { @@ -22,7 +23,7 @@ template safe_uint_t safe_uint_t::operator* { uint512_t new_max = uint512_t(current_max) * uint512_t(other.current_max); - ASSERT(new_max.hi == 0); + BB_ASSERT_EQ(new_max.hi, 0U); return safe_uint_t((value * other.value), new_max.lo, IS_UNSAFE); } @@ -41,7 +42,7 @@ safe_uint_t safe_uint_t::subtract(const safe_uint_t& other, const size_t difference_bit_size, std::string const& description) const { - ASSERT(difference_bit_size <= MAX_BIT_NUM); + BB_ASSERT_LTE(difference_bit_size, MAX_BIT_NUM); ASSERT(!(this->value.is_constant() && other.value.is_constant())); field_ct difference_val = this->value - other.value; @@ -115,9 +116,9 @@ safe_uint_t safe_uint_t::divide( std::string const& description, const std::function(uint256_t, uint256_t)>& get_quotient) const { - ASSERT(this->value.is_constant() == false); - ASSERT(quotient_bit_size <= MAX_BIT_NUM); - ASSERT(remainder_bit_size <= MAX_BIT_NUM); + BB_ASSERT_EQ(this->value.is_constant(), false); + BB_ASSERT_LTE(quotient_bit_size, MAX_BIT_NUM); + BB_ASSERT_LTE(remainder_bit_size, MAX_BIT_NUM); uint256_t val = this->value.get_value(); auto [quotient_val, remainder_val] = get_quotient(val, (uint256_t)other.value.get_value()); field_ct quotient_field(witness_t(value.context, quotient_val)); @@ -150,7 +151,7 @@ safe_uint_t safe_uint_t::divide( */ template safe_uint_t safe_uint_t::operator/(const safe_uint_t& other) const { - ASSERT(this->value.is_constant() == false); + BB_ASSERT_EQ(this->value.is_constant(), false); uint256_t val = this->value.get_value(); auto [quotient_val, remainder_val] = val.divmod((uint256_t)other.value.get_value()); @@ -213,15 +214,15 @@ template bool_t safe_uint_t::operator!=(con template std::array, 3> safe_uint_t::slice(const uint8_t msb, const uint8_t lsb) const { - ASSERT(msb >= lsb); - ASSERT(static_cast(msb) <= grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH); + BB_ASSERT_GTE(msb, lsb); + BB_ASSERT_LTE(static_cast(msb), grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH); const safe_uint_t lhs = *this; Builder* ctx = lhs.get_context(); const uint256_t value = uint256_t(get_value()); // This should be caught by the proof itself, but the circuit creator will have now way of knowing where the issue // is - ASSERT(value < (static_cast(1) << grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH)); + BB_ASSERT_LT(value, (static_cast(1) << grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH)); const auto msb_plus_one = uint32_t(msb) + 1; const auto hi_mask = ((uint256_t(1) << (256 - uint32_t(msb))) - 1); const auto hi = (value >> msb_plus_one) & hi_mask; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp index d7f60fec3579..f9ced099e6ac 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp @@ -29,11 +29,8 @@ template class safe_uint_t { : value(value) , current_max(current_max) { - ASSERT(safety == IS_UNSAFE); - if (current_max > MAX_VALUE) // For optimal efficiency this should only be checked while testing a circuit - { - throw_or_abort("exceeded modulus in safe_uint class"); - } + BB_ASSERT_EQ(safety, IS_UNSAFE); + BB_ASSERT_LTE(current_max, MAX_VALUE, "exceeded modulus in safe_uint class"); } public: @@ -52,7 +49,7 @@ template class safe_uint_t { safe_uint_t(field_ct const& value, size_t bit_num, std::string const& description = "unknown") : value(value) { - ASSERT(bit_num <= MAX_BIT_NUM); + BB_ASSERT_LTE(bit_num, MAX_BIT_NUM); this->value.create_range_constraint(bit_num, format("safe_uint_t range constraint failure: ", description)); current_max = ((uint256_t)1 << bit_num) - 1; } @@ -123,7 +120,7 @@ template class safe_uint_t { safe_uint_t add_two(const safe_uint_t& add_a, const safe_uint_t& add_b) const { - ASSERT(current_max + add_a.current_max + add_b.current_max <= MAX_VALUE && "Exceeded modulus in add_two"); + BB_ASSERT_LTE(current_max + add_a.current_max + add_b.current_max, MAX_VALUE, "Exceeded modulus in add_two"); auto new_val = value.add_two(add_a.value, add_b.value); auto new_max = current_max + add_a.current_max + add_b.current_max; return safe_uint_t(new_val, new_max, IS_UNSAFE); @@ -131,8 +128,9 @@ template class safe_uint_t { safe_uint_t madd(const safe_uint_t& to_mul, const safe_uint_t& to_add) const { - ASSERT((uint512_t)current_max * (uint512_t)to_mul.current_max + (uint512_t)to_add.current_max <= MAX_VALUE && - "Exceeded modulus in madd"); + BB_ASSERT_LTE((uint512_t)current_max * (uint512_t)to_mul.current_max + (uint512_t)to_add.current_max, + MAX_VALUE, + "Exceeded modulus in madd"); auto new_val = value.madd(to_mul.value, to_add.value); auto new_max = current_max * to_mul.current_max + to_add.current_max; return safe_uint_t(new_val, new_max, IS_UNSAFE); 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 d271748c0c8a..195a1365913e 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 @@ -5,6 +5,7 @@ #include "barretenberg/stdlib/primitives/bool/bool.hpp" #include "barretenberg/stdlib/primitives/witness/witness.hpp" #include "barretenberg/transcript/origin_tag.hpp" +#include "gmock/gmock.h" #include #include @@ -112,7 +113,7 @@ TYPED_TEST(SafeUintTest, TestMultiplyOperationOutOfRangeFails) FAIL() << "Expected out of range error"; } catch (std::runtime_error const& err) { EXPECT_TRUE(CircuitChecker::check(builder)); // no failing constraints should be created from multiply - EXPECT_EQ(err.what(), std::string("exceeded modulus in safe_uint class")); + EXPECT_THAT(err.what(), testing::HasSubstr("exceeded modulus in safe_uint class")); } catch (...) { FAIL() << "Expected std::runtime_error modulus in safe_uint class"; } @@ -145,7 +146,7 @@ TYPED_TEST(SafeUintTest, TestMultiplyOperationOnConstantsOutOfRangeFails) FAIL() << "Expected out of range error"; } catch (std::runtime_error const& err) { EXPECT_TRUE(CircuitChecker::check(builder)); // no failing constraint from multiply - EXPECT_EQ(err.what(), std::string("exceeded modulus in safe_uint class")); + EXPECT_THAT(err.what(), testing::HasSubstr("exceeded modulus in safe_uint class")); } catch (...) { FAIL() << "Expected std::runtime_error modulus in safe_uint class"; } @@ -192,7 +193,7 @@ TYPED_TEST(SafeUintTest, TestAddOperationOutOfRangeFails) FAIL() << "Expected out of range error"; } catch (std::runtime_error const& err) { EXPECT_TRUE(CircuitChecker::check(builder)); // no failing constraints from add or multiply - EXPECT_EQ(err.what(), std::string("exceeded modulus in safe_uint class")); + EXPECT_THAT(err.what(), testing::HasSubstr("exceeded modulus in safe_uint class")); } catch (...) { FAIL() << "Expected std::runtime_error modulus in safe_uint class"; } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/arithmetic.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/arithmetic.cpp index 03ea16decf69..dcc0329b65d8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/arithmetic.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/arithmetic.cpp @@ -5,6 +5,7 @@ // ===================== #include "../circuit_builders/circuit_builders.hpp" +#include "barretenberg/common/assert.hpp" #include "uint.hpp" using namespace bb; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp index 6d93eda97f64..db497289f7f8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp @@ -5,6 +5,7 @@ // ===================== #include "protogalaxy_recursive_verifier.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/honk/library/grand_product_delta.hpp" #include "barretenberg/protogalaxy/prover_verifier_shared.hpp" #include "barretenberg/stdlib/honk_verifier/oink_recursive_verifier.hpp" @@ -120,12 +121,12 @@ std::shared_ptr ProtogalaxyRecursiv std::vector accumulator_commitments; std::vector instance_commitments; for (const auto& precomputed : keys_to_fold.get_precomputed_commitments()) { - ASSERT(precomputed.size() == 2); + BB_ASSERT_EQ(precomputed.size(), 2U); accumulator_commitments.emplace_back(precomputed[0]); instance_commitments.emplace_back(precomputed[1]); } for (const auto& witness : keys_to_fold.get_witness_commitments()) { - ASSERT(witness.size() == 2); + BB_ASSERT_EQ(witness.size(), 2U); accumulator_commitments.emplace_back(witness[0]); instance_commitments.emplace_back(witness[1]); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp index aea68f639d6b..caa64584db97 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp @@ -252,7 +252,7 @@ class ProtogalaxyRecursiveTests : public testing::Test { auto recursive_folding_manifest = verifier.transcript->get_manifest(); auto native_folding_manifest = native_folding_verifier.transcript->get_manifest(); - ASSERT(recursive_folding_manifest.size() > 0); + ASSERT_GT(recursive_folding_manifest.size(), 0); for (size_t i = 0; i < recursive_folding_manifest.size(); ++i) { EXPECT_EQ(recursive_folding_manifest[i], native_folding_manifest[i]) << "Recursive Verifier/Verifier manifest discrepency in round " << i; @@ -272,7 +272,7 @@ class ProtogalaxyRecursiveTests : public testing::Test { auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); - ASSERT(verified); + ASSERT_TRUE(verified); } }; @@ -335,7 +335,7 @@ class ProtogalaxyRecursiveTests : public testing::Test { auto recursive_folding_manifest = verifier.transcript->get_manifest(); auto native_folding_manifest = native_folding_verifier.transcript->get_manifest(); - ASSERT(recursive_folding_manifest.size() > 0); + ASSERT_GT(recursive_folding_manifest.size(), 0); for (size_t i = 0; i < recursive_folding_manifest.size(); ++i) { EXPECT_EQ(recursive_folding_manifest[i], native_folding_manifest[i]) << "Recursive Verifier/Verifier manifest discrepency in round " << i; @@ -370,7 +370,7 @@ class ProtogalaxyRecursiveTests : public testing::Test { auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); - ASSERT(verified); + ASSERT_TRUE(verified); } }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_decider_verification_keys.hpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_decider_verification_keys.hpp index 47c0f5f639f3..d7dea08daffa 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_decider_verification_keys.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_decider_verification_keys.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/stdlib/protogalaxy_verifier/recursive_decider_verification_key.hpp" @@ -33,7 +34,7 @@ template struct RecursiveDeciderVerific const std::vector>& vk_and_hashs) : builder(builder) { - ASSERT(vk_and_hashs.size() == NUM - 1); + BB_ASSERT_EQ(vk_and_hashs.size(), NUM - 1); _data[0] = accumulator; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/transcript/transcript.hpp b/barretenberg/cpp/src/barretenberg/stdlib/transcript/transcript.hpp index e284402f7420..dcda0dc71acf 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/transcript/transcript.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/transcript/transcript.hpp @@ -6,6 +6,7 @@ #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/crypto/poseidon2/poseidon2.hpp" #include "barretenberg/stdlib/hash/poseidon2/poseidon2.hpp" #include "barretenberg/stdlib/primitives/field/field_conversion.hpp" @@ -20,7 +21,8 @@ template struct StdlibTranscriptParams { static inline Fr hash(const std::vector& data) { - ASSERT(!data.empty() && data[0].get_context() != nullptr); + ASSERT(!data.empty()); + ASSERT(data[0].get_context() != nullptr); Builder* builder = data[0].get_context(); return stdlib::poseidon2::hash(*builder, data); @@ -55,7 +57,8 @@ template struct StdlibTranscriptParams { template static inline T convert_from_bn254_frs(std::span frs) { - ASSERT(!frs.empty() && frs[0].get_context() != nullptr); + ASSERT(!frs.empty()); + ASSERT(frs[0].get_context() != nullptr); Builder* builder = frs[0].get_context(); return bb::stdlib::field_conversion::convert_from_bn254_frs(*builder, frs); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/translator_vm_verifier/translator_recursive_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/translator_vm_verifier/translator_recursive_verifier.test.cpp index 7febead18098..cc3935eea68d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/translator_vm_verifier/translator_recursive_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/translator_vm_verifier/translator_recursive_verifier.test.cpp @@ -131,7 +131,7 @@ class TranslatorRecursiveTests : public ::testing::Test { auto proof = prover.construct_proof(); bool verified = verifier.verify_proof(proof); - ASSERT(verified); + ASSERT_TRUE(verified); } } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp index 28be391e8469..ff3c085de106 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/curves/bn254/bn254.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" @@ -118,7 +119,7 @@ template class CircuitBuilderBase { * */ inline FF get_variable(const uint32_t index) const { - ASSERT(variables.size() > real_variable_index[index]); + BB_ASSERT_GT(variables.size(), real_variable_index[index]); return variables[real_variable_index[index]]; } @@ -135,7 +136,7 @@ template class CircuitBuilderBase { */ inline void set_variable(const uint32_t index, const FF& value) { - ASSERT(variables.size() > real_variable_index[index]); + BB_ASSERT_GT(variables.size(), real_variable_index[index]); variables[real_variable_index[index]] = value; } @@ -149,7 +150,7 @@ template class CircuitBuilderBase { * */ inline const FF& get_variable_reference(const uint32_t index) const { - ASSERT(variables.size() > index); + BB_ASSERT_GT(variables.size(), index); return variables[real_variable_index[index]]; } @@ -246,7 +247,6 @@ template class CircuitBuilderBase { // is equal to IS_CONSTANT; assuming that we will never have // uint32::MAX number of variables void assert_valid_variables(const std::vector& variable_indices); - bool is_valid_variable(uint32_t variable_index) { return variable_index < variables.size(); }; bool failed() const; const std::string& err() const; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base_impl.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base_impl.hpp index 8630740d23d7..e0c538804514 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base_impl.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/serialize/msgpack_impl.hpp" #include "circuit_builder_base.hpp" @@ -92,7 +93,7 @@ template uint32_t CircuitBuilderBase::add_variable(const FF& template void CircuitBuilderBase::set_variable_name(uint32_t index, const std::string& name) { - ASSERT(variables.size() > index); + BB_ASSERT_GT(variables.size(), index); uint32_t first_idx = get_first_variable_in_class(index); if (variable_names.contains(first_idx)) { @@ -236,7 +237,7 @@ template void CircuitBuilderBase::assert_valid_variables(const std::vector& variable_indices) { for (const auto& variable_index : variable_indices) { - ASSERT(is_valid_variable(variable_index)); + BB_ASSERT_LT(variable_index, variables.size()); } } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/databus.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/databus.hpp index fd4addd8c5d8..ea3af42175b3 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/databus.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/databus.hpp @@ -6,6 +6,7 @@ #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/honk/types/aggregation_object_type.hpp" #include "barretenberg/stdlib_circuit_builders/public_component_key.hpp" @@ -42,19 +43,19 @@ struct BusVector { const uint32_t& operator[](size_t idx) const { - ASSERT(idx < size()); + BB_ASSERT_LT(idx, size()); return data[idx]; } const uint32_t& get_read_count(size_t idx) const { - ASSERT(idx < read_counts.size()); + BB_ASSERT_LT(idx, read_counts.size()); return read_counts[idx]; } void increment_read_count(size_t idx) { - ASSERT(idx < read_counts.size()); + BB_ASSERT_LT(idx, read_counts.size()); read_counts[idx]++; } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_circuit_builder.cpp index 72628548d04e..ace60e30d26c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_circuit_builder.cpp @@ -5,6 +5,7 @@ // ===================== #include "mega_circuit_builder.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/crypto/poseidon2/poseidon2_params.hpp" #include "barretenberg/flavor/mega_flavor.hpp" #include @@ -202,7 +203,7 @@ uint32_t MegaCircuitBuilder_::read_bus_vector(BusId bus_idx, const uint32_t& // Get the raw index into the databus column const uint32_t read_idx = static_cast(uint256_t(this->get_variable(read_idx_witness_idx))); - ASSERT(read_idx < bus_vector.size()); // Ensure that the read index is valid + BB_ASSERT_LT(read_idx, bus_vector.size()); // Ensure that the read index is valid // Create a variable corresponding to the result of the read. Note that we do not in general connect reads from // databus via copy constraints (i.e. we create a unique variable for the result of each read) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp index 80156d323cfa..e4db21500cdf 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/stdlib_circuit_builders/mega_circuit_builder.hpp" namespace bb { @@ -141,7 +142,7 @@ class MockCircuits { { const size_t target_dyadic_size = 1 << target_log2_dyadic_size; const size_t num_preamble_gates = builder.num_gates; - ASSERT(target_dyadic_size >= num_preamble_gates); + BB_ASSERT_GTE(target_dyadic_size, num_preamble_gates); // For good measure, include a gate with some public inputs if (include_public_inputs && target_dyadic_size > num_preamble_gates) { @@ -157,7 +158,7 @@ class MockCircuits { static constexpr size_t OFFSET_HACK = 10; // to prevent underflow of the loop upper limit; target size >= 16 should suffice - ASSERT(target_dyadic_size > OFFSET_HACK + num_preamble_gates); + BB_ASSERT_GT(target_dyadic_size, OFFSET_HACK + num_preamble_gates); size_t num_gates_to_add = target_dyadic_size - OFFSET_HACK - 1 - num_preamble_gates; // Add arbitrary arithmetic gates to obtain a total of num_gates-many gates @@ -177,4 +178,4 @@ class MockCircuits { builder.queue_ecc_eq(); } }; -} // namespace bb \ No newline at end of file +} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp index afffd3daa0f0..fa3351341f03 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp @@ -13,6 +13,7 @@ * */ +#include "barretenberg/common/assert.hpp" #include "types.hpp" namespace bb::plookup::dummy_tables { @@ -50,7 +51,7 @@ inline BasicTable generate_honk_dummy_table(const BasicTableId id, const size_t // We do the assertion, since this function is templated, but the general API for these functions contains the id, // too. This helps us ensure that the correct instantion is used for a particular BasicTableId - ASSERT(table_id == static_cast(id)); + BB_ASSERT_EQ(table_id, static_cast(id)); const size_t base = 1 << 1; // Probably has to be a power of 2 BasicTable table; table.id = id; @@ -97,4 +98,4 @@ inline MultiTable get_honk_dummy_multitable() table.get_table_values.emplace_back(&get_value_from_key); return table; } -} // namespace bb::plookup::dummy_tables \ No newline at end of file +} // namespace bb::plookup::dummy_tables diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.cpp index 7b4fca41f34f..9eed7e922089 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.cpp @@ -6,6 +6,7 @@ #include "./fixed_base.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/crypto/pedersen_hash/pedersen.hpp" #include "barretenberg/numeric/bitop/pow.hpp" @@ -191,9 +192,9 @@ template BasicTable table::generate_basic_fixed_base_table(BasicTableId id, size_t basic_table_index, size_t table_index) { static_assert(multitable_index < NUM_FIXED_BASE_MULTI_TABLES); - ASSERT(table_index < MAX_NUM_TABLES_IN_MULTITABLE); + BB_ASSERT_LT(table_index, MAX_NUM_TABLES_IN_MULTITABLE); - const size_t multitable_bits = get_num_bits_of_multi_table(multitable_index); + const size_t multitable_bits = get_num_bits_of_multi_table(); const size_t bits_covered_by_previous_tables_in_multitable = BITS_PER_TABLE * table_index; const bool is_small_table = (multitable_bits - bits_covered_by_previous_tables_in_multitable) < BITS_PER_TABLE; const size_t table_bits = diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp index 003887d74c64..31e18edd776d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp @@ -95,7 +95,7 @@ class table : public FixedBaseParams { static std::array get_basic_fixed_base_table_values(const std::array key) { static_assert(multitable_index < NUM_FIXED_BASE_MULTI_TABLES); - static_assert(table_index < get_num_bits_of_multi_table(multitable_index)); + static_assert(table_index < get_num_bits_of_multi_table()); const auto& basic_table = fixed_base_tables()[multitable_index][table_index]; const auto index = static_cast(key[0]); return { basic_table[index].x, basic_table[index].y }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base_params.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base_params.hpp index 87e55374dcb4..d2617ca6e4d5 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base_params.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base_params.hpp @@ -69,9 +69,9 @@ struct FixedBaseParams { * @param multitable_index Ranges from 0 to NUM_FIXED_BASE_MULTI_TABLES - 1 * @return constexpr size_t */ - static constexpr size_t get_num_bits_of_multi_table(const size_t multitable_index) + template static constexpr size_t get_num_bits_of_multi_table() { - ASSERT(multitable_index < NUM_FIXED_BASE_MULTI_TABLES); + static_assert(multitable_index < NUM_FIXED_BASE_MULTI_TABLES); constexpr std::array MULTI_TABLE_BIT_LENGTHS{ BITS_PER_LO_SCALAR, BITS_PER_HI_SCALAR, BITS_PER_LO_SCALAR, BITS_PER_HI_SCALAR }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp index 8f6a5963101d..2f9a55b1556e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp @@ -10,6 +10,8 @@ #include #include "./fixed_base/fixed_base_params.hpp" +#include "barretenberg/common/assert.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" namespace bb::plookup { @@ -323,13 +325,8 @@ struct LookupHashTable { Value operator[](const Key& key) const { auto it = index_map.find(key); - if (it != index_map.end()) { - return it->second; - } else { - info("LookupHashTable: Key not found!"); - ASSERT(false); - return 0; - } + ASSERT(it != index_map.end(), "LookupHashTable: Key not found!"); + return it->second; } bool operator==(const LookupHashTable& other) const = default; @@ -389,7 +386,8 @@ struct BasicTable { size_t size() const { - ASSERT(column_1.size() == column_2.size() && column_2.size() == column_3.size()); + BB_ASSERT_EQ(column_1.size(), column_2.size()); + BB_ASSERT_EQ(column_2.size(), column_3.size()); return column_1.size(); } }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/rom_ram_logic.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/rom_ram_logic.cpp index dcd25d3be71e..6be10845b20b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/rom_ram_logic.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/rom_ram_logic.cpp @@ -1,4 +1,5 @@ #include "rom_ram_logic.hpp" +#include "barretenberg/common/assert.hpp" #include "ultra_circuit_builder.hpp" #include @@ -26,12 +27,12 @@ void RomRamLogic_::set_ROM_element(CircuitBuilder* builder, const size_t index_value, const uint32_t value_witness) { - ASSERT(rom_arrays.size() > rom_id); + BB_ASSERT_GT(rom_arrays.size(), rom_id); RomTranscript& rom_array = rom_arrays[rom_id]; const uint32_t index_witness = (index_value == 0) ? builder->zero_idx : builder->put_constant_variable((uint64_t)index_value); - ASSERT(rom_array.state.size() > index_value); - ASSERT(rom_array.state[index_value][0] == UNINITIALIZED_MEMORY_RECORD); + BB_ASSERT_GT(rom_array.state.size(), index_value); + BB_ASSERT_EQ(rom_array.state[index_value][0], UNINITIALIZED_MEMORY_RECORD); RomRecord new_record{ .index_witness = index_witness, @@ -53,12 +54,12 @@ void RomRamLogic_::set_ROM_element_pair(CircuitBuilder* builder, const size_t index_value, const std::array& value_witnesses) { - ASSERT(rom_arrays.size() > rom_id); + BB_ASSERT_GT(rom_arrays.size(), rom_id); RomTranscript& rom_array = rom_arrays[rom_id]; const uint32_t index_witness = (index_value == 0) ? builder->zero_idx : builder->put_constant_variable((uint64_t)index_value); - ASSERT(rom_array.state.size() > index_value); - ASSERT(rom_array.state[index_value][0] == UNINITIALIZED_MEMORY_RECORD); + BB_ASSERT_GT(rom_array.state.size(), index_value); + BB_ASSERT_EQ(rom_array.state[index_value][0], UNINITIALIZED_MEMORY_RECORD); RomRecord new_record{ .index_witness = index_witness, .value_column1_witness = value_witnesses[0], @@ -78,10 +79,10 @@ uint32_t RomRamLogic_::read_ROM_array(CircuitBuilder* builder, const size_t rom_id, const uint32_t index_witness) { - ASSERT(rom_arrays.size() > rom_id); + BB_ASSERT_GT(rom_arrays.size(), rom_id); RomTranscript& rom_array = rom_arrays[rom_id]; const uint32_t index = static_cast(uint256_t(builder->get_variable(index_witness))); - ASSERT(rom_array.state.size() > index); + BB_ASSERT_GT(rom_array.state.size(), index); ASSERT(rom_array.state[index][0] != UNINITIALIZED_MEMORY_RECORD); const auto value = builder->get_variable(rom_array.state[index][0]); const uint32_t value_witness = builder->add_variable(value); @@ -108,9 +109,9 @@ std::array RomRamLogic_::read_ROM_array_pair(Circui std::array value_witnesses; const uint32_t index = static_cast(uint256_t(builder->get_variable(index_witness))); - ASSERT(rom_arrays.size() > rom_id); + BB_ASSERT_GT(rom_arrays.size(), rom_id); RomTranscript& rom_array = rom_arrays[rom_id]; - ASSERT(rom_array.state.size() > index); + BB_ASSERT_GT(rom_array.state.size(), index); ASSERT(rom_array.state[index][0] != UNINITIALIZED_MEMORY_RECORD); ASSERT(rom_array.state[index][1] != UNINITIALIZED_MEMORY_RECORD); const auto value1 = builder->get_variable(rom_array.state[index][0]); @@ -270,12 +271,12 @@ void RomRamLogic_::init_RAM_element(CircuitBuilder* builder, const size_t index_value, const uint32_t value_witness) { - ASSERT(ram_arrays.size() > ram_id); + BB_ASSERT_GT(ram_arrays.size(), ram_id); RamTranscript& ram_array = ram_arrays[ram_id]; const uint32_t index_witness = (index_value == 0) ? builder->zero_idx : builder->put_constant_variable((uint64_t)index_value); - ASSERT(ram_array.state.size() > index_value); - ASSERT(ram_array.state[index_value] == UNINITIALIZED_MEMORY_RECORD); + BB_ASSERT_GT(ram_array.state.size(), index_value); + BB_ASSERT_EQ(ram_array.state[index_value], UNINITIALIZED_MEMORY_RECORD); RamRecord new_record{ .index_witness = index_witness, .timestamp_witness = builder->put_constant_variable((uint64_t)ram_array.access_count), .value_witness = value_witness, @@ -295,10 +296,10 @@ uint32_t RomRamLogic_::read_RAM_array(CircuitBuilder* builder, const size_t ram_id, const uint32_t index_witness) { - ASSERT(ram_arrays.size() > ram_id); + BB_ASSERT_GT(ram_arrays.size(), ram_id); RamTranscript& ram_array = ram_arrays[ram_id]; const uint32_t index = static_cast(uint256_t(builder->get_variable(index_witness))); - ASSERT(ram_array.state.size() > index); + BB_ASSERT_GT(ram_array.state.size(), index); ASSERT(ram_array.state[index] != UNINITIALIZED_MEMORY_RECORD); const auto value = builder->get_variable(ram_array.state[index]); const uint32_t value_witness = builder->add_variable(value); @@ -327,10 +328,10 @@ void RomRamLogic_::write_RAM_array(CircuitBuilder* builder, const uint32_t index_witness, const uint32_t value_witness) { - ASSERT(ram_arrays.size() > ram_id); + BB_ASSERT_GT(ram_arrays.size(), ram_id); RamTranscript& ram_array = ram_arrays[ram_id]; const uint32_t index = static_cast(uint256_t(builder->get_variable(index_witness))); - ASSERT(ram_array.state.size() > index); + BB_ASSERT_GT(ram_array.state.size(), index); ASSERT(ram_array.state[index] != UNINITIALIZED_MEMORY_RECORD); RamRecord new_record{ .index_witness = index_witness, @@ -505,7 +506,7 @@ void RomRamLogic_::process_RAM_array(CircuitBuilder* builder, co break; } default: { - ASSERT(false); // shouldn't get here! + throw_or_abort("Unexpected record.access_type."); // shouldn't get here! } } } @@ -522,7 +523,7 @@ void RomRamLogic_::process_RAM_array(CircuitBuilder* builder, co FF timestamp_delta = 0; if (share_index) { - ASSERT(next.timestamp > current.timestamp); + BB_ASSERT_GT(next.timestamp, current.timestamp); timestamp_delta = FF(next.timestamp - current.timestamp); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp index 44a21acbd8a8..1e285c2b99c8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp @@ -12,6 +12,7 @@ * */ #include "ultra_circuit_builder.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/crypto/poseidon2/poseidon2_params.hpp" #include "rom_ram_logic.hpp" @@ -867,7 +868,7 @@ std::vector UltraCircuitBuilder_::decompose_into_defau { this->assert_valid_variables({ variable_index }); - ASSERT(num_bits > 0); + BB_ASSERT_GT(num_bits, 0U); uint256_t val = (uint256_t)(this->get_variable(variable_index)); @@ -1023,7 +1024,7 @@ void UltraCircuitBuilder_::create_new_range_constraint(const uin } } } - ASSERT(found_tag == true); + ASSERT(found_tag); } assign_tag(variable_index, list.range_tag); list.variable_indices.emplace_back(variable_index); @@ -1034,7 +1035,7 @@ template void UltraCircuitBuilder_::pr { this->assert_valid_variables(list.variable_indices); - ASSERT(list.variable_indices.size() > 0); + BB_ASSERT_GT(list.variable_indices.size(), 0U); // replace witness index in variable_indices with the real variable index i.e. if a copy constraint has been // applied on a variable after it was range constrained, this makes sure the indices in list point to the updated @@ -1108,7 +1109,7 @@ template void UltraCircuitBuilder_::create_sort_constraint(const std::vector& variable_index) { constexpr size_t gate_width = NUM_WIRES; - ASSERT(variable_index.size() % gate_width == 0); + BB_ASSERT_EQ(variable_index.size() % gate_width, 0U); this->assert_valid_variables(variable_index); for (size_t i = 0; i < variable_index.size(); i += gate_width) { @@ -1200,7 +1201,8 @@ void UltraCircuitBuilder_::create_sort_constraint_with_edges( { // Convenient to assume size is at least 8 (gate_width = 4) for separate gates for start and end conditions constexpr size_t gate_width = NUM_WIRES; - ASSERT(variable_index.size() % gate_width == 0 && variable_index.size() > gate_width); + BB_ASSERT_EQ(variable_index.size() % gate_width, 0U); + BB_ASSERT_GT(variable_index.size(), gate_width); this->assert_valid_variables(variable_index); auto& block = blocks.delta_range; @@ -1583,8 +1585,8 @@ void UltraCircuitBuilder_::range_constrain_two_limbs(const uint3 { // Validate limbs are <= 70 bits. If limbs are larger we require more witnesses and cannot use our limb accumulation // custom gate - ASSERT(lo_limb_bits <= (14 * 5)); - ASSERT(hi_limb_bits <= (14 * 5)); + BB_ASSERT_LTE(lo_limb_bits, 14U * 5U); + BB_ASSERT_LTE(hi_limb_bits, 14U * 5U); // Sometimes we try to use limbs that are too large. It's easier to catch this issue here const auto get_sublimbs = [&](const uint32_t& limb_idx, const std::array& sublimb_masks) { @@ -1658,17 +1660,17 @@ template std::array UltraCircuitBuilder_::decompose_non_native_field_double_width_limb( const uint32_t limb_idx, const size_t num_limb_bits) { - ASSERT(uint256_t(this->get_variable_reference(limb_idx)) < (uint256_t(1) << num_limb_bits)); + BB_ASSERT_LT(uint256_t(this->get_variable_reference(limb_idx)), (uint256_t(1) << num_limb_bits)); constexpr FF LIMB_MASK = (uint256_t(1) << DEFAULT_NON_NATIVE_FIELD_LIMB_BITS) - 1; const uint256_t value = this->get_variable(limb_idx); const uint256_t low = value & LIMB_MASK; const uint256_t hi = value >> DEFAULT_NON_NATIVE_FIELD_LIMB_BITS; - ASSERT(low + (hi << DEFAULT_NON_NATIVE_FIELD_LIMB_BITS) == value); + BB_ASSERT_EQ(low + (hi << DEFAULT_NON_NATIVE_FIELD_LIMB_BITS), value); const uint32_t low_idx = this->add_variable(low); const uint32_t hi_idx = this->add_variable(hi); - ASSERT(num_limb_bits > DEFAULT_NON_NATIVE_FIELD_LIMB_BITS); + BB_ASSERT_GT(num_limb_bits, DEFAULT_NON_NATIVE_FIELD_LIMB_BITS); const size_t lo_bits = DEFAULT_NON_NATIVE_FIELD_LIMB_BITS; const size_t hi_bits = num_limb_bits - DEFAULT_NON_NATIVE_FIELD_LIMB_BITS; range_constrain_two_limbs(low_idx, hi_idx, lo_bits, hi_bits); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp index 35a339434a96..bbd4627c44eb 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/honk/execution_trace/mega_execution_trace.hpp" #include "barretenberg/honk/execution_trace/ultra_execution_trace.hpp" #include "barretenberg/honk/types/circuit_type.hpp" @@ -329,7 +330,7 @@ class UltraCircuitBuilder_ : public CircuitBuilderBase& variable_index, const FF&, const FF&); void assign_tag(const uint32_t variable_index, const uint32_t tag) { - ASSERT(tag <= this->current_tag); + BB_ASSERT_LTE(tag, this->current_tag); // If we've already assigned this tag to this variable, return (can happen due to copy constraints) if (this->real_variable_tags[this->real_variable_index[variable_index]] == tag) { return; } - ASSERT(this->real_variable_tags[this->real_variable_index[variable_index]] == DUMMY_TAG); + BB_ASSERT_EQ(this->real_variable_tags[this->real_variable_index[variable_index]], DUMMY_TAG); this->real_variable_tags[this->real_variable_index[variable_index]] = tag; } diff --git a/barretenberg/cpp/src/barretenberg/transcript/origin_tag.hpp b/barretenberg/cpp/src/barretenberg/transcript/origin_tag.hpp index a100a526b27e..ecb4cdc66ca6 100644 --- a/barretenberg/cpp/src/barretenberg/transcript/origin_tag.hpp +++ b/barretenberg/cpp/src/barretenberg/transcript/origin_tag.hpp @@ -13,6 +13,7 @@ * to detect dangerous behaviours in-circuit. The mechanism is only enabled in DEBUG builds * */ +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" #include @@ -108,7 +109,7 @@ struct OriginTag { : parent_tag(parent_index) , child_tag((static_cast(1) << (child_index + (is_submitted ? 0 : 128)))) { - ASSERT(child_index < 128); + BB_ASSERT_LT(child_index, 128U); } /** @@ -210,4 +211,4 @@ inline std::ostream& operator<<(std::ostream& os, OriginTag const&) #endif } // namespace bb template -concept usesTag = requires(T x, const bb::OriginTag& tag) { x.set_origin_tag(tag); }; \ No newline at end of file +concept usesTag = requires(T x, const bb::OriginTag& tag) { x.set_origin_tag(tag); }; diff --git a/barretenberg/cpp/src/barretenberg/transcript/transcript.hpp b/barretenberg/cpp/src/barretenberg/transcript/transcript.hpp index 05cdd154de21..29cf828a63ca 100644 --- a/barretenberg/cpp/src/barretenberg/transcript/transcript.hpp +++ b/barretenberg/cpp/src/barretenberg/transcript/transcript.hpp @@ -8,6 +8,7 @@ // #define LOG_CHALLENGES // #define LOG_INTERACTIONS +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/debug_log.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" @@ -203,7 +204,7 @@ template class BaseTranscript { [[nodiscard]] std::array get_next_duplex_challenge_buffer(size_t num_challenges) { // challenges need at least 110 bits in them to match the presumed security parameter of the BN254 curve. - ASSERT(num_challenges <= 2); + BB_ASSERT_LTE(num_challenges, 2U); // Prevent challenge generation if this is the first challenge we're generating, // AND nothing was sent by the prover. if (is_first_challenge) { @@ -284,7 +285,7 @@ template class BaseTranscript { template T deserialize_from_buffer(const Proof& proof_data, size_t& offset) const { constexpr size_t element_fr_size = TranscriptParams::template calc_num_bn254_frs(); - ASSERT(offset + element_fr_size <= proof_data.size()); + BB_ASSERT_LTE(offset + element_fr_size, proof_data.size()); auto element_frs = std::span{ proof_data }.subspan(offset, element_fr_size); offset += element_fr_size; @@ -554,7 +555,7 @@ template class BaseTranscript { template T receive_from_prover(const std::string& label) { const size_t element_size = TranscriptParams::template calc_num_bn254_frs(); - ASSERT(num_frs_read + element_size <= proof_data.size()); + BB_ASSERT_LTE(num_frs_read + element_size, proof_data.size()); auto element_frs = std::span{ proof_data }.subspan(num_frs_read, element_size); num_frs_read += element_size; diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator.fuzzer.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator.fuzzer.hpp index 5123c7e296a2..7a41f53f34f9 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator.fuzzer.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator.fuzzer.hpp @@ -11,6 +11,7 @@ * @date 2024-02-25 * */ +#include "barretenberg/common/assert.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" #include "translator_circuit_builder.hpp" @@ -24,7 +25,7 @@ using G1 = curve::BN254::AffineElement; // Don't use dereference casts, since the data may be not aligned and it causes segfault uint256_t read_uint256(const uint8_t* data, size_t buffer_size = 32) { - ASSERT(buffer_size <= 32); + BB_ASSERT_LTE(buffer_size, 32U); uint64_t parts[4] = { 0, 0, 0, 0 }; diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_circuit_builder.cpp index 460322c48b7a..efb75138f0e2 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_circuit_builder.cpp @@ -14,6 +14,7 @@ * */ #include "translator_circuit_builder.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" #include "barretenberg/op_queue/ecc_op_queue.hpp" @@ -192,7 +193,7 @@ TranslatorCircuitBuilder::AccumulationInput TranslatorCircuitBuilder::generate_w uint512_t quotient = quotient_by_modulus / uint512_t(Fq::modulus); - ASSERT(quotient_by_modulus == (quotient * uint512_t(Fq::modulus))); + BB_ASSERT_EQ(quotient_by_modulus, quotient * uint512_t(Fq::modulus)); // Compute quotient and remainder bigfield representation auto remainder_limbs = split_fq_into_limbs(remainder); @@ -217,7 +218,7 @@ TranslatorCircuitBuilder::AccumulationInput TranslatorCircuitBuilder::generate_w SHIFT_1; // Low bits have to be zero - ASSERT(uint256_t(low_wide_relation_limb).slice(0, 2 * NUM_LIMB_BITS) == 0); + BB_ASSERT_EQ(uint256_t(low_wide_relation_limb).slice(0, 2 * NUM_LIMB_BITS), 0U); Fr low_wide_relation_limb_divided = low_wide_relation_limb * SHIFT_2_INVERSE; @@ -247,7 +248,7 @@ TranslatorCircuitBuilder::AccumulationInput TranslatorCircuitBuilder::generate_w SHIFT_1; // Check that the results lower 136 bits are zero - ASSERT(uint256_t(high_wide_relation_limb).slice(0, 2 * NUM_LIMB_BITS) == 0); + BB_ASSERT_EQ(uint256_t(high_wide_relation_limb).slice(0, 2 * NUM_LIMB_BITS), 0U); // Get divided version auto high_wide_relation_limb_divided = high_wide_relation_limb * SHIFT_2_INVERSE; @@ -330,16 +331,16 @@ void TranslatorCircuitBuilder::assert_well_formed_ultra_op(const UltraOp& ultra_ ASSERT(op_code == 0 || op_code == 3 || op_code == 4 || op_code == 8); // Check and insert x_lo and y_hi into wire 1 - ASSERT(uint256_t(ultra_op.x_lo) <= MAX_LOW_WIDE_LIMB_SIZE); - ASSERT(uint256_t(ultra_op.y_hi) <= MAX_HIGH_WIDE_LIMB_SIZE); + BB_ASSERT_LTE(uint256_t(ultra_op.x_lo), MAX_LOW_WIDE_LIMB_SIZE); + BB_ASSERT_LTE(uint256_t(ultra_op.y_hi), MAX_HIGH_WIDE_LIMB_SIZE); // Check and insert x_hi and z_1 into wire 2 - ASSERT(uint256_t(ultra_op.x_hi) <= MAX_HIGH_WIDE_LIMB_SIZE); - ASSERT(uint256_t(ultra_op.z_1) <= MAX_LOW_WIDE_LIMB_SIZE); + BB_ASSERT_LTE(uint256_t(ultra_op.x_hi), MAX_HIGH_WIDE_LIMB_SIZE); + BB_ASSERT_LTE(uint256_t(ultra_op.z_1), MAX_LOW_WIDE_LIMB_SIZE); // Check and insert y_lo and z_2 into wire 3 - ASSERT(uint256_t(ultra_op.y_lo) <= MAX_LOW_WIDE_LIMB_SIZE); - ASSERT(uint256_t(ultra_op.z_2) <= MAX_LOW_WIDE_LIMB_SIZE); + BB_ASSERT_LTE(uint256_t(ultra_op.y_lo), MAX_LOW_WIDE_LIMB_SIZE); + BB_ASSERT_LTE(uint256_t(ultra_op.z_2), MAX_LOW_WIDE_LIMB_SIZE); } void TranslatorCircuitBuilder::assert_well_formed_accumulation_input(const AccumulationInput& acc_step) @@ -348,12 +349,12 @@ void TranslatorCircuitBuilder::assert_well_formed_accumulation_input(const Accum assert_well_formed_ultra_op(acc_step.ultra_op); // Check decomposition of values from the Queue into limbs used in bigfield evaluations - ASSERT(acc_step.ultra_op.x_lo == (acc_step.P_x_limbs[0] + acc_step.P_x_limbs[1] * SHIFT_1)); - ASSERT(acc_step.ultra_op.x_hi == (acc_step.P_x_limbs[2] + acc_step.P_x_limbs[3] * SHIFT_1)); - ASSERT(acc_step.ultra_op.y_lo == (acc_step.P_y_limbs[0] + acc_step.P_y_limbs[1] * SHIFT_1)); - ASSERT(acc_step.ultra_op.y_hi == (acc_step.P_y_limbs[2] + acc_step.P_y_limbs[3] * SHIFT_1)); - ASSERT(acc_step.ultra_op.z_1 == (acc_step.z_1_limbs[0] + acc_step.z_1_limbs[1] * SHIFT_1)); - ASSERT(acc_step.ultra_op.z_2 == (acc_step.z_2_limbs[0] + acc_step.z_2_limbs[1] * SHIFT_1)); + BB_ASSERT_EQ(acc_step.ultra_op.x_lo, acc_step.P_x_limbs[0] + acc_step.P_x_limbs[1] * SHIFT_1); + BB_ASSERT_EQ(acc_step.ultra_op.x_hi, acc_step.P_x_limbs[2] + acc_step.P_x_limbs[3] * SHIFT_1); + BB_ASSERT_EQ(acc_step.ultra_op.y_lo, acc_step.P_y_limbs[0] + acc_step.P_y_limbs[1] * SHIFT_1); + BB_ASSERT_EQ(acc_step.ultra_op.y_hi, acc_step.P_y_limbs[2] + acc_step.P_y_limbs[3] * SHIFT_1); + BB_ASSERT_EQ(acc_step.ultra_op.z_1, acc_step.z_1_limbs[0] + acc_step.z_1_limbs[1] * SHIFT_1); + BB_ASSERT_EQ(acc_step.ultra_op.z_2, acc_step.z_2_limbs[0] + acc_step.z_2_limbs[1] * SHIFT_1); /** * @brief Check correctness of limbs values * @@ -362,9 +363,9 @@ void TranslatorCircuitBuilder::assert_well_formed_accumulation_input(const Accum const uint256_t& MAX_LAST_LIMB = (uint256_t(1) << NUM_LAST_LIMB_BITS)) { for (size_t i = 0; i < total_limbs - 1; i++) { - ASSERT(uint256_t(limbs[i]) < SHIFT_1); + BB_ASSERT_LT(uint256_t(limbs[i]), SHIFT_1); } - ASSERT(uint256_t(limbs[total_limbs - 1]) < MAX_LAST_LIMB); + BB_ASSERT_LT(uint256_t(limbs[total_limbs - 1]), MAX_LAST_LIMB); }; const auto MAX_Z_LAST_LIMB = uint256_t(1) << (NUM_Z_BITS - NUM_LIMB_BITS); @@ -384,7 +385,7 @@ void TranslatorCircuitBuilder::assert_well_formed_accumulation_input(const Accum const std::array, binary_limb_count>& limbs) { for (size_t i = 0; i < binary_limb_count; i++) { for (size_t j = 0; j < micro_limb_count; j++) { - ASSERT(uint256_t(limbs[i][j]) < MICRO_SHIFT); + BB_ASSERT_LT(uint256_t(limbs[i][j]), MICRO_SHIFT); } } }; @@ -395,8 +396,8 @@ void TranslatorCircuitBuilder::assert_well_formed_accumulation_input(const Accum check_micro_limbs_maximum_values(acc_step.current_accumulator_microlimbs); // Check that relation limbs are in range - ASSERT(uint256_t(acc_step.relation_wide_limbs[0]) < MAX_RELATION_WIDE_LIMB_SIZE); - ASSERT(uint256_t(acc_step.relation_wide_limbs[1]) < MAX_RELATION_WIDE_LIMB_SIZE); + BB_ASSERT_LT(uint256_t(acc_step.relation_wide_limbs[0]), MAX_RELATION_WIDE_LIMB_SIZE); + BB_ASSERT_LT(uint256_t(acc_step.relation_wide_limbs[1]), MAX_RELATION_WIDE_LIMB_SIZE); } void TranslatorCircuitBuilder::populate_wires_from_ultra_op(const UltraOp& ultra_op) @@ -508,7 +509,7 @@ void TranslatorCircuitBuilder::create_accumulation_gate(const AccumulationInput& num_gates += 2; // Check that all the wires are filled equally - bb::constexpr_for<0, TOTAL_COUNT, 1>([&]() { ASSERT(std::get(wires).size() == num_gates); }); + bb::constexpr_for<0, TOTAL_COUNT, 1>([&]() { BB_ASSERT_EQ(std::get(wires).size(), num_gates); }); } void TranslatorCircuitBuilder::feed_ecc_op_queue_into_circuit(const std::shared_ptr ecc_op_queue) diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_mini.fuzzer.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_mini.fuzzer.cpp index 54e8b895c292..5198b4173815 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_mini.fuzzer.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_mini.fuzzer.cpp @@ -5,6 +5,7 @@ // ===================== #include "barretenberg/circuit_checker/translator_circuit_checker.hpp" +#include "barretenberg/common/assert.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" #include "translator_circuit_builder.hpp" @@ -17,7 +18,7 @@ using Fq = curve::BN254::BaseField; // Don't use dereference casts, since the data may be not aligned and it causes segfault uint256_t read_uint256(const uint8_t* data, size_t buffer_size = 32) { - ASSERT(buffer_size <= 32); + BB_ASSERT_LTE(buffer_size, 32U); uint64_t parts[4] = { 0, 0, 0, 0 }; diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.cpp index dc9a708beae4..14f9631a1680 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.cpp @@ -5,6 +5,7 @@ // ===================== #include "translator_proving_key.hpp" +#include "barretenberg/common/assert.hpp" namespace bb { /** * @brief Construct a set of polynomials that are the result of interleaving a group of polynomials into one. Used in @@ -31,12 +32,12 @@ void TranslatorProvingKey::compute_interleaved_polynomials() auto targets = proving_key->polynomials.get_interleaved(); const size_t num_polys_in_group = interleaved[0].size(); - ASSERT(num_polys_in_group == Flavor::INTERLEAVING_GROUP_SIZE); + BB_ASSERT_EQ(num_polys_in_group, Flavor::INTERLEAVING_GROUP_SIZE); // Targets have to be full-sized proving_key->polynomials. We can compute the mini circuit size from them by // dividing by the number of polynomials in the group const size_t MINI_CIRCUIT_SIZE = targets[0].size() / num_polys_in_group; - ASSERT(MINI_CIRCUIT_SIZE * num_polys_in_group == targets[0].size()); + BB_ASSERT_EQ(MINI_CIRCUIT_SIZE * num_polys_in_group, targets[0].size()); auto ordering_function = [&](size_t index) { // Get the index of the interleaved polynomial @@ -137,7 +138,7 @@ void TranslatorProvingKey::compute_translator_range_constraint_ordered_polynomia // 2. Comparison operators for finite fields are operating on internal form, so we'd have to convert them // from Montgomery std::sort(ordered_vectors_uint.begin(), ordered_vectors_uint.end()); - ASSERT(ordered_vectors_uint.size() == dyadic_circuit_size_without_masking); + BB_ASSERT_EQ(ordered_vectors_uint.size(), dyadic_circuit_size_without_masking); // Copy the values into the actual polynomial ordered_constraint_polynomials[i].copy_vector(ordered_vectors_uint); }; @@ -221,7 +222,8 @@ void TranslatorProvingKey::split_interleaved_random_coefficients_to_ordered() // configurations ensure this still remain within boundaries of the polynomial size otherwise the assignment would // fail. size_t index_into_random = num_ordered_polynomials * num_random_values_per_ordered; - ASSERT(remaining_random_values < num_ordered_polynomials && end < ordered[0].end_index()); + BB_ASSERT_LT(remaining_random_values, num_ordered_polynomials); + BB_ASSERT_LT(end, ordered[0].end_index()); for (size_t i = 0; i < remaining_random_values; i++) { ordered[i].at(end) = random_values[index_into_random]; index_into_random++; diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.hpp index af2745a8fcf4..f1b6fb639b5d 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_proving_key.hpp @@ -7,6 +7,7 @@ #pragma once #include +#include "barretenberg/common/assert.hpp" #include "barretenberg/translator_vm/translator_flavor.hpp" namespace bb { // TODO(https://github.com/AztecProtocol/barretenberg/issues/1317) @@ -63,7 +64,7 @@ class TranslatorProvingKey { if (i >= wire_poly.start_index() && i < wire_poly.end_index()) { wire_poly.at(i) = circuit.get_variable(wire[i]); } else { - ASSERT(circuit.get_variable(wire[i]) == 0); + BB_ASSERT_EQ(circuit.get_variable(wire[i]), 0); } } }); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp index b1a8bc73ae9e..c2e001e6fb83 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp @@ -5,6 +5,7 @@ // ===================== #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/ultra_honk/decider_proving_key.hpp" #include "barretenberg/ultra_honk/decider_verification_key.hpp" @@ -34,7 +35,7 @@ template struct DeciderProvingKeys_ DeciderProvingKeys_() = default; DeciderProvingKeys_(std::vector> data) { - ASSERT(data.size() == NUM); + BB_ASSERT_EQ(data.size(), NUM); for (size_t idx = 0; idx < data.size(); idx++) { _data[idx] = std::move(data[idx]); } @@ -124,7 +125,7 @@ template struct DeciderVerification DeciderVerificationKeys_() = default; DeciderVerificationKeys_(const std::vector>& data) { - ASSERT(data.size() == NUM); + BB_ASSERT_EQ(data.size(), NUM); for (size_t idx = 0; idx < data.size(); idx++) { _data[idx] = std::move(data[idx]); } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.cpp index a49ca586921e..10228a8c44b1 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.cpp @@ -5,6 +5,8 @@ // ===================== #include "decider_proving_key.hpp" +#include "barretenberg/common/assert.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/honk/composer/permutation_lib.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" @@ -103,7 +105,7 @@ void DeciderProvingKey_::allocate_table_lookup_polynomials(const Circuit size_t table_offset = circuit.blocks.lookup.trace_offset(); // TODO(https://github.com/AztecProtocol/barretenberg/issues/1193): can potentially improve memory footprint const size_t max_tables_size = dyadic_size() - table_offset; - ASSERT(dyadic_size() > max_tables_size); + BB_ASSERT_GT(dyadic_size(), max_tables_size); // Allocate the polynomials containing the actual table data if constexpr (IsUltraOrMegaHonk) { @@ -255,18 +257,16 @@ void DeciderProvingKey_::move_structured_trace_overflow_to_overflow_bloc if (block_size > fixed_block_size && block != overflow_block) { // Disallow overflow in blocks that are not expected to be used by App circuits if (&block == &blocks.pub_inputs) { - info("WARNING: Number of public inputs (", - block_size, - ") cannot exceed capacity specified in structured trace: ", - fixed_block_size); - ASSERT(false); + std::ostringstream oss; + oss << "WARNING: Number of public inputs (" << block_size + << ") cannot exceed capacity specified in structured trace: " << fixed_block_size; + throw_or_abort(oss.str()); } if (&block == &blocks.ecc_op) { - info("WARNING: Number of ecc op gates (", - block_size, - ") cannot exceed capacity specified in structured trace: ", - fixed_block_size); - ASSERT(false); + std::ostringstream oss; + oss << "WARNING: Number of ecc op gates (" << block_size + << ") cannot exceed capacity specified in structured trace: " << fixed_block_size; + throw_or_abort(oss.str()); } // Set has_overflow to true if at least one block exceeds its capacity diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp index 8ebf62426264..128a5f3059b8 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp @@ -203,7 +203,7 @@ TYPED_TEST(MegaTranscriptTests, ProverManifestConsistency) auto manifest_expected = TestFixture::construct_mega_honk_manifest(); auto prover_manifest = prover.transcript->get_manifest(); // Note: a manifest can be printed using manifest.print() - ASSERT(manifest_expected.size() > 0); + ASSERT_GT(manifest_expected.size(), 0); for (size_t round = 0; round < manifest_expected.size(); ++round) { if (prover_manifest[round] != manifest_expected[round]) { info("Prover manifest discrepency in round ", round); @@ -211,7 +211,7 @@ TYPED_TEST(MegaTranscriptTests, ProverManifestConsistency) prover_manifest[round].print(); info("Expected manifest:"); manifest_expected[round].print(); - ASSERT(false); + FAIL(); } } } @@ -251,13 +251,13 @@ TYPED_TEST(MegaTranscriptTests, VerifierManifestConsistency) auto verifier_manifest = verifier.transcript->get_manifest(); // Note: a manifest can be printed using manifest.print() - ASSERT(prover_manifest.size() > 0); + ASSERT_GT(prover_manifest.size(), 0); for (size_t round = 0; round < prover_manifest.size(); ++round) { if (prover_manifest[round] != verifier_manifest[round]) { info("Prover/Verifier manifest discrepency in round ", round); prover_manifest[round].print(); verifier_manifest[round].print(); - ASSERT(false); + FAIL(); } } } @@ -334,4 +334,4 @@ TYPED_TEST(MegaTranscriptTests, StructureTest) prover.transcript->deserialize_full_transcript(verification_key->num_public_inputs); EXPECT_EQ(static_cast(prover.transcript->z_perm_comm), one_group_val * rand_val); } -} \ No newline at end of file +} 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 b99e9e0daee3..9a670c375fe3 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp @@ -235,7 +235,7 @@ TYPED_TEST(UltraTranscriptTests, ProverManifestConsistency) // Note: a manifest can be printed using manifest.print() manifest_expected.print(); prover_manifest.print(); - ASSERT(manifest_expected.size() > 0); + ASSERT_GT(manifest_expected.size(), 0); for (size_t round = 0; round < manifest_expected.size(); ++round) { if (prover_manifest[round] != manifest_expected[round]) { info("Prover manifest discrepency in round ", round); @@ -243,7 +243,7 @@ TYPED_TEST(UltraTranscriptTests, ProverManifestConsistency) prover_manifest[round].print(); info("Expected manifest:"); manifest_expected[round].print(); - ASSERT(false); + FAIL(); } } } @@ -278,7 +278,7 @@ TYPED_TEST(UltraTranscriptTests, VerifierManifestConsistency) const size_t num_public_inputs = static_cast(verification_key->num_public_inputs); // The extra calculation is for the IPA proof length. // TODO(https://github.com/AztecProtocol/barretenberg/issues/1182): Handle in ProofSurgeon. - ASSERT(proof.size() == HONK_PROOF_LENGTH + IPA_PROOF_LENGTH + num_public_inputs); + ASSERT_EQ(proof.size(), HONK_PROOF_LENGTH + IPA_PROOF_LENGTH + num_public_inputs); // split out the ipa proof const std::ptrdiff_t honk_proof_with_pub_inputs_length = static_cast(HONK_PROOF_LENGTH + num_public_inputs); @@ -294,7 +294,7 @@ TYPED_TEST(UltraTranscriptTests, VerifierManifestConsistency) auto verifier_manifest = verifier.transcript->get_manifest(); // Note: a manifest can be printed using manifest.print() - ASSERT(prover_manifest.size() > 0); + ASSERT_GT(prover_manifest.size(), 0); for (size_t round = 0; round < prover_manifest.size(); ++round) { ASSERT_EQ(prover_manifest[round], verifier_manifest[round]) << "Prover/Verifier manifest discrepency in round " << round; diff --git a/barretenberg/cpp/src/barretenberg/vm2/constraining/flavor.cpp b/barretenberg/cpp/src/barretenberg/vm2/constraining/flavor.cpp index e373a5447cbd..45909e7119a4 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/constraining/flavor.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/constraining/flavor.cpp @@ -1,15 +1,16 @@ #include "flavor.hpp" +#include "barretenberg/common/assert.hpp" namespace bb::avm2 { AvmFlavor::ProverPolynomials::ProverPolynomials(ProvingKey& proving_key) { for (auto [prover_poly, key_poly] : zip_view(this->get_unshifted(), proving_key.get_all())) { - ASSERT(flavor_get_label(*this, prover_poly) == flavor_get_label(proving_key, key_poly)); + BB_ASSERT_EQ(flavor_get_label(*this, prover_poly), flavor_get_label(proving_key, key_poly)); prover_poly = key_poly.share(); } for (auto [prover_poly, key_poly] : zip_view(this->get_shifted(), proving_key.get_to_be_shifted())) { - ASSERT(flavor_get_label(*this, prover_poly) == (flavor_get_label(proving_key, key_poly) + "_shift")); + BB_ASSERT_EQ(flavor_get_label(*this, prover_poly), (flavor_get_label(proving_key, key_poly) + "_shift")); prover_poly = key_poly.shifted(); } } @@ -73,7 +74,7 @@ void AvmFlavor::Transcript::serialize_full_transcript() serialize_to_buffer(kzg_w_comm, proof_data); // sanity check to make sure we generate the same length of proof as before. - ASSERT(proof_data.size() == old_proof_length); + BB_ASSERT_EQ(proof_data.size(), old_proof_length); } AvmFlavor::PartiallyEvaluatedMultivariates::PartiallyEvaluatedMultivariates(const size_t circuit_size) diff --git a/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/ecc.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/ecc.test.cpp index e8e3f7636d5e..f212523d0c9b 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/ecc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/ecc.test.cpp @@ -580,7 +580,7 @@ TEST(ScalarMulConstrainingTest, MulAddInteractionsInfinity) EccSimulator ecc_simulator(to_radix_simulator, ecc_add_event_emitter, scalar_mul_event_emitter); EmbeddedCurvePoint result = ecc_simulator.scalar_mul(EmbeddedCurvePoint::infinity(), FF(10)); - ASSERT(result.is_infinity()); + ASSERT_TRUE(result.is_infinity()); TestTraceContainer trace = TestTraceContainer::from_rows({ { .precomputed_first_row = 1 }, diff --git a/barretenberg/cpp/src/barretenberg/vm2/proving_helper.cpp b/barretenberg/cpp/src/barretenberg/vm2/proving_helper.cpp index d61955b421d1..ebe40a607b42 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/proving_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/proving_helper.cpp @@ -5,6 +5,7 @@ #include #include +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/serialize.hpp" #include "barretenberg/common/thread.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" @@ -26,7 +27,7 @@ std::shared_ptr create_proving_key(AvmProver::ProverPolyn auto proving_key = std::make_shared(CIRCUIT_SUBGROUP_SIZE, /*num_public_inputs=*/0); for (auto [key_poly, prover_poly] : zip_view(proving_key->get_all(), polynomials.get_unshifted())) { - ASSERT(flavor_get_label(*proving_key, key_poly) == flavor_get_label(polynomials, prover_poly)); + BB_ASSERT_EQ(flavor_get_label(*proving_key, key_poly), flavor_get_label(polynomials, prover_poly)); key_poly = std::move(prover_poly); }