From 345b1fb82777ccf937e4d9959e5161a709a6c462 Mon Sep 17 00:00:00 2001 From: Rachel Franks Date: Fri, 6 May 2022 09:45:57 -0500 Subject: [PATCH] abi: fix checks when all fields are indexed (#24792) This PR fixes abi checks in the edge case where all arguments are indexed --- accounts/abi/argument.go | 8 ++++---- accounts/abi/unpack_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/accounts/abi/argument.go b/accounts/abi/argument.go index e6c117fe5..c5326d570 100644 --- a/accounts/abi/argument.go +++ b/accounts/abi/argument.go @@ -78,7 +78,7 @@ func (arguments Arguments) isTuple() bool { // Unpack performs the operation hexdata -> Go format. func (arguments Arguments) Unpack(data []byte) ([]interface{}, error) { if len(data) == 0 { - if len(arguments) != 0 { + if len(arguments.NonIndexed()) != 0 { return nil, fmt.Errorf("abi: attempting to unmarshall an empty string while arguments are expected") } return make([]interface{}, 0), nil @@ -93,7 +93,7 @@ func (arguments Arguments) UnpackIntoMap(v map[string]interface{}, data []byte) return fmt.Errorf("abi: cannot unpack into a nil map") } if len(data) == 0 { - if len(arguments) != 0 { + if len(arguments.NonIndexed()) != 0 { return fmt.Errorf("abi: attempting to unmarshall an empty string while arguments are expected") } return nil // Nothing to unmarshal, return @@ -115,8 +115,8 @@ func (arguments Arguments) Copy(v interface{}, values []interface{}) error { return fmt.Errorf("abi: Unpack(non-pointer %T)", v) } if len(values) == 0 { - if len(arguments) != 0 { - return fmt.Errorf("abi: attempting to copy no values while %d arguments are expected", len(arguments)) + if len(arguments.NonIndexed()) != 0 { + return fmt.Errorf("abi: attempting to copy no values while arguments are expected") } return nil // Nothing to copy, return } diff --git a/accounts/abi/unpack_test.go b/accounts/abi/unpack_test.go index e617f8abc..bf40c301b 100644 --- a/accounts/abi/unpack_test.go +++ b/accounts/abi/unpack_test.go @@ -201,6 +201,23 @@ var unpackTests = []unpackTest{ IntOne *big.Int }{big.NewInt(1)}, }, + { + def: `[{"type":"bool"}]`, + enc: "", + want: false, + err: "abi: attempting to unmarshall an empty string while arguments are expected", + }, + { + def: `[{"type":"bytes32","indexed":true},{"type":"uint256","indexed":false}]`, + enc: "", + want: false, + err: "abi: attempting to unmarshall an empty string while arguments are expected", + }, + { + def: `[{"type":"bool","indexed":true},{"type":"uint64","indexed":true}]`, + enc: "", + want: false, + }, } // TestLocalUnpackTests runs test specially designed only for unpacking.