Skip to content

Commit

Permalink
Saya Prove and Verify (#1708)
Browse files Browse the repository at this point in the history
* proof serialization

* proof verification on deployed contract

* calling verifier contract from rust

* cleaned implementation

* cleaned dependecies

* refined custom serialization

* most of state fetched

* fetching prev and genesis blocks

* minimal reproduction

* final touches

* typo

* fetching optimization

* minor PR fixes

* removed leftover scsript

* using cartridge repository for parser

* moved setup to the new method

* passing prover and veryfier to cli

* insuffiecient fee fix

* typo in cli

Co-authored-by: glihm <[email protected]>

* typo in cli

Co-authored-by: glihm <[email protected]>

* typo in the comment

Co-authored-by: glihm <[email protected]>

* removed unneeded dependency

Co-authored-by: glihm <[email protected]>

* changes after review

* formatting

* fix: minor formatting and skip empty blocks

* fix: ensure correct parsing of enums + fix args test

* dev: add podman to the dev container

* ci: test new container image with podman

* fix: disable DinD which is not supported for now by CI

* devcontainer: remove podman for now

---------

Co-authored-by: Mateusz Zając <[email protected]>
Co-authored-by: Mateusz Zając <[email protected]>
Co-authored-by: glihm <[email protected]>
  • Loading branch information
4 people authored Apr 1, 2024
1 parent b8ed6db commit ad58e43
Show file tree
Hide file tree
Showing 16 changed files with 766 additions and 29 deletions.
24 changes: 20 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ saya-core = { path = "crates/saya/core" }
saya-provider = { path = "crates/saya/provider" }

# sozo
sozo-signers = { path = "crates/sozo/signers" }
sozo-ops = { path = "crates/sozo/ops" }
sozo-signers = { path = "crates/sozo/signers" }

anyhow = "1.0.75"
anyhow = "1.0.80"
assert_matches = "1.5.0"
async-trait = "0.1.68"
base64 = "0.21.2"
Expand All @@ -123,10 +123,11 @@ cairo-lang-test-plugin = "=2.5.4"
cairo-lang-test-runner = "=2.5.4"
cairo-lang-test-utils = "=2.5.4"
cairo-lang-utils = "=2.5.4"
cairo-proof-parser = { git = "https://github.com/cartridge-gg/cairo-proof-parser.git", version = "0.1.2" }
cairo-vm = "0.9.2"
camino = { version = "1.1.2", features = [ "serde1" ] }
chrono = { version = "0.4.24", features = [ "serde" ] }
clap = { version = "4.2", features = [ "derive" ] }
clap = { version = "4.5", features = [ "derive" ] }
clap_complete = "4.3"
console = "0.15.7"
convert_case = "0.6.0"
Expand All @@ -150,7 +151,7 @@ salsa = "0.16.1"
scarb = { git = "https://github.com/software-mansion/scarb", tag = "v2.5.4" }
scarb-ui = { git = "https://github.com/software-mansion/scarb", tag = "v2.5.4" }
semver = "1.0.5"
serde = { version = "1.0.192", features = [ "derive" ] }
serde = { version = "1.0.197", features = [ "derive" ] }
serde_json = { version = "1.0", features = [ "arbitrary_precision" ] }
serde_with = "2.3.1"
similar-asserts = "1.5.0"
Expand Down
10 changes: 10 additions & 0 deletions bin/saya/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ use tracing_subscriber::{fmt, EnvFilter};
use url::Url;

use crate::args::data_availability::{DataAvailabilityChain, DataAvailabilityOptions};
use crate::args::proof::ProofOptions;

mod data_availability;
mod proof;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand Down Expand Up @@ -45,6 +47,10 @@ pub struct SayaArgs {
#[command(flatten)]
#[command(next_help_heading = "Data availability options")]
pub data_availability: DataAvailabilityOptions,

#[command(flatten)]
#[command(next_help_heading = "Choose the proof pipeline configuration")]
pub proof: ProofOptions,
}

impl SayaArgs {
Expand Down Expand Up @@ -109,6 +115,8 @@ impl TryFrom<SayaArgs> for SayaConfig {
katana_rpc: args.rpc_url,
start_block: args.start_block,
data_availability: da_config,
prover: args.proof.prover.into(),
verifier: args.proof.verifier.into(),
})
}
}
Expand Down Expand Up @@ -140,7 +148,9 @@ mod tests {
celestia_namespace: None,
},
},
proof: ProofOptions { prover: Default::default(), verifier: Default::default() },
};

let config: SayaConfig = args.try_into().unwrap();

assert_eq!(config.katana_rpc.as_str(), "http://localhost:5050/");
Expand Down
135 changes: 135 additions & 0 deletions bin/saya/src/args/proof.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//! Selecting prover and verifier.
use std::fmt::Display;
use std::str::FromStr;

use anyhow::Result;
use clap::builder::PossibleValue;
use clap::{Args, ValueEnum};
use saya_core::prover::ProverIdentifier;
use saya_core::verifier::VerifierIdentifier;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Prover {
Stone,
}

impl From<Prover> for ProverIdentifier {
fn from(p: Prover) -> Self {
match p {
Prover::Stone => ProverIdentifier::Stone,
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Verifier {
StoneLocal,
HerodotusStarknetSepolia,
}

impl From<Verifier> for VerifierIdentifier {
fn from(p: Verifier) -> Self {
match p {
Verifier::StoneLocal => VerifierIdentifier::StoneLocal,
Verifier::HerodotusStarknetSepolia => VerifierIdentifier::HerodotusStarknetSepolia,
}
}
}

#[derive(Debug, Args, Clone)]
pub struct ProofOptions {
#[arg(long)]
#[arg(help = "Prover to generated the proof from the provable program.")]
pub prover: Prover,

#[arg(long)]
#[arg(help = "Verifier on which the proof should be sent to.")]
pub verifier: Verifier,
}

// -- Prover.
impl Default for Prover {
fn default() -> Self {
Self::Stone
}
}

impl ValueEnum for Prover {
fn value_variants<'a>() -> &'a [Self] {
&[Self::Stone]
}

fn to_possible_value(&self) -> Option<PossibleValue> {
match self {
Self::Stone => Some(PossibleValue::new("stone").alias("Stone")),
}
}
}

impl FromStr for Prover {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self> {
match s {
"stone" | "Stone" => Ok(Self::Stone),
_ => Err(anyhow::anyhow!("unknown prover: {}", s)),
}
}
}

impl Display for Prover {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Prover::Stone => write!(f, "stone"),
}
}
}

// -- Verifier.
impl Default for Verifier {
fn default() -> Self {
Self::StoneLocal
}
}

impl ValueEnum for Verifier {
fn value_variants<'a>() -> &'a [Self] {
&[Self::StoneLocal, Self::HerodotusStarknetSepolia]
}

fn to_possible_value(&self) -> Option<PossibleValue> {
match self {
Self::StoneLocal => {
Some(PossibleValue::new("stone-local").alias("stone_local").alias("StoneLocal"))
}
Self::HerodotusStarknetSepolia => Some(
PossibleValue::new("herodotus_starknet_sepolia")
.alias("herodotus-starknet-sepolia")
.alias("HerodotusStarknetSepolia"),
),
}
}
}

impl FromStr for Verifier {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self> {
match s {
"stone-local" | "stone_local" | "StoneLocal" => Ok(Self::StoneLocal),
"herodotus-starknet-sepolia"
| "herodotus_starknet_sepolia"
| "HerodotusStarknetSepolia" => Ok(Self::HerodotusStarknetSepolia),
_ => Err(anyhow::anyhow!("unknown verifier: {}", s)),
}
}
}

impl Display for Verifier {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Verifier::StoneLocal => write!(f, "local-stone"),
Verifier::HerodotusStarknetSepolia => write!(f, "herodotus-starknet-sepolia"),
}
}
}
4 changes: 3 additions & 1 deletion bin/saya/src/args/test_saya_config_file.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"node_auth_token": "your_auth_token",
"namespace": "katana"
}
}
},
"prover": "Stone",
"verifier": "StoneLocal"
}
10 changes: 7 additions & 3 deletions crates/saya/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ saya-provider.workspace = true

anyhow.workspace = true
async-trait.workspace = true
convert_case.workspace = true
cairo-proof-parser.workspace = true
cairo-vm.workspace = true
convert_case.workspace = true
flate2.workspace = true
futures.workspace = true
lazy_static = "1.4.0"
lazy_static.workspace = true
parking_lot.workspace = true
rand = { version = "0.8.5", features = [ "small_rng" ] }
serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
starknet-types-core = { version = "0.0.9", default-features = false, features = [ "curve", "num-traits", "serde" ] }
starknet.workspace = true
starknet_api.workspace = true
thiserror.workspace = true
tokio.workspace = true
tracing.workspace = true
url.workspace = true
starknet-types-core = { version = "0.0.9", default-features = false, features = ["serde", "curve", "num-traits"] }

# TODO: use features for each possible DA.
celestia-rpc = "0.1.1"
celestia-types = "0.1.1"

cairo-felt = "0.9.1"
num-bigint = "0.4.4"
Loading

0 comments on commit ad58e43

Please sign in to comment.