Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,11 @@ template <class Params_> struct alignas(32) field {
BB_INLINE constexpr field add(const field& other) const noexcept;
BB_INLINE constexpr field subtract(const field& other) const noexcept;

// Debug-only assertion: checks that the field element is in the strict coarse form [0, 2p).
// Debug-only check: logs a warning if the field element is outside the strict coarse form [0, 2p).
// Only meaningful for "small" moduli (<=254 bits) which use the coarse representation.
// Not constexpr in debug builds (BB_ASSERT_DEBUG uses std::ostringstream).
// This is an audit/diagnostic tool — violations are known to occur intermittently in x64 asm
// coarse-reduction paths and are harmless (values get reduced to canonical form before use).
// Not constexpr in debug builds.
// Callers must guard with `if (!std::is_constant_evaluated())` in constexpr functions.
#ifdef NDEBUG
constexpr void assert_coarse_form() const noexcept {}
Expand All @@ -616,7 +618,9 @@ template <class Params_> struct alignas(32) field {
{
if constexpr (modulus.data[3] < MODULUS_TOP_LIMB_LARGE_THRESHOLD) {
uint256_t val{ data[0], data[1], data[2], data[3] };
BB_ASSERT_DEBUG(val < twice_modulus, "field element exceeds coarse form [0, 2p)");
if (!(val < twice_modulus)) {
info("WARNING: field element exceeds coarse form [0, 2p)");
}
}
}
#endif
Expand Down
Loading