Skip to content

Commit

Permalink
internal/ethapi: handle odd length hex in decodeHash (#25883)
Browse files Browse the repository at this point in the history
This change adds zero-padding (prefix) of odd nibbles in the decodeHash function. 

Co-authored-by: ty <ty@oncoder.com>
  • Loading branch information
f01c5700 and ty committed Sep 28, 2022
1 parent 85aafcf commit 88132af
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,9 @@ func decodeHash(s string) (common.Hash, error) {
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
s = s[2:]
}
if (len(s) & 1) > 0 {
s = "0" + s
}
b, err := hex.DecodeString(s)
if err != nil {
return common.Hash{}, fmt.Errorf("hex string invalid")
Expand Down

0 comments on commit 88132af

Please sign in to comment.