-
Notifications
You must be signed in to change notification settings - Fork 333
Optimize ecrecover and p256verify with Shamir trick multi-scalar multiplication #1390
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
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1390 +/- ##
==========================================
- Coverage 81.36% 81.32% -0.04%
==========================================
Files 151 151
Lines 13360 13339 -21
Branches 3190 3191 +1
==========================================
- Hits 10870 10848 -22
Misses 346 346
- Partials 2144 2145 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Before: After: |
85ae237 to
3d820f8
Compare
Support adding the same point for `add` jacobian and affine overload. Co-authored-by: Paweł Bylica <[email protected]>
|
Final benchmarks: GCC15: Clang 22: |
0c24f4f to
5198f9c
Compare
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.
Pull request overview
This PR optimizes the ecrecover and p256verify precompiles by implementing multi-scalar multiplication using the "Straus-Shamir trick" (also known as Shamir's trick). The optimization replaces two separate scalar multiplications followed by a point addition with a single, more efficient combined operation. According to the benchmarks, this results in approximately 39% performance improvement for ecrecover (from 132,861 ns to 81,059 ns).
Key changes:
- Added new
msmfunction implementing Shamir's trick for computing u×P ⊕ v×Q - Modified the mixed point addition function to handle point doubling (when P == Q)
- Simplified
ecrecoverandp256verifyimplementations to use the newmsmfunction
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
lib/evmone_precompiles/ecc.hpp |
Added msm function for multi-scalar multiplication using Shamir's trick; updated mixed addition to handle doubling |
lib/evmone_precompiles/secp256k1.cpp |
Replaced separate multiplications and addition with single msm call in secp256k1_ecdsa_recover |
lib/evmone_precompiles/secp256r1.cpp |
Replaced separate multiplications and addition with single msm call in verify |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
chfast
left a comment
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.
Tests are failing
Before:
After: