From 44f9915f0365634400e7ab943741659c8f748f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mi=C5=82kowski?= Date: Mon, 19 Feb 2024 17:32:04 +0100 Subject: [PATCH] Return error on nil tokenID --- eth/tracers/blocknative/decoder/evm_caller.go | 8 ++++++++ eth/tracers/blocknative/decoder/methods.go | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/eth/tracers/blocknative/decoder/evm_caller.go b/eth/tracers/blocknative/decoder/evm_caller.go index 5e5bdd9b1fd0..e54c785adb78 100644 --- a/eth/tracers/blocknative/decoder/evm_caller.go +++ b/eth/tracers/blocknative/decoder/evm_caller.go @@ -88,6 +88,10 @@ func evmCallMethodDecimals(evmCall evmCallFn, addr common.Address) (uint8, error // evmCallMethodTokenURI decodes the tokenURI of an asset from the EVM. func evmCallMethodTokenURI(evmCall evmCallFn, addr common.Address, tokenID *big.Int) (string, error) { + if tokenID == nil { + return "", fmt.Errorf("tokenID is nil") + } + tokenIDBytes := tokenID.Bytes() if len(tokenIDBytes) > 32 { return "", fmt.Errorf("tokenID is too large") @@ -99,6 +103,10 @@ func evmCallMethodTokenURI(evmCall evmCallFn, addr common.Address, tokenID *big. // evmCallMethodURI decodes the URI of an asset from the EVM. func evmCallMethodURI(evmCall evmCallFn, addr common.Address, tokenID *big.Int) (string, error) { + if tokenID == nil { + return "", fmt.Errorf("tokenID is nil") + } + tokenIDBytes := common.LeftPadBytes(tokenID.Bytes(), 32) input := append(methodIDURI, tokenIDBytes...) return callAndDecodeString(evmCall, addr, input) diff --git a/eth/tracers/blocknative/decoder/methods.go b/eth/tracers/blocknative/decoder/methods.go index 1400c2087972..0719d38857be 100644 --- a/eth/tracers/blocknative/decoder/methods.go +++ b/eth/tracers/blocknative/decoder/methods.go @@ -5,6 +5,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/ethereum/go-ethereum/common" ) @@ -82,7 +83,7 @@ var methodSignatures = map[string]string{ type MethodID []byte func (m MethodID) Is(other MethodID) bool { - return bytes.Compare(m, other) == 0 + return bytes.Equal(m, other) } func (m MethodID) String() string { @@ -113,7 +114,6 @@ func (m *MethodID) UnmarshalJSON(b []byte) error { } if len(b) > methodIDEncodedLen { - fmt.Println("sdfasdfasdf:", len(b), string(b), b) return ErrMethodIDTooLong }