Skip to content

Commit

Permalink
feat: use deployed kzg-rs (#76)
Browse files Browse the repository at this point in the history
* add

* fix"

* fix

* feat: use deployed kzg-rs

* fix: kzg-rs dep

---------

Co-authored-by: Ratan Kaliani <[email protected]>
  • Loading branch information
0xWOLAND and ratankaliani authored Aug 27, 2024
1 parent 329daf8 commit 06ec2f3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 44 deletions.
70 changes: 44 additions & 26 deletions Cargo.lock

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

8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +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" }

# sp1
[profile.release-client-lto]
Expand All @@ -100,5 +97,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 }
35 changes: 23 additions & 12 deletions crates/client-utils/src/oracle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,29 @@ 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<Bytes48> = blobs
.keys()
.cloned()
.map(|blob| Bytes48::from_slice(&blob.0).unwrap())
.collect_vec();
let kzg_proofs: Vec<Bytes48> = blobs
.values()
.map(|blob| Bytes48::from_slice(&blob.kzg_proof.0).unwrap())
.collect_vec();
let blob_datas: Vec<KzgRsBlob> = 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,
commitments,
kzg_proofs,
&get_kzg_settings(),
)
.map_err(|e| anyhow!("blob verification failed for batch: {:?}", e))?;
println!("cycle-tracker-report-end: blob-verification");

Ok(())
}
Expand Down

0 comments on commit 06ec2f3

Please sign in to comment.