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

fix(MSM): properly handle edge condition in parallel MSM when bits is exactly divided by c #484

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mratsim
Copy link
Owner

@mratsim mratsim commented Nov 27, 2024

The parallel MSM skips the top window if the number of bits is exactly divided by MSM parameter c.

This is easy to reproduce with 3 points and by removing the endomorphism acceleration (which multiply the number of points by 2x or 4x) here:

proc multiScalarMul_dispatch_vartime_parallel[bits: static int, F, G](
tp: Threadpool,
r: ptr (EC_ShortW_Jac[F, G] or EC_ShortW_Prj[F, G]),
coefs: ptr UncheckedArray[BigInt[bits]],
points: ptr UncheckedArray[EC_ShortW_Aff[F, G]], N: int) =
## Multiscalar multiplication:
## r <- [a₀]P₀ + [a₁]P₁ + ... + [aₙ]Pₙ
let c = bestBucketBitSize(N, bits, useSignedBuckets = true, useManualTuning = true)
# Given that bits and N change after applying an endomorphism,
# we are able to use a bigger `c`
# but it has no significant impact on performance
case c
of 2: withEndo(msmImpl_vartime_parallel, tp, r, coefs, points, N, c = 2)
of 3: withEndo(msmImpl_vartime_parallel, tp, r, coefs, points, N, c = 3)
of 4: withEndo(msmImpl_vartime_parallel, tp, r, coefs, points, N, c = 4)
of 5: withEndo(msmImpl_vartime_parallel, tp, r, coefs, points, N, c = 5)
of 6: withEndo(msmImpl_vartime_parallel, tp, r, coefs, points, N, c = 6)

This might help for #479, cc @Vindaar

@mratsim mratsim added bug 🪲 Something isn't working correctness 🛂 labels Nov 27, 2024
@mratsim
Copy link
Owner Author

mratsim commented Nov 27, 2024

failure go test on Windows

image

@mratsim
Copy link
Owner Author

mratsim commented Nov 28, 2024

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working correctness 🛂
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant