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

Bandersnatch / Banderwagon endomorphism acceleration #298

Open
mratsim opened this issue Nov 20, 2023 · 4 comments · May be fixed by #380
Open

Bandersnatch / Banderwagon endomorphism acceleration #298

mratsim opened this issue Nov 20, 2023 · 4 comments · May be fixed by #380

Comments

@mratsim
Copy link
Owner

mratsim commented Nov 20, 2023

Scalar multiplication and Multi-scalar-multiplication for Bandersnatch and Banderwagon can be improved by 30% by adding endomorphism acceleration.

See:

Impl direction

We need to derive the lattice used for splitting a scalar as a linear combination of the endomorphism base.
This is done here:

def derive_lattice(r, lambdaR, m):
lat = Matrix(matrix.identity(m))
lat[0, 0] = r
for i in range(1, m):
lat[i, 0] = -lambdaR^i
return lat.LLL()

It seems like it should match the input of the LLL here:
https://github.com/asanso/Bandersnatch/blob/e280929/python-ref-impl/bandersnatch.py#L20-L21

@namn-grg
Copy link

Hey Mamy, I spent some time trying to tackle this issue and I have some knowledge gaps.

I was not familiar with endomorphism so I read about it and came across GLV endomorphism through this paper.

I was able to understand that -
The GLV endomorphism decomposes a scalar into two smaller scalars. This decomposition is done in such a way that the scalar multiplication can be split into two smaller scalar multiplications.

One part of the scalar is multiplied by the original point, and the other part is multiplied by a specially chosen point on the curve that is related to the original point through the endomorphism.

The results of the two scalar multiplications are then combined to obtain the final result of the scalar multiplication.

Am I approaching this issue the correct way? Is there any implementation of endomorphism acceleration that I can refer?

@agnxsh
Copy link
Collaborator

agnxsh commented Nov 24, 2023

Yes you are correct, if you want to collaborate with me on this issue, hmu on discord.

@mratsim
Copy link
Owner Author

mratsim commented Nov 24, 2023

As mentioned on Discord, I have an old Sage code here to actually see it working in practice: https://github.com/mratsim/constantine/blob/eee0f4f0fc5283ecb807f6756203df2819d0210f/sage/lattice_decomposition_bls12_381_g1.sage

The description of what is happening is there:

def check_cubic_root_endo(G1, Fp, r, cofactor, lambdaR, phiP):
## Check the Endomorphism for p mod 3 == 1
## Endomorphism can be field multiplication by one of the non-trivial cube root of unity 𝜑
## Rationale:
## curve equation is y² = x³ + b, and y² = (x𝜑)³ + b <=> y² = x³ + b (with 𝜑³ == 1) so we are still on the curve
## this means that multiplying by 𝜑 the x-coordinate is equivalent to a scalar multiplication by some λᵩ
## with λᵩ² + λᵩ + 1 ≡ 0 (mod r) and 𝜑² + 𝜑 + 1 ≡ 0 (mod p), see below.
## Hence we have a 2 dimensional decomposition of the scalar multiplication
## i.e. For any [s]P, we can find a corresponding [k1]P + [k2][λᵩ]P with [λᵩ]P being a simple field multiplication by 𝜑
## Finding cube roots:
## x³−1=0 <=> (x−1)(x²+x+1) = 0, if x != 1, x solves (x²+x+1) = 0 <=> x = (-1±√3)/2

@mratsim
Copy link
Owner Author

mratsim commented May 8, 2024

Implemented in #380

@mratsim mratsim linked a pull request May 8, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants