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

montgomery arithmetic #23

Merged
merged 4 commits into from
May 4, 2024
Merged

montgomery arithmetic #23

merged 4 commits into from
May 4, 2024

Conversation

lonerapier
Copy link
Collaborator

@lonerapier lonerapier commented May 3, 2024

closes #16
closes #17
closes #18

It changes the following:

  • Adds montgomery arithmetic for field. I've kept the implementation closer to theory. Let me know if we should change it back to Plonky3's implementation.
  • Barret reduction

src/field.rs Outdated
// const MONTY_MU: u32 = 80;
const MONTY_BITS: u32 = 7;
const MONTY_MASK: u32 = (1 << MONTY_BITS) - 1;
const MONTY_MU: u32 = 19; // (-P^-1) mod 2^MONTY_BITS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I think functionally this PR is amazing. My main feedback is i think we should go hard on some comments since we plan to make this a learning resource. If you had to explain to someone what you where doing, who didn't have much prior experience how would you paint the intuition? What intuition made the optimization clique for you? Is there a small example we can include in the comments or another test? Personally i find if i can explain things well it really solidifies my understanding too :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0xJepsen added comments and examples for montgomery and barret reduction. Let me know if those are not clearly explained.

Copy link
Contributor

@0xJepsen 0xJepsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is awesome :) Thanks for adding those! Looks like a test isn't passing

@lonerapier
Copy link
Collaborator Author

Looks like a test isn't passing

fixed

@0xJepsen 0xJepsen merged commit 26d31d7 into pluto:main May 4, 2024
4 checks passed
@lonerapier lonerapier deleted the modular_arith branch June 6, 2024 15:20
@github-actions github-actions bot mentioned this pull request Jul 1, 2024
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

Successfully merging this pull request may close these issues.

Barrett modular arithmetic Montgomery modular arithmetic feat: Modular Arithmetic Optimization
2 participants