From 79153a9eccd64e9bfa069e2ed7aba3bc7edb02fc Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Tue, 12 Mar 2024 15:36:17 +0800 Subject: [PATCH] chunk-prover: check proof after generated --- prover/src/zkevm/prover.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/prover/src/zkevm/prover.rs b/prover/src/zkevm/prover.rs index 6d634d91ec..9533b2f368 100644 --- a/prover/src/zkevm/prover.rs +++ b/prover/src/zkevm/prover.rs @@ -14,6 +14,7 @@ use eth_types::l2_types::BlockTrace; pub struct Prover { // Make it public for testing with inner functions (unnecessary for FFI). pub inner: common::Prover, + verifier: super::verifier::Verifier, raw_vk: Option>, } @@ -30,7 +31,13 @@ impl Prover { ); } - Self { inner, raw_vk } + let verifier = super::verifier::Verifier::from_dirs(params_dir, assets_dir); + + Self { + inner, + raw_vk, + verifier, + } } pub fn get_vk(&self) -> Option> { @@ -73,7 +80,9 @@ impl Prover { self.check_and_clear_raw_vk(); - match output_dir.and_then(|output_dir| ChunkProof::from_json_file(output_dir, &name).ok()) { + let chunk_proof = match output_dir + .and_then(|output_dir| ChunkProof::from_json_file(output_dir, &name).ok()) + { Some(proof) => Ok(proof), None => { let chunk_hash = ChunkHash::from_witness_block(&witness_block, false); @@ -87,7 +96,13 @@ impl Prover { result } + }?; + + if !self.verifier.verify_chunk_proof(chunk_proof.clone()) { + anyhow::bail!("chunk prover cannot generate valid proof"); } + + Ok(chunk_proof) } fn check_and_clear_raw_vk(&mut self) {