DISCLAIMER: This implementation is still being developed and has not been reviewed or audited. Use at your own risk.
This is a precompile library implemented in Yul to speedup arithmetic operations of elliptic curves. In the next weeks we will add more optimizations and benchmarks.
Precompile | MVP | Optimized |
---|---|---|
ecAdd | ✅ | ✅ |
ecMul | ✅ | ✅ |
ecPairing | 🏗️ | ❌ |
modexp | ✅ | 🏗️ |
ecAdd
is optimized with finite field arithmetic in Montgomery form and optimized modular inverse with a modification of the binary extended Euclidean algorithm that skips the Montgomery reduction step for inverting. There is not much more room for optimizations, maybe we could think of Montgomery squaring (SOS) to improve the finite field squaring.ecMul
is optimized with finite field arithmetic in Montgomery form, optimized modular inverse with a modification of the binary extended Euclidean algorithm that skips the Montgomery reduction step for inverting, and the elliptic curve point arithmetic is being done in homogeneous projective coordinates. There are some other possible optimizations to implement, one is the one discussed in the Slack channel (endomorphism: GLV or wGLV), the windowed method, the sliding-window method, wNAF (windowed non-adjacent form) to improve the elliptic curve point arithmetic, and Montgomery squaring (SOS) to improve the finite field squaring, Jacobian projective coordinates (this would have similar performance and gas costs as working with the homogeneous projective coordinates but it would be free to add it since we need this representation for ecPairing
).modexp
status: TODOecPairing
will be implemented as it is detailed in this document. We currently have the towered field extensions working and started working on the line functions for the addition and the double step of the miller loop.Unoptimized | Optimized | |||||
---|---|---|---|---|---|---|
Operation | ecAdd | ecMul | modexp | ecAdd | ecMul | modexp |
Modular Addition | addmod | addmod | addmod | addmod + Montgomery form | addmod + Montgomery form | addmod + Montgomery form |
Modular Subtraction | addmod | addmod | addmod | addmod + Montgomery form | addmod + Montgomery form | addmod + Montgomery form |
Modular Multiplication | mulmod | mulmod | mulmod | Montgomery multiplication | Montgomery multiplication | Montgomery multiplication |
Modular Exponentiation | Binary exponentiation | Binary exponentiation | Binary exponentiation | Binary exponentiation + Montgomery form | Binary exponentiation + Montgomery form | Binary exponentiation + Montgomery form |
Modular Inversion | Fermat’s little theorem | Fermat’s little theorem | None | Binary Extended GCD + Montgomery form | Binary Extended GCD + Montgomery form |
Follow the instructions below to setup the repo and run a development L2 node.
make setup
make update
make run
If you want to run all the tests:
make test
If you want to run a specific test:
make test PRECOMPILE=<precompile_name>