GithubHelp home page GithubHelp logo

gmh5225 / zksync_era_precompiles Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lambdaclass/zksync_era_precompiles

0.0 0.0 0.0 172 KB

Yul precompile library to speedup elliptic curves operations.

License: Apache License 2.0

Python 2.60% Rust 80.16% Makefile 0.10% Yul 17.15%

zksync_era_precompiles's Introduction

zkSync Era Precompiles

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.

Current Status

Precompile MVP Optimized
ecAdd
ecMul
ecPairing 🏗️
modexp 🏗️

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, 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 coordiantes (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 is detailed in this Slack message

    https://lambdaclass.slack.com/archives/C03GS78HS02/p1692141200550299

  • ecPairing 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.

Used algorithms

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

Resources

Development

Follow the instructions below to setup the repo and run a development L2 node.

Setup the repo

make setup

Update the submodules (if needed)

make update

Run a development L2 node

make run

Run the tests

If you want to run all the tests:

make test

If you want to run a specific test:

make test PRECOMPILE=<precompile_name>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.