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

ScalarMul on Bandersnatch #263

Merged
merged 33 commits into from
Mar 24, 2022
Merged

ScalarMul on Bandersnatch #263

merged 33 commits into from
Mar 24, 2022

Conversation

yelhousni
Copy link
Contributor

@yelhousni yelhousni commented Feb 16, 2022

ScalarMul on Bandersnatch now uses the D=-8 endomorphism with a hinted scalar decomposition.

Groth16 bench:

  • variable-base ScalarMul 2436 constraints
  • fixed-base ScalarMul 1914 constraints
  • variable-double-base ScalarMul 4844 constraints

For Jubjub, it costs:

  • variable-base ScalarMul 3060 constraints
  • fixed-base ScalarMul 2538 constraints
  • variable-double-base ScalarMul 4844 constraints

Note 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 two ScalarMul. Therefore, EdDSA verification cost is (almost) the same on both curve (Bandersnatch has 4C less as the cofactor clearing costs one doubling less), but the ScalarMul independently costs 624C less.

std/algebra/twistededwards/bandersnatch/point.go Outdated Show resolved Hide resolved
std/algebra/twistededwards/bandersnatch/point.go Outdated Show resolved Hide resolved
std/algebra/twistededwards/bandersnatch/point.go Outdated Show resolved Hide resolved
std/algebra/twistededwards/bandersnatch/point.go Outdated Show resolved Hide resolved
std/algebra/twistededwards/bandersnatch/point.go Outdated Show resolved Hide resolved
std/algebra/twistededwards/bandersnatch/point.go Outdated Show resolved Hide resolved
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])))
Copy link
Collaborator

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

Copy link
Contributor Author

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

@yelhousni yelhousni marked this pull request as draft February 18, 2022 10:07
@yelhousni
Copy link
Contributor Author

converting the PR to draft until we make sure of the hinted scalar decomposition.

@gbotrel
Copy link
Collaborator

gbotrel commented Mar 9, 2022

@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 :)

@gbotrel
Copy link
Collaborator

gbotrel commented Mar 10, 2022

@yelhousni ⬆️ ?

@yelhousni
Copy link
Contributor Author

@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
@gbotrel gbotrel marked this pull request as ready for review March 24, 2022 13:56
@gbotrel gbotrel merged commit aab0884 into develop Mar 24, 2022
@gbotrel gbotrel deleted the perf/EdDSA-Bandersnatch branch March 24, 2022 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants