@@ -18,24 +18,31 @@ use crate::proofs::ChunkProof;
1818mod utils;
1919use utils:: { base64, point_eval} ;
2020
21+ #[ derive( Clone , serde:: Deserialize , serde:: Serialize ) ]
22+ pub struct BatchHeaderValidiumWithHash {
23+ #[ serde( flatten) ]
24+ header : BatchHeaderValidium ,
25+ batch_hash : B256 ,
26+ }
27+
2128/// Define variable batch header type, since BatchHeaderV6 can not
2229/// be decoded as V7 we can always has correct deserialization
2330/// Notice: V6 header MUST be put above V7 since untagged enum
2431/// try to decode each defination in order
2532#[ derive( Clone , serde:: Deserialize , serde:: Serialize ) ]
2633#[ serde( untagged) ]
2734pub enum BatchHeaderV {
35+ Validium ( BatchHeaderValidiumWithHash ) ,
2836 V6 ( BatchHeaderV6 ) ,
2937 V7_8 ( BatchHeaderV7 ) ,
30- Validium ( BatchHeaderValidium ) ,
3138}
3239
3340impl BatchHeaderV {
3441 pub fn batch_hash ( & self ) -> B256 {
3542 match self {
3643 BatchHeaderV :: V6 ( h) => h. batch_hash ( ) ,
3744 BatchHeaderV :: V7_8 ( h) => h. batch_hash ( ) ,
38- BatchHeaderV :: Validium ( h) => h. batch_hash ( ) ,
45+ BatchHeaderV :: Validium ( h) => h. header . batch_hash ( ) ,
3946 }
4047 }
4148
@@ -62,7 +69,7 @@ impl BatchHeaderV {
6269
6370 pub fn must_validium_header ( & self ) -> & BatchHeaderValidium {
6471 match self {
65- BatchHeaderV :: Validium ( h) => h ,
72+ BatchHeaderV :: Validium ( h) => & h . header ,
6673 _ => panic ! ( "try to pick other header type" ) ,
6774 }
6875 }
@@ -197,6 +204,15 @@ impl BatchProvingTask {
197204 self . challenge_digest. is_none( ) ,
198205 "domain=validium has no blob-da"
199206 ) ;
207+
208+ match & self . batch_header {
209+ BatchHeaderV :: Validium ( h) => assert_eq ! (
210+ h. header. batch_hash( ) ,
211+ h. batch_hash,
212+ "calculated batch hash match which from coordinator"
213+ ) ,
214+ _ => panic ! ( "unexpected header type" ) ,
215+ }
200216 None
201217 } ;
202218
@@ -244,3 +260,58 @@ impl BatchProvingTask {
244260 Ok ( metadata)
245261 }
246262}
263+
264+
265+
266+ #[ test]
267+ fn test_deserde_batch_header_v_validium ( ) {
268+ use std:: str:: FromStr ;
269+
270+ // Top-level JSON: flattened enum tag "V1" + batch_hash
271+ let json = r#"{
272+ "V1": {
273+ "version": 1,
274+ "batch_index": 42,
275+ "parent_batch_hash": "0x1111111111111111111111111111111111111111111111111111111111111111",
276+ "post_state_root": "0x2222222222222222222222222222222222222222222222222222222222222222",
277+ "withdraw_root": "0x3333333333333333333333333333333333333333333333333333333333333333",
278+ "commitment": "0x4444444444444444444444444444444444444444444444444444444444444444"
279+ },
280+ "batch_hash": "0x5555555555555555555555555555555555555555555555555555555555555555"
281+ }"# ;
282+
283+ let parsed: BatchHeaderV = serde_json:: from_str ( json) . expect ( "deserialize BatchHeaderV" ) ;
284+
285+ match parsed {
286+ BatchHeaderV :: Validium ( v) => {
287+ // Check the batch_hash field
288+ let expected_batch_hash = B256 :: from_str (
289+ "0x5555555555555555555555555555555555555555555555555555555555555555" ,
290+ )
291+ . unwrap ( ) ;
292+ assert_eq ! ( v. batch_hash, expected_batch_hash) ;
293+
294+ // Check the inner header variant and fields
295+ match v. header {
296+ BatchHeaderValidium :: V1 ( h) => {
297+ assert_eq ! ( h. version, 1 ) ;
298+ assert_eq ! ( h. batch_index, 42 ) ;
299+
300+ let p = B256 :: from_str ( "0x1111111111111111111111111111111111111111111111111111111111111111" ) . unwrap ( ) ;
301+ let s = B256 :: from_str ( "0x2222222222222222222222222222222222222222222222222222222222222222" ) . unwrap ( ) ;
302+ let w = B256 :: from_str ( "0x3333333333333333333333333333333333333333333333333333333333333333" ) . unwrap ( ) ;
303+ let c = B256 :: from_str ( "0x4444444444444444444444444444444444444444444444444444444444444444" ) . unwrap ( ) ;
304+
305+ assert_eq ! ( h. parent_batch_hash, p) ;
306+ assert_eq ! ( h. post_state_root, s) ;
307+ assert_eq ! ( h. withdraw_root, w) ;
308+ assert_eq ! ( h. commitment, c) ;
309+
310+ // Sanity: computed batch hash equals the provided one (if method available)
311+ // assert_eq!(v.header.batch_hash(), expected_batch_hash);
312+ }
313+ }
314+ }
315+ _ => panic ! ( "expected validium header variant" ) ,
316+ }
317+ }
0 commit comments