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

Sdk::verify_evm_proof fallible #1288

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 8 additions & 8 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions crates/cli/src/commands/verify.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(())
Expand Down
3 changes: 1 addition & 2 deletions crates/sdk/examples/sdk_evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
)?;

// 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(())
Expand Down
16 changes: 9 additions & 7 deletions crates/sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<u64> {
let gas_cost = Halo2WrapperProvingKey::evm_verify(evm_verifier, evm_proof)
.map_err(|reason| eyre::eyre!("Sdk::verify_evm_proof: {reason:?}"))?;
Ok(gas_cost)
}
}
4 changes: 2 additions & 2 deletions crates/sdk/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions extensions/native/recursion/src/halo2/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64, String> {
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 {
Expand Down
Loading