You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current Metal shader code, particularly in the bigint, field, and curve directories, is becoming increasingly complex and difficult to maintain. There's a lot of boilerplate code, especially around passing and using the prime modulus, and the lack of structure makes it harder to reason about the code. This issue proposes a refactoring of the shader code as follow.
Introduce Classes
Wrap the core data structures (e.g., BigInt, Jacobian, Affine) into proper classes. This will allow us to associate methods with the data, improving code organization.
Overload Operators
Implement operator overloading for these classes (e.g., +, -, *, >=, etc.) to make the code more readable and less verbose. This will reduce the need for explicit function calls like bigint_add_unsafe(), ff_add(), mont_cios(), etc.
Abstract Prime Modulus
Currently, the prime modulus is passed as an argument to many functions. We should abstract this away, possibly by making it a member of a FieldElement class or a template parameter, to avoid redundant code and improve readability.
Acceptance criteria
New classes are created:
BigInt class for big integer arithmetic
FieldElement class for field elements modulo p
JacobianPoint and AffinePoint classes for elliptic curve points
Key operators are overloaded for these types
Modulus is abstracted:
p is a static property of FieldElement class
Functions no longer take p as a redundant parameter
Kernel functions refactored:
Use new classes instead of raw BigInt values
Update function signatures to match
Shader tests pass:
Existing shader tests still pass with refactored code
Add any missing tests for edge cases
The text was updated successfully, but these errors were encountered:
Problem
The current Metal shader code, particularly in the bigint, field, and curve directories, is becoming increasingly complex and difficult to maintain. There's a lot of boilerplate code, especially around passing and using the prime modulus, and the lack of structure makes it harder to reason about the code. This issue proposes a refactoring of the shader code as follow.
Introduce Classes
Wrap the core data structures (e.g.,
BigInt
,Jacobian
,Affine
) into proper classes. This will allow us to associate methods with the data, improving code organization.Overload Operators
Implement operator overloading for these classes (e.g.,
+
,-
,*
,>=
, etc.) to make the code more readable and less verbose. This will reduce the need for explicit function calls likebigint_add_unsafe()
,ff_add()
,mont_cios()
, etc.Abstract Prime Modulus
Currently, the prime modulus is passed as an argument to many functions. We should abstract this away, possibly by making it a member of a FieldElement class or a template parameter, to avoid redundant code and improve readability.
Acceptance criteria
The text was updated successfully, but these errors were encountered: