Skip to content

Commit

Permalink
Update README.md (matter-labs#162)
Browse files Browse the repository at this point in the history
* Update README

* Update README

* Update Used Algorithms table
  • Loading branch information
ilitteri authored Oct 6, 2023
1 parent 2da5282 commit f272068
Show file tree
Hide file tree
Showing 2 changed files with 261 additions and 17 deletions.
42 changes: 25 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ In the next weeks we will add more optimizations and benchmarks.

# Current Status

| Precompile | MVP | Optimized |
| --- | --- | --- |
| ecAdd |||
| ecMul |||
| ecPairing |||
| modexp || 🏗️ |
| Precompile | MVP | Optimized | Audited |
| --- | --- | --- | --- |
| ecAdd ||| 🏗️ |
| ecMul ||| 🏗️ |
| ecPairing ||| 🏗️ |
| modexp | 🏗️ |||
| P256VERIFY ||||
| secp256k1VERIFY ||||

## Summary

- `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](https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#Windowed_method), the [sliding-window method](https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#Sliding-window_method), [wNAF (windowed non-adjacent form)](https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#w-ary_non-adjacent_form_(wNAF)_method) 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: TODO
- `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. *This precompile has been audited a first time and it is currently being audited a second time (after the fixes).*
- `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](https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#Windowed_method), the [sliding-window method](https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#Sliding-window_method), [wNAF (windowed non-adjacent form)](https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#w-ary_non-adjacent_form_(wNAF)_method) 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`). *This precompile has been audited a first time and it is currently being audited a second time (after the fixes).*
- `modexp` status: is soon to be finished using Big Unsigned Int arithmetic.
- `ecPairing`:
We have based our algorithm implementation primarily on the guidelines presented in the paper ["High-Speed Software Implementation of the Optimal Ate Pairing over Barreto–Naehrig Curves"](https://eprint.iacr.org/2010/354.pdf) . This implementation includes the utilization of Tower Extension Field Arithmetic and the Frobenius Operator.

Expand All @@ -32,18 +34,24 @@ In the next weeks we will add more optimizations and benchmarks.
- **Optimizing Accumulated Value:** We are currently naively multiplying two fp12 elements, which contain many zeros. Modifying this calculation could enhance efficiency.

**Future Investigations:** We need to investigate the reliability of additional optimizations, such as the application of the GLV method for multiplication of rational points of elliptic curves.
- `P256VERIFY` is already working. Shamir’s trick could be implemented in order to optimize the algorithm.
- `secp256k1VERIFY` is already working. Shamir’s trick could be implemented in order to optimize the algorithm.

## [Gas Consumption](./docs/src/gas_consumption.md)

# Used algorithms
## Used Algorithms

| | Unoptimized | | | Optimized | | |
| | | **Precompile** | | | | |
| --- | --- | --- | --- | --- | --- | --- |
| 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 | |
| **Arithmetic** | **Operation** | **ecAdd** | **ecMul** | **modexp** | **P256VERIFY** | **secp256k1VERIFY** |
| **Prime Field Arithmetic** | **Addition** | Montgomery Modular Addition | Montgomery Modular Addition | Big Unsigned Integer Addition | Montgomery Modular Addition | Montgomery Modular Addition |
| | **Subtraction** | Montgomery Modular Subtraction | Montgomery Modular Subtraction | Big Unsigned Integer Subtraction With Borrow | Montgomery Modular Subtraction | Montgomery Modular Subtraction |
| | **Multiplication** | Montgomery Modular Multiplication | Montgomery multiplication | Big Unsigned Integer Multiplication | Montgomery multiplication | Montgomery multiplication |
| | **Exponentiation** | - | - | Binary exponentiation | - | - |
| | **Inversion** | Modified Binary Extended GCD (adapted for Montgomery Form) | Modified Binary Extended GCD (adapted for Montgomery Form) | - | Modified Binary Extended GCD (adapted for Montgomery Form) | Modified Binary Extended GCD (adapted for Montgomery Form) |
| **Elliptic Curve Arithmetic** | **Addition** | Addition in Affine Form | Addition in Homogeneous Projective Form | - | Addition in Homogeneous Projective Form | Addition in Homogeneous Projective Form |
| | **Double** | Double in Affine Form | Double in Homogeneous Projective Form | - | Double in Homogeneous Projective Form | Double in Homogeneous Projective Form |
| | **Scalar Multiplication** | - | Double-and-add | - | Double-and-add | Double-and-add |

## Resources

Expand Down
Loading

0 comments on commit f272068

Please sign in to comment.