cairo-proof-parser

Crates.iocairo-proof-parser
lib.rscairo-proof-parser
version0.3.0
sourcesrc
created_at2024-04-11 14:38:42.798797
updated_at2024-04-11 14:38:42.798797
descriptionParser that translates beetwen different cairo proof formats
homepage
repository
max_upload_size
id1205006
size73,312
Szymon Wojtulewicz (piniom)

documentation

README

Cairo Proof Parser

This lib crate is a parser written to translate beetwen different cairo proof formats. It exports a function:

pub fn parse(input: String) -> anyhow::Result<Exprs>

Input

The input to the parse function is a proof in a json string format. The proof is expected to be generated by the stone prover with the -generate_annotations flag. Currently only the recursive and starknet layouts are supported.

Output

The output is the AST wchich can be deserialized to a string using Exprs::to_string(&self) method. This can than be serialized to the arguments expected by the cairo verifier, and run using cairo args runner.

Example usage

An example usage:

use cairo_args_runner::{Arg, Felt252, VecFelt252};
use cairo_proof_parser::parse;

fn main() -> anyhow::Result<()> {
    // Read the stone prover input
    let input = std::fs::read_to_string("main_proof.json")?;

    // Parse the input as an AST
    let parsed = parse(input)?;
    
    // Parse the AST as cairo arguments
    let args: VecFelt252 = serde_json::from_str(
        &parsed.to_string()
    )?;

    // Run the cairo verifier with the aruments
    let result = cairo_args_runner::run(
        "cairo_verifier.sierra.json",
        "main",
        &[Arg::Array(args.to_vec())],
    )?;
    
    println!("{result:?}");
    Ok(())
}

Roadmap

In the future we might parse directly to cairo-args-runner::Args to skip one parsing step. For now the current approach is absolutely sufficent and gives most flexibility. There were also some bug fixes in the cairo-lang-runner crate enabling the cairo-args-runner to pass multiple arrays correctly.

Commit count: 0

cargo fmt