-
Notifications
You must be signed in to change notification settings - Fork 12
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
Conversation
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.
Only minor comments
*/ | ||
function computeFieldConstants(p: bigint) { | ||
// figure out the factorization p - 1 = 2^M * t | ||
let oddFactor = p - 1n; |
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.
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?
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.
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)
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.
we need the oddFactor
in some algorithms -- for example, right below in the same function to find a primitive root of unity
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.