Skip to content

Commit

Permalink
fix: Update transaction validation logic in ethclient (#1435)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Leekyungun authored Feb 5, 2025
1 parent d1219ff commit 51af82c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ethclient/bor_ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 51af82c

Please sign in to comment.