Announcing our own Elliptic Curve Cryptography in Solidity
But, why have we implemented our own crypto library? As you all know, developing your own crypto libraries is not usually encouraged. However, we found several reasons to do so:
elliptic-curve-solidity is a cost-efficient, flexible and ergonomic library for Elliptic Curve arithmetic operations. It has been generalized in order to support any elliptic curve based on prime numbers up to 256 bits.
The library has been designed with only pure functions aiming at decreasing gas consumption as much as possible. It aims to be as complete as possible by providing the following operations.
- Modular: inverse, exponentiation
- Jacobian: addition, double, multiplication
- Affine: inverse, addition, subtraction, multiplication
- Auxiliary: convert to affine, derive coordinate Y, point on curve
The supported and tested curves are secp256k1, secp256r1 (P-256), secp192r1 (P-192), and secp224r1 (P-224).
EllipticCurve.sol contract can be used directly by inheritance or by instantiating it. The following Secp256k1 example depicts how to inherit the library by providing a function to derive a public key from a secret key:
pragma solidity ^0.5.0;import "./EllipticCurve.sol";contract Secp256k1 is EllipticCurve
}
The repository includes a thorough gas consumption analysis of all library functions.
As illustrative example, the cost of a key derivation operation in Secp256k1 is around 550k gas.
We want to thank the following resources and authors, on which our library has been inspired:
Published at Mon, 08 Jul 2019 11:44:49 +0000
