Assessment reports>Barretenberg Bigfield>Discussion>Assumptions regarding bit width of the modulus

Assumptions regarding bit width of the modulus

The implementation of the bigfield class assumes that the emulated modulus has a bit width between 204 and 256 bits, as can be seen from these lines:

// code assumes modulus is at most 256 bits so good to define it via a uint256_t
static constexpr uint256_t modulus = (uint256_t(T::modulus_0, T::modulus_1, T::modulus_2, T::modulus_3));
// ...
static constexpr uint64_t NUM_LAST_LIMB_BITS = modulus_u512.get_msb() + 1 - (NUM_LIMB_BITS * 3);

Here, NUM_LIMB_BITS has value 68, so the bit width of the modulus must be at least 3*68 = 204. We recommend documenting this requirement. Optimally, a compile-time check that the modulus is in the required range would also be added.

Zellic © 2025Back to top ↑