forked from privacy-scaling-explorations/zkevm-circuits
-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25f8bde
commit f7b4a19
Showing
7 changed files
with
154 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod chunk; | ||
mod inner; | ||
|
||
pub use chunk::chunk_prove; | ||
pub use inner::inner_prove; |
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,67 @@ | ||
use crate::{ | ||
common::{Prover, Verifier}, | ||
config::{LayerId, ZKEVM_DEGREES}, | ||
utils::read_env_var, | ||
CompressionCircuit, WitnessBlock, | ||
}; | ||
use once_cell::sync::Lazy; | ||
use std::env; | ||
|
||
static mut CHUNK_PROVER: Lazy<Prover> = Lazy::new(|| { | ||
let params_dir = read_env_var("SCROLL_PROVER_PARAMS_DIR", "./test_params".to_string()); | ||
let prover = Prover::from_params_dir(¶ms_dir, &ZKEVM_DEGREES); | ||
log::info!("Constructed chunk-prover"); | ||
|
||
prover | ||
}); | ||
|
||
static mut CHUNK_VERIFIER: Lazy<Verifier<CompressionCircuit>> = Lazy::new(|| { | ||
env::set_var("COMPRESSION_CONFIG", LayerId::Layer2.config_path()); | ||
|
||
let prover = unsafe { &mut CHUNK_PROVER }; | ||
let params = prover.params(LayerId::Layer2.degree()).clone(); | ||
|
||
let pk = prover | ||
.pk(LayerId::Layer2.id()) | ||
.expect("Failed to get chunk-prove PK"); | ||
let vk = pk.get_vk().clone(); | ||
|
||
let verifier = Verifier::new(params, vk); | ||
log::info!("Constructed chunk-verifier"); | ||
|
||
verifier | ||
}); | ||
|
||
pub fn chunk_prove(test: &str, witness_block: &WitnessBlock) { | ||
log::info!("{test}: chunk-prove BEGIN"); | ||
|
||
let prover = unsafe { &mut CHUNK_PROVER }; | ||
let inner_id = read_env_var("INNER_LAYER_ID", LayerId::Inner.id().to_string()); | ||
let inner_id_changed = prover.pk(&inner_id).is_none(); | ||
|
||
// Clear previous PKs if inner-layer ID changed. | ||
if inner_id_changed { | ||
prover.clear_pks(); | ||
} | ||
|
||
let snark = prover | ||
.load_or_gen_final_chunk_snark(test, witness_block, Some(&inner_id), None) | ||
.unwrap_or_else(|err| panic!("{test}: failed to generate chunk snark: {err}")); | ||
log::info!("{test}: generated chunk snark"); | ||
|
||
let verifier = unsafe { &mut CHUNK_VERIFIER }; | ||
|
||
// Reset VK if inner-layer ID changed. | ||
if inner_id_changed { | ||
let pk = prover | ||
.pk(LayerId::Layer2.id()) | ||
.unwrap_or_else(|| panic!("{test}: failed to get inner-prove PK")); | ||
let vk = pk.get_vk().clone(); | ||
verifier.set_vk(vk); | ||
} | ||
|
||
let verified = verifier.verify_snark(snark); | ||
assert!(verified, "{test}: failed to verify chunk snark"); | ||
|
||
log::info!("{test}: chunk-prove END"); | ||
} |
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,66 @@ | ||
use crate::{ | ||
common::{Prover, Verifier}, | ||
config::{LayerId, INNER_DEGREE}, | ||
utils::{gen_rng, read_env_var}, | ||
zkevm::circuit::{SuperCircuit, TargetCircuit}, | ||
WitnessBlock, | ||
}; | ||
use once_cell::sync::Lazy; | ||
|
||
static mut INNER_PROVER: Lazy<Prover> = Lazy::new(|| { | ||
let params_dir = read_env_var("SCROLL_PROVER_PARAMS_DIR", "./test_params".to_string()); | ||
let prover = Prover::from_params_dir(¶ms_dir, &[*INNER_DEGREE]); | ||
log::info!("Constructed inner-prover"); | ||
|
||
prover | ||
}); | ||
|
||
static mut INNER_VERIFIER: Lazy<Verifier<<SuperCircuit as TargetCircuit>::Inner>> = | ||
Lazy::new(|| { | ||
let prover = unsafe { &mut INNER_PROVER }; | ||
let params = prover.params(*INNER_DEGREE).clone(); | ||
|
||
let inner_id = read_env_var("INNER_LAYER_ID", LayerId::Inner.id().to_string()); | ||
let pk = prover.pk(&inner_id).expect("Failed to get inner-prove PK"); | ||
let vk = pk.get_vk().clone(); | ||
|
||
let verifier = Verifier::new(params, vk); | ||
log::info!("Constructed inner-verifier"); | ||
|
||
verifier | ||
}); | ||
|
||
pub fn inner_prove(test: &str, witness_block: &WitnessBlock) { | ||
log::info!("{test}: inner-prove BEGIN"); | ||
|
||
let prover = unsafe { &mut INNER_PROVER }; | ||
let inner_id = read_env_var("INNER_LAYER_ID", LayerId::Inner.id().to_string()); | ||
let inner_id_changed = prover.pk(&inner_id).is_none(); | ||
|
||
// Clear previous PKs if inner-layer ID changed. | ||
if inner_id_changed { | ||
prover.clear_pks(); | ||
} | ||
|
||
let rng = gen_rng(); | ||
let snark = prover | ||
.gen_inner_snark::<SuperCircuit>(&inner_id, rng, witness_block) | ||
.unwrap_or_else(|err| panic!("{test}: failed to generate inner snark: {err}")); | ||
log::info!("{test}: generated inner snark"); | ||
|
||
let verifier = unsafe { &mut INNER_VERIFIER }; | ||
|
||
// Reset VK if inner-layer ID changed. | ||
if inner_id_changed { | ||
let pk = prover | ||
.pk(&inner_id) | ||
.unwrap_or_else(|| panic!("{test}: failed to get inner-prove PK")); | ||
let vk = pk.get_vk().clone(); | ||
verifier.set_vk(vk); | ||
} | ||
|
||
let verified = verifier.verify_snark(snark); | ||
assert!(verified, "{test}: failed to verify inner snark"); | ||
|
||
log::info!("{test}: inner-prove END"); | ||
} |
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