Skip to content
This repository was archived by the owner on Aug 4, 2026. It is now read-only.
This repository was archived by the owner on Aug 4, 2026. It is now read-only.

Refactoring of non-native field gadgets  #152

Description

@UlrichHaboeck75

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

  • unify NonNativeFieldGadget and NonNativeFieldMultResultGadget: 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, assuming SURFEIT=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 a

  • different treatment of parameters: Let us introduce separate NonNativeFieldParameters to allow a manual specification, and let us run find_parameters() over the real constraint counts provided by ConstraintSystem. 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

  • implement big integer gadgets: The key principle of simulating non-native field arithmetics is its translation of mod p identities to big integer equalities. In particular, the core piece is the grouped normalization procedure group_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestoptimizationPerformance improvement for the current codebasesw designSW design choice to be made or implemented

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions