Skip to content

Commit bf86754

Browse files
feat(taiko-client): add more double-checks in isKnownCanonicalBlock (#19473)
Co-authored-by: Copilot <[email protected]>
1 parent 3a90600 commit bf86754

File tree

1 file changed

+58
-0
lines changed
  • packages/taiko-client/driver/chain_syncer/event/blocks_inserter

1 file changed

+58
-0
lines changed

packages/taiko-client/driver/chain_syncer/event/blocks_inserter/common.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,64 @@ func isKnownCanonicalBlock(
334334
txListHash.Hex(),
335335
)
336336
}
337+
defer func() {
338+
if err != nil {
339+
log.Warn("Invalid known block", "blockID", blockID, "coinbase", block.Coinbase(), "reason", err)
340+
}
341+
}()
342+
343+
if block.ParentHash() != meta.Parent.Hash() {
344+
err = fmt.Errorf("parent hash mismatch: %s != %s", block.ParentHash(), meta.Parent.Hash())
345+
return nil, err
346+
}
347+
if block.Transactions().Len() == 0 {
348+
err = errors.New("transactions list is empty")
349+
return nil, err
350+
}
351+
if block.Transactions()[0].Hash() != anchorTx.Hash() {
352+
err = fmt.Errorf("anchor transaction mismatch: %s != %s", block.Transactions()[0].Hash(), anchorTx.Hash())
353+
return nil, err
354+
}
355+
if block.UncleHash() != types.EmptyUncleHash {
356+
err = fmt.Errorf("uncle hash mismatch: %s != %s", block.UncleHash(), types.EmptyUncleHash)
357+
return nil, err
358+
}
359+
if block.Coinbase() != meta.SuggestedFeeRecipient {
360+
err = fmt.Errorf("coinbase mismatch: %s != %s", block.Coinbase(), meta.SuggestedFeeRecipient)
361+
return nil, err
362+
}
363+
if block.Difficulty().Cmp(common.Big0) != 0 {
364+
err = fmt.Errorf("difficulty mismatch: %s != 0", block.Difficulty())
365+
return nil, err
366+
}
367+
if block.MixDigest() != meta.Difficulty {
368+
err = fmt.Errorf("mixDigest mismatch: %s != %s", block.MixDigest(), meta.Difficulty)
369+
return nil, err
370+
}
371+
if block.Number().Uint64() != meta.BlockID.Uint64() {
372+
err = fmt.Errorf("block number mismatch: %d != %d", block.Number(), meta.BlockID)
373+
return nil, err
374+
}
375+
if block.GasLimit() != meta.GasLimit+consensus.AnchorV3GasLimit {
376+
err = fmt.Errorf("gas limit mismatch: %d != %d", block.GasLimit(), meta.GasLimit+consensus.AnchorV3GasLimit)
377+
return nil, err
378+
}
379+
if block.Time() != meta.Timestamp {
380+
err = fmt.Errorf("timestamp mismatch: %d != %d", block.Time(), meta.Timestamp)
381+
return nil, err
382+
}
383+
if !bytes.Equal(block.Extra(), meta.ExtraData) {
384+
err = fmt.Errorf("extra data mismatch: %s != %s", block.Extra(), meta.ExtraData)
385+
return nil, err
386+
}
387+
if block.BaseFee().Cmp(meta.BaseFee) != 0 {
388+
err = fmt.Errorf("base fee mismatch: %s != %s", block.BaseFee(), meta.BaseFee)
389+
return nil, err
390+
}
391+
if block.Withdrawals().Len() != 0 {
392+
err = fmt.Errorf("withdrawals mismatch: %d != 0", block.Withdrawals().Len())
393+
return nil, err
394+
}
337395

338396
return block.Header(), nil
339397
}

0 commit comments

Comments
 (0)