-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `test-batch-prove`. * Add enum `LayerId`, and test functions `gen_and_verify_batch_proofs` and `gen_and_verify_chunk_proofs`. * Add `verify_chunk_proof`. * Dump chunk-procotol in `batch_tests`.
- Loading branch information
1 parent
a29cbaa
commit 132b2a7
Showing
11 changed files
with
290 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
use crate::{ | ||
aggregator::{Prover, Verifier}, | ||
common, | ||
config::LayerId, | ||
test_util::PARAMS_DIR, | ||
zkevm, BatchProof, ChunkProof, EvmProof, | ||
}; | ||
use aggregator::CompressionCircuit; | ||
use snark_verifier_sdk::Snark; | ||
use std::env; | ||
use types::eth::StorageTrace; | ||
|
||
pub fn gen_and_verify_batch_proofs(agg_prover: &mut Prover, layer3_snark: Snark, output_dir: &str) { | ||
let normal_proof = gen_normal_proof( | ||
&mut agg_prover.inner, | ||
LayerId::Layer4, | ||
layer3_snark.clone(), | ||
output_dir, | ||
); | ||
let evm_proof = gen_evm_proof( | ||
&mut agg_prover.inner, | ||
LayerId::Layer4, | ||
layer3_snark, | ||
output_dir, | ||
); | ||
verify_normal_and_evm_proofs( | ||
&mut agg_prover.inner, | ||
LayerId::Layer4, | ||
normal_proof, | ||
&evm_proof, | ||
output_dir, | ||
); | ||
verify_batch_proof(evm_proof, output_dir); | ||
} | ||
|
||
pub fn gen_and_verify_chunk_proofs( | ||
zkevm_prover: &mut zkevm::Prover, | ||
layer1_snark: Snark, | ||
output_dir: &str, | ||
) { | ||
let normal_proof = gen_normal_proof( | ||
&mut zkevm_prover.inner, | ||
LayerId::Layer2, | ||
layer1_snark.clone(), | ||
output_dir, | ||
); | ||
let evm_proof = gen_evm_proof( | ||
&mut zkevm_prover.inner, | ||
LayerId::Layer2, | ||
layer1_snark, | ||
output_dir, | ||
); | ||
verify_normal_and_evm_proofs( | ||
&mut zkevm_prover.inner, | ||
LayerId::Layer2, | ||
normal_proof.clone(), | ||
&evm_proof, | ||
output_dir, | ||
); | ||
verify_chunk_proof(&zkevm_prover.inner, normal_proof, output_dir); | ||
} | ||
|
||
fn gen_evm_proof( | ||
prover: &mut common::Prover, | ||
layer_id: LayerId, | ||
previous_snark: Snark, | ||
output_dir: &str, | ||
) -> EvmProof { | ||
let id = layer_id.id(); | ||
let degree = layer_id.degree(); | ||
|
||
// Load or generate compression EVM proof. | ||
let evm_proof = prover | ||
.load_or_gen_comp_evm_proof("evm", id, true, degree, previous_snark, Some(output_dir)) | ||
.unwrap(); | ||
log::info!("Generated EVM proof: {id}"); | ||
|
||
evm_proof | ||
} | ||
|
||
fn gen_normal_proof( | ||
prover: &mut common::Prover, | ||
layer_id: LayerId, | ||
previous_snark: Snark, | ||
output_dir: &str, | ||
) -> Snark { | ||
let id = layer_id.id(); | ||
let degree = layer_id.degree(); | ||
|
||
// Load or generate compression snark. | ||
let snark = prover | ||
.load_or_gen_comp_snark("normal", id, true, degree, previous_snark, Some(output_dir)) | ||
.unwrap(); | ||
log::info!("Generated compression snark: {id}"); | ||
|
||
snark | ||
} | ||
|
||
fn verify_batch_proof(evm_proof: EvmProof, output_dir: &str) { | ||
let batch_proof = BatchProof::from(evm_proof.proof); | ||
batch_proof.dump(output_dir, "agg").unwrap(); | ||
batch_proof.clone().assert_calldata(); | ||
|
||
env::set_var("AGG_VK_FILENAME", "vk_evm_layer4_evm.vkey"); | ||
let verifier = Verifier::from_dirs(PARAMS_DIR, output_dir); | ||
log::info!("Constructed aggregator verifier"); | ||
|
||
assert!(verifier.verify_agg_evm_proof(batch_proof)); | ||
log::info!("Verified batch proof"); | ||
} | ||
|
||
fn verify_chunk_proof(prover: &common::Prover, normal_proof: Snark, output_dir: &str) { | ||
let pk = prover.pk(LayerId::Layer2.id()).unwrap(); | ||
let chunk_proof = | ||
ChunkProof::new(normal_proof, StorageTrace::default(), Some(pk), None).unwrap(); | ||
chunk_proof.dump(output_dir, "0").unwrap(); | ||
|
||
env::set_var("CHUNK_VK_FILENAME", "vk_chunk_0.vkey"); | ||
let verifier = zkevm::Verifier::from_dirs(PARAMS_DIR, output_dir); | ||
log::info!("Constructed zkevm verifier"); | ||
|
||
assert!(verifier.verify_chunk_proof(chunk_proof)); | ||
log::info!("Verified chunk proof"); | ||
} | ||
|
||
fn verify_normal_and_evm_proofs( | ||
prover: &mut common::Prover, | ||
layer_id: LayerId, | ||
normal_proof: Snark, | ||
evm_proof: &EvmProof, | ||
output_dir: &str, | ||
) { | ||
let id = layer_id.id(); | ||
let degree = layer_id.degree(); | ||
let config_path = layer_id.config_path(); | ||
|
||
env::set_var("COMPRESSION_CONFIG", config_path); | ||
let vk = evm_proof.proof.vk::<CompressionCircuit>(); | ||
|
||
let params = prover.params(degree).clone(); | ||
let verifier = common::Verifier::<CompressionCircuit>::new(params, vk); | ||
log::info!("Constructed common verifier"); | ||
|
||
assert!(verifier.verify_snark(normal_proof)); | ||
log::info!("Verified normal proof: {id}"); | ||
|
||
verifier.evm_verify(evm_proof, output_dir); | ||
log::info!("Verified EVM proof: {id}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.