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 scalarMul_vartime for tiny multiple 5 #426

Merged
merged 1 commit into from
Jul 12, 2024
Merged

Conversation

Vindaar
Copy link
Collaborator

@Vindaar Vindaar commented Jul 12, 2024

Another minor issue I encountered playing around with moonmath's BLS6-6. The code previously accidentally only returned 3 for the case 5 using X.scalarMul_vartime(5).

I noticed it when comparing manual addition of the generator vs scalar multiplication, in order to construct all elements of the G1 subgroup:

# generator for G1
let fx = Fp[BLS6_6].fromUint(13'u32)
let fy = Fp[BLS6_6].fromUint(15'u32)

var gen {.noinit.}: EC_ShortW_Aff[Fp[BLS6_6], G1]
gen.x = fx
gen.y = fy
let genJ = gen.getJacobian()

var curA = genJ
for i in 1 .. 13:
  let x = BigInt[6].fromUint(i.uint32)
  var cur = genJ
  # cur.scalarMul(x) # <- works fine
  cur.scalarMul_vartime(x) # <- element 5 returned element 3 before this fix
  echo "Index: ", i, " [i] g = ", cur.toDecimal() # (I added `toDecimal for EC points)
  echo "Addition: ", curA.toDecimal()
  echo "\n=======================\n"
  curA = curA + genJ # works fine

I'd consider adding BLS6-6 as a test curve at a later time. Then I can write a couple of test cases for it (to check all the tiny number code branches) and an example showing some basic curve operations with constantine. Such an example could be quite illustrative. Maybe with some comments of how equivalent operations would look like in SageMath.

The code previously accidentally only return 3 for the case 5.
@mratsim
Copy link
Owner

mratsim commented Jul 12, 2024

Oh nice catch!

@mratsim mratsim merged commit 405ec70 into master Jul 12, 2024
24 checks passed
@mratsim mratsim deleted the fixScalarMulVarTiny branch July 12, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants