Skip to content

Commit 7fd6b6d

Browse files
roynalnarutolispc
andauthored
Upgrade-5: prover Refactor (#1446)
* chunk prover error and refactor * layer-2 compress only (sp1 chunk proof) * more refactoring and better inline docs * refactor prover::aggregator module * return BatchProverError instead of using anyhow * tidy up lib.rs of prover crate * refactor prover::types and minor changes * more refactoring * move more modules into prover::utils * proof v2 * use bundle proof v2 * chore: fmt + clippy * fix building * fix building * test: bundle proof v2 can be serialised * fix: bundle proof calldata * chore: remove unused util methods * fix: dump YUL code for verifier --------- Co-authored-by: Zhang Zhuo <[email protected]>
1 parent 940d55f commit 7fd6b6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2206
-1287
lines changed

Cargo.lock

+114-50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aggregator/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ num-bigint.workspace = true
3838

3939
# da-compression
4040
bitstream-io = "2.2.0"
41-
zstd-encoder = { package = "encoder", git = "https://github.com/scroll-tech/da-codec.git", tag = "v0.1.0" }
41+
zstd-encoder = { package = "encoder", git = "https://github.com/scroll-tech/da-codec.git", tag = "v0.1.2" }
4242

4343
[dev-dependencies]
4444

aggregator/src/blob_consistency.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ mod eip4844;
1919
cfg_if! {
2020
if #[cfg(feature = "da-avail")] {
2121
// const DATA_AVAILABILITY: DataAvailability = DataAvailability::Avail;
22-
pub use avail::{BlobConsistencyConfig, BlobConsistencyWitness, BLOB_WIDTH};
22+
pub use avail::{BlobConsistencyConfig, BlobConsistencyWitness, BLOB_WIDTH, get_blob_bytes};
2323
} else {
2424
// const DATA_AVAILABILITY: DatayAvailability = DataAvailability::Eip4844;
25-
pub use eip4844::{BlobConsistencyConfig, BlobConsistencyWitness, BLOB_WIDTH};
25+
pub use eip4844::{BlobConsistencyConfig, BlobConsistencyWitness, BLOB_WIDTH, get_blob_bytes};
2626
}
2727
}

aggregator/src/blob_consistency/avail.rs

+5
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,8 @@ pub struct AssignedBarycentricEvaluationConfig {
9898
/// 32 Assigned cells representing the LE-bytes of evaluation y.
9999
pub(crate) y_le: Vec<AssignedValue<Fr>>,
100100
}
101+
102+
/// Get the blob data bytes that will be populated in BlobDataConfig.
103+
pub fn get_blob_bytes(_batch_bytes: &[u8]) -> Vec<u8> {
104+
unimplemented!("trick for linting");
105+
}

aggregator/src/blob_consistency/eip4844.rs

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ fn kzg_to_versioned_hash(commitment: &c_kzg::KzgCommitment) -> H256 {
8484
H256::from_slice(&res[..])
8585
}
8686

87-
#[cfg(test)]
8887
/// Get the blob data bytes that will be populated in BlobDataConfig.
8988
pub fn get_blob_bytes(batch_bytes: &[u8]) -> Vec<u8> {
9089
let mut blob_bytes = crate::witgen::zstd_encode(batch_bytes);

aggregator/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod tests;
2727
pub use self::core::extract_proof_and_instances_with_pairing_check;
2828
pub use aggregation::*;
2929
pub use batch::{BatchHash, BatchHeader};
30+
pub use blob_consistency::get_blob_bytes;
3031
pub use chunk::ChunkInfo;
3132
pub use compression::*;
3233
pub use constants::MAX_AGG_SNARKS;

prover/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ serde.workspace = true
3434
serde_derive = "1.0"
3535
serde_json = { workspace = true, features = ["unbounded_depth"] }
3636
serde_stacker.workspace = true
37+
thiserror = "1.0"
3738
sha2 ="0.10.2"
3839
revm = { version = "17.1.0", default-features = false, features = ["std"] }
3940

41+
[dev-dependencies]
42+
tempdir = "0.3"
43+
4044
[features]
4145
default = ["scroll"]
4246
parallel_syn = ["halo2_proofs/parallel_syn", "zkevm-circuits/parallel_syn"]

prover/src/aggregator.rs

-6
This file was deleted.

prover/src/aggregator/error.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/// Errors encountered in the proof generation pipeline for batch and bundle proving.
2+
#[derive(thiserror::Error, Debug)]
3+
pub enum BatchProverError {
4+
/// Represents a mismatch in the verifying key at the specified proof layer.
5+
#[error("verifying key mismatch: layer={0}, expected={1}, found={2}")]
6+
VerifyingKeyMismatch(crate::config::LayerId, String, String),
7+
/// Verifying key for the specified layer was not found in the prover.
8+
#[error("verifying key not found: layer={0}, expected={1}")]
9+
VerifyingKeyNotFound(crate::config::LayerId, String),
10+
/// Sanity check failure indicating that the [`Snark`][snark_verifier_sdk::Snark]
11+
/// [`protocol`][snark_verifier::Protocol] did not match the expected protocols.
12+
#[error("SNARK protocol mismatch: index={0}, expected={1}, found={2}")]
13+
ChunkProtocolMismatch(usize, String, String),
14+
/// Indicates that after generating an EVM verifier contract, the proof itself could not be
15+
/// verified successfully, implying that this sanity check failed.
16+
#[error("EVM verifier contract could not verify proof")]
17+
SanityEVMVerifier,
18+
/// Error indicating that the verification of batch proof failed.
19+
#[error("proof verification failure")]
20+
Verification,
21+
/// Error indicating that the verifier contract's deployment code is not found.
22+
#[error("EVM verifier deployment code not found!")]
23+
VerifierCodeMissing,
24+
/// Error indicating that in the final [`BundleProof`][crate::BundleProofV2] the number of
25+
/// instances found does not match the number of instances expected.
26+
#[error("number of instances in bundle proof mismatch! expected={0}, got={1}")]
27+
PublicInputsMismatch(usize, usize),
28+
/// This variant represents other errors.
29+
#[error("custom: {0}")]
30+
Custom(String),
31+
}
32+
33+
impl From<String> for BatchProverError {
34+
fn from(value: String) -> Self {
35+
Self::Custom(value)
36+
}
37+
}
38+
39+
impl From<anyhow::Error> for BatchProverError {
40+
fn from(value: anyhow::Error) -> Self {
41+
Self::Custom(value.to_string())
42+
}
43+
}

prover/src/aggregator/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
mod error;
2+
pub use error::BatchProverError;
3+
4+
mod prover;
5+
pub use prover::{check_chunk_hashes, Prover};
6+
7+
mod recursion;
8+
pub use recursion::RecursionTask;
9+
10+
mod verifier;
11+
pub use verifier::Verifier;
12+
13+
/// Re-export some types from the [`aggregator`] crate.
14+
pub use aggregator::{get_blob_bytes, BatchData, BatchHash, BatchHeader, MAX_AGG_SNARKS};
15+
16+
/// Alias for convenience.
17+
pub type BatchProver<'a> = Prover<'a>;
18+
19+
/// Alias for convenience.
20+
pub type BatchVerifier<'a> = Verifier<'a>;

0 commit comments

Comments
 (0)