Skip to content

Commit

Permalink
Update proof parser and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Sep 22, 2024
1 parent db50638 commit a9f40ca
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["runner", "benches", "examples/starknet"]
members = ["runner", "benches", "serializer"]

[workspace.package]
edition = "2021"
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@

## Using Verifier contracts on Starknet

Integrity verifier is deployed on Starknet and can be used for verifying proofs onchain. The intended way of using the verifier is through FactRegistry contract, which besides running the verification process, also stores data for all verified proofs. (For more information see [FactRegistry and Proxy contract](#factregistry-and-proxy-contract))

There are two ways of serializing proof into calldata: monolith and split proof. The former should be used if possible, because it's easier and more efficient. The latter should only be used if monolith proof did not fit in a single transaction, either because of calldata limit or steps limit.

### Monolith proof

Calldata for monolith proof can be generated with the following command:

```bash
cargo run --release --bin proof_serializer < examples/proofs/recursive/cairo0_example_proof.json > examples/calldata
```

Then make sure that you have `sncast` installed and `snfoundry.toml` is configured correctly.

After that, you can use `verify-on-starknet.sh` script to send the transaction to FactRegistry contract. Remember to select appropriate settings for your proof. For more information on supported settings, see [Verifier settings](TODO).

For example, run:

```bash
./verify-on-starknet.sh 0x7a5340bf1a500d94185cde6fc9cdc4b32c1159d1db5c056841d21bfb0d9c2bd examples/calldata recursive keccak_248_lsb stone5 cairo0
```

### Split proof

TODO: check if below is valid

To use the Verifier for verifying proofs on starknet, you need to generate calldata for your proof. The easiest way to do that is to use [Calldata Generator](https://github.com/HerodotusDev/integrity-calldata-generator). It also provides script for automatic transaction sending (proof verification is split into multiple transactions, for more information see [Split Verifier Architecture](#split-verifier-architecture)).

## Running locally
Expand Down Expand Up @@ -91,3 +117,5 @@ After proof is verified, `FactRegistered` event is emitted which contains `fact_
- `get_all_verifications_for_fact_hash(fact_hash)` - returns list of all verification hashes, security bits and settings for given `fact_hash`. This method is useful for checking if given program has been verified by someone with secure enough proof.

FactRegistry contract is trustless which means that owner of the contract can't override or change any existing behavior, they can only add new verifiers. Proxy contract on the other hand is upgradable, so every function can be changed or removed. It has the advantage of having all future updates of the verifier logic without having to replace the address of FactRegistry contract.

TODO: how to read FactRegistered event
2 changes: 1 addition & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ blake2s = []
monolith = []
split = []

default = ["recursive", "keccak"]
default = ["recursive", "keccak", "monolith"]
3 changes: 0 additions & 3 deletions examples/starknet/.gitignore

This file was deleted.

29 changes: 0 additions & 29 deletions examples/starknet/1-verify-proof.sh

This file was deleted.

13 changes: 0 additions & 13 deletions examples/starknet/Scarb.toml

This file was deleted.

3 changes: 1 addition & 2 deletions examples/starknet/Cargo.toml → serializer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[package]
name = "snfoundry_proof_serializer"
name = "proof_serializer"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow.workspace = true
clap.workspace = true
itertools.workspace = true
runner.workspace = true
serde_json.workspace = true
Expand Down
14 changes: 2 additions & 12 deletions examples/starknet/src/main.rs → serializer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
use clap::Parser;
use itertools::chain;
use runner::{transform::StarkProofExprs, CairoVersion, VecFelt252};
use runner::{transform::StarkProofExprs, VecFelt252};
use std::io::{stdin, Read};
use swiftness_proof_parser::parse;

#[derive(Parser)]
#[command(author, version, about)]
struct Cli {
/// Cairo version - public memory pattern
#[clap(value_enum, short, long, default_value_t=CairoVersion::Cairo0)]
cairo_version: CairoVersion,
}

fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
let mut input = String::new();
stdin().read_to_string(&mut input)?;

Expand All @@ -32,7 +22,7 @@ fn main() -> anyhow::Result<()> {
witness.into_iter()
);

let calldata_string = chain!(proof, vec![cli.cairo_version.into()].into_iter())
let calldata_string = proof.into_iter()
.map(|f| f.to_string())
.collect::<Vec<String>>()
.join(" ");
Expand Down
43 changes: 43 additions & 0 deletions verify-on-starknet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

# Check if the arguments are provided
if [ $# -ne 6 ]; then
echo "Usage: $0 <fact_registry_address> <calldata_file> <layout> <hasher> <stone_version> <cairo_version>"
exit 1
fi

string_to_hex() {
input_string="$1"
hex_string="0x"
for ((i = 0; i < ${#input_string}; i++)); do
hex_char=$(printf "%x" "'${input_string:$i:1}")
hex_string+=$hex_char
done
echo "$hex_string"
}

# Assign arguments to variables
contract_address=$1
calldata_file=$2
layout=$(string_to_hex $3)
hasher=$(string_to_hex $4)
stone_version=$(string_to_hex $5)
cairo_version=$(string_to_hex $6)

# Check if the file exists
if [ ! -f "$calldata_file" ]; then
echo "Error: File '$calldata_file' not found."
exit 1
fi

# Read calldata from the specified file
calldata=$(<$calldata_file)

# Pass the calldata to the sncast command
sncast \
--wait \
invoke \
--contract-address "$contract_address" \
--function "verify_proof_full_and_register_fact" \
--calldata $layout $hasher $stone_version $cairo_version $calldata \
--fee-token eth

0 comments on commit a9f40ca

Please sign in to comment.