From e2f2b6cb42e2f52c6d333fe717f42e4e9c9378bd Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Mon, 29 Jun 2026 15:07:03 +0800 Subject: [PATCH] eth: reject invalid setHead target --- eth/api_backend.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/eth/api_backend.go b/eth/api_backend.go index d527d4756e..86dada4108 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -19,6 +19,7 @@ package eth import ( "context" "errors" + "fmt" "math/big" "time" @@ -64,6 +65,13 @@ func (b *EthAPIBackend) CurrentBlock() *types.Header { } func (b *EthAPIBackend) SetHead(number uint64) error { + // Reject rewinding to a point before the snap-sync pivot. The earliest + // recoverable state is the pivot block, so a target below it would simply + // reset the chain to genesis, which is almost never the intent behind a + // manual debug_setHead. + if pivot := rawdb.ReadLastPivotNumber(b.eth.ChainDb()); pivot != nil && number < *pivot { + return fmt.Errorf("rewind target %d is before the snap-sync pivot %d", number, *pivot) + } b.eth.handler.downloader.Cancel() return b.eth.blockchain.SetHead(number) }