From 1b615cac4fcd7cd8aea1734affce31635211c341 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Sat, 14 Sep 2024 11:19:50 +0200 Subject: [PATCH 1/5] test_fixtures & air fixtures --- crates/air/Cargo.toml | 3 ++- crates/air/src/layout/mod.rs | 7 +++++++ crates/air/src/lib.rs | 3 ++- crates/fri/Cargo.toml | 1 + crates/fri/src/lib.rs | 3 ++- crates/pow/Cargo.toml | 1 + crates/pow/src/lib.rs | 3 ++- crates/stark/Cargo.toml | 10 ++++++++++ crates/stark/src/lib.rs | 3 ++- 9 files changed, 29 insertions(+), 5 deletions(-) diff --git a/crates/air/Cargo.toml b/crates/air/Cargo.toml index 6ecd47c..d0b91a5 100644 --- a/crates/air/Cargo.toml +++ b/crates/air/Cargo.toml @@ -29,6 +29,7 @@ keccak_160_lsb = ["swiftness_commitment/keccak_160_lsb"] keccak_248_lsb = ["swiftness_commitment/keccak_248_lsb"] blake2s_160_lsb = ["swiftness_commitment/blake2s_160_lsb"] blake2s_248_lsb = ["swiftness_commitment/blake2s_248_lsb"] +test_fixtures = [] [dependencies] num-bigint.workspace = true @@ -41,4 +42,4 @@ thiserror = { optional = true, workspace = true } thiserror-no-std.workspace = true swiftness_commitment.workspace = true -swiftness_transcript.workspace = true \ No newline at end of file +swiftness_transcript.workspace = true diff --git a/crates/air/src/layout/mod.rs b/crates/air/src/layout/mod.rs index 3fb8aaf..b5aa1d8 100644 --- a/crates/air/src/layout/mod.rs +++ b/crates/air/src/layout/mod.rs @@ -5,12 +5,19 @@ use starknet_crypto::Felt; use starknet_types_core::felt::FeltIsZeroError; use swiftness_transcript::transcript::Transcript; +#[cfg(feature = "dex")] pub mod dex; +#[cfg(feature = "dynamic")] pub mod dynamic; +#[cfg(feature = "recursive")] pub mod recursive; +#[cfg(feature = "recursive_with_poseidon")] pub mod recursive_with_poseidon; +#[cfg(feature = "small")] pub mod small; +#[cfg(feature = "starknet")] pub mod starknet; +#[cfg(feature = "starknet_with_keccak")] pub mod starknet_with_keccak; // StarkCurve diff --git a/crates/air/src/lib.rs b/crates/air/src/lib.rs index 4698f76..03ed9e5 100644 --- a/crates/air/src/lib.rs +++ b/crates/air/src/lib.rs @@ -9,12 +9,13 @@ pub mod consts; pub mod diluted; pub mod domains; pub mod dynamic; -pub mod fixtures; pub mod layout; pub mod periodic_columns; pub mod public_memory; pub mod trace; pub mod types; +#[cfg(feature = "test_fixtures")] +pub mod fixtures; #[cfg(test)] pub mod tests; diff --git a/crates/fri/Cargo.toml b/crates/fri/Cargo.toml index 0846515..0879684 100644 --- a/crates/fri/Cargo.toml +++ b/crates/fri/Cargo.toml @@ -20,6 +20,7 @@ keccak_160_lsb = ["swiftness_commitment/keccak_160_lsb"] keccak_248_lsb = ["swiftness_commitment/keccak_248_lsb"] blake2s_160_lsb = ["swiftness_commitment/blake2s_160_lsb"] blake2s_248_lsb = ["swiftness_commitment/blake2s_248_lsb"] +test_fixtures = [] [dependencies] num-bigint.workspace = true diff --git a/crates/fri/src/lib.rs b/crates/fri/src/lib.rs index f88b5b1..bc7d4ae 100644 --- a/crates/fri/src/lib.rs +++ b/crates/fri/src/lib.rs @@ -7,7 +7,6 @@ extern crate std; pub mod config; pub mod first_layer; -pub mod fixtures; pub mod formula; pub mod fri; pub mod group; @@ -15,5 +14,7 @@ pub mod last_layer; pub mod layer; pub mod types; +#[cfg(feature = "test_fixtures")] +pub mod fixtures; #[cfg(test)] pub mod tests; diff --git a/crates/pow/Cargo.toml b/crates/pow/Cargo.toml index 20838a4..75e573e 100644 --- a/crates/pow/Cargo.toml +++ b/crates/pow/Cargo.toml @@ -16,6 +16,7 @@ std = [ ] keccak = [] blake2s = [] +test_fixtures = [] [dependencies] blake2.workspace = true diff --git a/crates/pow/src/lib.rs b/crates/pow/src/lib.rs index 566f79e..0fc50ef 100644 --- a/crates/pow/src/lib.rs +++ b/crates/pow/src/lib.rs @@ -6,8 +6,9 @@ extern crate alloc; extern crate std; pub mod config; -pub mod fixtures; pub mod pow; +#[cfg(feature = "test_fixtures")] +pub mod fixtures; #[cfg(test)] pub mod tests; diff --git a/crates/stark/Cargo.toml b/crates/stark/Cargo.toml index c01c673..4ed54cd 100644 --- a/crates/stark/Cargo.toml +++ b/crates/stark/Cargo.toml @@ -47,6 +47,11 @@ blake2s_248_lsb = [ "swiftness_pow/blake2s", "swiftness_commitment/blake2s_248_lsb" ] +test_fixtures = [ + "swiftness_air/test_fixtures", + "swiftness_fri/test_fixtures", + "swiftness_pow/test_fixtures", +] [dependencies] serde_with.workspace = true @@ -61,3 +66,8 @@ swiftness_commitment.workspace = true swiftness_fri.workspace = true swiftness_pow.workspace = true swiftness_transcript.workspace = true + +[dev-dependencies] +swiftness_air = { workspace = true, features = ["test_fixtures"] } +swiftness_fri = { workspace = true, features = ["test_fixtures"] } +swiftness_pow = { workspace = true, features = ["test_fixtures"] } \ No newline at end of file diff --git a/crates/stark/src/lib.rs b/crates/stark/src/lib.rs index 4c754b1..1adcaba 100644 --- a/crates/stark/src/lib.rs +++ b/crates/stark/src/lib.rs @@ -24,11 +24,12 @@ import_module_if_layout!(commit); import_module_if_layout!(oods); import_module_if_layout!(stark); import_module_if_layout!(verify); -import_module_if_layout!(fixtures); pub mod config; pub mod queries; pub mod types; +#[cfg(test)] +pub mod fixtures; #[cfg(test)] pub mod tests; From 19034f39f522356ac00adeff80416625b228f7d9 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Sat, 14 Sep 2024 11:43:47 +0200 Subject: [PATCH 2/5] version bump v0.1.1 --- Cargo.lock | 12 ++++++------ Cargo.toml | 14 +++++++------- README.md | 2 +- cli/Cargo.lock | 16 ++++++++-------- cli/Cargo.toml | 14 +++++++------- examples/no_std_build/Cargo.toml | 2 +- proof_parser/Cargo.lock | 2 +- proof_parser/Cargo.toml | 2 +- wasm_bindings/Cargo.lock | 18 +++++++++--------- wasm_bindings/Cargo.toml | 10 +++++----- wasm_bindings/README.md | 2 +- 11 files changed, 47 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 21152b9..4e46a7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -534,7 +534,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "swiftness_air" -version = "0.1.0" +version = "0.1.1" dependencies = [ "num-bigint", "serde", @@ -550,7 +550,7 @@ dependencies = [ [[package]] name = "swiftness_commitment" -version = "0.1.0" +version = "0.1.1" dependencies = [ "blake2", "num-bigint", @@ -567,7 +567,7 @@ dependencies = [ [[package]] name = "swiftness_fri" -version = "0.1.0" +version = "0.1.1" dependencies = [ "num-bigint", "serde", @@ -583,7 +583,7 @@ dependencies = [ [[package]] name = "swiftness_pow" -version = "0.1.0" +version = "0.1.1" dependencies = [ "blake2", "serde", @@ -597,7 +597,7 @@ dependencies = [ [[package]] name = "swiftness_stark" -version = "0.1.0" +version = "0.1.1" dependencies = [ "serde", "serde_with 3.9.0", @@ -614,7 +614,7 @@ dependencies = [ [[package]] name = "swiftness_transcript" -version = "0.1.0" +version = "0.1.1" dependencies = [ "starknet-crypto", ] diff --git a/Cargo.toml b/Cargo.toml index 66cb0f5..7e63ba8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ edition = "2021" license-file = "LICENSE" readme = "README.md" repository = "https://github.com/iosis-tech/swiftness" -version = "0.1.0" +version = "0.1.1" [workspace.dependencies] blake2 = { version = "0.10.6", default-features = false } @@ -39,9 +39,9 @@ starknet-types-core = { version = "0.1.5", default-features = false } thiserror = "1.0.61" thiserror-no-std = "2.0.2" -swiftness_air = { path = "crates/air", default-features = false, version = "0.1.0" } -swiftness_commitment = { path = "crates/commitment", default-features = false, version = "0.1.0" } -swiftness_fri = { path = "crates/fri", default-features = false, version = "0.1.0" } -swiftness_pow = { path = "crates/pow", default-features = false, version = "0.1.0" } -swiftness_stark = { path = "crates/stark", default-features = false, version = "0.1.0" } -swiftness_transcript = { path = "crates/transcript", default-features = false, version = "0.1.0" } +swiftness_air = { path = "crates/air", default-features = false, version = "0.1.1" } +swiftness_commitment = { path = "crates/commitment", default-features = false, version = "0.1.1" } +swiftness_fri = { path = "crates/fri", default-features = false, version = "0.1.1" } +swiftness_pow = { path = "crates/pow", default-features = false, version = "0.1.1" } +swiftness_stark = { path = "crates/stark", default-features = false, version = "0.1.1" } +swiftness_transcript = { path = "crates/transcript", default-features = false, version = "0.1.1" } diff --git a/README.md b/README.md index b7eb874..bca4180 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@
-![Version](https://img.shields.io/badge/v0.1.0-green?style=flat-square&logo=git&logoColor=white&label=version) +![Version](https://img.shields.io/badge/v0.1.1-green?style=flat-square&logo=git&logoColor=white&label=version) ![Continuous Integration](https://img.shields.io/github/actions/workflow/status/iosis-tech/swiftness/ci.yml?style=flat-square&logo=githubactions&logoColor=white&label=Continuous%20Integration) [![Crates.io Version](https://img.shields.io/crates/v/swiftness?style=flat-square&logo=lootcrate)](https://crates.io/crates/swiftness) diff --git a/cli/Cargo.lock b/cli/Cargo.lock index 0eb573b..8208c01 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -686,7 +686,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "swiftness" -version = "0.1.0" +version = "0.1.1" dependencies = [ "clap", "swiftness_air", @@ -699,7 +699,7 @@ dependencies = [ [[package]] name = "swiftness_air" -version = "0.1.0" +version = "0.1.1" dependencies = [ "num-bigint", "serde", @@ -715,7 +715,7 @@ dependencies = [ [[package]] name = "swiftness_commitment" -version = "0.1.0" +version = "0.1.1" dependencies = [ "blake2", "num-bigint", @@ -732,7 +732,7 @@ dependencies = [ [[package]] name = "swiftness_fri" -version = "0.1.0" +version = "0.1.1" dependencies = [ "num-bigint", "serde", @@ -748,7 +748,7 @@ dependencies = [ [[package]] name = "swiftness_pow" -version = "0.1.0" +version = "0.1.1" dependencies = [ "blake2", "serde", @@ -762,7 +762,7 @@ dependencies = [ [[package]] name = "swiftness_proof_parser" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "clap", @@ -777,7 +777,7 @@ dependencies = [ [[package]] name = "swiftness_stark" -version = "0.1.0" +version = "0.1.1" dependencies = [ "serde", "serde_with 3.9.0", @@ -794,7 +794,7 @@ dependencies = [ [[package]] name = "swiftness_transcript" -version = "0.1.0" +version = "0.1.1" dependencies = [ "starknet-crypto", ] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index f8e5db3..7774d81 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -5,27 +5,27 @@ edition = "2021" license-file = "LICENSE" readme = "../README.md" repository = "https://github.com/iosis-tech/swiftness" -version = "0.1.0" +version = "0.1.1" [dependencies] clap = { version = "4.4.4", features = ["derive"] } swiftness_air = { path = "../crates/air", default-features = false, features = [ "std", -], version = "0.1.0" } +], version = "0.1.1" } swiftness_commitment = { path = "../crates/commitment", default-features = false, features = [ "std", -], version = "0.1.0" } +], version = "0.1.1" } swiftness_fri = { path = "../crates/fri", default-features = false, features = [ "std", -], version = "0.1.0" } +], version = "0.1.1" } swiftness_pow = { path = "../crates/pow", default-features = false, features = [ "std", -], version = "0.1.0" } +], version = "0.1.1" } swiftness_stark = { path = "../crates/stark", default-features = false, features = [ "std", -], version = "0.1.0" } -swiftness_proof_parser = { path = "../proof_parser", version = "0.1.0" } +], version = "0.1.1" } +swiftness_proof_parser = { path = "../proof_parser", version = "0.1.1" } [features] default = ["recursive", "keccak_160_lsb", "stone5"] diff --git a/examples/no_std_build/Cargo.toml b/examples/no_std_build/Cargo.toml index bf17569..70e175d 100644 --- a/examples/no_std_build/Cargo.toml +++ b/examples/no_std_build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "no_std_build" -version = "0.1.0" +version = "0.1.1" edition = "2021" [dependencies] diff --git a/proof_parser/Cargo.lock b/proof_parser/Cargo.lock index 9e824e5..9cef2c2 100644 --- a/proof_parser/Cargo.lock +++ b/proof_parser/Cargo.lock @@ -473,7 +473,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "swiftness_proof_parser" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "clap", diff --git a/proof_parser/Cargo.toml b/proof_parser/Cargo.toml index 607a4a5..f36753a 100644 --- a/proof_parser/Cargo.toml +++ b/proof_parser/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license-file = "LICENSE" readme = "README.md" repository = "https://github.com/iosis-tech/swiftness" -version = "0.1.0" +version = "0.1.1" [dependencies] anyhow = "1.0.80" diff --git a/wasm_bindings/Cargo.lock b/wasm_bindings/Cargo.lock index 6f78de9..758da5d 100644 --- a/wasm_bindings/Cargo.lock +++ b/wasm_bindings/Cargo.lock @@ -726,7 +726,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "swiftness" -version = "0.1.0" +version = "0.1.1" dependencies = [ "clap", "swiftness_air", @@ -739,7 +739,7 @@ dependencies = [ [[package]] name = "swiftness_air" -version = "0.1.0" +version = "0.1.1" dependencies = [ "num-bigint", "serde", @@ -755,7 +755,7 @@ dependencies = [ [[package]] name = "swiftness_commitment" -version = "0.1.0" +version = "0.1.1" dependencies = [ "blake2", "num-bigint", @@ -772,7 +772,7 @@ dependencies = [ [[package]] name = "swiftness_fri" -version = "0.1.0" +version = "0.1.1" dependencies = [ "num-bigint", "serde", @@ -788,7 +788,7 @@ dependencies = [ [[package]] name = "swiftness_pow" -version = "0.1.0" +version = "0.1.1" dependencies = [ "blake2", "serde", @@ -802,7 +802,7 @@ dependencies = [ [[package]] name = "swiftness_proof_parser" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "clap", @@ -817,7 +817,7 @@ dependencies = [ [[package]] name = "swiftness_stark" -version = "0.1.0" +version = "0.1.1" dependencies = [ "serde", "serde_with 3.9.0", @@ -834,14 +834,14 @@ dependencies = [ [[package]] name = "swiftness_transcript" -version = "0.1.0" +version = "0.1.1" dependencies = [ "starknet-crypto", ] [[package]] name = "swiftness_wasm" -version = "0.1.0" +version = "0.1.1" dependencies = [ "getrandom", "serde_json", diff --git a/wasm_bindings/Cargo.toml b/wasm_bindings/Cargo.toml index 97535fa..d27dc7e 100644 --- a/wasm_bindings/Cargo.toml +++ b/wasm_bindings/Cargo.toml @@ -5,20 +5,20 @@ edition = "2021" license-file = "LICENSE" readme = "README.md" repository = "https://github.com/iosis-tech/swiftness" -version = "0.1.0" +version = "0.1.1" [dependencies] serde_json = "1.0.114" wasm-bindgen = "0.2" -swiftness = { path = "../cli", default-features = false, version = "0.1.0" } +swiftness = { path = "../cli", default-features = false, version = "0.1.1" } swiftness_air = { path = "../crates/air", default-features = false, features = [ "std", -], version = "0.1.0" } +], version = "0.1.1" } swiftness_stark = { path = "../crates/stark", default-features = false, features = [ "std", -], version = "0.1.0" } -swiftness_proof_parser = { path = "../proof_parser", version = "0.1.0" } +], version = "0.1.1" } +swiftness_proof_parser = { path = "../proof_parser", version = "0.1.1" } [lib] crate-type = ["cdylib", "rlib"] diff --git a/wasm_bindings/README.md b/wasm_bindings/README.md index 4e4ff5c..41e8adb 100644 --- a/wasm_bindings/README.md +++ b/wasm_bindings/README.md @@ -2,7 +2,7 @@
-![Version](https://img.shields.io/badge/v0.1.0-green?style=flat-square&logo=git&logoColor=white&label=version) +![Version](https://img.shields.io/badge/v0.1.1-green?style=flat-square&logo=git&logoColor=white&label=version) ![Continuous Integration](https://img.shields.io/github/actions/workflow/status/iosis-tech/swiftness/ci.yml?style=flat-square&logo=githubactions&logoColor=white&label=Continuous%20Integration) [![Crates.io Version](https://img.shields.io/crates/v/swiftness?style=flat-square&logo=lootcrate)](https://crates.io/crates/swiftness) From b78639326e85c8d629c3cdeed4b9eeca29d717dd Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Sat, 14 Sep 2024 11:46:59 +0200 Subject: [PATCH 3/5] test_fixtures config fix --- crates/air/src/lib.rs | 2 +- crates/fri/src/lib.rs | 2 +- crates/pow/src/lib.rs | 2 +- crates/stark/src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/air/src/lib.rs b/crates/air/src/lib.rs index 03ed9e5..e20db92 100644 --- a/crates/air/src/lib.rs +++ b/crates/air/src/lib.rs @@ -15,7 +15,7 @@ pub mod public_memory; pub mod trace; pub mod types; -#[cfg(feature = "test_fixtures")] +#[cfg(any(test, feature = "test_fixtures"))] pub mod fixtures; #[cfg(test)] pub mod tests; diff --git a/crates/fri/src/lib.rs b/crates/fri/src/lib.rs index bc7d4ae..d25b7d1 100644 --- a/crates/fri/src/lib.rs +++ b/crates/fri/src/lib.rs @@ -14,7 +14,7 @@ pub mod last_layer; pub mod layer; pub mod types; -#[cfg(feature = "test_fixtures")] +#[cfg(any(test, feature = "test_fixtures"))] pub mod fixtures; #[cfg(test)] pub mod tests; diff --git a/crates/pow/src/lib.rs b/crates/pow/src/lib.rs index 0fc50ef..a45ab34 100644 --- a/crates/pow/src/lib.rs +++ b/crates/pow/src/lib.rs @@ -8,7 +8,7 @@ extern crate std; pub mod config; pub mod pow; -#[cfg(feature = "test_fixtures")] +#[cfg(any(test, feature = "test_fixtures"))] pub mod fixtures; #[cfg(test)] pub mod tests; diff --git a/crates/stark/src/lib.rs b/crates/stark/src/lib.rs index 1adcaba..75eea7a 100644 --- a/crates/stark/src/lib.rs +++ b/crates/stark/src/lib.rs @@ -29,7 +29,7 @@ pub mod config; pub mod queries; pub mod types; -#[cfg(test)] +#[cfg(any(test, feature = "test_fixtures"))] pub mod fixtures; #[cfg(test)] pub mod tests; From f87a6dda4926664c5e6988a53c55fe8f8f1c4a30 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Sat, 14 Sep 2024 21:41:46 +0200 Subject: [PATCH 4/5] stone proof serialize --- proof_parser/src/lib.rs | 21 ++++++++------ proof_parser/src/stark_proof.rs | 49 +++++++++++++++++---------------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/proof_parser/src/lib.rs b/proof_parser/src/lib.rs index 1c15424..bd82590 100644 --- a/proof_parser/src/lib.rs +++ b/proof_parser/src/lib.rs @@ -16,51 +16,54 @@ mod tests { #[test] fn test_parse_dex() { - let input = include_str!("../../examples/proofs/dex/cairo0_example_proof.json"); + let input = include_str!("../../examples/proofs/dex/cairo0_stone5_example_proof.json"); let proof_json = serde_json::from_str::(input).unwrap(); stark_proof::StarkProof::try_from(proof_json).unwrap(); } #[test] fn test_parse_dynamic() { - let input = include_str!("../../examples/proofs/dynamic/cairo0_example_proof.json"); + let input = include_str!("../../examples/proofs/dynamic/cairo0_stone6_example_proof.json"); let proof_json = serde_json::from_str::(input).unwrap(); stark_proof::StarkProof::try_from(proof_json).unwrap(); } #[test] fn test_parse_recursive() { - let input = include_str!("../../examples/proofs/recursive/cairo0_example_proof.json"); + let input = + include_str!("../../examples/proofs/recursive/cairo0_stone5_example_proof.json"); let proof_json = serde_json::from_str::(input).unwrap(); stark_proof::StarkProof::try_from(proof_json).unwrap(); } #[test] fn test_parse_recursive_with_poseidon() { - let input = - include_str!("../../examples/proofs/recursive_with_poseidon/cairo0_example_proof.json"); + let input = include_str!( + "../../examples/proofs/recursive_with_poseidon/cairo0_stone5_example_proof.json" + ); let proof_json = serde_json::from_str::(input).unwrap(); stark_proof::StarkProof::try_from(proof_json).unwrap(); } #[test] fn test_parse_small() { - let input = include_str!("../../examples/proofs/small/cairo0_example_proof.json"); + let input = include_str!("../../examples/proofs/small/cairo0_stone5_example_proof.json"); let proof_json = serde_json::from_str::(input).unwrap(); stark_proof::StarkProof::try_from(proof_json).unwrap(); } #[test] fn test_parse_starknet() { - let input = include_str!("../../examples/proofs/starknet/cairo0_example_proof.json"); + let input = include_str!("../../examples/proofs/starknet/cairo0_stone5_example_proof.json"); let proof_json = serde_json::from_str::(input).unwrap(); stark_proof::StarkProof::try_from(proof_json).unwrap(); } #[test] fn test_parse_starknet_with_keccak() { - let input = - include_str!("../../examples/proofs/starknet_with_keccak/cairo0_example_proof.json"); + let input = include_str!( + "../../examples/proofs/starknet_with_keccak/cairo0_stone5_example_proof.json" + ); let proof_json = serde_json::from_str::(input).unwrap(); stark_proof::StarkProof::try_from(proof_json).unwrap(); } diff --git a/proof_parser/src/stark_proof.rs b/proof_parser/src/stark_proof.rs index f8a93af..1174d2c 100644 --- a/proof_parser/src/stark_proof.rs +++ b/proof_parser/src/stark_proof.rs @@ -1,14 +1,15 @@ use num_bigint::BigUint; +use serde::Serialize; use std::collections::BTreeMap; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct StarkProof { pub config: StarkConfig, pub public_input: PublicInput, pub unsent_commitment: StarkUnsentCommitment, pub witness: StarkWitness, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct StarkConfig { pub traces: TracesConfig, pub composition: TableCommitmentConfig, @@ -19,22 +20,22 @@ pub struct StarkConfig { pub log_n_cosets: u32, pub n_verifier_friendly_commitment_layers: u32, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct TracesConfig { pub original: TableCommitmentConfig, pub interaction: TableCommitmentConfig, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct TableCommitmentConfig { pub n_columns: u32, pub vector: VectorCommitmentConfig, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct VectorCommitmentConfig { pub height: u32, pub n_verifier_friendly_commitment_layers: u32, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct FriConfig { pub log_input_size: u32, pub n_layers: u32, @@ -42,12 +43,12 @@ pub struct FriConfig { pub fri_step_sizes: Vec, pub log_last_layer_degree_bound: u32, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct ProofOfWorkConfig { pub n_bits: u32, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct StarkUnsentCommitment { pub traces: TracesUnsentCommitment, pub composition: BigUint, @@ -56,24 +57,24 @@ pub struct StarkUnsentCommitment { pub proof_of_work: ProofOfWorkUnsentCommitment, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct TracesUnsentCommitment { pub original: BigUint, pub interaction: BigUint, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct FriUnsentCommitment { pub inner_layers: Vec, pub last_layer_coefficients: Vec, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct ProofOfWorkUnsentCommitment { pub nonce: BigUint, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct StarkWitness { pub traces_decommitment: TracesDecommitment, pub traces_witness: TracesWitness, @@ -82,59 +83,59 @@ pub struct StarkWitness { pub fri_witness: FriWitness, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct TracesDecommitment { pub original: TableDecommitment, pub interaction: TableDecommitment, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct TableDecommitment { pub n_values: usize, pub values: Vec, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct TracesWitness { pub original: TableCommitmentWitness, pub interaction: TableCommitmentWitness, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct TableCommitmentWitness { pub vector: VectorCommitmentWitness, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct VectorCommitmentWitness { pub n_authentications: usize, pub authentications: Vec, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct TableCommitmentWitnessFlat { pub vector: VectorCommitmentWitnessFlat, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct VectorCommitmentWitnessFlat { pub n_authentications: usize, pub authentications: Vec, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct FriWitness { pub layers: Vec, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct FriLayerWitness { pub n_leaves: usize, pub leaves: Vec, pub table_witness: TableCommitmentWitnessFlat, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct PublicInput { pub log_n_steps: u32, pub range_check_min: u32, @@ -151,13 +152,13 @@ pub struct PublicInput { pub continuous_page_headers: Vec, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct PubilcMemoryCell { pub address: u32, pub value: BigUint, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct SegmentInfo { pub begin_addr: u32, pub stop_ptr: u32, From b86e2aba266d6b53f49838a5d50040e8c1449625 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Sun, 15 Sep 2024 08:58:27 +0200 Subject: [PATCH 5/5] wasm improved & proof parser serialize trait --- proof_parser/src/lib.rs | 1 + proof_parser/src/stark_proof.rs | 50 ++++++++++++++++----------------- wasm_bindings/src/lib.rs | 47 +++++++++++++++++++++++++------ 3 files changed, 65 insertions(+), 33 deletions(-) diff --git a/proof_parser/src/lib.rs b/proof_parser/src/lib.rs index bd82590..091f9ff 100644 --- a/proof_parser/src/lib.rs +++ b/proof_parser/src/lib.rs @@ -3,6 +3,7 @@ pub mod builtins; pub mod json_parser; pub mod layout; pub mod stark_proof; + pub use stark_proof::*; pub fn parse(input: String) -> anyhow::Result { diff --git a/proof_parser/src/stark_proof.rs b/proof_parser/src/stark_proof.rs index 1174d2c..10f384d 100644 --- a/proof_parser/src/stark_proof.rs +++ b/proof_parser/src/stark_proof.rs @@ -1,15 +1,15 @@ use num_bigint::BigUint; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StarkProof { pub config: StarkConfig, pub public_input: PublicInput, pub unsent_commitment: StarkUnsentCommitment, pub witness: StarkWitness, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StarkConfig { pub traces: TracesConfig, pub composition: TableCommitmentConfig, @@ -20,22 +20,22 @@ pub struct StarkConfig { pub log_n_cosets: u32, pub n_verifier_friendly_commitment_layers: u32, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct TracesConfig { pub original: TableCommitmentConfig, pub interaction: TableCommitmentConfig, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct TableCommitmentConfig { pub n_columns: u32, pub vector: VectorCommitmentConfig, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct VectorCommitmentConfig { pub height: u32, pub n_verifier_friendly_commitment_layers: u32, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct FriConfig { pub log_input_size: u32, pub n_layers: u32, @@ -43,12 +43,12 @@ pub struct FriConfig { pub fri_step_sizes: Vec, pub log_last_layer_degree_bound: u32, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ProofOfWorkConfig { pub n_bits: u32, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StarkUnsentCommitment { pub traces: TracesUnsentCommitment, pub composition: BigUint, @@ -57,24 +57,24 @@ pub struct StarkUnsentCommitment { pub proof_of_work: ProofOfWorkUnsentCommitment, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct TracesUnsentCommitment { pub original: BigUint, pub interaction: BigUint, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct FriUnsentCommitment { pub inner_layers: Vec, pub last_layer_coefficients: Vec, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ProofOfWorkUnsentCommitment { pub nonce: BigUint, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct StarkWitness { pub traces_decommitment: TracesDecommitment, pub traces_witness: TracesWitness, @@ -83,59 +83,59 @@ pub struct StarkWitness { pub fri_witness: FriWitness, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct TracesDecommitment { pub original: TableDecommitment, pub interaction: TableDecommitment, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct TableDecommitment { pub n_values: usize, pub values: Vec, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct TracesWitness { pub original: TableCommitmentWitness, pub interaction: TableCommitmentWitness, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct TableCommitmentWitness { pub vector: VectorCommitmentWitness, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct VectorCommitmentWitness { pub n_authentications: usize, pub authentications: Vec, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct TableCommitmentWitnessFlat { pub vector: VectorCommitmentWitnessFlat, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct VectorCommitmentWitnessFlat { pub n_authentications: usize, pub authentications: Vec, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct FriWitness { pub layers: Vec, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct FriLayerWitness { pub n_leaves: usize, pub leaves: Vec, pub table_witness: TableCommitmentWitnessFlat, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PublicInput { pub log_n_steps: u32, pub range_check_min: u32, @@ -152,13 +152,13 @@ pub struct PublicInput { pub continuous_page_headers: Vec, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PubilcMemoryCell { pub address: u32, pub value: BigUint, } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SegmentInfo { pub begin_addr: u32, pub stop_ptr: u32, diff --git a/wasm_bindings/src/lib.rs b/wasm_bindings/src/lib.rs index 61681c9..a086ba2 100644 --- a/wasm_bindings/src/lib.rs +++ b/wasm_bindings/src/lib.rs @@ -13,25 +13,56 @@ use swiftness_air::layout::starknet::Layout; #[cfg(feature = "starknet_with_keccak")] use swiftness_air::layout::starknet_with_keccak::Layout; -use swiftness::transform::TransformTo; +use serde_json::json; +use swiftness::{transform::TransformTo, types::StarkProof as StarkProofVerifier}; use swiftness_proof_parser::parse; use wasm_bindgen::prelude::*; #[wasm_bindgen] -pub fn verify_proof(proof: JsValue) -> Result { +pub fn parse_proof(stark_proof: JsValue) -> Result { // Deserialize input from JsValue to Rust types - let proof_str: String = proof.as_string().ok_or_else(|| JsError::new("Invalid input"))?; + let proof_str: String = stark_proof + .as_string() + .ok_or_else(|| JsError::new("Failed to convert input to string. Expected a valid string representation of the proof"))?; // Parse the proof - let stark_proof = parse(proof_str).map_err(|e| JsError::new(&e.to_string()))?.transform_to(); + let stark_proof: StarkProofVerifier = parse(proof_str) + .map_err(|e| JsError::new(&format!("Error parsing proof: {}", e)))? + .transform_to(); + + // Serialize result to JsValue + let result = serde_json::to_value(stark_proof) + .map_err(|e| JsError::new(&format!("Failed to serialize proof to JSON: {}", e)))?; + + Ok(JsValue::from_str(&result.to_string())) +} + +#[wasm_bindgen] +pub fn verify_proof(stark_proof: JsValue) -> Result { + // Deserialize proof from JsValue + let proof_str = stark_proof.as_string().ok_or_else(|| { + JsError::new( + "Input is not a valid string. Expected a JSON string representation of the proof", + ) + })?; + + let stark_proof: StarkProofVerifier = serde_json::from_str(&proof_str) + .map_err(|e| JsError::new(&format!("Error deserializing proof: {}", e)))?; // Get security bits and verify let security_bits = stark_proof.config.security_bits(); - let (program_hash, output_hash) = - stark_proof.verify::(security_bits).map_err(|e| JsError::new(&e.to_string()))?; + let (program_hash, output_hash) = stark_proof + .verify::(security_bits) + .map_err(|e| JsError::new(&format!("Verification failed: {}", e)))?; // Serialize result to JsValue - let result = serde_json::to_value((program_hash, output_hash)) - .map_err(|e| JsError::new(&e.to_string()))?; + let result = serde_json::to_value(json!({ + "program_hash": program_hash, + "output_hash": output_hash, + })) + .map_err(|e| { + JsError::new(&format!("Failed to serialize verification result to JSON: {}", e)) + })?; + Ok(JsValue::from_str(&result.to_string())) }