Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit a8c2733

Browse files
committed
more refactoring and better inline docs
1 parent 667ace4 commit a8c2733

File tree

6 files changed

+160
-97
lines changed

6 files changed

+160
-97
lines changed

prover/src/zkevm.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
#[cfg(feature = "scroll")]
22
mod capacity_checker;
3+
#[cfg(feature = "scroll")]
4+
pub use capacity_checker::{CircuitCapacityChecker, RowUsage, SubCircuitRowUsage};
5+
36
pub mod circuit;
7+
48
mod error;
9+
pub use error::ChunkProverError;
10+
511
mod prover;
6-
mod verifier;
12+
pub use prover::Prover;
713

8-
pub use self::prover::Prover;
9-
#[cfg(feature = "scroll")]
10-
pub use capacity_checker::{CircuitCapacityChecker, RowUsage};
11-
pub use error::ChunkProverError;
12-
use serde::{Deserialize, Serialize};
14+
mod verifier;
1315
pub use verifier::Verifier;
1416

15-
#[derive(Debug, Clone, Deserialize, Serialize)]
16-
pub struct SubCircuitRowUsage {
17-
pub name: String,
18-
pub row_number: usize,
19-
}
17+
/// Alias to be re-exported.
18+
pub type ChunkProver<'a> = Prover<'a>;
19+
20+
/// Alias to be re-exported.
21+
pub type ChunkVerifier<'a> = Verifier<'a>;

prover/src/zkevm/capacity_checker.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use super::circuit::{calculate_row_usage_of_witness_block, finalize_builder};
2-
use bus_mapping::circuit_input_builder::{self, CircuitInputBuilder};
1+
use bus_mapping::circuit_input_builder::{Blocks, CircuitInputBuilder};
32
use eth_types::{
43
l2_types::BlockTrace,
54
state_db::{CodeDB, StateDB},
@@ -14,7 +13,13 @@ use zkevm_circuits::{
1413
super_circuit::params::{get_sub_circuit_limit_and_confidence, get_super_circuit_params},
1514
};
1615

17-
pub use super::SubCircuitRowUsage;
16+
use super::circuit::{calculate_row_usage_of_witness_block, finalize_builder};
17+
18+
#[derive(Debug, Clone, Deserialize, Serialize)]
19+
pub struct SubCircuitRowUsage {
20+
pub name: String,
21+
pub row_number: usize,
22+
}
1823

1924
#[derive(Debug, Clone, Deserialize, Serialize)]
2025
pub struct RowUsage {
@@ -145,8 +150,7 @@ impl CircuitCapacityChecker {
145150
// the previous one and do not use zktrie state,
146151
// notice the prev_root in current builder may be not invalid (since the state has
147152
// changed but we may not update it in light mode)
148-
let mut builder_block =
149-
circuit_input_builder::Blocks::init(trace.chain_id, get_super_circuit_params());
153+
let mut builder_block = Blocks::init(trace.chain_id, get_super_circuit_params());
150154
builder_block.start_l1_queue_index = trace.start_l1_queue_index;
151155
builder_block.prev_state_root = mpt_state
152156
.as_ref()

prover/src/zkevm/circuit/builder.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::zkevm::{ChunkProverError, SubCircuitRowUsage};
21
use bus_mapping::{circuit_input_builder::CircuitInputBuilder, Error as CircuitBuilderError};
32
use eth_types::{l2_types::BlockTrace, ToWord};
43
use itertools::Itertools;
@@ -9,6 +8,10 @@ use zkevm_circuits::{
98
witness::block_convert,
109
};
1110

11+
use crate::zkevm::{ChunkProverError, SubCircuitRowUsage};
12+
13+
/// Returns the row-usage for all sub-circuits in the process of applying the entire witness block
14+
/// to the super circuit.
1215
pub fn calculate_row_usage_of_witness_block(
1316
witness_block: &Block,
1417
) -> Result<Vec<SubCircuitRowUsage>, ChunkProverError> {
@@ -45,14 +48,17 @@ pub fn calculate_row_usage_of_witness_block(
4548
.collect_vec())
4649
}
4750

48-
pub fn dummy_witness_block() -> anyhow::Result<Block> {
49-
log::debug!("generate dummy witness block");
51+
/// Generate a dummy witness block to eventually generate proving key and verifying key for the
52+
/// target circuit without going through the expensive process of actual witness assignment.
53+
pub fn dummy_witness_block() -> Block {
5054
let dummy_chain_id = 0;
51-
let witness_block = zkevm_circuits::witness::dummy_witness_block(dummy_chain_id);
52-
log::debug!("generate dummy witness block done");
53-
Ok(witness_block)
55+
zkevm_circuits::witness::dummy_witness_block(dummy_chain_id)
5456
}
5557

58+
/// Build a witness block from block traces for all blocks in the chunk.
59+
///
60+
/// Kind of a duplication of [`self::chunk_trace_to_witness_block`], so should eventually be
61+
/// deprecated.
5662
pub fn block_traces_to_witness_block(
5763
block_traces: Vec<BlockTrace>,
5864
) -> Result<Block, ChunkProverError> {
@@ -103,6 +109,7 @@ pub fn block_traces_to_witness_block(
103109
Ok(witness_block)
104110
}
105111

112+
/// Build a witness block from block traces for all blocks in the chunk.
106113
pub fn chunk_trace_to_witness_block(
107114
chunk_trace: Vec<BlockTrace>,
108115
) -> Result<Block, ChunkProverError> {

prover/src/zkevm/circuit.rs renamed to prover/src/zkevm/circuit/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,28 @@ use snark_verifier_sdk::CircuitExt;
33
use zkevm_circuits::{super_circuit::params::ScrollSuperCircuit, util::SubCircuit, witness};
44

55
mod builder;
6-
pub use self::builder::{
6+
pub use builder::{
77
block_traces_to_witness_block, calculate_row_usage_of_witness_block,
88
chunk_trace_to_witness_block, finalize_builder,
99
};
1010

11-
pub use zkevm_circuits::super_circuit::params::{MAX_CALLDATA, MAX_INNER_BLOCKS, MAX_TXS};
12-
1311
/// A target circuit trait is a wrapper of inner circuit, with convenient APIs for building
1412
/// circuits from traces.
1513
pub trait TargetCircuit {
1614
/// The actual inner circuit that implements Circuit trait.
1715
type Inner: CircuitExt<Fr> + SubCircuit<Fr>;
1816

19-
/// Generate a dummy circuit with an empty trace.
20-
/// This is useful for generating vk and pk.
17+
/// Generate a dummy circuit with an empty trace. This is useful for generating vk and pk.
2118
fn dummy_inner_circuit() -> anyhow::Result<Self::Inner>
2219
where
2320
Self: Sized,
2421
{
25-
let witness_block = builder::dummy_witness_block()?;
22+
let witness_block = builder::dummy_witness_block();
2623
let circuit = Self::from_witness_block(&witness_block)?;
2724
Ok(circuit)
2825
}
2926

30-
/// Build the inner circuit and the instances from the witness block
27+
/// Build the inner circuit and the instances from the witness block.
3128
fn from_witness_block(witness_block: &witness::Block) -> anyhow::Result<Self::Inner>
3229
where
3330
Self: Sized,

0 commit comments

Comments
 (0)