-
Notifications
You must be signed in to change notification settings - Fork 412
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
ScalarMul on Bandersnatch #263
Conversation
B := Point{} | ||
// s1 + λ * s2 == s + k*r | ||
// api.AssertIsEqual(api.Add(s1, api.Mul(s2, &curve.lambda)), api.Add(scalar, api.Mul(&curve.Order, sd[2]))) | ||
api.AssertIsEqual(api.Sub(api.Mul(s2, &curve.lambda), s1), api.Add(scalar, api.Mul(&curve.Order, sd[2]))) |
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.
Aren't there bounds to check as well? If o
is the order of bandersnatch's prime group, in Z we have
s1 + λ * s2 - s - k*o = 0
s1, s2 < sqrt(o)
o<r
Here you only check that s1 + λ * s2 = s + k*o mod r
, so it means that in Z s1 + λ * s2 - s - k*o = c * r
. From the scalar decomposition we know that s1, s2 < sqrt(o)<sqrt(r)
, but λ
is anywhere between 0
and o
, so to me nothing guarantees that c=0
here... I feel that something is missing, linked to the emulation of Z/oZ arithmetic in Z/rZ
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.
creating a ticket for this #268
converting the PR to draft until we make sure of the hinted scalar decomposition. |
@yelhousni when is is going to be mergeable? I want to fix the weird apis in twistededwards / eddsa (see #262 ) and you may get quite a lot of conflicts if I do so before this PR :) |
@yelhousni ⬆️ ? |
I'll take care of that tomorrow. The GLV decomposition is correct (and scalar size bound is increased) but we may need to constrain few more things. |
* build: updated to latest gnark-crypto * build: updated to latest gnark-crypto * refactor: introduce Curve interface in std/ and updated eddsa tests * feat: added std/eddsa publicKey and signature assign helpers * refactor(std): merged twistededwards and bandersnatch. IsOnCurve failing for bandersnatch * fix: closes #283. ensure test.Assert compile cache handles different object of same type * fix: use UnsafeAddr instead of UnsafePointer to be retro compatible * fix: fix previous commit * test: test all twisted ed curve operations * Fixes #283 : ensure test.Assert compile cache handles different objects of same type (#284) * fix: closes #283. ensure test.Assert compile cache handles different object of same type * fix: use UnsafeAddr instead of UnsafePointer to be retro compatible * fix: fix previous commit * fix: apply pr patch * style: make twistededwards/Point methods package private
ScalarMul
on Bandersnatch now uses the D=-8 endomorphism with a hinted scalar decomposition.Groth16 bench:
ScalarMul
2436 constraintsScalarMul
1914 constraintsScalarMul
4844 constraintsFor Jubjub, it costs:
ScalarMul
3060 constraintsScalarMul
2538 constraintsScalarMul
4844 constraintsNote that the variable-double-base
ScalarMul
algortihm is the same for both curves. It uses an interleaved simultaneous scanning of two scalars and a window table of 4 (Lookup2
). It is better constraint-wise to do so than using the endomorphism separately on twoScalarMul
. Therefore, EdDSA verification cost is (almost) the same on both curve (Bandersnatch has 4C less as the cofactor clearing costs one doubling less), but theScalarMul
independently costs 624C less.