Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Docs to main. #252

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/gitbook/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Garaga documentation

Welcome to Garaga's documentation ! \


\
\
Repository link : [https://github.com/keep-starknet-strange/garaga](https://github.com/keep-starknet-strange/garaga)
20 changes: 17 additions & 3 deletions docs/gitbook/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@

* [Garaga documentation](README.md)
* [Installation](installation/README.md)
* [Developer setup](installation/developer-setup.md)
* [Python package](installation/python-package.md)
* [Rust Crate](installation/rust-crate.md)
* [Npm package](installation/npm-package.md)
* [Developer setup & guides](developer-setup-and-guides/README.md)
* [Working with auto-generated Cairo Code](developer-setup-and-guides/working-with-auto-generated-cairo-code.md)
* [garaga-rs crate](developer-setup-and-guides/garaga-rs-crate/README.md)
* [Rust -> Python bindings](developer-setup-and-guides/garaga-rs-crate/rust-greater-than-python-bindings.md)
* [Rust -> Wasm bidings](developer-setup-and-guides/garaga-rs-crate/rust-greater-than-wasm-bidings.md)
* [Using garaga libraries in your Cairo project](using-garaga-libraries-in-your-cairo-project/README.md)
* [EC (Multi)-Scalar Multiplication](using-garaga-libraries-in-your-cairo-project/ec-multi-scalar-multiplication.md)
* [Deploy your SNARK verifier on Starknet](deploy-your-snark-verifier-on-starknet/README.md)
* [EC-Signatures](using-garaga-libraries-in-your-cairo-project/ec-signatures.md)
* [Deploy your own SNARK verifier on Starknet](deploy-your-snark-verifier-on-starknet/README.md)
* [Groth16](deploy-your-snark-verifier-on-starknet/groth16/README.md)
* [Generate and deploy your verifier contract](deploy-your-snark-verifier-on-starknet/groth16/generate-and-deploy-your-verifier-contract.md)
* [Generating calldata from a proof and using your deployed contract](deploy-your-snark-verifier-on-starknet/groth16/generating-calldata-from-a-proof-and-using-your-deployed-contract.md)
* [Generating calldata from a proof and using your deployed contract](deploy-your-snark-verifier-on-starknet/groth16/generating-calldata-from-a-proof-and-using-your-deployed-contract/README.md)
* [Using Python/Garaga CLI](deploy-your-snark-verifier-on-starknet/groth16/generating-calldata-from-a-proof-and-using-your-deployed-contract/using-python-garaga-cli.md)
* [Using Rust](deploy-your-snark-verifier-on-starknet/groth16/generating-calldata-from-a-proof-and-using-your-deployed-contract/using-rust.md)
* [Using Typescript](deploy-your-snark-verifier-on-starknet/groth16/generating-calldata-from-a-proof-and-using-your-deployed-contract/using-typescript.md)
* [Noir](deploy-your-snark-verifier-on-starknet/noir.md)
* [Maintained Smart Contracts](maintained-smart-contracts/README.md)
* [RiscZero](maintained-smart-contracts/risczero.md)
* [SP1](maintained-smart-contracts/sp1.md)
* [Drand](maintained-smart-contracts/drand.md)
* [Support](support.md)
* [Updating these docs](updating-these-docs.md)
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ icon: file-lock

# Generate and deploy your verifier contract



{% hint style="info" %}
Only Starknet Sepolia is supported. Starknet Mainnet will be supported on version 0.13.2
{% endhint %}

## Prepare your Groth16 verifying key

{% hint style="info" %}
Expand Down Expand Up @@ -113,7 +107,7 @@ func SaveToJSON(filePath string, v interface{}) error {
## Generate the Smart contract code

\
Using the [developer-setup.md](../../installation/developer-setup.md "mention") or the [python-package.md](../../installation/python-package.md "mention"), you should now have access to the Garaga CLI from your terminal, using the command `garaga`
Using the [developer-setup-and-guides](../../developer-setup-and-guides/ "mention") or the [python-package.md](../../installation/python-package.md "mention"), you should now have access to the Garaga CLI from your terminal, using the command `garaga`

```bash
garaga
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ To do this, use the garaga `verify-onchain` command. 
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```

As for the verifying key, both Snarkjs and Gnark `proof.json` and `public.json` are supported out of the box. See the example in the [generate-and-deploy-your-verifier-contract.md](generate-and-deploy-your-verifier-contract.md "mention") for Gnark export.
As for the verifying key, both Snarkjs and Gnark `proof.json` and `public.json` are supported out of the box. See the example in the [generate-and-deploy-your-verifier-contract.md](../generate-and-deploy-your-verifier-contract.md "mention") for Gnark export.

Alternatively, the `--public-inputs` parameter can be omitted if your proof include everything at once, as below.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Using Python/Garaga CLI

Using the `garaga calldata` command from the CLI, you can generate the calldata needed to verify a proof for the `verify_groth16_proof_[curve_name]`.

First, ensure that:
- Your circuit is compiled and the verification key `verification_key.json` is created
- The public input file `public.json` and the associated proof `proof.json` are created

The call the following command by replacing the parameters with your data:

```bash
garaga calldata --system groth16 --vk verification_key.json --proof proof.json --public-inputs public.json
2789 41983001825546257095993508953 3045291465937026073442547681 1840582864647114302 0 69020349870260156176548317333 16784567729677911275297018120 1865382613176499468 0 51545988015561248414407597558 44248521764831362261757723052 8850086 ...
```

## `starkli` usage

Using the command option `--format starkli`,
you can directly pipe the generated calldata to `starkli` to invoke a transaction on your deployed contract.

The proof must be the last parameter of your contract's method.

```bash
garaga calldata --system groth16 --vk verification_key.json --proof proof.json --public-inputs public.json --format starkli | xargs starkli invoke --keystore-password $KEYSTORE_PASSWORD --watch $YOUR_CONTRACT your_verify_method YOUR_PARAMETERS
```

## Cairo code usage

Use the command option `--format array` to generate calldata in array format to be used in your smart-contract tests.

```bash
garaga calldata --system groth16 --vk verification_key.json --proof proof.json --public-inputs public.json --format array
[2789, 41983001825546257095993508953, 3045291465937026073442547681, 1840582864647114302, 0, 69020349870260156176548317333, 16784567729677911275297018120, 1865382613176499468, 0, 51545988015561248414407597558, 44248521764831362261757723052, 88500861247646845, 0, ... ]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Using Rust

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Using Typescript

159 changes: 158 additions & 1 deletion docs/gitbook/deploy-your-snark-verifier-on-starknet/noir.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,161 @@ icon: octopus

# Noir

Soon
## Requirements

* Noir 0.36.0 (install with \`noirup --version 0.36.0\`)
* Barretenberg 0.61.0 (install with \`bbup --version 0.61.0\`)
* Garaga CLI [python-package.md](../installation/python-package.md "mention")

To install `noirup` and `bbup`, follow the [quickstart guide from aztec ](https://noir-lang.org/docs/getting_started/quick_start):

We recall the installations commands here:

```bash
curl -L noirup.dev | bash
```

```bash
curl -L bbup.dev | bash
```

## Generate a Starknet smart contract for your Noir program

First, we'll create a new Noir project and compile it.

```bash
nargo init hello
cd hello
nargo build
```

This will create a json file in `hello/target/hello.json`

Now you can generate the corresponding verifying key using barretenberg :

```bash
bb write_vk_ultra_keccak_honk -b target/hello.json -o target/vk.bin
```

Finally, you can generate a smart contract from the verifying key using the garaga CLI

```bash
garaga gen --system ultra_keccak_honk --vk target/vk.bin
```

This will create a smart contract folder with the following structure.

```
Generating Smart Contract project for ProofSystem.UltraKeccakHonk using vk.bin...
Done!
Smart Contract project created:
/noir/hello/my_project/
├── .tools-versions
├── Scarb.toml
└── src/
├── honk_verifier.cairo
├── honk_verifier_circuits.cairo
├── honk_verifier_constants.cairo
└── lib.cairo
```

The main function of interest is located in `honk_verifier.cairo`

The contract interface will be

```rust
#[starknet::interface]
trait IUltraKeccakHonkVerifier<TContractState> {
fn verify_ultra_keccak_honk_proof(
self: @TContractState, full_proof_with_hints: Span<felt252>,
) -> Option<Span<u256>>;
}

```

In order to interact with the endpoint, you need to generate the `full_proof_with_hints`array.

To do so, you need a specific proof for your program. But first, Noir requires you to specify the inputs of your program in `hello/Prover.toml`

```toml
// The "hello" program simply prove that x!=y, with x being private and y public.
x = "1"
y = "2"
```

You can now generate a proof with barretenberg, after running the program :

```bash
nargo execute witness
bb prove_ultra_keccak_honk -b target/hello.json -w target/witness.gz -o target/proof.bin
```

Finally, you can obtain the `full_proof_with_hints` array using the garaga CLI. From within the "target" directory:

```bash
garaga calldata --system ultra_keccak_honk --vk vk.bin --proof proof.bin --format array
```

{% hint style="info" %}
Using `garaga calldata`with the `--format array` lets you paste this array in cairo code for unit tests by doing let proof:Array\<felt252> = \[ ... ] ; . The `--format starkli` has a formatting which is composable with starkli in the command line and also preprends the length of the array so that it can be deserialized by starknet.
{% endhint %}



## The Ultra Starknet Flavor

We are in the process of adding a new flavor to Noir proofs called Ultra Starknet. It contrasts with with Ultra Keccak presented in the previous section.

The Ultra Starknet flavor replaces the Keccak hash function by [Poseidon](https://www.poseidon-hash.info/), which is a ZK-friendly hash function and therefore better suited in the context of Starknet and Cairo contracts.

In order to provide the Ultra Starknet flavor we forked and customized the Barretenberg (`bb`) implementation. Here the steps to build the customized `bb`:

1. Install [build dependencies](https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg#development) (assuming here a Debian-compatible system)

```bash
sudo apt install -y cmake clang clang-16 clang-format libstdc++-12-dev ninja-build
```

2. Clone our fork of the Aztec Packages repository and checkout the specific branch

```bash
git clone https://github.com/raugfer/aztec-packages.git
cd aztec-packages
git checkout ultra-starknet-honk
```

3. Perform the build

```bash
cd barretenberg/cpp
cmake --preset clang16
cmake --build --preset clang16 --target bb
```

4. Manually install the custom `bb` command, conveniently, under the Nargo config folder

```bash
install build/bin/bb ~/.nargo/bin/
mkdir ~/.nargo/lib/
install build/src/barretenberg/crypto/poseidon/sources/lib_pos* ~/.nargo/lib/
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/.nargo/lib/"
```

Now, in order to generate a Ultra Starknet proof and verifying key using the customized Barretenberg implementation, simply issue the following commands:

```bash
bb prove_ultra_starnet_honk -b target/hello.json -w target/witness.gz -o target/proof.bin
bb write_vk_ultra_starnet_honk -b target/hello.json -o target/vk.bin
```

To generate a contract using the Ultra Starknet system, use the following command, which is similar to the previous process:

```bash
garaga gen --system ultra_starknet_honk --vk target/vk.bin
```

And, as with the Ultra Keccak flavor, one can obtain the `full_proof_with_hints` array using the garaga CLI :

```bash
garaga calldata --system ultra_starknet_honk --vk vk.bin --proof proof.bin --format array
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
icon: wrench
---

# Developer setup
# Developer setup & guides

To work with Garaga, you need the following dependencies :&#x20;
### Installation

To work with Garaga, you need the following dependencies :

* Python 3.10. The command `python3.10` should be available and working in your terminal.&#x20;
* [Scarb](https://docs.swmansion.com/scarb/download.html) v2.8.4.&#x20;
* [Scarb](https://docs.swmansion.com/scarb/download.html) with the version specified in [https://github.com/keep-starknet-strange/garaga/blob/main/src/.tool-versions](https://github.com/keep-starknet-strange/garaga/blob/main/src/.tool-versions)
* [Rust](https://www.rust-lang.org/tools/install)

Simply clone the [repository](https://github.com/keep-starknet-strange/garaga) :
Expand All @@ -18,22 +20,26 @@ Using git:
git clone https://github.com/keep-starknet-strange/garaga.git
```

Using [github cli ](https://cli.github.com/) :
Using [github cli ](https://cli.github.com/):

```bash
gh repo clone keep-starknet-strange/garaga
```

After that, go into the root of the directory and run the command :&#x20;
After that, go into the root of the directory and run the command :

```bash
make setup
```

Pay attention to any message indicating failure. Contact us on Garaga telegram if you have any trouble at this point.&#x20;
Pay attention to any message indicating failure. Contact us on Garaga telegram if you have any trouble at this point.

If everything succeeded, you're good to go!

{% hint style="info" %}
Make sure to activate the virtual environment created with this setup, using `source/venv/bin/activate`&#x20;
Make sure to activate the virtual environment created with this setup, using `source/venv/bin/activate`
{% endhint %}



### &#x20;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
icon: crab
---

# garaga-rs crate

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Rust -> Python bindings

## Adding a binding

TODO.&#x20;
Loading