-
Notifications
You must be signed in to change notification settings - Fork 756
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
Use BN reduction context in modexp precompile #463
Conversation
73e5087
to
8453ed8
Compare
lib/precompiled/05-modexp.js
Outdated
if (E.mod(new BN(2)).isZero()) return R | ||
return (R.mul(BM)).mod(M) | ||
// Red asserts M > 1 | ||
if (M.cmpn(1) === 0) return new BN(0) |
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.
Use .lten
?
If you could that would be interesting to see. |
I read here that if r is a power of 2, then the modulus |
Thanks @cdetrio, that seems to be it. To get an initial idea of how they compare, I ran the state tests on master and this branch, and measured the time it took to execute the |
Add checks for E == 0 and M == 1 Fix M == 1 check Check M lten 1 instead of eq
a57733a
to
e70d0c0
Compare
Rebased this. |
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.
Looks good.
This PR attempts to fix #214. I tried to use
BN.mont
explicitly, but got some weird result:new BN(1).toRed(BN.mont(new BN('64', 16))).fromRed()
which I thought should return0x1
, actually returns0x18
! Not sure if this is a bug or intended?Should I do benchmarks to make sure this is actually more performant?
Update: It's running out of heap memory onmodexp_37120_37111_1_1000000