From 0221c99a3a0b06c5b330f1e8cdb84139e434709e Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Tue, 17 Dec 2024 15:35:25 +0000 Subject: [PATCH] fix_: revert "fix(sha3)_: support hex string (#6216)" This reverts commit b84be51f912fa129dbcdb05ba672846826ed1e12. --- abi-spec/utils.go | 19 +------------------ abi-spec/utils_test.go | 3 --- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/abi-spec/utils.go b/abi-spec/utils.go index 8353a606a6f..6be505c44f6 100644 --- a/abi-spec/utils.go +++ b/abi-spec/utils.go @@ -1,18 +1,14 @@ package abispec import ( - "encoding/hex" "fmt" "math/big" "regexp" "strings" "unicode" - "go.uber.org/zap" - "github.com/ethereum/go-ethereum/common" "github.com/status-im/status-go/eth-node/crypto" - "github.com/status-im/status-go/logutils" ) var unicodeZeroPattern = regexp.MustCompile("^(?:\u0000)*") @@ -24,8 +20,6 @@ var addressBasicPattern = regexp.MustCompile("(?i)^(0x)?[0-9a-f]{40}$") var addressLowerCasePattern = regexp.MustCompile("^(0x|0X)?[0-9a-f]{40}$") var addressUpperCasePattern = regexp.MustCompile("^(0x|0X)?[0-9A-F]{40}$") -var hexStrictPattern = regexp.MustCompile(`(?i)^((-)?0x[0-9a-f]+|(0x))$`) - func HexToNumber(hex string) string { num, success := big.NewInt(0).SetString(hex, 16) if success { @@ -43,18 +37,7 @@ func NumberToHex(numString string) string { } func Sha3(str string) string { - var bytes []byte - var err error - if hexStrictPattern.MatchString(str) { - bytes, err = hex.DecodeString(str[2:]) - if err != nil { - logutils.ZapLogger().Error("failed to decode hex string when sha3", zap.String("hex", str), zap.Error(err)) - return "" - } - } else { - bytes = []byte(str) - } - bytes = crypto.Keccak256(bytes) + bytes := crypto.Keccak256([]byte(str)) return common.Bytes2Hex(bytes) } diff --git a/abi-spec/utils_test.go b/abi-spec/utils_test.go index ee4a020f1c5..2f62250598d 100644 --- a/abi-spec/utils_test.go +++ b/abi-spec/utils_test.go @@ -36,9 +36,6 @@ func TestNumberToHex(t *testing.T) { func TestSha3(t *testing.T) { require.Equal(t, "48bed44d1bcd124a28c27f343a817e5f5243190d3c52bf347daf876de1dbbf77", Sha3("abcd")) - require.Equal(t, "79bc958fa37445ba1b909c34a73cecfa4966a6e6783f90863dd6df5a80f96ad0", Sha3("12786e7b2111caae36dd91aca91ce627f26fa3c77018a98880ab50a82ac6b6aa835f6bbf96da54aa6b88ceffb8107ef40a4ef8a85bf4eb0e81a9464e0a27fcf3")) - require.Equal(t, "04d874cdee68658bd64a07b6180dd36b735b60876ca79a29f88114bc78e6fc32", Sha3("0x12786e7b2111caae36dd91aca91ce627f26fa3c77018a98880ab50a82ac6b6aa835f6bbf96da54aa6b88ceffb8107ef40a4ef8a85bf4eb0e81a9464e0a27fcf3")) - require.Equal(t, "04d874cdee68658bd64a07b6180dd36b735b60876ca79a29f88114bc78e6fc32", Sha3("0x12786E7b2111caae36dd91aca91ce627f26fa3c77018a98880ab50a82ac6b6aa835f6bbf96da54aa6b88ceffb8107ef40a4ef8a85bf4eb0e81a9464e0a27fcf3")) } func TestHexToUtf8(t *testing.T) {