Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ repository = "https://github.com/scroll-tech/scroll"
version = "4.7.1"

[workspace.dependencies]
scroll-zkvm-prover = { git = "https://github.com/scroll-tech/zkvm-prover", branch = "feat/galileo" }
scroll-zkvm-verifier = { git = "https://github.com/scroll-tech/zkvm-prover", branch = "feat/galileo" }
scroll-zkvm-types = { git = "https://github.com/scroll-tech/zkvm-prover", branch = "feat/galileo" }
scroll-zkvm-prover = { git = "https://github.com/scroll-tech/zkvm-prover", tag = "v0.7.0-rc.4" }
scroll-zkvm-verifier = { git = "https://github.com/scroll-tech/zkvm-prover", tag = "v0.7.0-rc.4" }
scroll-zkvm-types = { git = "https://github.com/scroll-tech/zkvm-prover", tag = "v0.7.0-rc.4" }

sbv-primitives = { git = "https://github.com/scroll-tech/stateless-block-verifier", tag = "scroll-v91", features = ["scroll", "rkyv"] }
sbv-utils = { git = "https://github.com/scroll-tech/stateless-block-verifier", tag = "scroll-v91" }
Expand Down
37 changes: 30 additions & 7 deletions crates/libzkp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use verifier::{TaskType, VerifierConfig};
mod utils;

use sbv_primitives::B256;
use scroll_zkvm_types::utils::vec_as_base64;
use scroll_zkvm_types::{utils::vec_as_base64, version::Version};
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue;
use std::{collections::HashMap, path::Path, sync::OnceLock};
Expand Down Expand Up @@ -138,35 +138,56 @@ pub fn gen_universal_task(
let mut task = serde_json::from_str::<ChunkProvingTask>(task_json)?;
// normailze fork name field in task
task.fork_name = task.fork_name.to_lowercase();
let version = Version::from(task.version);
// always respect the fork_name_str (which has been normalized) being passed
// if the fork_name wrapped in task is not match, consider it a malformed task
if fork_name_str != task.fork_name.as_str() {
eyre::bail!("fork name in chunk task not match the calling arg, expected {fork_name_str}, get {}", task.fork_name);
}
if fork_name_str != version.fork.as_str() {
eyre::bail!(
"given task version, expected fork={fork_name_str}, got={version_fork}",
version_fork = version.fork.as_str()
);
}
let (pi_hash, metadata, u_task) =
utils::panic_catch(move || gen_universal_chunk_task(task, fork_name_str.into()))
utils::panic_catch(move || gen_universal_chunk_task(task))
.map_err(|e| eyre::eyre!("caught panic in chunk task{e}"))??;
(pi_hash, AnyMetaData::Chunk(metadata), u_task)
}
x if x == TaskType::Batch as i32 => {
let mut task = serde_json::from_str::<BatchProvingTask>(task_json)?;
task.fork_name = task.fork_name.to_lowercase();
let version = Version::from(task.version);
if fork_name_str != task.fork_name.as_str() {
eyre::bail!("fork name in batch task not match the calling arg, expected {fork_name_str}, get {}", task.fork_name);
}
if fork_name_str != version.fork.as_str() {
eyre::bail!(
"given task version, expected fork={fork_name_str}, got={version_fork}",
version_fork = version.fork.as_str()
);
}
let (pi_hash, metadata, u_task) =
utils::panic_catch(move || gen_universal_batch_task(task, fork_name_str.into()))
utils::panic_catch(move || gen_universal_batch_task(task))
.map_err(|e| eyre::eyre!("caught panic in chunk task{e}"))??;
(pi_hash, AnyMetaData::Batch(metadata), u_task)
}
x if x == TaskType::Bundle as i32 => {
let mut task = serde_json::from_str::<BundleProvingTask>(task_json)?;
task.fork_name = task.fork_name.to_lowercase();
let version = Version::from(task.version);
if fork_name_str != task.fork_name.as_str() {
eyre::bail!("fork name in bundle task not match the calling arg, expected {fork_name_str}, get {}", task.fork_name);
}
if fork_name_str != version.fork.as_str() {
eyre::bail!(
"given task version, expected fork={fork_name_str}, got={version_fork}",
version_fork = version.fork.as_str()
);
}
let (pi_hash, metadata, u_task) =
utils::panic_catch(move || gen_universal_bundle_task(task, fork_name_str.into()))
utils::panic_catch(move || gen_universal_bundle_task(task))
.map_err(|e| eyre::eyre!("caught panic in chunk task{e}"))??;
(pi_hash, AnyMetaData::Bundle(metadata), u_task)
}
Expand Down Expand Up @@ -233,9 +254,11 @@ pub fn verifier_init(config: &str) -> eyre::Result<()> {
);
(
config.fork_name.to_lowercase(),
config.features.as_ref()
.map(|features| FeatureOptions::new(features.as_str()))
.unwrap_or_default()
config
.features
.as_ref()
.map(|features| FeatureOptions::new(features.as_str()))
.unwrap_or_default(),
)
})))
.map_err(|c| eyre::eyre!("Fail to init additional features: {c:?}"))?;
Expand Down
2 changes: 0 additions & 2 deletions crates/libzkp/src/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ impl ProofMetadata for ChunkProofMetadata {
pub struct BatchProofMetadata {
/// The batch information describing the list of chunks.
pub batch_info: BatchInfo,
/// The [`scroll_zkvm_types::batch::BatchHeader`]'s digest.
pub batch_hash: B256,
}

impl ProofMetadata for BatchProofMetadata {
Expand Down
16 changes: 4 additions & 12 deletions crates/libzkp/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
utils::panic_catch,
};
use sbv_primitives::B256;
use scroll_zkvm_types::public_inputs::{ForkName, MultiVersionPublicInputs, Version};
use scroll_zkvm_types::public_inputs::{MultiVersionPublicInputs, Version};

fn encode_task_to_witness<T: serde::Serialize>(task: &T) -> eyre::Result<Vec<u8>> {
let config = bincode::config::standard();
Expand Down Expand Up @@ -61,7 +61,6 @@ impl ProvintTaskExt {
/// Generate required staff for chunk proving
pub fn gen_universal_chunk_task(
task: ChunkProvingTask,
_: ForkName,
) -> eyre::Result<(B256, ChunkProofMetadata, ProvingTask)> {
let chunk_total_gas = task.stats().total_gas_used;
let (chunk_info, pi_hash) = task.precheck_and_build_metadata()?;
Expand All @@ -79,29 +78,22 @@ pub fn gen_universal_chunk_task(
/// Generate required staff for batch proving
pub fn gen_universal_batch_task(
task: BatchProvingTask,
_: ForkName,
) -> eyre::Result<(B256, BatchProofMetadata, ProvingTask)> {
let (batch_info, batch_hash) = task.precheck_and_build_metadata()?;
let (batch_info, batch_pi_hash) = task.precheck_and_build_metadata()?;
let proving_task = task.try_into()?;

Ok((
batch_hash,
BatchProofMetadata {
batch_info,
batch_hash,
},
batch_pi_hash,
BatchProofMetadata { batch_info },
proving_task,
))
}

/// Generate required staff for bundle proving
pub fn gen_universal_bundle_task(
task: BundleProvingTask,
_: ForkName,
) -> eyre::Result<(B256, BundleProofMetadata, ProvingTask)> {
let (bundle_info, bundle_pi_hash) = task.precheck_and_build_metadata()?;
let proving_task = task.try_into()?;

Ok((
bundle_pi_hash,
BundleProofMetadata {
Expand Down
43 changes: 15 additions & 28 deletions crates/libzkp/src/tasks/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use eyre::Result;
use sbv_primitives::{B256, U256};
use scroll_zkvm_types::{
batch::{
build_point_eval_witness, BatchHeader, BatchHeaderV6, BatchHeaderV7, BatchHeaderV8,
BatchHeaderValidium, BatchInfo, BatchWitness, Envelope, EnvelopeV6, EnvelopeV7, EnvelopeV8,
LegacyBatchWitness, ReferenceHeader, N_BLOB_BYTES,
build_point_eval_witness, BatchHeader, BatchHeaderV6, BatchHeaderV7, BatchHeaderValidium,
BatchInfo, BatchWitness, Envelope, EnvelopeV6, EnvelopeV7, LegacyBatchWitness,
ReferenceHeader, N_BLOB_BYTES,
},
chunk::ChunkInfo,
public_inputs::{ForkName, Version, MultiVersionPublicInputs},
public_inputs::{ForkName, MultiVersionPublicInputs, Version},
task::ProvingTask,
utils::{to_rkyv_bytes, RancorError},
version::{Codec, Domain, STFVersion},
Expand All @@ -34,6 +34,7 @@ pub struct BatchHeaderValidiumWithHash {
/// defination, i.e. v6- v8 (current), and validium
#[derive(Clone, serde::Deserialize, serde::Serialize)]
#[serde(untagged)]
#[allow(non_camel_case_types)]
pub enum BatchHeaderV {
/// Header for validium mode.
Validium(BatchHeaderValidiumWithHash),
Expand All @@ -43,14 +44,14 @@ pub enum BatchHeaderV {
///
/// Since the codec essentially is unchanged for the above STF versions, we do not define new
/// variants, instead re-using the [`BatchHeaderV7`] variant.
V7_8_9(BatchHeaderV7),
V7_V8_V9(BatchHeaderV7),
}

impl core::fmt::Display for BatchHeaderV {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
BatchHeaderV::V6(_) => write!(f, "V6"),
BatchHeaderV::V7_8_9(_) => write!(f, "V7_8_9"),
BatchHeaderV::V7_V8_V9(_) => write!(f, "V7_V8_V9"),
BatchHeaderV::Validium(_) => write!(f, "Validium"),
}
}
Expand All @@ -60,7 +61,7 @@ impl BatchHeaderV {
pub fn batch_hash(&self) -> B256 {
match self {
BatchHeaderV::V6(h) => h.batch_hash(),
BatchHeaderV::V7_8_9(h) => h.batch_hash(),
BatchHeaderV::V7_V8_V9(h) => h.batch_hash(),
BatchHeaderV::Validium(h) => h.header.batch_hash(),
}
}
Expand All @@ -72,17 +73,10 @@ impl BatchHeaderV {
}
}

pub fn must_v7_header(&self) -> &BatchHeaderV7 {
pub fn must_v7_v8_v9_header(&self) -> &BatchHeaderV7 {
match self {
BatchHeaderV::V7_8_9(h) => h,
_ => unreachable!("A header of {} is considered to be v7", self),
}
}

pub fn must_v8_header(&self) -> &BatchHeaderV8 {
match self {
BatchHeaderV::V7_8_9(h) => h,
_ => unreachable!("A header of {} is considered to be v8", self),
BatchHeaderV::V7_V8_V9(h) => h,
_ => unreachable!("A header of {} is considered to be in [v7, v8, v9]", self),
}
}

Expand Down Expand Up @@ -162,10 +156,8 @@ impl BatchProvingTask {
version.fork,
ForkName::EuclidV1,
),
BatchHeaderV::V7_8_9(_) => assert!(
version.fork == ForkName::EuclidV2 ||
version.fork == ForkName::Feynman ||
version.fork == ForkName::Galileo,
BatchHeaderV::V7_V8_V9(_) => assert!(
matches!(version.fork, ForkName::EuclidV2 | ForkName::Feynman | ForkName::Galileo),
"hardfork mismatch for da-codec@v7/8/9 header: found={}, expected={:?}",
version.fork,
[ForkName::EuclidV2, ForkName::Feynman, ForkName::Galileo],
Expand All @@ -192,8 +184,6 @@ impl BatchProvingTask {
}
Codec::V7 => <EnvelopeV7 as Envelope>::from_slice(padded_blob_bytes.as_slice())
.challenge_digest(versioned_hash),
Codec::V8 => <EnvelopeV8 as Envelope>::from_slice(padded_blob_bytes.as_slice())
.challenge_digest(versioned_hash),
};
let (proof, _) = point_eval::get_kzg_proof(&blob, challenge_digest);

Expand Down Expand Up @@ -242,9 +232,6 @@ impl BatchProvingTask {
(Domain::Scroll, STFVersion::V6) => {
ReferenceHeader::V6(*self.batch_header.must_v6_header())
}
(Domain::Scroll, STFVersion::V7) => {
ReferenceHeader::V7(*self.batch_header.must_v7_header())
}
// The da-codec for STF versions v7, v8, v9 is identical. In zkvm-prover we do not
// create additional variants to indicate the identical behaviour of codec. Instead we
// add a separate variant for the STF version.
Expand All @@ -255,8 +242,8 @@ impl BatchProvingTask {
// hard-fork (feynman or galileo) and the codec from the version byte.
//
// Refer [`scroll_zkvm_types::public_inputs::Version`].
(Domain::Scroll, STFVersion::V8) | (Domain::Scroll, STFVersion::V9) => {
ReferenceHeader::V8(*self.batch_header.must_v8_header())
(Domain::Scroll, STFVersion::V7 | STFVersion::V8 | STFVersion::V9) => {
ReferenceHeader::V7_V8_V9(*self.batch_header.must_v7_v8_v9_header())
}
(Domain::Validium, STFVersion::V1) => {
ReferenceHeader::Validium(*self.batch_header.must_validium_header())
Expand Down
4 changes: 3 additions & 1 deletion crates/libzkp/src/tasks/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use eyre::Result;
use sbv_primitives::B256;
use scroll_zkvm_types::{
bundle::{BundleInfo, BundleWitness, LegacyBundleWitness},
public_inputs::{Version, MultiVersionPublicInputs},
public_inputs::{MultiVersionPublicInputs, Version},
task::ProvingTask,
utils::{to_rkyv_bytes, RancorError},
};
Expand Down Expand Up @@ -33,11 +33,13 @@ impl BundleProvingTask {
.first()
.expect(BUNDLE_SANITY_MSG)
.metadata
.batch_info
.batch_hash,
self.batch_proofs
.last()
.expect(BUNDLE_SANITY_MSG)
.metadata
.batch_info
.batch_hash,
);

Expand Down
2 changes: 1 addition & 1 deletion crates/libzkp/src/tasks/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use sbv_core::BlockWitness;
use sbv_primitives::{types::consensus::BlockHeader, B256};
use scroll_zkvm_types::{
chunk::{execute, ChunkInfo, ChunkWitness, LegacyChunkWitness, ValidiumInputs},
public_inputs::{MultiVersionPublicInputs, Version},
task::ProvingTask,
utils::{to_rkyv_bytes, RancorError},
public_inputs::{Version, MultiVersionPublicInputs},
};

use super::chunk_interpreter::*;
Expand Down