Skip to content

Commit

Permalink
Merge pull request #16 from scroll-tech/verify-evm-proof
Browse files Browse the repository at this point in the history
Add a function `verify_evm_proof` to return a bool
  • Loading branch information
lispc authored Jul 31, 2023
2 parents a530941 + ea43b80 commit 6eeba77
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 12 additions & 9 deletions snark-verifier-sdk/src/evm_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,20 @@ pub fn gen_evm_verifier_shplonk<C: CircuitExt<Fr>>(
}

pub fn evm_verify(deployment_code: Vec<u8>, instances: Vec<Vec<Fr>>, proof: Vec<u8>) {
let success = verify_evm_proof(deployment_code, instances, proof);

assert!(success);
}

pub fn verify_evm_proof(deployment_code: Vec<u8>, instances: Vec<Vec<Fr>>, proof: Vec<u8>) -> 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
}
2 changes: 2 additions & 0 deletions snark-verifier-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down

0 comments on commit 6eeba77

Please sign in to comment.