Awesome
<div align="center"> <h1>Garaga</h1> <img src="docs/images/logo.png" height="200"> <br /> <a href="https://github.com/keep-starknet-strange/garaga/issues/new?assignees=&labels=bug&template=01_BUG_REPORT.md&title=bug%3A+">Report a Bug</a> - <a href="https://github.com/keep-starknet-strange/garaga/issues/new?assignees=&labels=enhancement&template=02_FEATURE_REQUEST.md&title=feat%3A+">Request a Feature</a> - <a href="https://github.com/keep-starknet-strange/garaga/discussions">Ask a Question</a> </div> <div align="center"> <br /> </div> </details>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
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.
-
Create a new directory for you project, and bring the jsons files for verification key, proof file and public inputs inside it.
-
Install the garaga pip package with
pip install garaga
. Python3.10 is mandatory and a virtual environment is recommended. Entergaraga
in your terminal to get started. -
Run the
garaga gen
command in your terminal to generate the code for the SNARK verifier given your verification key. -
Edit the generated smart contract to fit the needs of your dapp.
-
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. -
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. -
Run the
garaga deploy
command in your terminal using the class hash obtained in the previous step to get the contract address. -
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.
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 - /!\ 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 thefastecdsa
python package. See here for linux and here for macos. - Scarb 2.8.4 - The Cairo package manager. Comes with Cairo inside. Requires Rust.
Optionally :
- pprof - A tool for visualization and analysis of profiling data. Requires Go.
- graphviz - 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.
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 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 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 to show your support.
- Spread the word: Share your excitement about Garaga on social platforms like Twitter, Dev.to, Medium, or your personal blog.
- Join the conversation: Connect with us and other Garaga enthusiasts on our Telegram group.
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.
License
This project is licensed under the MIT license.
See LICENSE for more information.
Acknowledgements
- Huge props to tekkac and feltroidprime for their initial work on provable pairing-based cryptography in StarkNet.
- Credits to Nethermind for their initial work on optimized modular arithmetic.
- Herodotus for supporting this project.
- Gnark project and team, especially yelhousni for his amazing knowledge and support.
- OnlyDust and Starkware.
- Liam Eagen and Andrija Novakovic for their support and amazing research.
Resources
- Craig Costello, Pairing for beginners
- Y. El Housni, "Pairings in Rank-1 Constraint Systems," Cryptology ePrint Archive, Report 2022/1162, 2022. Available: https://eprint.iacr.org/2022/1162.
- feltroidprime. "Faster Extension Field multiplications for Emulated Pairing Circuits." HackMD, 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
- Andrija Novakovic and Liam Eagen, "On Proving Pairings," Cryptology ePrint Archive, Paper 2024/640, 2024. Available: 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.
Thanks goes to these wonderful people (emoji key):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tbody> <tr> <td align="center" valign="top" width="14.28%"><a href="https://github.com/feltroidprime"><img src="https://avatars.githubusercontent.com/u/96737978?v=4?s=100" width="100px;" alt="Feltroid Prime"/><br /><sub><b>Feltroid Prime</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/garaga/commits?author=feltroidprime" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/abdelhamidbakhta"><img src="https://avatars.githubusercontent.com/u/45264458?v=4?s=100" width="100px;" alt="Abdel @ StarkWare "/><br /><sub><b>Abdel @ StarkWare </b></sub></a><br /><a href="https://github.com/keep-starknet-strange/garaga/commits?author=abdelhamidbakhta" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/tekkac"><img src="https://avatars.githubusercontent.com/u/98529704?v=4?s=100" width="100px;" alt="Tarik K."/><br /><sub><b>Tarik K.</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/garaga/commits?author=tekkac" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/bacharif"><img src="https://avatars.githubusercontent.com/u/22233193?v=4?s=100" width="100px;" alt="Bachir Arif"/><br /><sub><b>Bachir Arif</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/garaga/commits?author=bacharif" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/rdubois-crypto"><img src="https://avatars.githubusercontent.com/u/103030189?v=4?s=100" width="100px;" alt="Renaud Dubois"/><br /><sub><b>Renaud Dubois</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/garaga/commits?author=rdubois-crypto" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://raugfer.com/"><img src="https://avatars.githubusercontent.com/u/725060?v=4?s=100" width="100px;" alt="Rodrigo Ferreira"/><br /><sub><b>Rodrigo Ferreira</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/garaga/commits?author=raugfer" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/luiz-lvj"><img src="https://avatars.githubusercontent.com/u/64055364?v=4?s=100" width="100px;" alt="Luiz Vasconcelos Júnior"/><br /><sub><b>Luiz Vasconcelos Júnior</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/garaga/commits?author=luiz-lvj" title="Code">💻</a></td> </tr> <tr> <td align="center" valign="top" width="14.28%"><a href="http://shramee.me/"><img src="https://avatars.githubusercontent.com/u/11048263?v=4?s=100" width="100px;" alt="Shramee Srivastav"/><br /><sub><b>Shramee Srivastav</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/garaga/commits?author=shramee" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/akinovak"><img src="https://avatars.githubusercontent.com/u/28649205?v=4?s=100" width="100px;" alt="Andrija Novakovic"/><br /><sub><b>Andrija Novakovic</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/garaga/commits?author=akinovak" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/Liam-Eagen"><img src="https://avatars.githubusercontent.com/u/5618692?v=4?s=100" width="100px;" alt="Liam Eagen"/><br /><sub><b>Liam Eagen</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/garaga/commits?author=Liam-Eagen" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/petscheit"><img src="https://avatars.githubusercontent.com/u/10947187?v=4?s=100" width="100px;" alt="Paul Etscheit"/><br /><sub><b>Paul Etscheit</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/garaga/commits?author=petscheit" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/stefanMadzharov"><img src="https://avatars.githubusercontent.com/u/83451593?v=4?s=100" width="100px;" alt="stefanMadzharov"/><br /><sub><b>stefanMadzharov</b></sub></a><br /><a href="https://github.com/keep-starknet-strange/garaga/commits?author=stefanMadzharov" title="Code">💻</a></td> </tr> </tbody> <tfoot> <tr> <td align="center" size="13px" colspan="7"> <img src="https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg"> <a href="https://all-contributors.js.org/docs/en/bot/usage">Add your contributions</a> </img> </td> </tr> </tfoot> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->This project follows the all-contributors specification. Contributions of any kind welcome!