fix: Update transaction validation logic in ethclient (#1435)

- Declare zeroAddress as a constant
- If there is only one transaction in the block and the header's txHash is `EmptyTxsHash`, it indicates a state-sync transaction. No error handling is required in this case.
This commit is contained in:
Leekyungun 2025-02-05 13:13:51 +09:00 committed by GitHub
parent d1219ff6d4
commit 51af82cca1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -8,6 +8,10 @@ import (
"github.com/ethereum/go-ethereum/core/types"
)
const (
zeroAddress = "0x0000000000000000000000000000000000000000"
)
// GetRootHash returns the merkle root of the block headers
func (ec *Client) GetRootHash(ctx context.Context, startBlockNumber uint64, endBlockNumber uint64) (string, error) {
var rootHash string

View file

@ -163,7 +163,13 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
return nil, errors.New("server returned empty uncle list but block header indicates uncles")
}
if head.TxHash == types.EmptyTxsHash && len(body.Transactions) > 0 {
return nil, errors.New("server returned non-empty transaction list but block header indicates no transactions")
// If there is only one transaction in the block and the header's txHash is `EmptyTxsHash`,
// it indicates a state-sync transaction. No error handling is required in this case.
tx := body.Transactions[0]
if (tx.From != nil && *tx.From != common.HexToAddress(zeroAddress)) ||
(tx.tx.To() != nil && *tx.tx.To() != common.HexToAddress(zeroAddress)) {
return nil, errors.New("server returned non-empty transaction list but block header indicates no transactions")
}
}
if head.TxHash != types.EmptyTxsHash && len(body.Transactions) == 0 {
return nil, errors.New("server returned empty transaction list but block header indicates transactions")