@@ -422,9 +422,28 @@ func (s *RollupSyncService) decodeChunkBlockRanges(txData []byte) ([]*rawdb.Chun
422
422
return nil , fmt .Errorf ("unexpected method name: %v" , method .Name )
423
423
}
424
424
425
- // validateBatch verifies the consistency between the L1 contract and L2 node data.
425
+ // validateBatch verifies the consistency between L1 contract and L2 node data.
426
+ // It performs the following checks:
427
+ // 1. Recalculates the batch hash locally
428
+ // 2. Compares local state root, withdraw root, and batch hash with L1 data (for the last batch only when "finalize by bundle")
429
+ //
426
430
// The function will terminate the node and exit if any consistency check fails.
427
- // It returns the number of the end block, a finalized batch meta data, and an error if any.
431
+ //
432
+ // Parameters:
433
+ // - event: L1 finalize batch event data
434
+ // - parentBatchMeta: metadata of the parent batch
435
+ // - chunks: slice of chunk data for the current batch
436
+ // - chainCfg: chain configuration to identify the codec version
437
+ // - stack: node stack to terminate the node in case of inconsistency
438
+ // - lastBatch: boolean indicating if this is the last batch in a bundle
439
+ //
440
+ // Returns:
441
+ // - uint64: the end block height of the batch
442
+ // - *rawdb.FinalizedBatchMeta: finalized batch metadata
443
+ // - error: any error encountered during validation
444
+ //
445
+ // Note: This function is compatible with both "finalize by batch" and "finalize by bundle" methods.
446
+ // In "finalize by bundle", only the last batch of each bundle is fully verified.
428
447
func validateBatch (event * L1FinalizeBatchEvent , parentBatchMeta * rawdb.FinalizedBatchMeta , chunks []* encoding.Chunk , chainCfg * params.ChainConfig , stack * node.Node , lastBatch bool ) (uint64 , * rawdb.FinalizedBatchMeta , error ) {
429
448
if len (chunks ) == 0 {
430
449
return 0 , nil , fmt .Errorf ("invalid argument: length of chunks is 0, batch index: %v" , event .BatchIndex .Uint64 ())
@@ -499,9 +518,9 @@ func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.Finalized
499
518
os .Exit (1 )
500
519
}
501
520
502
- // The rollup verifier recalculates all batch hashes locally.
503
- // Each batch hash depends on the parent hash, so checking the last batch hash of each bundle when "finalize by bundle"
504
- // still ensures all batch hashes are correct.
521
+ // Verify batch hash
522
+ // This check ensures the correctness of all batch hashes in the bundle
523
+ // due to the parent-child relationship between batch hashes
505
524
if localBatchHash != event .BatchHash {
506
525
log .Error ("Batch hash mismatch" , "batch index" , event .BatchIndex .Uint64 (), "start block" , startBlock .Header .Number .Uint64 (), "end block" , endBlock .Header .Number .Uint64 (), "parent batch hash" , parentBatchMeta .BatchHash .Hex (), "parent TotalL1MessagePopped" , parentBatchMeta .TotalL1MessagePopped , "l1 finalized batch hash" , event .BatchHash .Hex (), "l2 batch hash" , localBatchHash .Hex ())
507
526
chunksJson , err := json .Marshal (chunks )
0 commit comments