Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion execution/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,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: %w", err)
}
Expand Down
19 changes: 19 additions & 0 deletions execution/abi/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,22 @@ func TestGetTypeSize(t *testing.T) {
}
}
}

// 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(), "unsupported arg type") {
t.Fatalf("type %q: got %v; want error containing %q", s, err, "unsupported arg type")
}
}
}
Loading