From cf63deda673f402bb5bede2b6458982a48a28b0a Mon Sep 17 00:00:00 2001 From: Rohit Narurkar Date: Sat, 25 Jan 2025 23:25:02 +0000 Subject: [PATCH 1/2] feat: Sdk::verify_evm_proof fallible --- Cargo.lock | 16 ++++++++-------- crates/cli/src/commands/verify.rs | 6 ++---- crates/sdk/src/lib.rs | 16 +++++++++------- extensions/native/recursion/src/halo2/wrapper.rs | 5 ++--- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c45899e753..bf9962f3d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1284,7 +1284,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys 0.59.0", + "windows-sys 0.48.0", ] [[package]] @@ -1955,7 +1955,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -2854,7 +2854,7 @@ checksum = "e19b23d53f35ce9f56aebc7d1bb4e6ac1e9c0db7ac85c8d1760c04379edced37" dependencies = [ "hermit-abi 0.4.0", "libc", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -5797,7 +5797,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -6224,7 +6224,7 @@ checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" [[package]] name = "snark-verifier" version = "0.1.8" -source = "git+https://github.com/axiom-crypto/snark-verifier?branch=zkvm-v0.1#001b25ef0b387c54ed342de2ff6f423fca6db0f6" +source = "git+https://github.com/axiom-crypto/snark-verifier?branch=zkvm-v0.1#ab65fda41b56571aa33dd27f68ef1ea461e3fadc" dependencies = [ "halo2-base", "halo2-ecc", @@ -6245,7 +6245,7 @@ dependencies = [ [[package]] name = "snark-verifier-sdk" version = "0.1.8" -source = "git+https://github.com/axiom-crypto/snark-verifier?branch=zkvm-v0.1#001b25ef0b387c54ed342de2ff6f423fca6db0f6" +source = "git+https://github.com/axiom-crypto/snark-verifier?branch=zkvm-v0.1#ab65fda41b56571aa33dd27f68ef1ea461e3fadc" dependencies = [ "ark-std 0.3.0", "bincode 1.3.3", @@ -6474,7 +6474,7 @@ dependencies = [ "getrandom", "once_cell", "rustix", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -7154,7 +7154,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.48.0", ] [[package]] diff --git a/crates/cli/src/commands/verify.rs b/crates/cli/src/commands/verify.rs index ef02f34510..e0531cccf1 100644 --- a/crates/cli/src/commands/verify.rs +++ b/crates/cli/src/commands/verify.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use clap::Parser; -use eyre::{eyre, Result}; +use eyre::Result; use openvm_sdk::{ fs::{ read_app_proof_from_file, read_app_vk_from_file, read_evm_proof_from_file, @@ -49,9 +49,7 @@ impl VerifyCmd { eyre::eyre!("Failed to read EVM verifier: {}\nPlease run 'cargo openvm evm-proving-setup' first", e) })?; let evm_proof = read_evm_proof_from_file(proof)?; - if !Sdk.verify_evm_proof(&evm_verifier, &evm_proof) { - return Err(eyre!("EVM proof verification failed")); - } + Sdk.verify_evm_proof(&evm_verifier, &evm_proof)?; } } Ok(()) diff --git a/crates/sdk/src/lib.rs b/crates/sdk/src/lib.rs index df4861b923..3e4e8f4049 100644 --- a/crates/sdk/src/lib.rs +++ b/crates/sdk/src/lib.rs @@ -1,6 +1,6 @@ extern crate core; -use std::{fs::read, panic::catch_unwind, path::Path, sync::Arc}; +use std::{fs::read, path::Path, sync::Arc}; use commit::commit_app_exe; use config::AppConfig; @@ -228,11 +228,13 @@ impl Sdk { Ok(evm_verifier) } - pub fn verify_evm_proof(&self, evm_verifier: &EvmVerifier, evm_proof: &EvmProof) -> bool { - // FIXME: we should return the concrete error. - catch_unwind(|| { - Halo2WrapperProvingKey::evm_verify(evm_verifier, evm_proof); - }) - .is_ok() + pub fn verify_evm_proof( + &self, + evm_verifier: &EvmVerifier, + evm_proof: &EvmProof, + ) -> Result { + let gas_cost = Halo2WrapperProvingKey::evm_verify(evm_verifier, evm_proof) + .map_err(|reason| eyre::eyre!("Sdk::verify_evm_proof: {reason:?}"))?; + Ok(gas_cost) } } diff --git a/extensions/native/recursion/src/halo2/wrapper.rs b/extensions/native/recursion/src/halo2/wrapper.rs index 8ffa53f497..e8041e66a9 100644 --- a/extensions/native/recursion/src/halo2/wrapper.rs +++ b/extensions/native/recursion/src/halo2/wrapper.rs @@ -78,13 +78,12 @@ impl Halo2WrapperProvingKey { } } /// A helper function for testing to verify the proof of this circuit with evm verifier. - // FIXME: the signature is not ideal. It should return an Error instead of panicking when the verification fails. - pub fn evm_verify(evm_verifier: &EvmVerifier, evm_proof: &EvmProof) { + pub fn evm_verify(evm_verifier: &EvmVerifier, evm_proof: &EvmProof) -> Result { evm_verify( evm_verifier.0.clone(), evm_proof.instances.clone(), evm_proof.proof.clone(), - ); + ) } /// Return deployment code for EVM verifier which can verify the snark of this circuit. pub fn generate_evm_verifier(&self, params: &Halo2Params) -> EvmVerifier { From 97877e9a73773edd9c988bf3d8ca3f061338478a Mon Sep 17 00:00:00 2001 From: Rohit Narurkar Date: Sun, 26 Jan 2025 06:08:51 +0000 Subject: [PATCH 2/2] fix: tests usage of --- crates/sdk/examples/sdk_evm.rs | 3 +-- crates/sdk/tests/integration_test.rs | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/sdk/examples/sdk_evm.rs b/crates/sdk/examples/sdk_evm.rs index 41b91c71cf..4192feba31 100644 --- a/crates/sdk/examples/sdk_evm.rs +++ b/crates/sdk/examples/sdk_evm.rs @@ -109,8 +109,7 @@ fn main() -> Result<(), Box> { )?; // 11. Verify the EVM proof - let success = sdk.verify_evm_proof(&verifier, &proof); - assert!(success); + sdk.verify_evm_proof(&verifier, &proof)?; // ANCHOR_END: evm_verification Ok(()) diff --git a/crates/sdk/tests/integration_test.rs b/crates/sdk/tests/integration_test.rs index 7fa7cd7686..6738201ceb 100644 --- a/crates/sdk/tests/integration_test.rs +++ b/crates/sdk/tests/integration_test.rs @@ -353,7 +353,7 @@ fn test_static_verifier_custom_pv_handler() { StdIn::default(), ) .unwrap(); - assert!(Sdk.verify_evm_proof(&evm_verifier, &evm_proof)); + assert!(Sdk.verify_evm_proof(&evm_verifier, &evm_proof).is_ok()); } #[test] @@ -382,7 +382,7 @@ fn test_e2e_proof_generation_and_verification() { StdIn::default(), ) .unwrap(); - assert!(Sdk.verify_evm_proof(&evm_verifier, &evm_proof)); + assert!(Sdk.verify_evm_proof(&evm_verifier, &evm_proof).is_ok()); } #[test]