internal/ethapi: handle odd length hex in decodeHash (#25883)

This change adds zero-padding (prefix) of odd nibbles in the decodeHash function. 

Co-authored-by: ty <ty@oncoder.com>
This commit is contained in:
TY 2022-09-29 01:55:44 +09:00 committed by GitHub
parent 85aafcfb2b
commit 88132afc3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -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")