@@ -394,6 +394,14 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
394394 return
395395 }
396396
397+ // check codec version
398+ for _ , dbChunk := range dbChunks {
399+ if dbBatch .CodecVersion != dbChunk .CodecVersion {
400+ log .Error ("batch codec version is different from chunk codec version" , "batch index" , dbBatch .Index , "chunk index" , dbChunk .Index , "batch codec version" , dbBatch .CodecVersion , "chunk codec version" , dbChunk .CodecVersion )
401+ return
402+ }
403+ }
404+
397405 chunks := make ([]* encoding.Chunk , len (dbChunks ))
398406 for i , c := range dbChunks {
399407 blocks , getErr := r .l2BlockOrm .GetL2BlocksInRange (r .ctx , c .StartBlockNumber , c .EndBlockNumber )
@@ -415,6 +423,11 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
415423 return
416424 }
417425
426+ if dbParentBatch .CodecVersion > dbBatch .CodecVersion {
427+ log .Error ("parent batch codec version is greater than current batch codec version" , "index" , dbBatch .Index , "hash" , dbBatch .Hash , "parent codec version" , dbParentBatch .CodecVersion , "current codec version" , dbBatch .CodecVersion )
428+ return
429+ }
430+
418431 var calldata []byte
419432 var blob * kzg4844.Blob
420433 codecVersion := encoding .CodecVersion (dbBatch .CodecVersion )
@@ -528,14 +541,41 @@ func (r *Layer2Relayer) ProcessPendingBundles() {
528541}
529542
530543func (r * Layer2Relayer ) finalizeBundle (bundle * orm.Bundle , withProof bool ) error {
544+ // Check if current bundle codec version is not less than the preceding one
545+ if bundle .StartBatchIndex > 0 {
546+ prevBatch , err := r .batchOrm .GetBatchByIndex (r .ctx , bundle .StartBatchIndex - 1 )
547+ if err != nil {
548+ log .Error ("failed to get previous batch" ,
549+ "current bundle index" , bundle .Index ,
550+ "start batch index" , bundle .StartBatchIndex ,
551+ "error" , err )
552+ return err
553+ }
554+ if bundle .CodecVersion < prevBatch .CodecVersion {
555+ log .Error ("current bundle codec version is less than the preceding batch" ,
556+ "current bundle index" , bundle .Index ,
557+ "current codec version" , bundle .CodecVersion ,
558+ "prev batch index" , prevBatch .Index ,
559+ "prev codec version" , prevBatch .CodecVersion )
560+ return errors .New ("current bundle codec version cannot be less than the preceding batch" )
561+ }
562+ }
563+
531564 // Check batch status before sending `finalizeBundle` tx.
532- if r .cfg .ChainMonitor .Enabled {
533- for batchIndex := bundle .StartBatchIndex ; batchIndex <= bundle .EndBatchIndex ; batchIndex ++ {
534- tmpBatch , getErr := r .batchOrm .GetBatchByIndex (r .ctx , batchIndex )
535- if getErr != nil {
536- log .Error ("failed to get batch by index" , "batch index" , batchIndex , "error" , getErr )
537- return getErr
538- }
565+ for batchIndex := bundle .StartBatchIndex ; batchIndex <= bundle .EndBatchIndex ; batchIndex ++ {
566+ tmpBatch , getErr := r .batchOrm .GetBatchByIndex (r .ctx , batchIndex )
567+ if getErr != nil {
568+ log .Error ("failed to get batch by index" , "batch index" , batchIndex , "error" , getErr )
569+ return getErr
570+ }
571+
572+ // check codec version
573+ if tmpBatch .CodecVersion != bundle .CodecVersion {
574+ log .Error ("bundle codec version is different from batch codec version" , "bundle index" , bundle .Index , "batch index" , tmpBatch .Index , "bundle codec version" , bundle .CodecVersion , "batch codec version" , tmpBatch .CodecVersion )
575+ return errors .New ("bundle codec version is different from batch codec version" )
576+ }
577+
578+ if r .cfg .ChainMonitor .Enabled {
539579 batchStatus , getErr := r .getBatchStatusByIndex (tmpBatch )
540580 if getErr != nil {
541581 r .metrics .rollupL2ChainMonitorLatestFailedCall .Inc ()
0 commit comments