-
Notifications
You must be signed in to change notification settings - Fork 0
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
Polynomial ring operations #19
base: main
Are you sure you want to change the base?
Conversation
Implement Zq struct representing elements in ℤ/(2³²)ℤ ring arithmetic with native u32 operations. Key features: - Fully derived Debug, Clone, Copy, PartialEq, Eq, and Default traits - Implements Add/Sub/Mul operator traits with implicit modulo reduction - Provides Assign variants for in-place operations (AddAssign, etc) - Macro-generated trait impls ensuring DRY principle adherence - Display trait for formatted output in user interfaces - Extensive test coverage including edge cases: - Additive/multiplicative identity properties - Wrapping overflow/underflow behavior - Assignment operator correctness - u32 conversion invariants - Display formatting checks Enables safe, zero-cost abstraction for cryptographic primitives requiring modular arithmetic (e.g., FHE schemes, lattice-based crypto). Leverages: - Rust's wrapping arithmetic for constant-time operations - Type-safe API preventing raw integer misuse Performance characteristics: - All operations compile to single CPU instructions - No heap allocations Issue-URL: #17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great Work Matteo! 🚀 See my suggestions 😄
Additionally, I suggest:
-
Rename the struct to Rq to align with cryptographical terms and rename poly_rings.rs to rq.rs
-
Implement operator traits for natural arithmetic syntax. This will enable idiomatic usage like let sum = &rq1 + &rq2; and if rq1 == rq2 while maintaining ring arithmetic correctness.
-
I noticed you went beyond, but the original task only required:
- Addition
- Multiplication
- Modular Reduction
Not sure if we need the additional operations. Maybe @NiDimi can confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good job Mateo! 👍 You're doing a great progress with Rust! 🔥
Igor has made a thorough review 👍 I've only added some minors. Will review again later.
@pycckuu My reasoning for adding it was that we need it for all the summation operations on the paper. For example for Ajtai: The prover has to compute the commitment vector t as: The vector is computed using matrix-vector multiplication: That requires adding the results of the polynomial multiplication. Of course this is a suggestion if you think it can be done better feel free to suggest how to do it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Left some comments. 😄
- You need to consider what happens when the polynomials do not have the same number of coefficient. Right now If I am not mistaken the code will just fail.
- In rust commonly we use // for line comment and /// for doc comments. What that means is that we should use /// when explaining what the function does.
Overall a very good starting step 🔥
Thank you very much, @pycckuu, @maksimryndin, @NiDimi, for all the help and comments! I think all the issues are now resolved, but if there's any other change I should make, please let me know |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattsuffern Code looks great! See my very minor suggestions!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome job! 🥇
let's finish some minor things and move further! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, @mattsuffern ! 👍 great progress!
@NiDimi I believe this is already resolved. Could you please take a final look? :) |
Module Description
This module provides the implementation of various operations in the polynomial ring:
Based on the "modular arithmetic primitive using wrapping operations" module by @pycckuu (unchanged)
Implemented Functions:
add()
mul()
inner_product()
sub()
neg()
scalar_mul()
div_by_monomial()
eval()
is_zero()
is_equal()
(closes #5)