Unnecessary reductons in operator+
The implementation of operator+
essentially obtains the limbs of the result by adding the relevant limbs of the two summands. A problem can occur should addition of any of the prime limbs cause a wraparound modulo the native circuit prime modulus (which is a 254-bit prime). This is prevented by carrying out a reduction check on both summands at the start:
template <typename Builder, typename T>
bigfield<Builder, T> bigfield<Builder, T>::operator+(const bigfield& other) const
{
reduction_check();
other.reduction_check();
This will, if necessary, use a reduction to ensure that all binary limbs are at most about 117 bits. Note that as the sum of two 117-bit values can at most be a 118-bit value, there is a very large buffer between this and the 254-bit number . It is also unlikely that normal usage of bigfield
binary limbs with maximum values close to would occur. It thus might make sense to remove these two reduction checks and instead only assert that the sum of binary limbs is less than , or perhaps reduce the two summands conditionally on this occurring. This could save on unnecessary reductions.