From 73d7f7c36ecfe38675f75c42f8bd18d02402f7c2 Mon Sep 17 00:00:00 2001 From: Weixie Cui Date: Sat, 25 Apr 2026 14:39:02 +0800 Subject: [PATCH] accounts/abi: fix index error --- accounts/abi/type.go | 2 +- accounts/abi/type_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/accounts/abi/type.go b/accounts/abi/type.go index 2fd11ac123..f44bf56742 100644 --- a/accounts/abi/type.go +++ b/accounts/abi/type.go @@ -126,7 +126,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty var varSize int if len(parsedType[3]) > 0 { var err error - varSize, err = strconv.Atoi(parsedType[2]) + varSize, err = strconv.Atoi(parsedType[3]) if err != nil { return Type{}, fmt.Errorf("abi: error parsing variable size: %v", err) } diff --git a/accounts/abi/type_test.go b/accounts/abi/type_test.go index 95922548c4..16f15c762b 100644 --- a/accounts/abi/type_test.go +++ b/accounts/abi/type_test.go @@ -19,6 +19,7 @@ package abi import ( "math/big" "reflect" + "strings" "testing" "github.com/davecgh/go-spew/spew" @@ -378,3 +379,22 @@ func TestNewFixedBytesOver32(t *testing.T) { t.Errorf("fixed bytes with size over 32 is not spec'd") } } + +// TestNewTypeFixedPointWrongSizeSubmatch is a regression test for a bug in NewType +// that used the wrong regexp submatch (parsedType[2]) for the first numeric size. +// For types like fixed128x18, the overall second group is "128x18", not an integer +// string; the first integer is parsedType[3] ("128"). The bug caused strconv.Atoi +// to fail with "error parsing variable size" instead of the intended "unsupported +// arg type" outcome for unimplemented fixed-point encodings. +func TestNewTypeFixedPointWrongSizeSubmatch(t *testing.T) { + t.Parallel() + for _, s := range []string{"fixed128x18", "ufixed256x10"} { + _, err := NewType(s, "", nil) + if err == nil { + t.Fatalf("type %q: expected error for unsupported fixed-point type", s) + } + if strings.Contains(err.Error(), "error parsing variable size") { + t.Fatalf("type %q: got size parse error (wrong regexp submatch); want unsupported: %v", s, err) + } + } +}