Skip to content

Commit

Permalink
feat: add inner-prove and chunk-prove to testool (privacy-scaling-exp…
Browse files Browse the repository at this point in the history
…lorations#921)

* Add inner-prove and chunk-prove to testool.

* Make build successfully with feature `inner-prove` and `chunk-prove`.

* Generate pk/vk by coinbase address.

* Clear import.

* Fix wrong cfg for mock-prove.

* Fix chunk-prove bug.

* Fix

* Update coinbase in inner-prove.
  • Loading branch information
silathdiir authored Sep 10, 2023
1 parent 95f8276 commit 25c5810
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 33 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions prover/src/common/prover/chunk.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::Prover;
use crate::{
config::{LAYER1_DEGREE, LAYER2_DEGREE},
utils::gen_rng,
};
use crate::{config::LayerId, utils::gen_rng};
use aggregator::extract_proof_and_instances_with_pairing_check;
use anyhow::{anyhow, Result};
use halo2_proofs::halo2curves::bn256::Fr;
Expand All @@ -14,16 +11,18 @@ impl Prover {
&mut self,
name: &str,
witness_block: &Block<Fr>,
inner_id: Option<&str>,
output_dir: Option<&str>,
) -> Result<Snark> {
let layer1_snark = self.load_or_gen_last_chunk_snark(name, witness_block, output_dir)?;
let layer1_snark =
self.load_or_gen_last_chunk_snark(name, witness_block, inner_id, output_dir)?;

// Load or generate compression thin snark (layer-2).
let layer2_snark = self.load_or_gen_comp_snark(
name,
"layer2",
LayerId::Layer2.id(),
true,
*LAYER2_DEGREE,
LayerId::Layer2.degree(),
layer1_snark,
output_dir,
)?;
Expand All @@ -38,15 +37,21 @@ impl Prover {
&mut self,
name: &str,
witness_block: &Block<Fr>,
inner_id: Option<&str>,
output_dir: Option<&str>,
) -> Result<Snark> {
// Load or generate inner snark.
let inner_snark = self.load_or_gen_inner_snark(name, "inner", witness_block, output_dir)?;
let inner_snark = self.load_or_gen_inner_snark(
name,
inner_id.unwrap_or(LayerId::Inner.id()),
witness_block,
output_dir,
)?;
log::info!("Got inner snark: {name}");

// Check pairing for super circuit.
extract_proof_and_instances_with_pairing_check(
self.params(*LAYER1_DEGREE),
self.params(LayerId::Layer1.degree()),
&[inner_snark.clone()],
gen_rng(),
)
Expand All @@ -55,9 +60,9 @@ impl Prover {
// Load or generate compression wide snark (layer-1).
let layer1_snark = self.load_or_gen_comp_snark(
name,
"layer1",
LayerId::Layer1.id(),
false,
*LAYER1_DEGREE,
LayerId::Layer1.degree(),
inner_snark,
output_dir,
)?;
Expand Down
4 changes: 4 additions & 0 deletions prover/src/common/prover/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ impl Prover {
pub fn raw_vk(&self, id: &str) -> Option<Vec<u8>> {
self.pk_map.get(id).map(|pk| serialize_vk(pk.get_vk()))
}

pub fn clear_pks(&mut self) {
self.pk_map.clear();
}
}
4 changes: 4 additions & 0 deletions prover/src/common/verifier/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ impl<C: CircuitExt<Fr>> Verifier<C> {
pub fn vk(&self) -> &VerifyingKey<G1Affine> {
&self.vk
}

pub fn set_vk(&mut self, vk: VerifyingKey<G1Affine>) {
self.vk = vk;
}
}
5 changes: 5 additions & 0 deletions prover/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub static AGG_DEGREES: Lazy<Vec<u32>> =

#[derive(Clone, Copy, Debug)]
pub enum LayerId {
/// Super (inner) circuit layer
Inner,
/// Compression wide layer
Layer1,
/// Compression thin layer (to generate chunk-proof)
Expand All @@ -50,6 +52,7 @@ impl fmt::Display for LayerId {
impl LayerId {
pub fn id(&self) -> &str {
match self {
Self::Inner => "inner",
Self::Layer1 => "layer1",
Self::Layer2 => "layer2",
Self::Layer3 => "layer3",
Expand All @@ -59,6 +62,7 @@ impl LayerId {

pub fn degree(&self) -> u32 {
match self {
Self::Inner => *INNER_DEGREE,
Self::Layer1 => *LAYER1_DEGREE,
Self::Layer2 => *LAYER2_DEGREE,
Self::Layer3 => *LAYER3_DEGREE,
Expand All @@ -72,6 +76,7 @@ impl LayerId {
Self::Layer2 => &LAYER2_CONFIG_PATH,
Self::Layer3 => &LAYER3_CONFIG_PATH,
Self::Layer4 => &LAYER4_CONFIG_PATH,
Self::Inner => unreachable!("No config file for super (inner) circuit"),
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions prover/src/zkevm/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl Prover {
&mut self,
chunk_trace: Vec<BlockTrace>,
name: Option<&str>,
inner_id: Option<&str>,
output_dir: Option<&str>,
) -> Result<ChunkProof> {
assert!(!chunk_trace.is_empty());
Expand All @@ -64,9 +65,12 @@ impl Prover {
|name| name.to_string(),
);

let snark = self
.inner
.load_or_gen_final_chunk_snark(&name, &witness_block, output_dir)?;
let snark = self.inner.load_or_gen_final_chunk_snark(
&name,
&witness_block,
inner_id,
output_dir,
)?;

self.check_and_clear_raw_vk();

Expand Down
8 changes: 6 additions & 2 deletions testool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ itertools = "0.10"
mock = { path = "../mock" }
once_cell = "1.10"
prettytable-rs = "0.10"
prover = { path = "../prover", optional = true }
rayon = "1.5"
regex = "1"
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -43,5 +44,8 @@ default = ["ignore-test-docker", "skip-self-destruct", "shanghai"]
onephase = ["zkevm-circuits/onephase"]
ignore-test-docker = []
skip-self-destruct = []
shanghai = ["bus-mapping/shanghai", "eth-types/shanghai", "mock/shanghai", "zkevm-circuits/shanghai"]
scroll = ["bus-mapping/scroll", "eth-types/scroll", "external-tracer/scroll", "mock/scroll", "zkevm-circuits/scroll"]
shanghai = ["bus-mapping/shanghai", "eth-types/shanghai", "mock/shanghai", "zkevm-circuits/shanghai", "prover?/shanghai"]
scroll = ["bus-mapping/scroll", "eth-types/scroll", "external-tracer/scroll", "mock/scroll", "zkevm-circuits/scroll", "prover?/scroll"]
parallel_syn = ["halo2_proofs/parallel_syn", "zkevm-circuits/parallel_syn", "prover?/parallel_syn"]
inner-prove = ["prover", "parallel_syn", "scroll", "shanghai"]
chunk-prove = ["prover", "parallel_syn", "scroll", "shanghai"]
6 changes: 6 additions & 0 deletions testool/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.PHONY: download-setup

# Could be called as `make download-setup -e degree=DEGREE params_dir=PARAMS_DIR`.
# As default `degree=26` and `params_dir=./test_params`.
download-setup:
sh download_setup.sh ${degree} ${params_dir}
15 changes: 15 additions & 0 deletions testool/download_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set -x
set -e

# Set degree to env AGG_DEGREE, first input or default value 26.
degree="${AGG_DEGREE:-${1:-26}}"

# Set the output dir to second input or default as `./test_params`.
params_dir="${2:-"./test_params"}"
mkdir -p "$params_dir"

output_file="$params_dir"/params"${degree}"
rm -f "$output_file"

# degree 1 - 26
axel -ac https://circuit-release.s3.us-west-2.amazonaws.com/setup/params"$degree" -o "$output_file"
Loading

0 comments on commit 25c5810

Please sign in to comment.