Skip to content

keep-starknet-strange/garaga

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


CI Status Project license Pull Requests welcome

Exploration_Team

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.
  • Noir smart contract verifiers generators for ultra keccak honk flavour.

Architecture overview

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.

  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.

  8. 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 the fastecdsa python package. See here for linux and here for macos.
  • Scarb 2.11.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.

Cairo Benchmarks

πŸ“Š Click on any section below to expand and view detailed benchmark tables with test performance metrics.

Note: Click on the test name to view the profiling image. Resources shown in the table for contracts include extra costs due to the foundry logic. Check the profile file for more details.

contracts
└── groth16_example_bls12_381_integrationtest::test_contract
Test Name Steps Range Check Range Check 96 Poseidon Add Mod Mul Mod Sierra Gas
test_verify_groth16_proof_bls12_381 245,251 12,083 61,344 597 5,325 7,504 34,856,467
└── groth16_example_bn254_integrationtest::test_contract
Test Name Steps Range Check Range Check 96 Poseidon Add Mod Mul Mod Sierra Gas
test_verify_groth16_proof_bn254 251,542 11,215 75,704 681 6,341 9,662 37,807,323
└── noir_ultra_keccak_honk_example_integrationtest::test_contract
Test Name Steps Range Check Range Check 96 Bitwise Poseidon Add Mod Mul Mod Sierra Gas
test_verify_ultra_keccak_honk_proof 1,300,439 68,874 412,841 3,180 608 45,756 43,622 197,008,212
└── noir_ultra_keccak_zk_honk_example_integrationtest::test_contract
Test Name Steps Range Check Range Check 96 Bitwise Poseidon Add Mod Mul Mod Sierra Gas
test_verify_ultra_keccak_zk_honk_proof 1,401,065 73,884 452,092 3,476 608 49,930 48,054 213,429,084
└── noir_ultra_starknet_honk_example_integrationtest::test_contract
Test Name Steps Range Check Range Check 96 Poseidon Add Mod Mul Mod Sierra Gas
test_verify_ultra_starknet_honk_proof 1,166,626 61,827 412,707 1,139 45,742 43,606 181,520,015
└── noir_ultra_starknet_zk_honk_example_integrationtest::test_contract
Test Name Steps Range Check Range Check 96 Poseidon Add Mod Mul Mod Sierra Gas
test_verify_ultra_starknet_zk_honk_proof 1,260,556 66,600 451,134 1,191 49,860 47,958 197,000,317
└── risc0_verifier_bn254_integrationtest::test_contract
Test Name Steps Range Check Range Check 96 Bitwise Poseidon Add Mod Mul Mod Sierra Gas
test_verify_r0_groth16_proof_bn254 290,849 14,593 91,204 6,698 681 8,151 11,240 48,116,829
└── sp1_verifier_bn254_integrationtest::test_contract
Test Name Steps Range Check Range Check 96 Bitwise Poseidon Add Mod Mul Mod Sierra Gas
test_verify_sp1_groth16_proof_bn254 269,236 13,584 91,460 2,230 681 8,167 11,264 43,312,567
garaga
└── crypto::mmr::tests
Test Name Steps Range Check Sierra Gas
test_trailing_ones 549 62 59,240
└── ec::ec_ops_g2::tests
Test Name Steps Range Check Range Check 96 Add Mod Mul Mod Sierra Gas
test_ec_mul_g2 122,500 1,075 93,069 8,793 10,239 25,743,860
└── hashes::poseidon_bn254::tests
Test Name Steps Range Check Range Check 96 Add Mod Mul Mod Sierra Gas
test_run_poseidon_grumpkin_circuit_1 16,108 328 6,393 353 919 2,628,034
└── tests
β”‚ └── autogenerated
β”‚ β”‚ └── ecdsa_tests
Test Name Steps Range Check Range Check 96 Add Mod Mul Mod Sierra Gas
test_ecdsa_SECP256R1 16,574 1,074 20,022 2,367 2,184 4,717,358
test_ecdsa_SECP256K1 21,452 2,084 15,629 1,810 1,592 4,544,172
β”‚ β”‚ └── eddsa_tests
Test Name Steps Range Check Range Check 96 Bitwise Add Mod Mul Mod Sierra Gas
test_eddsa_32_64B 100,238 14,068 20,418 3,288 2,388 2,236 15,968,656
test_eddsa_16_32B 59,460 7,748 20,496 1,656 2,394 2,244 10,507,580
test_eddsa_0_0B 58,375 7,686 20,521 1,656 2,395 2,246 10,397,578
β”‚ β”‚ └── msm_tests
Test Name Steps Range Check Range Check 96 Add Mod Mul Mod Sierra Gas
test_msm_SECP256R1_3P 23,742 1,577 29,835 3,546 3,252 6,935,138
test_msm_SECP256K1_3P 30,945 3,088 23,194 2,707 2,359 6,656,970
test_msm_SECP256R1_2P 15,910 1,054 19,865 2,363 2,166 4,628,974
test_msm_SECP256K1_2P 20,601 2,062 15,369 1,799 1,564 4,423,530
test_msm_SECP256R1_1P 8,262 531 9,945 1,182 1,084 2,346,886
test_msm_SECP256K1_1P 10,621 1,038 7,697 900 783 2,245,724
β”‚ β”‚ └── pairing_tests
Test Name Steps Range Check Range Check 96 Poseidon Add Mod Mul Mod Sierra Gas
test_BN254_mpcheck_3P_2F_with_extra_miller_loop_result 77,448 574 59,838 681 4,505 8,043 17,364,401
test_BLS12_381_mpcheck_3P_2F_with_extra_miller_loop_result 65,720 368 45,634 597 3,501 5,901 13,815,825
test_BN254_mpcheck_2P_2F 61,456 462 33,232 607 1,731 4,702 11,575,107
test_BLS12_381_mpcheck_2P_2F 53,498 309 25,204 544 1,397 3,354 9,397,084
β”‚ β”‚ └── schnorr_tests
Test Name Steps Range Check Range Check 96 Add Mod Mul Mod Sierra Gas
test_schnorr_SECP256K1 21,009 2,083 15,512 1,808 1,580 4,485,542
β”‚ β”‚ └── tower_pairing_tests
Test Name Steps Range Check Range Check 96 Add Mod Mul Mod Sierra Gas
test_tower_pairing_BN254_3P 298,906 622 626,255 94,555 50,514 117,262,526
test_tower_pairing_BLS12_381_3P 268,002 812 544,901 87,847 37,874 100,452,202
test_tower_pairing_BN254_2P 244,049 546 486,548 73,494 38,661 91,944,672
test_tower_pairing_BLS12_381_2P 222,511 749 429,096 69,571 28,951 79,820,640
test_tower_pairing_BN254_1P 189,192 470 346,841 52,433 26,808 66,626,818
test_tower_pairing_BLS12_381_1P 177,020 686 313,291 51,295 20,028 59,189,078
test_tower_final_exp_BN254 134,382 394 207,134 31,372 14,955 41,313,664
test_tower_final_exp_BLS12_381 131,576 623 197,486 33,019 11,105 38,562,216
β”‚ └── calldata_tests
Test Name Steps Range Check Sierra Gas
test_deserialize_full_proof_with_hints_bls12_381 63,341 5,339 6,707,830
β”‚ └── sha512_tests
Test Name Steps Range Check Bitwise Sierra Gas
test_sha512_lorem_ipsum 115,350 18,467 4,904 15,686,722
test_size_zero 43,353 6,605 1,640 5,753,770
test_sha512_size_one 43,330 6,603 1,640 5,751,330
└── utils
β”‚ └── drand::tests
Test Name Steps Range Check Range Check 96 Bitwise Add Mod Mul Mod Sierra Gas
test_decrypt_at_round 317,522 4,183 397,265 14,506 59,198 29,332 94,080,916
test_hash_to_curve 29,589 1,007 4,559 12,289 422 602 10,909,849
test_hash_to_two_bls_felts 25,468 936 74 12,289 2 8 9,786,243
test_isogeny 2,938 59 878 0 51 111 425,872
test_map_to_curve 729 12 264 0 6 39 113,460
test_drand_quicknet_public_key 307 4 158 0 14 17 53,316
β”‚ └── neg_3::tests
Test Name Steps Range Check Sierra Gas
test_scalar_to_epns 6,904 929 755,430
test_scalar_to_epns_single 2,215 298 242,360
β”‚ └── noir
β”‚ β”‚ └── honk_transcript::tests
Test Name Steps Range Check Bitwise Poseidon Sierra Gas
test_transcript_keccak 91,992 8,282 3,180 1 11,633,371
test_transcript_starknet 24,448 1,397 0 532 2,803,802
β”‚ β”‚ └── zk_honk_transcript::tests
Test Name Steps Range Check Bitwise Poseidon Sierra Gas
test_zk_transcript_keccak 94,677 8,626 3,476 1 12,098,519
test_zk_transcript_starknet 26,179 1,507 0 584 3,010,134
β”‚ └── risc0::risc0_utils_tests
Test Name Steps Range Check Bitwise Sierra Gas
test_receipt_claim 12,239 448 5,591 4,514,813
test_output_digest 4,896 179 2,230 1,802,220
β”‚ └── sp1::tests
Test Name Steps Range Check Sierra Gas
test_convert_u32_to_u128 80 4 8,280

πŸ”„ To regenerate these benchmarks: Run make profile-test from the project root.

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

Resources

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):

Feltroid Prime
Feltroid Prime

πŸ’»
Abdel @ StarkWare
Abdel @ StarkWare

πŸ’»
Tarik K.
Tarik K.

πŸ’»
Bachir Arif
Bachir Arif

πŸ’»
Renaud Dubois
Renaud Dubois

πŸ’»
Rodrigo Ferreira
Rodrigo Ferreira

πŸ’»
Luiz Vasconcelos JΓΊnior
Luiz Vasconcelos JΓΊnior

πŸ’»
Shramee Srivastav
Shramee Srivastav

πŸ’»
Andrija Novakovic
Andrija Novakovic

πŸ’»
Liam Eagen
Liam Eagen

πŸ’»
Paul Etscheit
Paul Etscheit

πŸ’»
stefanMadzharov
stefanMadzharov

πŸ’»
Add your contributions

This project follows the all-contributors specification. Contributions of any kind welcome!