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

Poseidon hasher for channel #107

Merged
merged 52 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
1cde4ca
Change channel to poseidon
fmkra Feb 22, 2024
5f5c3e0
Fix public input and memory
fmkra Feb 22, 2024
559fe56
Change queries to match channel
fmkra Feb 22, 2024
7127ce1
Remove unnecessary try into
fmkra Feb 22, 2024
afe7034
Remove commented code and format
fmkra Feb 22, 2024
fcf0a74
tmp switch off benches
Okm165 Feb 23, 2024
c96056a
del unrel channel tests
Okm165 Feb 23, 2024
284ffd6
code refactor
Okm165 Feb 23, 2024
bd692d4
tests mocked data -> compiles&formats
Okm165 Feb 23, 2024
f4bb2fb
channel tests
Okm165 Feb 23, 2024
fefa946
Fix table commitment
fmkra Feb 26, 2024
0a9cf37
runner update
Okm165 Mar 4, 2024
8ca378e
fmt
Okm165 Mar 4, 2024
78c236c
autogenerated changes
Okm165 Mar 4, 2024
4e3ab24
composition changes
Okm165 Mar 4, 2024
f0d53d2
constants changes
Okm165 Mar 4, 2024
c7b0034
global vals changes
Okm165 Mar 4, 2024
6d68ffb
Merge branch 'feat/poseidon-channel' into feat/stone5_compatibility
Okm165 Mar 4, 2024
8ce1500
public input
Okm165 Mar 4, 2024
73d543b
autogenerated fmt
Okm165 Mar 4, 2024
daeb83e
queries fix
Okm165 Mar 4, 2024
715cf5e
vector commitment
Okm165 Mar 4, 2024
bb56c2d
traces
Okm165 Mar 4, 2024
fa9d048
fmt
Okm165 Mar 5, 2024
f06a2b2
Merge pull request #109 from HerodotusDev/feat/stone5_compatibility
Okm165 Mar 5, 2024
a65e853
FriConfig
Okm165 Mar 6, 2024
6c886de
Fri test data
Okm165 Mar 6, 2024
9fe074c
fri commit test fixed
Okm165 Mar 6, 2024
309d7bf
verify public input hash fix
Okm165 Mar 6, 2024
69cdb39
air tests
Okm165 Mar 6, 2024
5a0adb6
fri tests
Okm165 Mar 6, 2024
8547040
queries tests
Okm165 Mar 6, 2024
2629d32
commitment tests
Okm165 Mar 6, 2024
f6079d3
stark tests
Okm165 Mar 6, 2024
03c3358
security bits externalize
Okm165 Mar 6, 2024
886fce0
hasher refactor
Okm165 Mar 6, 2024
e6613fe
blake2s fri tests
Okm165 Mar 7, 2024
06b1c71
blake2s stark tests
Okm165 Mar 7, 2024
2dcfe93
test autogenerated
Okm165 Mar 7, 2024
f0239bb
blake2s oods test
Okm165 Mar 7, 2024
d1ab08c
change to poseidon-keccak
Okm165 Mar 7, 2024
578776d
change to poseidon-blake2s
Okm165 Mar 7, 2024
7d561c2
fmt
Okm165 Mar 7, 2024
1b64e4b
change to poseidon-keccak
Okm165 Mar 7, 2024
11dbc50
refactor
Okm165 Mar 7, 2024
85556b5
Merge pull request #110 from HerodotusDev/fix/stone5_test
Okm165 Mar 7, 2024
2e9c5f1
Merge branch 'main' into feat/poseidon-channel
Okm165 Mar 7, 2024
564e666
scarb 2.6.0 & runner update
Okm165 Mar 7, 2024
ca0ff95
fmt
Okm165 Mar 7, 2024
36761c0
readme benches
Okm165 Mar 7, 2024
55ed773
readme fix
Okm165 Mar 7, 2024
306a086
update prover examples configs & example proof
Okm165 Mar 15, 2024
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
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scarb 2.4.3
scarb 2.6.0
25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ edition = "2021"
version = "0.1.0"

[workspace.dependencies]
anyhow = "1.0.79"
cairo-args-runner = "1.0.1"
anyhow = "1"
cairo-felt = "0.9"
cairo-lang-runner = "2.5.0"
cairo-lang-sierra = "2.5.0"
cairo-lang-utils = "2.5.0"
cairo-proof-parser = { git = "https://github.com/cartridge-gg/cairo-proof-parser", tag = "v0.1.0" }
cairo-vm = "0.9.2"
clap = { version = "4.4.18", features = ["derive"] }
cairo-lang-casm = "=2.6.0"
cairo-lang-runner = "=2.6.0"
cairo-lang-sierra = "=2.6.0"
cairo-lang-utils = "=2.6.0"
cairo-proof-parser = { git = "https://github.com/Okm165/cairo-proof-parser" }
cairo-vm = "=0.9.2"
clap = { version = "4.5.2", features = ["derive"] }
itertools = "0.12.0"
num-bigint = "0.4"
serde = { version = "1.0.196", features = ["derive"] }
serde_json = "1.0.113"
thiserror = "1.0"
num-bigint = "0.4.4"
runner = { path = "runner" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
thiserror = "1.0"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ cpu_air_prover \

You can `verify` this the proof `locally` or on the `Starknet Cairo verifier` contract by specifying the path `examples/proofs/fibonacci_proof.json` to the newly generated proof.

## Benchmarking

In order to launch benchmarking just run this:

```bash
cargo run --release --bin benches -- target/dev/cairo_verifier.sierra.json
```

## Changing the Hasher

By default, the verifier uses Pedersen for verifier-friendly layers and Keccak for unfriendly layers. To change the hasher for unfriendly layers, use the provided Python script:
Expand Down
47 changes: 13 additions & 34 deletions benches/src/bench.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
use cairo_lang_runner::{
build_hints_dict, CairoHintProcessor, RunResult, SierraCasmRunner, StarknetState,
ProfilingInfoCollectionConfig, RunResultStarknet, RunnerError, SierraCasmRunner,
};
use cairo_lang_sierra::program::Program;
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
use cairo_vm::vm::runners::cairo_runner::RunResources;
use itertools::chain;

pub fn bench(sierra_program: Program, function: &str) -> anyhow::Result<RunResult> {
let sierra_runner = SierraCasmRunner::new(
sierra_program,
pub fn bench(sierra_program: Program, function: &str) -> Result<RunResultStarknet, RunnerError> {
let runner = SierraCasmRunner::new(
sierra_program.clone(),
Some(Default::default()),
OrderedHashMap::default(),
true,
)?;

let func = sierra_runner.find_function(function)?;
let initial_gas = sierra_runner.get_initial_available_gas(func, Some(usize::MAX))?;
let (entry_code, builtins) = sierra_runner.create_entry_code(func, &[], initial_gas)?;
let footer = SierraCasmRunner::create_code_footer();
let (hints_dict, string_to_hint) = build_hints_dict(chain!(
entry_code.iter(),
sierra_runner.get_casm_program().instructions.iter()
));
let assembled_program = sierra_runner
.get_casm_program()
.assemble_ex(&entry_code, &footer);

let mut hint_processor = CairoHintProcessor {
runner: Some(&sierra_runner),
starknet_state: StarknetState::default(),
string_to_hint,
run_resources: RunResources::default(),
};

Ok(sierra_runner.run_function(
Some(ProfilingInfoCollectionConfig::default()),
)
.unwrap();
let func = runner.find_function(function).unwrap();
runner.run_function_with_starknet_context(
func,
&mut hint_processor,
hints_dict,
assembled_program.bytecode.iter(),
builtins,
)?)
&[],
Some(u32::MAX as usize),
Default::default(),
)
}
7 changes: 1 addition & 6 deletions benches/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@ fn main() -> anyhow::Result<()> {
println!("Function: {f_name}");
// println!("---------------------------------");
// println!("Gas Used : {}", result.gas_counter.unwrap());
println!("Execution Steps : {}", result.memory.len());
println!("Number of steps : {}", result.memory.len());
// println!("Return Value : {:#?}", result.value);
println!("---------------------------------\n");

// let profiling_processor = ProfilingInfoProcessor::new(sierra_program.program);
// let processed_profiling_info = profiling_processor.process(&profiling_info.unwrap());

// println!("profiling: {}", processed_profiling_info);
});

Ok(())
Expand Down
9 changes: 5 additions & 4 deletions examples/starknet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ edition = "2021"

[dependencies]
anyhow.workspace = true
cairo-args-runner.workspace = true
clap.workspace = true
cairo-proof-parser.workspace = true
serde.workspace = true
serde_json.workspace = true
clap.workspace = true
itertools.workspace = true
runner.workspace = true
serde_json.workspace = true
serde.workspace = true
20 changes: 17 additions & 3 deletions examples/starknet/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
use cairo_args_runner::VecFelt252;
use cairo_proof_parser::parse;
use itertools::{chain, Itertools};
use runner::VecFelt252;
use std::io::{stdin, Read};

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

let exprs = parse(input)?.to_string();
let proof: VecFelt252 = serde_json::from_str(&exprs).unwrap();
let parsed = parse(input)?;

let config: VecFelt252 = serde_json::from_str(&parsed.config.to_string()).unwrap();
let public_input: VecFelt252 = serde_json::from_str(&parsed.public_input.to_string()).unwrap();
let unsent_commitment: VecFelt252 =
serde_json::from_str(&parsed.unsent_commitment.to_string()).unwrap();
let witness: VecFelt252 = serde_json::from_str(&parsed.witness.to_string()).unwrap();

let proof = chain!(
config.to_vec(),
public_input.to_vec(),
unsent_commitment.to_vec(),
witness.to_vec()
)
.collect_vec();

let proof_string = proof
.iter()
Expand Down
14 changes: 11 additions & 3 deletions runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ edition.workspace = true

[dependencies]
anyhow.workspace = true
cairo-args-runner.workspace = true
clap.workspace = true
cairo-felt.workspace = true
cairo-lang-casm.workspace = true
cairo-lang-runner.workspace = true
cairo-lang-sierra.workspace = true
cairo-lang-utils.workspace = true
cairo-proof-parser.workspace = true
serde.workspace = true
cairo-vm.workspace = true
clap.workspace = true
itertools.workspace = true
num-bigint.workspace = true
serde_json.workspace = true
serde.workspace = true
thiserror.workspace = true
2 changes: 2 additions & 0 deletions runner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod vec252;
pub use vec252::VecFelt252;
76 changes: 59 additions & 17 deletions runner/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
use clap::Parser;
use std::io::{stdin, Read};
mod vec252;
use crate::vec252::VecFelt252;

use cairo_lang_runner::{Arg, ProfilingInfoCollectionConfig, SierraCasmRunner};
use cairo_lang_sierra::program::VersionedProgram;
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
use cairo_proof_parser::parse;
use cairo_args_runner::{Arg, Felt252, VecFelt252};
use clap::Parser;
use itertools::{chain, Itertools};
use std::{
fs,
io::{stdin, Read},
};

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
Expand All @@ -11,23 +20,56 @@ struct Cli {
}

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

let result = run(exprs, args.target)?;
println!("{result:?}");
let target = cli.target;
let function = "main";

Ok(())
}
let config: VecFelt252 = serde_json::from_str(&parsed.config.to_string()).unwrap();
let public_input: VecFelt252 = serde_json::from_str(&parsed.public_input.to_string()).unwrap();
let unsent_commitment: VecFelt252 =
serde_json::from_str(&parsed.unsent_commitment.to_string()).unwrap();
let witness: VecFelt252 = serde_json::from_str(&parsed.witness.to_string()).unwrap();

fn run(parsed: String, target: String) -> anyhow::Result<Vec<Felt252>> {
let function = "main";
let args: VecFelt252 = serde_json::from_str(&parsed).unwrap();
Ok(cairo_args_runner::run(
&target,
function,
&[Arg::Array(args.to_vec())],
)?)
let proof = chain!(
config.to_vec(),
public_input.to_vec(),
unsent_commitment.to_vec(),
witness.to_vec()
)
.collect_vec();

println!("proof size: {} felts", proof.len());

let sierra_program =
serde_json::from_str::<VersionedProgram>(&fs::read_to_string(target)?)?.into_v1()?;

let runner = SierraCasmRunner::new(
sierra_program.program.clone(),
Some(Default::default()),
OrderedHashMap::default(),
Some(ProfilingInfoCollectionConfig::default()),
)
.unwrap();
let func = runner.find_function(function).unwrap();
let result = runner
.run_function_with_starknet_context(
func,
&[Arg::Array(proof.to_vec())],
Some(u32::MAX as usize),
Default::default(),
)
.unwrap();
// let profiling_processor =
// ProfilingInfoProcessor::new(None, sierra_program.program, UnorderedHashMap::default());
// let processed_profiling_info = profiling_processor.process(&result.profiling_info.unwrap());

println!("gas_counter: {}", result.gas_counter.unwrap());
println!("n_steps: {}", result.memory.len());
println!("return: {:#?}", result.value);

Ok(())
}
Loading
Loading