@@ -3,7 +3,7 @@ use bytesize::ByteSize;
33use sbv_core:: BlockWitness ;
44use sbv_primitives:: types:: consensus:: ScrollTransaction ;
55use sbv_primitives:: { B256 , types:: eips:: Encodable2718 } ;
6- use scroll_zkvm_types:: batch:: build_point_eval_witness;
6+ use scroll_zkvm_types:: batch:: { N_BLOB_BYTES , build_point_eval_witness} ;
77use scroll_zkvm_types:: {
88 batch:: {
99 BatchHeader , BatchHeaderV6 , BatchHeaderV7 , BatchHeaderValidium , BatchHeaderValidiumV1 ,
@@ -53,10 +53,9 @@ impl Default for LastHeader {
5353 // create a default LastHeader according to the dummy value
5454 // being set in the e2e test in scroll-prover:
5555 // https://github.com/scroll-tech/scroll-prover/blob/82f8ed3fabee5c3001b0b900cda1608413e621f8/integration/tests/e2e_tests.rs#L203C1-L207C8
56-
5756 Self {
5857 batch_index : 123 ,
59- version : testing_hardfork ( ) . to_protocol_version ( ) ,
58+ version : testing_version ( ) . as_version_byte ( ) ,
6059 batch_hash : B256 :: new ( [
6160 0xab , 0xac , 0xad , 0xae , 0xaf , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
6261 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -70,8 +69,10 @@ impl From<&ReferenceHeader> for LastHeader {
7069 fn from ( value : & ReferenceHeader ) -> Self {
7170 match value {
7271 ReferenceHeader :: V6 ( h) => h. into ( ) ,
73- ReferenceHeader :: V7 ( h) => h. into ( ) ,
74- ReferenceHeader :: V8 ( h) => h. into ( ) ,
72+ ReferenceHeader :: V7_V8_V9 ( h) => h. into ( ) ,
73+ ReferenceHeader :: V8 ( _) => {
74+ unreachable ! ( "Unexpected ReferenceHeader::V8 from 0.7.0 onwards" )
75+ }
7576 ReferenceHeader :: Validium ( h) => h. into ( ) ,
7677 }
7778 }
@@ -202,9 +203,17 @@ pub fn build_batch_witnesses(
202203 // compress ...
203204 let compressed_payload = zstd_encode ( & payload) ;
204205
205- let heading = compressed_payload. len ( ) as u32 + ( ( version. as_version_byte ( ) as u32 ) << 24 ) ;
206+ // 5 bytes are utilised by version (1), compressed_len (3) and is_encoded (1).
207+ if compressed_payload. len ( ) > N_BLOB_BYTES - 5 {
208+ return Err ( eyre:: eyre!(
209+ "compression payload of batch too big: len={}" ,
210+ compressed_payload. len( )
211+ ) ) ;
212+ }
213+
214+ let heading = compressed_payload. len ( ) as u32 + ( ( version. stf_version as u32 ) << 24 ) ;
206215
207- let blob_bytes = if testing_hardfork ( ) >= ForkName :: EuclidV2 {
216+ let blob_bytes = if version . fork >= ForkName :: EuclidV2 {
208217 let mut blob_bytes = Vec :: from ( heading. to_be_bytes ( ) ) ;
209218 blob_bytes. push ( 1u8 ) ; // compressed flag
210219 blob_bytes. extend ( compressed_payload) ;
@@ -289,20 +298,9 @@ pub fn build_batch_witnesses(
289298 blob_data_proof : point_evaluations. map ( |u| B256 :: new ( u. to_be_bytes ( ) ) ) ,
290299 } )
291300 }
292- ForkName :: EuclidV2 => {
301+ ForkName :: EuclidV2 | ForkName :: Feynman | ForkName :: Galileo => {
293302 use scroll_zkvm_types:: batch:: BatchHeaderV7 ;
294- let _ = x + z;
295- ReferenceHeader :: V7 ( BatchHeaderV7 {
296- version : last_header. version ,
297- batch_index : last_header. batch_index + 1 ,
298- parent_batch_hash : last_header. batch_hash ,
299- blob_versioned_hash,
300- } )
301- }
302- ForkName :: Feynman => {
303- use scroll_zkvm_types:: batch:: BatchHeaderV8 ;
304- let _ = x + z;
305- ReferenceHeader :: V8 ( BatchHeaderV8 {
303+ ReferenceHeader :: V7_V8_V9 ( BatchHeaderV7 {
306304 version : last_header. version ,
307305 batch_index : last_header. batch_index + 1 ,
308306 parent_batch_hash : last_header. batch_hash ,
@@ -429,6 +427,10 @@ fn test_build_and_parse_batch_task() -> eyre::Result<()> {
429427 block_range : ( 16525000 ..=16525003 ) . collect ( ) ,
430428 ..Default :: default ( )
431429 } ,
430+ ForkName :: Galileo => ChunkTaskGenerator {
431+ block_range : ( 20239156 ..=20239192 ) . collect ( ) ,
432+ ..Default :: default ( )
433+ } ,
432434 }
433435 . get_or_build_witness ( ) ?;
434436
@@ -447,14 +449,11 @@ fn test_build_and_parse_batch_task() -> eyre::Result<()> {
447449 let enveloped = batch:: EnvelopeV6 :: from_slice ( & task_wit. blob_bytes ) ;
448450 <batch:: PayloadV6 as Payload >:: from_envelope ( & enveloped) . validate ( h, infos) ;
449451 }
450- ReferenceHeader :: V7 ( h) => {
452+ ReferenceHeader :: V7_V8_V9 ( h) => {
451453 let enveloped = batch:: EnvelopeV7 :: from_slice ( & task_wit. blob_bytes ) ;
452454 <batch:: PayloadV7 as Payload >:: from_envelope ( & enveloped) . validate ( h, infos) ;
453455 }
454- ReferenceHeader :: V8 ( h) => {
455- let enveloped = batch:: EnvelopeV8 :: from_slice ( & task_wit. blob_bytes ) ;
456- <batch:: PayloadV8 as Payload >:: from_envelope ( & enveloped) . validate ( h, infos) ;
457- }
456+ ReferenceHeader :: V8 ( _) => unreachable ! ( "Unexpected ReferenceHeader::V8 from 0.7.0 onwards" ) ,
458457 ReferenceHeader :: Validium ( _h) => {
459458 todo ! ( )
460459 }
0 commit comments