Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1389 +/- ##
==========================================
+ Coverage 81.44% 81.66% +0.22%
==========================================
Files 152 152
Lines 13396 13596 +200
Branches 3211 3226 +15
==========================================
+ Hits 10910 11103 +193
- Misses 342 343 +1
- Partials 2144 2150 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Improvement 72 Mgas/s → 117 Mgas/s (+63%). |
4afee13 to
eb3b456
Compare
|
6533f2f to
48be2b0
Compare
|
The cost of decompose is 0.20%, out of which 0.14% is the division by DET. |
There was a problem hiding this comment.
Pull request overview
This PR optimizes the BN254 elliptic curve scalar multiplication using the GLV (Gallant-Lambert-Vanstone) endomorphism method, achieving a ~32% performance improvement (from ~56μs to ~38μs). The optimization decomposes a scalar k into two smaller scalars k₁ and k₂ such that k ≡ k₁ + k₂·λ (mod N), allowing the use of efficient multi-scalar multiplication instead of a full scalar multiplication.
Key changes:
- Introduces
ecc::decompose()function to split ECC scalars into two shorter signed scalars - Adds endomorphism parameters (LAMBDA, BETA, X1, MINUS_Y1, X2, Y2) to the BN254 Curve struct
- Modifies the
bn254::mul()function to use the decomposition and multi-scalar multiplication approach
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| lib/evmone_precompiles/ecc.hpp | Adds SignedScalar struct, decompose() function for scalar decomposition, and verify_scalar_decomposition() helper for testing |
| lib/evmone_precompiles/bn254.hpp | Adds endomorphism parameters (LAMBDA, BETA, lattice basis vectors) to the BN254 Curve struct |
| lib/evmone_precompiles/bn254.cpp | Replaces direct ecc::mul() call with decomposition-based multi-scalar multiplication using the GLV endomorphism |
| test/unittests/evmmax_bn254_mul_test.cpp | Adds comprehensive test coverage for the decompose() function with edge cases and fuzzer-found inputs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add `ecc::decompose()` procedure to split ECC scalar into two smaller ones. Use the decomposition to speed up BN254 scalar multiplication. Co-authored-by: Paweł Bylica <pawel@hepcolgum.band>
ecc::decompose()procedure to split ECC scalar into two smaller ones.with Efficient Endomorphisms
Before:
After: