diff --git a/crates/libzkp/src/lib.rs b/crates/libzkp/src/lib.rs index c81865738..5186b29e1 100644 --- a/crates/libzkp/src/lib.rs +++ b/crates/libzkp/src/lib.rs @@ -2,22 +2,28 @@ pub mod proofs; pub mod tasks; pub use tasks::ProvintTaskExt; pub mod verifier; -pub use verifier::{TaskType, VerifierConfig}; use verifier::HardForkName; +pub use verifier::{TaskType, VerifierConfig}; mod utils; use sbv_primitives::B256; use scroll_zkvm_types::utils::vec_as_base64; use serde::{Deserialize, Serialize}; use serde_json::value::RawValue; -use std::{path::Path, sync::OnceLock, collections::HashMap}; +use std::{collections::HashMap, path::Path, sync::OnceLock}; use tasks::chunk_interpreter::{ChunkInterpreter, TryFromWithInterpreter}; pub(crate) fn witness_use_legacy_mode(fork_name: &str) -> eyre::Result { - ADDITIONAL_FEATURES.get().and_then( - |features|features.get(fork_name) - ).map(|cfg|cfg.legacy_witness_encoding) - .ok_or_else(||eyre::eyre!("can not found features setting for unrecognized fork {}", fork_name)) + ADDITIONAL_FEATURES + .get() + .and_then(|features| features.get(fork_name)) + .map(|cfg| cfg.legacy_witness_encoding) + .ok_or_else(|| { + eyre::eyre!( + "can not found features setting for unrecognized fork {}", + fork_name + ) + }) } #[derive(Debug, Default, Clone)] @@ -30,7 +36,7 @@ static ADDITIONAL_FEATURES: OnceLock> = On impl FeatureOptions { pub fn new(feats: &str) -> Self { - let mut ret : Self = Default::default(); + let mut ret: Self = Default::default(); for feat_s in feats.split(':') { match feat_s.trim().to_lowercase().as_str() { @@ -172,12 +178,16 @@ pub fn gen_universal_task( let mut u_task_ext = ProvintTaskExt::new(u_task); // set additional settings from global features - if let Some(cfg) = ADDITIONAL_FEATURES.get().and_then( - |features|features.get(&fork_name) - ){ - u_task_ext.use_openvm_13 = cfg.for_openvm_13_prover; + if let Some(cfg) = ADDITIONAL_FEATURES + .get() + .and_then(|features| features.get(&fork_name)) + { + u_task_ext.use_openvm_13 = cfg.for_openvm_13_prover; } else { - tracing::warn!("can not found features setting for unrecognized fork {}", fork_name); + tracing::warn!( + "can not found features setting for unrecognized fork {}", + fork_name + ); } Ok(( @@ -214,15 +224,21 @@ pub fn gen_wrapped_proof(proof_json: &str, metadata: &str, vk: &[u8]) -> eyre::R /// init verifier pub fn verifier_init(config: &str) -> eyre::Result<()> { let cfg: VerifierConfig = serde_json::from_str(config)?; - ADDITIONAL_FEATURES.set( - HashMap::from_iter(cfg.circuits.iter().map(|config|{ - tracing::info!("start setting features [{}] for fork {}", config.features, config.fork_name); - (config.fork_name.to_lowercase(), FeatureOptions::new(&config.features)) - }, - )), - ).map_err(|c|eyre::eyre!("Fail to init additional features: {c:?}"))?; + ADDITIONAL_FEATURES + .set(HashMap::from_iter(cfg.circuits.iter().map(|config| { + tracing::info!( + "start setting features [{}] for fork {}", + config.features, + config.fork_name + ); + ( + config.fork_name.to_lowercase(), + FeatureOptions::new(&config.features), + ) + }))) + .map_err(|c| eyre::eyre!("Fail to init additional features: {c:?}"))?; - verifier::init(cfg); + verifier::init(cfg); Ok(()) } diff --git a/crates/libzkp/src/tasks/batch.rs b/crates/libzkp/src/tasks/batch.rs index 6d2f19c97..b1100e4a6 100644 --- a/crates/libzkp/src/tasks/batch.rs +++ b/crates/libzkp/src/tasks/batch.rs @@ -11,7 +11,7 @@ use scroll_zkvm_types::{ public_inputs::{ForkName, Version}, task::ProvingTask, utils::{to_rkyv_bytes, RancorError}, - version::{Domain, STFVersion, Codec}, + version::{Codec, Domain, STFVersion}, }; use crate::proofs::ChunkProof; @@ -28,7 +28,7 @@ pub struct BatchHeaderValidiumWithHash { /// Parse header types passed from golang side and adapt to the /// defination in zkvm-prover's types -/// We distinguish the header type in golang side according to the codec +/// We distinguish the header type in golang side according to the codec /// version, i.e. v6 - v9 (current), and validium /// And adapt it to different header version used in zkvm-prover's witness /// defination, i.e. v6- v8 (current), and validium @@ -141,7 +141,11 @@ impl TryFrom for ProvingTask { impl BatchProvingTask { fn build_guest_input(&self) -> BatchWitness { let version = Version::from(self.version); - tracing::info!("Handling batch task for input, version byte {}, Version data: {:?}", self.version, version); + tracing::info!( + "Handling batch task for input, version byte {}, Version data: {:?}", + self.version, + version + ); // sanity check for if result of header type parsing match to version match &self.batch_header { BatchHeaderV::Validium(_) => assert!( @@ -160,7 +164,7 @@ impl BatchProvingTask { "hardfork mismatch for da-codec@v7/8/9 header: found={}, expected={:?}", version.fork, [ForkName::EuclidV2, ForkName::Feynman, ForkName::Galileo], - ), + ), } let point_eval_witness = if !version.is_validium() { @@ -169,7 +173,7 @@ impl BatchProvingTask { let blob = point_eval::to_blob(&self.blob_bytes); let commitment = point_eval::blob_to_kzg_commitment(&blob); let versioned_hash = point_eval::get_versioned_hash(&commitment); - + let padded_blob_bytes = { let mut padded_blob_bytes = self.blob_bytes.to_vec(); padded_blob_bytes.resize(N_BLOB_BYTES, 0); @@ -181,14 +185,10 @@ impl BatchProvingTask { ::from_slice(self.blob_bytes.as_slice()) .challenge_digest(versioned_hash) } - Codec::V7 => { - ::from_slice(padded_blob_bytes.as_slice()) - .challenge_digest(versioned_hash) - } - Codec::V8 => { - ::from_slice(padded_blob_bytes.as_slice()) - .challenge_digest(versioned_hash) - } + Codec::V7 => ::from_slice(padded_blob_bytes.as_slice()) + .challenge_digest(versioned_hash), + Codec::V8 => ::from_slice(padded_blob_bytes.as_slice()) + .challenge_digest(versioned_hash), }; let (proof, _) = point_eval::get_kzg_proof(&blob, challenge_digest); @@ -240,7 +240,7 @@ impl BatchProvingTask { (Domain::Scroll, STFVersion::V7) => { ReferenceHeader::V7(*self.batch_header.must_v7_header()) } - (Domain::Scroll, STFVersion::V8) | (Domain::Scroll, STFVersion::V9)=> { + (Domain::Scroll, STFVersion::V8) | (Domain::Scroll, STFVersion::V9) => { ReferenceHeader::V8(*self.batch_header.must_v8_header()) } (Domain::Validium, STFVersion::V1) => { diff --git a/crates/prover-bin/src/prover.rs b/crates/prover-bin/src/prover.rs index 08b9b26e5..97fb535e4 100644 --- a/crates/prover-bin/src/prover.rs +++ b/crates/prover-bin/src/prover.rs @@ -298,10 +298,8 @@ impl LocalProver { .location_data .get_asset(&vk, &url_base, &base_config.workspace_path) .await?; - let circuits_handler = Arc::new(Mutex::new(UniversalHandler::new( - &asset_path, - &task_cfg, - )?)); + let circuits_handler = + Arc::new(Mutex::new(UniversalHandler::new(&asset_path, &task_cfg)?)); self.handlers.insert(vk, circuits_handler.clone()); circuits_handler }; diff --git a/crates/prover-bin/src/zk_circuits_handler/universal.rs b/crates/prover-bin/src/zk_circuits_handler/universal.rs index d3dc45a68..10532db5a 100644 --- a/crates/prover-bin/src/zk_circuits_handler/universal.rs +++ b/crates/prover-bin/src/zk_circuits_handler/universal.rs @@ -3,9 +3,9 @@ use std::path::Path; use super::CircuitsHandler; use async_trait::async_trait; use eyre::Result; +use libzkp::ProvintTaskExt; use scroll_zkvm_prover::{Prover, ProverConfig}; use scroll_zkvm_types::ProvingTask; -use libzkp::ProvintTaskExt; use tokio::sync::Mutex; pub struct UniversalHandler { prover: Prover, @@ -14,7 +14,7 @@ pub struct UniversalHandler { // additional config dispatched with proving task #[derive(Debug, Default)] pub(crate) struct TaskConfig { - pub is_openvm_v13: bool + pub is_openvm_v13: bool, } /// Safe for current usage as `CircuitsHandler` trait (protected inside of Mutex and NEVER extract @@ -44,7 +44,7 @@ impl UniversalHandler { } pub fn get_task_from_input(input: &str) -> Result<(ProvingTask, TaskConfig)> { - let task_ext : ProvintTaskExt = serde_json::from_str(input)?; + let task_ext: ProvintTaskExt = serde_json::from_str(input)?; let cfg = TaskConfig { is_openvm_v13: task_ext.use_openvm_13, };