Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/keep-starknet-strange/garaga
State-of-the-art Elliptic Curve operations and SNARKS verification for Cairo & Starknet πΊ.
https://github.com/keep-starknet-strange/garaga
cairo-lang elliptic-curve-cryptography elliptic-curves pairing snarks starknet starks zero-knowledge zero-knowledge-proofs zk-snarks zkp
Last synced: 21 days ago
JSON representation
State-of-the-art Elliptic Curve operations and SNARKS verification for Cairo & Starknet πΊ.
- Host: GitHub
- URL: https://github.com/keep-starknet-strange/garaga
- Owner: keep-starknet-strange
- License: mit
- Created: 2023-01-02T14:10:06.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T10:26:48.000Z (about 2 months ago)
- Last Synced: 2024-10-25T05:50:14.653Z (about 2 months ago)
- Topics: cairo-lang, elliptic-curve-cryptography, elliptic-curves, pairing, snarks, starknet, starks, zero-knowledge, zero-knowledge-proofs, zk-snarks, zkp
- Language: Cairo
- Homepage: https://garaga.gitbook.io/
- Size: 24.5 MB
- Stars: 193
- Watchers: 4
- Forks: 49
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Contributing: docs/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: docs/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: docs/SECURITY.md
Awesome Lists containing this project
- awesome-starknet - Garaga - Efficient pairing library using polynomial representation of field elements. (Additional developer resources)
README
[![GitHub Workflow Status](https://github.com/keep-starknet-strange/garaga/actions/workflows/test.yml/badge.svg)](https://github.com/keep-starknet-strange/garaga/actions/workflows/test.yml)
[![Project license](https://img.shields.io/github/license/keep-starknet-strange/garaga.svg?style=flat-square)](LICENSE)
[![Pull Requests welcome](https://img.shields.io/badge/PRs-welcome-ff69b4.svg?style=flat-square)](https://github.com/keep-starknet-strange/garaga/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)[![Exploration_Team](https://img.shields.io/badge/Exploration_Team-29296E.svg?&style=for-the-badge&logo=data:image/svg%2bx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DkuMDcsMTEuNTIsMTQuMjUsMTYuNzEsMS42OCwxLjY4LDIuNzIsMS42OCw0LjQsMGwzNC4zMi0zNS43NHExLjU1LTEuODEsMC00LjAxWm0tNzIuMjYsMTUuMTVjLTMuMTEtLjc4LTYuMDktMS41NS05LjE5LTIuNTktMS43OC0uMzQtMy42MSwuMy00Ljc5LDEuNjhsLTEyLjk1LDEzLjg2Yy0uNzYsLjg1LTEuNDUsMS43Ni0yLjA3LDIuNzJoLS42NWMxLjMtNS4zMSwyLjcyLTEwLjYyLDQuMDEtMTUuOGwxLjY4LTYuNzNjLjg0LTIuMTgsLjE1LTQuNjUtMS42OC02LjA5bC0xMi45NS0xNC4xMmMtLjY0LS40NS0xLjE0LTEuMDgtMS40Mi0xLjgxbDE5LjA0LDUuMTgsMi41OSwuNzhjMi4wNCwuNzYsNC4zMywuMTQsNS43LTEuNTVsMTIuOTUtMTQuMzhzLjc4LTEuMDQsMS42OC0xLjE3Yy0xLjgxLDYuNi0yLjk4LDE0LjEyLTUuNDQsMjAuNDYtMS4wOCwyLjk2LS4wOCw2LjI4LDIuNDYsOC4xNiw0LjI3LDQuMTQsOC4yOSw4LjU1LDEyLjk1LDEyLjk1LDAsMCwxLjMsLjkxLDEuNDIsMi4wN2wtMTMuMzQtMy42M1oiLz48L3N2Zz4=)](https://github.com/keep-starknet-strange)
## About
> State-of-the-art Elliptic Curve tooling and SNARKS verification for Cairo & Starknet πΊ.
Garaga enables efficient elliptic curve operations on Starknet.
It achieves state of the art performance by
- using a dedicated builtin made by Starkware for emulated modular arithmetic
- using a suite of non-deterministic techniques for extension field multiplication, pairings, and multi scalar multiplication to reduce the number of steps to verify results.Garaga currently supports:
- Scalar & Multi-scalar multiplication for any Weirstrass curve, including BN254, BLS12_381, SECP256/R1, and ED25519. You can add the one you need by specifying the curve parameters.
- Pairing operations for BN254 and BLS12_381.
- Groth16 smart contract verifiers generators for BN254 and BLS12_381.Following supported schemes will be
- BLS signatures contract generators.
- Plonk based SNARKs verifier, especially Noir.## Architecture overview
![Architecture Overview](docs/images/architecture_overview.svg)Garaga consists of a Pythonic backend with Rust bindings and CairoZero / Cairo libraries.
- The Pythonic backend is here to define emulated modular arithmetic circuits that can be compiled to Cairo or Cairo1 code.
It also handles witnesses generation for the non-deterministic computations, smart contract contract generation for a given proof system and elliptic curve, and calldata generation from a given proof.
- The CairoZero / Starknet interfaces are responsible for composing and calling the circuits, as well as adding all the extra logic needed to make the algorithms work (Fiat-Shamir heuristic, SNARKS verifiers algorithms, etc).## Quickstart : deploying a SNARK verifier on Starknet
Currently, only Groth16 on BN254 and BLS12_381 is supported with automatic support for json files coming from SnarkJS and Gnark.
1. Create a new directory for you project, and bring the jsons files for verification key, proof file and public inputs inside it.
2. Install the garaga pip package with `pip install garaga`. Python3.10 is mandatory and a virtual environment is recommended. Enter `garaga` in your terminal to get started.
3. Run the `garaga gen` command in your terminal to generate the code for the SNARK verifier given your verification key.
4. Edit the generated smart contract to fit the needs of your dapp.5. Create an environment file `.secrets` following the `.secrets.template` file in the root of this repository, containing the Starkner RPC url, your account address, and the private key.
6. Run the `garaga declare` command in your terminal to declare the smart contract on Starknet and obtain its class hash. Note that this is an expensive operation.
7. Run the `garaga deploy` command in your terminal using the class hash obtained in the previous step to get the contract address.7. Run the `garaga verify-onchain` command in your terminal using the contract address, the verification key, the proof and the public inputs to verify the proof against the SNARK verifier contract.
For more details, please refer to the [documentation](https://felt.gitbook.io/garaga/).
## Developer setup
To get started with Garaga, you'll need to have some tools and dependencies installed. Here's everything you need:
### Prerequisites
Ensure you have the following installed:
- [Python 3.10](https://www.python.org/downloads/) - /!\ Make sure `python3.10` is a valid command in your terminal. The core language used for development. Make sure you have the correct dependencies installed (in particular, GMP) for the `fastecdsa` python package. See [here](https://pypi.org/project/fastecdsa/#installing) for linux and [here](https://github.com/AntonKueltz/fastecdsa/issues/74) for macos.
- [Scarb 2.8.4](https://docs.swmansion.com/scarb/download.html) - The Cairo package manager. Comes with Cairo inside. Requires [Rust](https://www.rust-lang.org/tools/install).##### Optionally :
- [pprof](https://github.com/google/pprof) - A tool for visualization and analysis of profiling data. Requires [Go](https://go.dev/).
- [graphviz](https://graphviz.org/download/) - Necessary for generating graphical representations of profiling data.### Setup
Once you have the prerequisites installed, clone the repository, and set up your development environment with the following command. Be sure to run this command from the root of the repository.
```bash
make setup
```At this point, you should have everything you need to start developing with Garaga. Before proceeding, make sure to activate the virtual environment by running `source venv/bin/activate`.
## Benchmarks
| OP | Weight in steps | Comment |
|------------------|-------------------|-----------------------------------------------------------------------------------------|
| MULMOD | 8 | Equivalent cost of a*b % p with the modulo builtin in VM steps |
| ADDMOD | 4 | Equivalent cost of a+b % p with the modulo builtin in VM steps |
| ASSERT_EQ | 2 | Equivalent cost of a==b % p with the modulo builtin in VM steps |
| RLC | 28 | Cost of writing a field element to the value segment and retrieving random coefficients |
| POSEIDON 4 LIMBS | 17 | Cost of hashing the 4 limbs of 384 bits emulated field element with Poseidon || circuit | MULMOD | ADDMOD | ASSERT_EQ | POSEIDON | RLC | ~steps |
|-------------------------------------------|----------|----------|-------------|------------|-------|----------|
| Derive Point From X | 6 | 2 | 0 | 0 | 0 | 56 |
| Fp6 SQUARE_TORUS | 12 | 22 | 0 | 7 | 1 | 324 |
| Fp12 SQUARE | 25 | 11 | 0 | 13 | 1 | 480 |
| Fp12 MUL | 36 | 22 | 0 | 13 | 1 | 612 |
| Fp6 MUL_TORUS | 36 | 34 | 0 | 13 | 2 | 688 |
| MSM 1 points | 150 | 128 | 0 | 52 | 0 | 2544 |
| MSM 2 points | 194 | 166 | 0 | 64 | 0 | 3240 |
| MSM 3 points | 238 | 204 | 0 | 76 | 0 | 3936 |
| MSM 10 points | 546 | 470 | 0 | 160 | 0 | 8808 |
| MSM 50 points | 2306 | 1990 | 0 | 640 | 0 | 36648 |
| Miller n=1 BLS12_381 | 2672 | 2686 | 137 | 790 | 63 | 47588 |
| Miller n=1 BN254 | 3303 | 3228 | 177 | 828 | 66 | 53130 |
| Miller n=2 BLS12_381 | 4418 | 4525 | 273 | 812 | 63 | 69558 |
| Miller n=2 BN254 | 5639 | 5576 | 353 | 852 | 66 | 81898 |
| Miller n=3 BLS12_381 | 6164 | 6364 | 409 | 834 | 63 | 91528 |
| Final Exp BN254 | 4681 | 7218 | 3 | 1931 | 317 | 102236 |
| Miller n=3 BN254 | 7975 | 7924 | 529 | 876 | 66 | 110666 |
| Final Exp BLS12_381 | 5123 | 9056 | 3 | 2333 | 384 | 127627 |
| MultiPairing n=1 BN254 | 7984 | 10446 | 180 | 2759 | 383 | 155366 |
| MultiPairing n=1 BLS12_381 | 7795 | 11742 | 140 | 3123 | 447 | 175215 |
| MultiPairing n=2 BN254 | 10320 | 12794 | 356 | 2783 | 383 | 184134 |
| MultiPairing n=2 BLS12_381 | 9541 | 13581 | 276 | 3145 | 447 | 197185 |
| MultiPairing n=3 BN254 | 12656 | 15142 | 532 | 2807 | 383 | 212902 |
| MultiPairing n=3 BLS12_381 | 11287 | 15420 | 412 | 3167 | 447 | 219155 |
| BLS12FinalExp Fp12 Karabina No EXTF Trick | 7774 | 43002 | 0 | 0 | 0 | 234200 |## Support & How to Contribute
We warmly welcome contributions and support from the community! Here's how you can help Garaga grow and improve:
### Reporting Issues & Requesting Features
- **Spot a bug? Have a feature request?** Check out our [issues page](https://github.com/keep-starknet-strange/garaga/issues) to see if it's already been reported or to open a new issue.
### Contributing to Garaga
- **Interested in contributing?** Please take a moment to read our [contribution guidelines](docs/CONTRIBUTING.md) for details on how to get started. Your contributions make the open-source community an incredible place for learning, inspiration, and creation.
### Showing Support
- **Love Garaga?** Give us a [star on GitHub](https://github.com/keep-starknet-strange/garaga) to show your support.
- **Spread the word:** Share your excitement about Garaga on social platforms like Twitter, [Dev.to](https://dev.to/), [Medium](https://medium.com/), or your personal blog.
- **Join the conversation:** Connect with us and other Garaga enthusiasts on our [Telegram group](https://t.me/GaragaPairingCairo).Every contribution, whether it's code, feedback, or spreading the word, greatly benefits everyone and is deeply appreciated. Thank you for being a part of Garaga's journey!
## Security
Garaga follows good practices of security, but 100% security cannot be assured.
Garaga is provided **"as is"** without any **warranty**. Use at your own risk._For more information and to report security issues, please refer to our
[security documentation](docs/SECURITY.md)._## License
This project is licensed under the **MIT license**.
See [LICENSE](LICENSE) for more information.
## Acknowledgements
- Huge props to [tekkac](https://github.com/tekkac) and [feltroidprime](https://github.com/feltroidprime) for their initial work on provable pairing-based cryptography in StarkNet.
- Credits to [Nethermind](https://github.com/NethermindEth/) for their [initial work on optimized modular arithmetic](https://github.com/NethermindEth/research-basic-Cairo-operations-big-integers/tree/main/lib).
- [Herodotus](https://www.herodotus.dev/) for supporting this project.
- [Gnark project](https://github.com/ConsenSys/gnark-crypto) and team, especially [yelhousni](https://github.com/yelhousni) for his amazing knowledge and support.
- [OnlyDust](https://www.onlydust.xyz/) and [Starkware](https://starkware.co/).
- Liam Eagen and Andrija Novakovic for their support and amazing research.
## Resources
- Craig Costello, [Pairing for beginners](https://static1.squarespace.com/static/5fdbb09f31d71c1227082339/t/5ff394720493bd28278889c6/1609798774687/PairingsForBeginners.pdf)
- Y. El Housni, "Pairings in Rank-1 Constraint Systems," Cryptology ePrint Archive, Report 2022/1162, 2022. Available: [https://eprint.iacr.org/2022/1162](https://eprint.iacr.org/2022/1162).
- feltroidprime. "Faster Extension Field multiplications for Emulated Pairing Circuits." HackMD, [https://hackmd.io/@feltroidprime/B1eyHHXNT](https://hackmd.io/@feltroidprime/B1eyHHXNT).
- Liam Eagen, "Zero Knowledge Proofs of Elliptic Curve Inner Products from Principal Divisors and Weil Reciprocity," Cryptology ePrint Archive, Report 2022/596, 2022. Available: [https://eprint.iacr.org/2022/596](https://eprint.iacr.org/2022/596)
- Andrija Novakovic and Liam Eagen, "On Proving Pairings," Cryptology ePrint Archive, Paper 2024/640, 2024. Available: [https://eprint.iacr.org/2024/640](https://eprint.iacr.org/2024/640)> **Note:** This list is not exhaustive, and is not intended to be.
## Contributors
For a full list of all authors and contributors, see
[the contributors page](https://github.com/keep-starknet-strange/garaga/contributors).Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Feltroid Prime
π»
Abdel @ StarkWare
π»
Tarik K.
π»
Bachir Arif
π»
Renaud Dubois
π»
Rodrigo Ferreira
π»
Luiz Vasconcelos JΓΊnior
π»
Shramee Srivastav
π»
Andrija Novakovic
π»
Liam Eagen
π»
Paul Etscheit
π»
stefanMadzharov
π»
Add your contributions
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!