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

feat(field): add mersenne31 prime field #565

Closed

Conversation

PatStiles
Copy link
Collaborator

Adds Mersenne31 Prime Field

Description

Description of the pull request changes and motivation.

Starts #540

Adds an implementation of the Mersenne31 prime field following the implementation in Plonky 3.

Please delete options that are not relevant.

  • New feature

Checklist

  • Linked to Github Issue
  • Unit tests added

@PatStiles PatStiles requested review from schouhy, ajgara and a team as code owners September 20, 2023 04:53
@PatStiles PatStiles marked this pull request as draft September 20, 2023 04:53
@PatStiles PatStiles changed the title feat(field); add mersenne31 prime field feat(field): add mersenne31 prime field Sep 20, 2023
@codecov-commenter
Copy link

codecov-commenter commented Sep 21, 2023

Codecov Report

Merging #565 (f9e614a) into main (2c2e0f7) will decrease coverage by 0.04%.
The diff coverage is 93.33%.

@@            Coverage Diff             @@
##             main     #565      +/-   ##
==========================================
- Coverage   95.61%   95.58%   -0.04%     
==========================================
  Files         111      113       +2     
  Lines       19310    19595     +285     
==========================================
+ Hits        18464    18730     +266     
- Misses        846      865      +19     
Files Coverage Δ
math/src/field/fields/u32_mersenne_prime_field.rs 98.51% <98.51%> (ø)
...elds/fft_friendly/u64_mersenne_montgomery_field.rs 0.00% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@PatStiles
Copy link
Collaborator Author

PatStiles commented Sep 22, 2023

@MauroToscano @schouhy Bench results for the Mersenne31 backend in comparison to a U64 montgomery backend
Screenshot 2023-09-22 at 00 18 26

@MauroToscano
Copy link
Collaborator

@MauroToscano @schouhy Bench results for the Mersenne31 backend in comparison to a U64 montgomery backend Screenshot 2023-09-22 at 00 18 26

The benchmark seems wrong, it's based in the old benchmarks of the Math library which are also not good.

When using Criterion, the compiler may optimize when constants that are always the same. That's why you see one Pow taking 300 ps, which is highly suspicious. If you blackbox the paramater with "bench.iter(|| x.pow(black_box(*y)));", now the mersenne's backend is faster. Which is nice!

If you want to copy the ones of Math, you will have to fix this kind of issues. If you see some difference that big it may be the compiler optimizing something that it shouldn't be optimizing.

The ones used here are more solid: https://github.com/lambdaclass/lambdaworks/tree/main/benches. We can improve the ones in math and fix this kind of issues.

@PatStiles
Copy link
Collaborator Author

@MauroToscano Appreciate the feedback will get on it!

@MauroToscano
Copy link
Collaborator

Looks good now

@PatStiles
Copy link
Collaborator Author

@MauroToscano @schouhy I finished adding the field extensions and hooking into libfuzzer. One note is the lambdaworks quadratic extension differed slightly from the implementation of the inv() operation for the Mersenne31 fields complex extension in plonky3

@PatStiles PatStiles marked this pull request as ready for review October 16, 2023 17:30
@PatStiles PatStiles closed this Oct 20, 2023
@PatStiles PatStiles mentioned this pull request Oct 22, 2023
13 tasks
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.

3 participants