Skip to content

Commit 057c0ce

Browse files
committed
+ add v8 handling for batch
+ keep panic error in rust side + fixings according to review
1 parent 30c9728 commit 057c0ce

File tree

4 files changed

+71
-41
lines changed

4 files changed

+71
-41
lines changed

crates/libzkp/src/lib.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub use verifier::{TaskType, VerifierConfig};
55
mod utils;
66

77
use sbv_primitives::B256;
8-
use scroll_zkvm_types::{public_inputs::ForkName, util::vec_as_base64};
8+
use scroll_zkvm_types::util::vec_as_base64;
99
use serde::{Deserialize, Serialize};
1010
use serde_json::value::RawValue;
1111
use std::path::Path;
@@ -49,27 +49,39 @@ pub fn gen_universal_task(
4949
let (pi_hash, metadata, mut u_task) = match task_type {
5050
x if x == TaskType::Chunk as i32 => {
5151
let mut task = serde_json::from_str::<ChunkProvingTask>(task_json)?;
52-
let fork_name = ForkName::from(task.fork_name.to_lowercase().as_str());
53-
task.fork_name = fork_name.to_string();
54-
assert_eq!(fork_name_str, task.fork_name.as_str());
55-
let (pi_hash, metadata, u_task) =
56-
gen_universal_chunk_task(task, fork_name, interpreter)?;
52+
// normailze fork name field in task
53+
task.fork_name = task.fork_name.to_lowercase();
54+
// always respect the fork_name_str (which has been normalized) being passed
55+
// if the fork_name wrapped in task is not match, consider it a malformed task
56+
if fork_name_str != task.fork_name.as_str() {
57+
eyre::bail!("fork name in chunk task not match the calling arg, expected {fork_name_str}, get {}", task.fork_name);
58+
}
59+
let (pi_hash, metadata, u_task) = utils::panic_catch(move || {
60+
gen_universal_chunk_task(task, fork_name_str.into(), interpreter)
61+
})
62+
.map_err(|e| eyre::eyre!("catched panic in chunk task{e}"))??;
5763
(pi_hash, AnyMetaData::Chunk(metadata), u_task)
5864
}
5965
x if x == TaskType::Batch as i32 => {
6066
let mut task = serde_json::from_str::<BatchProvingTask>(task_json)?;
61-
let fork_name = ForkName::from(task.fork_name.to_lowercase().as_str());
62-
task.fork_name = fork_name.to_string();
63-
assert_eq!(fork_name_str, task.fork_name.as_str());
64-
let (pi_hash, metadata, u_task) = gen_universal_batch_task(task, fork_name)?;
67+
task.fork_name = task.fork_name.to_lowercase();
68+
if fork_name_str != task.fork_name.as_str() {
69+
eyre::bail!("fork name in batch task not match the calling arg, expected {fork_name_str}, get {}", task.fork_name);
70+
}
71+
let (pi_hash, metadata, u_task) =
72+
utils::panic_catch(move || gen_universal_batch_task(task, fork_name_str.into()))
73+
.map_err(|e| eyre::eyre!("catched panic in chunk task{e}"))??;
6574
(pi_hash, AnyMetaData::Batch(metadata), u_task)
6675
}
6776
x if x == TaskType::Bundle as i32 => {
6877
let mut task = serde_json::from_str::<BundleProvingTask>(task_json)?;
69-
let fork_name = ForkName::from(task.fork_name.to_lowercase().as_str());
70-
task.fork_name = fork_name.to_string();
71-
assert_eq!(fork_name_str, task.fork_name.as_str());
72-
let (pi_hash, metadata, u_task) = gen_universal_bundle_task(task, fork_name)?;
78+
task.fork_name = task.fork_name.to_lowercase();
79+
if fork_name_str != task.fork_name.as_str() {
80+
eyre::bail!("fork name in bundle task not match the calling arg, expected {fork_name_str}, get {}", task.fork_name);
81+
}
82+
let (pi_hash, metadata, u_task) =
83+
utils::panic_catch(move || gen_universal_bundle_task(task, fork_name_str.into()))
84+
.map_err(|e| eyre::eyre!("catched panic in chunk task{e}"))??;
7385
(pi_hash, AnyMetaData::Bundle(metadata), u_task)
7486
}
7587
_ => return Err(eyre::eyre!("unrecognized task type {task_type}")),

crates/libzkp/src/tasks.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ pub use chunk::{ChunkProvingTask, ChunkTask};
99
pub use chunk_interpreter::ChunkInterpreter;
1010
pub use scroll_zkvm_types::task::ProvingTask;
1111

12-
use crate::proofs::{self, BatchProofMetadata, BundleProofMetadata, ChunkProofMetadata};
12+
use crate::{
13+
proofs::{self, BatchProofMetadata, BundleProofMetadata, ChunkProofMetadata},
14+
utils::panic_catch,
15+
};
1316
use sbv_primitives::B256;
1417
use scroll_zkvm_types::public_inputs::{ForkName, MultiVersionPublicInputs};
1518

@@ -20,25 +23,14 @@ fn check_aggregation_proofs<Metadata>(
2023
where
2124
Metadata: proofs::ProofMetadata,
2225
{
23-
use std::panic::{self, AssertUnwindSafe};
24-
25-
panic::catch_unwind(AssertUnwindSafe(|| {
26+
panic_catch(|| {
2627
for w in proofs.windows(2) {
2728
w[1].metadata
2829
.pi_hash_info()
2930
.validate(w[0].metadata.pi_hash_info(), fork_name);
3031
}
31-
}))
32-
.map_err(|e| {
33-
let error_msg = if let Some(string) = e.downcast_ref::<String>() {
34-
string.clone()
35-
} else if let Some(str) = e.downcast_ref::<&str>() {
36-
str.to_string()
37-
} else {
38-
"Unknown validation error occurred".to_string()
39-
};
40-
eyre::eyre!("Chunk data validation failed: {}", error_msg)
41-
})?;
32+
})
33+
.map_err(|e| eyre::eyre!("Chunk data validation failed: {}", e))?;
4234

4335
Ok(())
4436
}

crates/libzkp/src/tasks/batch.rs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use eyre::Result;
44
use sbv_primitives::{B256, U256};
55
use scroll_zkvm_types::{
66
batch::{
7-
BatchHeader, BatchHeaderV6, BatchHeaderV7, BatchInfo, BatchWitness, Envelope, EnvelopeV6,
8-
EnvelopeV7, PointEvalWitness, ReferenceHeader, ToArchievedWitness, N_BLOB_BYTES,
7+
BatchHeader, BatchHeaderV6, BatchHeaderV7, BatchHeaderV8, BatchInfo, BatchWitness,
8+
Envelope, EnvelopeV6, EnvelopeV7, EnvelopeV8, PointEvalWitness, ReferenceHeader,
9+
ToArchievedWitness, N_BLOB_BYTES,
910
},
1011
public_inputs::ForkName,
1112
task::ProvingTask,
@@ -24,13 +25,15 @@ use utils::{base64, point_eval};
2425
pub enum BatchHeaderV {
2526
V6(BatchHeaderV6),
2627
V7(BatchHeaderV7),
28+
V8(BatchHeaderV8),
2729
}
2830

2931
impl From<BatchHeaderV> for ReferenceHeader {
3032
fn from(value: BatchHeaderV) -> Self {
3133
match value {
3234
BatchHeaderV::V6(h) => ReferenceHeader::V6(h),
3335
BatchHeaderV::V7(h) => ReferenceHeader::V7(h),
36+
BatchHeaderV::V8(h) => ReferenceHeader::V8(h),
3437
}
3538
}
3639
}
@@ -40,20 +43,28 @@ impl BatchHeaderV {
4043
match self {
4144
BatchHeaderV::V6(h) => h.batch_hash(),
4245
BatchHeaderV::V7(h) => h.batch_hash(),
46+
BatchHeaderV::V8(h) => h.batch_hash(),
4347
}
4448
}
4549

4650
pub fn must_v6_header(&self) -> &BatchHeaderV6 {
4751
match self {
4852
BatchHeaderV::V6(h) => h,
49-
BatchHeaderV::V7(_) => panic!("try to pick v7 header"),
53+
_ => panic!("try to pick v7 header"),
5054
}
5155
}
5256

5357
pub fn must_v7_header(&self) -> &BatchHeaderV7 {
5458
match self {
5559
BatchHeaderV::V7(h) => h,
56-
BatchHeaderV::V6(_) => panic!("try to pick v6 header"),
60+
_ => panic!("try to pick v6 header"),
61+
}
62+
}
63+
64+
pub fn must_v8_header(&self) -> &BatchHeaderV8 {
65+
match self {
66+
BatchHeaderV::V8(h) => h,
67+
_ => panic!("try to pick v8 header"),
5768
}
5869
}
5970
}
@@ -121,18 +132,33 @@ impl BatchProvingTask {
121132
.challenge_digest(versioned_hash)
122133
}
123134
BatchHeaderV::V7(_) => {
124-
match fork_name {
125-
ForkName::EuclidV2 => (),
126-
_ => unreachable!("hardfork mismatch for da-codec@v6 header: found={fork_name:?}, expected={:?}",
127-
[ForkName::EuclidV2],
128-
),
129-
}
135+
assert_eq!(
136+
fork_name,
137+
ForkName::EuclidV2,
138+
"hardfork mismatch for da-codec@v7 header: found={fork_name:?}, expected={:?}",
139+
ForkName::EuclidV2,
140+
);
141+
let padded_blob_bytes = {
142+
let mut padded_blob_bytes = self.blob_bytes.to_vec();
143+
padded_blob_bytes.resize(N_BLOB_BYTES, 0);
144+
padded_blob_bytes
145+
};
146+
<EnvelopeV7 as Envelope>::from_slice(padded_blob_bytes.as_slice())
147+
.challenge_digest(versioned_hash)
148+
}
149+
BatchHeaderV::V8(_) => {
150+
assert_eq!(
151+
fork_name,
152+
ForkName::Feynman,
153+
"hardfork mismatch for da-codec@v8 header: found={fork_name:?}, expected={:?}",
154+
ForkName::Feynman,
155+
);
130156
let padded_blob_bytes = {
131157
let mut padded_blob_bytes = self.blob_bytes.to_vec();
132158
padded_blob_bytes.resize(N_BLOB_BYTES, 0);
133159
padded_blob_bytes
134160
};
135-
EnvelopeV7::from_slice(padded_blob_bytes.as_slice())
161+
<EnvelopeV8 as Envelope>::from_slice(padded_blob_bytes.as_slice())
136162
.challenge_digest(versioned_hash)
137163
}
138164
};

tests/prover-e2e/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: clean setup_db test_tool
1+
.PHONY: clean setup_db test_tool all
22

33
GOOSE_CMD?=goose
44
BEGIN_BLOCK?=10405848

0 commit comments

Comments
 (0)