Refactoring of non-native field gadgets #152
Labels
enhancement
New feature or request
optimization
Performance improvement for the current codebase
sw design
SW design choice to be made or implemented
The current design of non-native field arithmetics treats non-native field gadgets and their multiplication results separately. This causes code duplication, as the arithmetic operations on multiplication results (as well as reduction to normal form) is identical to that of normal non-native gadgets. I therefore propose to
NonNativeFieldGadget
andNonNativeFieldMultResultGadget
: A unification of these gadgets by a sinlge non-native field gadgets which allows up to the double number of limbs (than that of the modulus) clarifies the architecture of non-native arithmetics, and moreover allows the extend the greedy pre-reduction strategy to multiplication results.Currently, the parameters are chosen by
find_parameters()
as the minimum number of constraints for a multiplication and post-reduction of two non-native gadgets, assumingSURFEIT=10
. I doubt that this approach is optimal, as the optimum depends on the specific arithmetic "network" to be simulated. For this reason I propose aNonNativeFieldParameters
to allow a manual specification, and let us runfind_parameters()
over the real constraint counts provided byConstraintSystem
. As reference circuit one can use again multiplication with post-reduction, or a custom circuit provided by the user.A further improvement on the code structure would be to
mod p
identities to big integer equalities. In particular, the core piece is the grouped normalization proceduregroup_and_check_equality()
, which checks the equality of big integers with oversized limbs. As big integer gadgets might be useful in application circuits anyway, I propose to implement the simulation of non-reduced big integer arithmetics, and build the non-native field arithmetics on top of it.The text was updated successfully, but these errors were encountered: