Prime limb witness indexes equality check in operator-
and operator+
In operator-
and operator+
, the optimized implementation of the last calculation step in the HasPlookup<Builder>
case is skipped if a boolean limbconst
is true:
if constexpr (HasPlookup<Builder>) {
if (prime_basis_limb.multiplicative_constant == 1 && other.prime_basis_limb.multiplicative_constant == 1 &&
!is_constant() && !other.is_constant()) {
bool limbconst = binary_basis_limbs[0].element.is_constant();
limbconst = limbconst || binary_basis_limbs[1].element.is_constant();
limbconst = limbconst || binary_basis_limbs[2].element.is_constant();
limbconst = limbconst || binary_basis_limbs[3].element.is_constant();
limbconst = limbconst || prime_basis_limb.is_constant();
limbconst = limbconst || other.binary_basis_limbs[0].element.is_constant();
limbconst = limbconst || other.binary_basis_limbs[1].element.is_constant();
limbconst = limbconst || other.binary_basis_limbs[2].element.is_constant();
limbconst = limbconst || other.binary_basis_limbs[3].element.is_constant();
limbconst = limbconst || other.prime_basis_limb.is_constant();
limbconst = limbconst || (prime_basis_limb.witness_index == other.prime_basis_limb.witness_index);
if (!limbconst) {
// optimized calculation saving a gate
// ...
return result;
}
}
}
// normal case calculation
// ...
return result;
The last condition in limbconst
, namely whether the two prime limbs have the same witness index, is not something that is necessary to ensure the code in the !limbconst
branch functions correctly. Thus, this check could be removed from limbconst
.
For operator-
, the reason it is assumed that the witness indexes are not the same is that if *this
and other
are equal, then instead of using up gates to constrain the subtraction, one could use the result zero directly. If usage of operator-
is to be prevented in those cases, it should instead be asserted that the indexes are different.