From ea43b804a2ad62ded48162160789196d8c519c95 Mon Sep 17 00:00:00 2001 From: Steven Gu Date: Mon, 31 Jul 2023 08:53:50 +0800 Subject: [PATCH] Add function `verify_evm_proof` to return a bool. --- snark-verifier-sdk/src/evm_api.rs | 21 ++++++++++++--------- snark-verifier-sdk/src/lib.rs | 2 ++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/snark-verifier-sdk/src/evm_api.rs b/snark-verifier-sdk/src/evm_api.rs index 4f53e94f..6b542347 100644 --- a/snark-verifier-sdk/src/evm_api.rs +++ b/snark-verifier-sdk/src/evm_api.rs @@ -180,17 +180,20 @@ pub fn gen_evm_verifier_shplonk>( } pub fn evm_verify(deployment_code: Vec, instances: Vec>, proof: Vec) { + let success = verify_evm_proof(deployment_code, instances, proof); + + assert!(success); +} + +pub fn verify_evm_proof(deployment_code: Vec, instances: Vec>, proof: Vec) -> bool { let calldata = encode_calldata(&instances, &proof); - let success = { - let mut evm = ExecutorBuilder::default().with_gas_limit(u64::MAX.into()).build(); + let mut evm = ExecutorBuilder::default().with_gas_limit(u64::MAX.into()).build(); - let caller = Address::from_low_u64_be(0xfe); - let verifier = evm.deploy(caller, deployment_code.into(), 0.into()).address.unwrap(); - let result = evm.call_raw(caller, verifier, calldata.into(), 0.into()); + let caller = Address::from_low_u64_be(0xfe); + let verifier = evm.deploy(caller, deployment_code.into(), 0.into()).address.unwrap(); + let result = evm.call_raw(caller, verifier, calldata.into(), 0.into()); - log::info!("gas used: {}", result.gas_used); + log::info!("gas used: {}", result.gas_used); - !result.reverted - }; - assert!(success); + !result.reverted } diff --git a/snark-verifier-sdk/src/lib.rs b/snark-verifier-sdk/src/lib.rs index 9d99530c..511944e7 100644 --- a/snark-verifier-sdk/src/lib.rs +++ b/snark-verifier-sdk/src/lib.rs @@ -53,6 +53,8 @@ pub use evm_api::{ gen_evm_verifier_gwc, // generate the bytecode that verifies proofs with keccak and KZG-BDFG gen_evm_verifier_shplonk, + // verify instances and proofs with the bytecode (returns bool) + verify_evm_proof, }; #[cfg(feature = "loader_halo2")] pub use halo2_api::{