Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor shaders to improve code readability and reduce redundancy #32

Open
10 tasks
moven0831 opened this issue Jan 5, 2025 · 0 comments
Open
10 tasks

Comments

@moven0831
Copy link
Collaborator

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 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

  1. 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
  2. Modulus is abstracted:
    • p is a static property of FieldElement class
    • Functions no longer take p as a redundant parameter
  3. Kernel functions refactored:
    • Use new classes instead of raw BigInt values
    • Update function signatures to match
  4. Shader tests pass:
    • Existing shader tests still pass with refactored code
    • Add any missing tests for edge cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant