-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
wrong result with scalarMul
in G2 curve
#345
Comments
btw |
Thanks for raising this, After discussing with @advaita-saha apparently this is used for Groth16, you can use This is likely related to this comment:
constantine/constantine/math/elliptic/ec_scalar_mul.nim Lines 243 to 251 in c4be82d
|
Deeper Analysis
gives the correct result. The base GLV-SAC algorithm with only positive numbers uses length of But to deal with negative mini-scalars that may arise from lattice reduction: constantine/constantine/math/constants/bn254_snarks_endomorphisms.nim Lines 39 to 65 in dbd2630
we need to: SpeculationI assume the change to +2 guarantees an extra "sign" bit. The numbers used are
The exponent is very small compared to the order. Hence I assume the lattice reduction which is supposed to reduce a 254-bit scalar into 4 64-bit scalars with substractions underflowed. TODOIn that case, it may be possible that this avoids this very restrictive condition in the scalarMul_vartime to only use endomorphism on exact bitlength match: constantine/constantine/math/elliptic/ec_scalar_mul_vartime.nim Lines 353 to 377 in dbd2630
CostThe cost has been detailed in the code: constantine/constantine/math/elliptic/ec_endomorphism_accel.nim Lines 50 to 59 in dbd2630
An extra double+addition, on G2 there are 64 minimum add+dbl so cost is 1.56% perf AlternativeWe can decompose those scalars with an alternative method that doesn't produce negative mini-scalars, for example with euclidean division. |
For a small number of possible exponents,
scalarMul
on G2 (tested with the BN254 curve) gives the wrong result.Standalone Nim code to reproduce:
The text was updated successfully, but these errors were encountered: