Skip to content

Commit

Permalink
fix: Update transaction validation logic in ethclient
Browse files Browse the repository at this point in the history
- Declare zeroAddress as a constant
  • Loading branch information
Leekyungun committed Feb 4, 2025
1 parent 4ff9604 commit a48254c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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
6 changes: 3 additions & 3 deletions ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
}
if head.TxHash == types.EmptyTxsHash && len(body.Transactions) > 0 {
// If there is only one transaction in the block and the header's txHash is `EmptyTxsHash`,
// it indicates a sync transaction. No error handling is required in this case.
// it indicates a state-sync transaction. No error handling is required in this case.
tx := body.Transactions[0]
zeroAddress := common.HexToAddress("0x0000000000000000000000000000000000000000")
if (tx.From != nil && *tx.From != zeroAddress) || (tx.tx.To() != nil && *tx.tx.To() != zeroAddress) {
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")
}
}
Expand Down

0 comments on commit a48254c

Please sign in to comment.