-
Notifications
You must be signed in to change notification settings - Fork 2
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
Change Scalar::new input from u128 to BigUint #4
Conversation
let bls_modulus = BigUint::from_str(BLS_MODULUS).unwrap(); | ||
let base_bigint = BigUint::from_bytes_le(self.to_le_bytes()?.as_slice()); | ||
let exp_bigint = BigUint::from_bytes_le(exp.to_le_bytes()?.as_slice()); | ||
let result = base_bigint.modpow(&exp_bigint, &bls_modulus); | ||
Ok(Scalar( | ||
ark_bls12_381::Fr::from_str(&*result.to_string()).map_err(|_| { | ||
exceptions::PyValueError::new_err("Failed to convert result to scalar") | ||
})?, | ||
)) | ||
} |
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.
Not blocking as we can speed this up after -- Fr should have a pow method that one can use too, which should allow us to remove the BLS_MODULUS import
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.
Unfortunately it's exponent parameter is a u32, so it won't work for us 😢
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.
I think its more than a u32, last time I checked or that would be almost unusable!
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.
It might have been &[u32] or something of that nature
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.
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.
No worries! Feel free to push another PR when ready :)
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.
Made this PR:
// Bug, Fr::to_string will print nothing if the value is zero | ||
BigUint::from_str(&*self.0.to_string()).unwrap_or(BigUint::ZERO) |
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.
Also not blocking: I've tried to avoid the str method in arkworks in place of using hex since the .to_string method had weird behaviours last time I checked and the way it was doing the conversion seemed non-optimal
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.
Good call. Made this PR:
Merging as comments were non-blocking |
This PR does these things:
pyo3
to the latest version.num-bigint
feature which allows us to use bigints.Scalar::new
method to takeBigUint
instead ofu128
.examples/scalar.py
to ensure it works.__truediv__
to allow scalar division.__int__
so we can convert back to an integer in Python.