Skip to content

Commit a75d8ab

Browse files
committed
fix batch task header issue
1 parent 057c0ce commit a75d8ab

File tree

1 file changed

+29
-44
lines changed

1 file changed

+29
-44
lines changed

crates/libzkp/src/tasks/batch.rs

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,35 @@ use utils::{base64, point_eval};
2424
#[serde(untagged)]
2525
pub enum BatchHeaderV {
2626
V6(BatchHeaderV6),
27-
V7(BatchHeaderV7),
28-
V8(BatchHeaderV8),
29-
}
30-
31-
impl From<BatchHeaderV> for ReferenceHeader {
32-
fn from(value: BatchHeaderV) -> Self {
33-
match value {
34-
BatchHeaderV::V6(h) => ReferenceHeader::V6(h),
35-
BatchHeaderV::V7(h) => ReferenceHeader::V7(h),
36-
BatchHeaderV::V8(h) => ReferenceHeader::V8(h),
37-
}
38-
}
27+
V7_8(BatchHeaderV7),
3928
}
4029

4130
impl BatchHeaderV {
4231
pub fn batch_hash(&self) -> B256 {
4332
match self {
4433
BatchHeaderV::V6(h) => h.batch_hash(),
45-
BatchHeaderV::V7(h) => h.batch_hash(),
46-
BatchHeaderV::V8(h) => h.batch_hash(),
34+
BatchHeaderV::V7_8(h) => h.batch_hash(),
4735
}
4836
}
4937

5038
pub fn must_v6_header(&self) -> &BatchHeaderV6 {
5139
match self {
5240
BatchHeaderV::V6(h) => h,
53-
_ => panic!("try to pick v7 header"),
41+
_ => panic!("try to pick other header type"),
5442
}
5543
}
5644

5745
pub fn must_v7_header(&self) -> &BatchHeaderV7 {
5846
match self {
59-
BatchHeaderV::V7(h) => h,
60-
_ => panic!("try to pick v6 header"),
47+
BatchHeaderV::V7_8(h) => h,
48+
_ => panic!("try to pick other header type"),
6149
}
6250
}
6351

6452
pub fn must_v8_header(&self) -> &BatchHeaderV8 {
6553
match self {
66-
BatchHeaderV::V8(h) => h,
67-
_ => panic!("try to pick v8 header"),
54+
BatchHeaderV::V7_8(h) => h,
55+
_ => panic!("try to pick other header type"),
6856
}
6957
}
7058
}
@@ -131,35 +119,28 @@ impl BatchProvingTask {
131119
EnvelopeV6::from_slice(self.blob_bytes.as_slice())
132120
.challenge_digest(versioned_hash)
133121
}
134-
BatchHeaderV::V7(_) => {
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-
);
122+
BatchHeaderV::V7_8(_) => {
156123
let padded_blob_bytes = {
157124
let mut padded_blob_bytes = self.blob_bytes.to_vec();
158125
padded_blob_bytes.resize(N_BLOB_BYTES, 0);
159126
padded_blob_bytes
160127
};
161-
<EnvelopeV8 as Envelope>::from_slice(padded_blob_bytes.as_slice())
162-
.challenge_digest(versioned_hash)
128+
129+
match fork_name {
130+
ForkName::EuclidV2 => {
131+
<EnvelopeV7 as Envelope>::from_slice(padded_blob_bytes.as_slice())
132+
.challenge_digest(versioned_hash)
133+
}
134+
ForkName::Feynman => {
135+
<EnvelopeV8 as Envelope>::from_slice(padded_blob_bytes.as_slice())
136+
.challenge_digest(versioned_hash)
137+
}
138+
f => unreachable!(
139+
"hardfork mismatch for da-codec@v7 header: found={}, expected={:?}",
140+
f,
141+
[ForkName::EuclidV2, ForkName::Feynman],
142+
),
143+
}
163144
}
164145
};
165146

@@ -185,7 +166,11 @@ impl BatchProvingTask {
185166
kzg_proof: kzg_proof.into_inner(),
186167
};
187168

188-
let reference_header = self.batch_header.clone().into();
169+
let reference_header = match fork_name {
170+
ForkName::EuclidV1 => ReferenceHeader::V6(*self.batch_header.must_v6_header()),
171+
ForkName::EuclidV2 => ReferenceHeader::V7(*self.batch_header.must_v7_header()),
172+
ForkName::Feynman => ReferenceHeader::V8(*self.batch_header.must_v8_header()),
173+
};
189174

190175
BatchWitness {
191176
fork_name,

0 commit comments

Comments
 (0)