From 1606ecb3db3d65a4cb870a0573fa746d37c29695 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Tue, 13 Aug 2024 13:03:48 -0700 Subject: [PATCH 1/5] add --- Cargo.toml | 3 +++ crates/client-utils/src/oracle/mod.rs | 25 +++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index febe7b5e..509e5071 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,6 +89,9 @@ kzg-rs = { git = "https://github.com/leruaa/kzg-rs", branch = "verify_blobs", fe ] } +# kzg +kzg-rs = { git = "https://github.com/leruaa/kzg-rs", branch = "verify_blobs" } + # sp1 [profile.release-client-lto] inherits = "release" diff --git a/crates/client-utils/src/oracle/mod.rs b/crates/client-utils/src/oracle/mod.rs index da1eee8b..e4c140ba 100644 --- a/crates/client-utils/src/oracle/mod.rs +++ b/crates/client-utils/src/oracle/mod.rs @@ -148,18 +148,19 @@ impl InMemoryOracle { } } - let kzg_settings = get_kzg_settings(); - for (commitment, blob) in blobs.iter() { - println!("cycle-tracker-report-start: blob-verification"); - kzg_rs::KzgProof::verify_blob_kzg_proof( - KzgRsBlob::from_slice(&blob.data.0).unwrap(), - &Bytes48::from_slice(&commitment.0).unwrap(), - &Bytes48::from_slice(&blob.kzg_proof.0).unwrap(), - &kzg_settings, - ) - .map_err(|e| anyhow!("blob verification failed: {:?}", e))?; - println!("cycle-tracker-report-end: blob-verification"); - } + println!("cycle-tracker-report-start: blob-verification"); + let commitments: Vec = blobs.keys().cloned().collect(); + let kzg_proofs: Vec = blobs.values().map(|blob| blob.kzg_proof).collect(); + let blob_datas: Vec = blobs.values().map(|blob| blob.data).collect(); + // Verify reconstructed blobs. + kzg_rs::KzgProof::verify_blob_kzg_proof_batch( + blob_datas, + commitments, + kzg_proofs, + &get_kzg_settings(), + ) + .map_err(|e| anyhow!("blob verification failed for {:?}: {:?}", commitment, e))?; + println!("cycle-tracker-report-end: blob-verification"); Ok(()) } From ea69ab26495294ea6e221330220b4c10373f2fa8 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Tue, 13 Aug 2024 14:26:01 -0700 Subject: [PATCH 2/5] fix" --- Cargo.toml | 4 +++- crates/client-utils/Cargo.toml | 1 + crates/client-utils/src/oracle/mod.rs | 18 ++++++++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 509e5071..37760dc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -90,7 +90,9 @@ kzg-rs = { git = "https://github.com/leruaa/kzg-rs", branch = "verify_blobs", fe # kzg -kzg-rs = { git = "https://github.com/leruaa/kzg-rs", branch = "verify_blobs" } +kzg-rs = { git = "https://github.com/leruaa/kzg-rs", branch = "verify_blobs", features = [ + "cache", +] } # sp1 [profile.release-client-lto] diff --git a/crates/client-utils/Cargo.toml b/crates/client-utils/Cargo.toml index 18779cfd..c70bafbf 100644 --- a/crates/client-utils/Cargo.toml +++ b/crates/client-utils/Cargo.toml @@ -35,3 +35,4 @@ itertools.workspace = true # kzg kzg-rs.workspace = true +itertools = "0.13.0" diff --git a/crates/client-utils/src/oracle/mod.rs b/crates/client-utils/src/oracle/mod.rs index e4c140ba..8308b1bd 100644 --- a/crates/client-utils/src/oracle/mod.rs +++ b/crates/client-utils/src/oracle/mod.rs @@ -149,9 +149,19 @@ impl InMemoryOracle { } println!("cycle-tracker-report-start: blob-verification"); - let commitments: Vec = blobs.keys().cloned().collect(); - let kzg_proofs: Vec = blobs.values().map(|blob| blob.kzg_proof).collect(); - let blob_datas: Vec = blobs.values().map(|blob| blob.data).collect(); + let commitments: Vec = blobs + .keys() + .cloned() + .map(|blob| Bytes48::from_slice(&blob.0).unwrap()) + .collect_vec(); + let kzg_proofs: Vec = blobs + .values() + .map(|blob| Bytes48::from_slice(&blob.kzg_proof.0).unwrap()) + .collect_vec(); + let blob_datas: Vec = blobs + .values() + .map(|blob| KzgRsBlob::from_slice(&blob.data.0).unwrap()) + .collect_vec(); // Verify reconstructed blobs. kzg_rs::KzgProof::verify_blob_kzg_proof_batch( blob_datas, @@ -159,7 +169,7 @@ impl InMemoryOracle { kzg_proofs, &get_kzg_settings(), ) - .map_err(|e| anyhow!("blob verification failed for {:?}: {:?}", commitment, e))?; + .map_err(|e| anyhow!("blob verification failed for batch: {:?}", e))?; println!("cycle-tracker-report-end: blob-verification"); Ok(()) From edab7d2252f391209e74de2480048da8f5e2a9c4 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Fri, 16 Aug 2024 12:51:02 -0700 Subject: [PATCH 3/5] fix --- crates/client-utils/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/client-utils/Cargo.toml b/crates/client-utils/Cargo.toml index c70bafbf..18779cfd 100644 --- a/crates/client-utils/Cargo.toml +++ b/crates/client-utils/Cargo.toml @@ -35,4 +35,3 @@ itertools.workspace = true # kzg kzg-rs.workspace = true -itertools = "0.13.0" From 1e85f59353628dc8dc4aa7093d5204bd94e42640 Mon Sep 17 00:00:00 2001 From: Bhargav Annem Date: Tue, 27 Aug 2024 11:45:14 -0700 Subject: [PATCH 4/5] feat: use deployed kzg-rs --- Cargo.lock | 70 ++++++++++++++++++++++++++++++++++-------------------- Cargo.toml | 7 ++---- 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edae6fc7..4ea90e3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,7 +58,7 @@ dependencies = [ "client-utils", "serde_cbor", "sha2", - "sp1-lib 1.1.1 (git+https://github.com/succinctlabs/sp1.git?branch=experimental)", + "sp1-lib 1.1.1", "sp1-zkvm", ] @@ -1201,7 +1201,8 @@ dependencies = [ [[package]] name = "bls12_381" version = "0.8.0" -source = "git+https://github.com/leruaa/bls12_381?branch=msm_variable_base#7608bbfb40f3fd2e40110c1c92cacea5acbf1a8b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7bc6d6292be3a19e6379786dac800f551e5865a5bb51ebbe3064ab80433f403" dependencies = [ "ff 0.13.0", "group 0.13.0", @@ -1470,7 +1471,7 @@ dependencies = [ "kona-mpt", "kona-preimage", "kona-primitives", - "kzg-rs 0.1.0 (git+https://github.com/leruaa/kzg-rs?branch=verify_blobs)", + "kzg-rs 0.2.1", "log", "op-alloy-consensus", "revm", @@ -1883,18 +1884,15 @@ checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "ecdsa" -version = "0.16.9" -source = "git+https://github.com/sp1-patches/signatures?branch=patch-ecdsa-v0.16.9#1caae137b2b2c458b8a542b1c4e9fb40293c67a3" +version = "0.16.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4b1e0c257a9e9f25f90ff76d7a68360ed497ee519c8e428d1825ef0000799d4" dependencies = [ - "anyhow", - "cfg-if", "der", "digest 0.10.7", "elliptic-curve", - "hex-literal", "rfc6979", "signature", - "sp1-lib 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "spki", ] @@ -3430,18 +3428,15 @@ dependencies = [ [[package]] name = "kzg-rs" -version = "0.1.0" -source = "git+https://github.com/leruaa/kzg-rs?branch=verify_blobs#1f29a9520602bbde32bb219a331d4cec3cc94853" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea38b4917cfb194709222324913a33a999b25f9da59e2c8da304fc0ef55f996a" dependencies = [ - "bls12_381 0.8.0", "ff 0.13.0", - "glob", "hex", "once_cell", - "serde", - "serde_derive", - "serde_yaml", "sha2", + "sp1_bls12_381", ] [[package]] @@ -5097,7 +5092,7 @@ dependencies = [ "enumn", "hashbrown 0.14.5", "hex", - "kzg-rs 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "kzg-rs 0.1.0", "once_cell", "serde", ] @@ -5105,7 +5100,8 @@ dependencies = [ [[package]] name = "rfc6979" version = "0.4.0" -source = "git+https://github.com/sp1-patches/signatures?branch=patch-ecdsa-v0.16.9#1caae137b2b2c458b8a542b1c4e9fb40293c67a3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" dependencies = [ "hmac", "subtle", @@ -5767,9 +5763,9 @@ dependencies = [ [[package]] name = "signature" -version = "2.2.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" dependencies = [ "digest 0.10.7", "rand_core", @@ -5930,19 +5926,21 @@ dependencies = [ [[package]] name = "sp1-lib" version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "839009d6aab5876710e2bc35170d1f328bc70f38992f0037b938623dadfcc61f" +source = "git+https://github.com/succinctlabs/sp1.git?branch=experimental#cb6465650ebed0e1d7e9a7d425810ad772217096" dependencies = [ "anyhow", "bincode", "cfg-if", + "hex", "serde", + "snowbridge-amcl", ] [[package]] name = "sp1-lib" -version = "1.1.1" -source = "git+https://github.com/succinctlabs/sp1.git?branch=experimental#cb6465650ebed0e1d7e9a7d425810ad772217096" +version = "1.2.0-rc1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f600a97b145e66f0f5e56595527c359f5cc8cb1f9dc8a6da1ba34bb845c9d1e" dependencies = [ "anyhow", "bincode", @@ -6246,10 +6244,25 @@ dependencies = [ "rand", "serde", "sha2", - "sp1-lib 1.1.1 (git+https://github.com/succinctlabs/sp1.git?branch=experimental)", + "sp1-lib 1.1.1", "sp1-primitives", ] +[[package]] +name = "sp1_bls12_381" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a27c4b8901334dc09099dd82f80a72ddfc76b0046f4b342584c808f1931bed5a" +dependencies = [ + "cfg-if", + "ff 0.13.0", + "group 0.13.0", + "pairing 0.23.0", + "rand_core", + "sp1-lib 1.2.0-rc1", + "subtle", +] + [[package]] name = "spin" version = "0.5.2" @@ -6343,7 +6356,7 @@ dependencies = [ "lazy_static", "rand", "rustc-hex", - "sp1-lib 1.1.1 (git+https://github.com/succinctlabs/sp1.git?branch=experimental)", + "sp1-lib 1.1.1", ] [[package]] @@ -7567,3 +7580,8 @@ dependencies = [ "sp1-sdk", "tokio", ] + +[[patch.unused]] +name = "ecdsa" +version = "0.16.9" +source = "git+https://github.com/sp1-patches/signatures?branch=patch-ecdsa-v0.16.9#1caae137b2b2c458b8a542b1c4e9fb40293c67a3" diff --git a/Cargo.toml b/Cargo.toml index 37760dc8..f26705a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,9 +84,7 @@ sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", branch = "experimen sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", branch = "experimental" } # kzg -kzg-rs = { git = "https://github.com/leruaa/kzg-rs", branch = "verify_blobs", features = [ - "cache", -] } +kzg-rs = { version = "0.2.1" } # kzg @@ -105,5 +103,4 @@ lto = "fat" tiny-keccak = { git = "https://github.com/sp1-patches/tiny-keccak", branch = "patch-v2.0.2" } sha2 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", branch = "patch-v0.10.8", package = "sha2" } ecdsa-core = { git = "https://github.com/sp1-patches/signatures", package = "ecdsa", branch = "patch-ecdsa-v0.16.9" } -bls12_381 = { git = "https://github.com/leruaa/bls12_381", branch = "msm_variable_base" } -bn = { git = "https://github.com/0xWOLAND/bn.git", package = "substrate-bn" } +bn = { git = "https://github.com/0xWOLAND/bn.git", package = "substrate-bn", default-features = false } From 09303e25f2175abe442602aab66a0cf2548d63c6 Mon Sep 17 00:00:00 2001 From: Bhargav Annem Date: Tue, 27 Aug 2024 11:59:20 -0700 Subject: [PATCH 5/5] fix: kzg-rs dep --- Cargo.toml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f26705a8..e47071b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,12 +86,6 @@ sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", branch = "experi # kzg kzg-rs = { version = "0.2.1" } - -# kzg -kzg-rs = { git = "https://github.com/leruaa/kzg-rs", branch = "verify_blobs", features = [ - "cache", -] } - # sp1 [profile.release-client-lto] inherits = "release"