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

Foreign field backend #203

Merged
merged 8 commits into from
Nov 13, 2023
Merged

Foreign field backend #203

merged 8 commits into from
Nov 13, 2023

Conversation

mitschabaude
Copy link
Collaborator

@mitschabaude mitschabaude commented Nov 2, 2023

This PR generalizes the bigint finite field code to work for all fields.
This enables foreign field tests in o1-labs/o1js#1220

We also add a file with a range of concrete finite fields that can be used for testing and in examples.

@mitschabaude mitschabaude changed the title Foreign field addition Non-native field backend Nov 13, 2023
@mitschabaude mitschabaude changed the title Non-native field backend Foreign field backend Nov 13, 2023
@mitschabaude mitschabaude marked this pull request as ready for review November 13, 2023 07:32
Copy link
Contributor

@rbonichon rbonichon left a comment

Choose a reason for hiding this comment

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

Only minor comments

*/
function computeFieldConstants(p: bigint) {
// figure out the factorization p - 1 = 2^M * t
let oddFactor = p - 1n;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the names make it somewhat hard to read.

Is p - 1n necessarily odd? If p is a prime number, as its naming can also suggest, then oddFactor usually starts by being even (and stays so by subsequent >> 1n). In any case. it's not ensured by the parameter type.

Maybe that's the right name, though. Can you refer to a source where this is used/defined?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The code right below that line divides oddFactor by 2 as many times as needed to become odd.

so this code, as the comment hints at (but could've used clearer naming), figures out the factorization
p - 1 = 2^twoadicity * oddFactor, for a prime p (well for any number)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we need the oddFactor in some algorithms -- for example, right below in the same function to find a primitive root of unity

@mitschabaude mitschabaude merged commit 5df84bf into main Nov 13, 2023
1 check passed
@mitschabaude mitschabaude deleted the feature/ffadd branch November 13, 2023 11:58
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