-
Notifications
You must be signed in to change notification settings - Fork 19
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
Optimization of G2 subgroup check using NAF representation #266
base: main
Are you sure you want to change the base?
Conversation
The table below presents the gas usage reports for the
As observed, there appears to be a slight regression in performance with these changes compared to the implementation of the |
// naf digit = -1 | ||
if and(naf, 2) { | ||
let pn00, pn01, pn10, pn11, pn20, pn21 := g2JacobianNeg(p00, p01, p10, p11, p20, p21) | ||
q00, q01, q10, q11, q20, q21 := g2JacobianAdd(q00, q01, q10, q11, q20, q21, pn00, pn01, pn10, pn11, pn20, pn21) |
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.
You may have better performance if iterating X_NAF
from MSB to LSB. Then you add either constant P or constant -P and the later can be computed once.
Here is snippet from wikipedia:
let bits = bit_representation(s) # the vector of bits (from LSB to MSB) representing s
let i = length(bits) - 2
let res = P
while (i >= 0): # traversing from second MSB to LSB
res = res + res # double
if bits[i] == 1:
res = res + P # add
i = i - 1
return res
function X_NAF() -> ret { | ||
// NAF in binary form | ||
// 010000000100010000100001000100100000010001001000100010000100000001000001000100010010000100000100000000010001000000001000000001 | ||
ret := 21356084665891114007971320526050427393 |
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.
This is correct.
This closes #237.