Skip to content

Commit 345b1fb

Browse files
abi: fix checks when all fields are indexed (#24792)
This PR fixes abi checks in the edge case where all arguments are indexed
1 parent 1b26991 commit 345b1fb

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

accounts/abi/argument.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (arguments Arguments) isTuple() bool {
7878
// Unpack performs the operation hexdata -> Go format.
7979
func (arguments Arguments) Unpack(data []byte) ([]interface{}, error) {
8080
if len(data) == 0 {
81-
if len(arguments) != 0 {
81+
if len(arguments.NonIndexed()) != 0 {
8282
return nil, fmt.Errorf("abi: attempting to unmarshall an empty string while arguments are expected")
8383
}
8484
return make([]interface{}, 0), nil
@@ -93,7 +93,7 @@ func (arguments Arguments) UnpackIntoMap(v map[string]interface{}, data []byte)
9393
return fmt.Errorf("abi: cannot unpack into a nil map")
9494
}
9595
if len(data) == 0 {
96-
if len(arguments) != 0 {
96+
if len(arguments.NonIndexed()) != 0 {
9797
return fmt.Errorf("abi: attempting to unmarshall an empty string while arguments are expected")
9898
}
9999
return nil // Nothing to unmarshal, return
@@ -115,8 +115,8 @@ func (arguments Arguments) Copy(v interface{}, values []interface{}) error {
115115
return fmt.Errorf("abi: Unpack(non-pointer %T)", v)
116116
}
117117
if len(values) == 0 {
118-
if len(arguments) != 0 {
119-
return fmt.Errorf("abi: attempting to copy no values while %d arguments are expected", len(arguments))
118+
if len(arguments.NonIndexed()) != 0 {
119+
return fmt.Errorf("abi: attempting to copy no values while arguments are expected")
120120
}
121121
return nil // Nothing to copy, return
122122
}

accounts/abi/unpack_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,23 @@ var unpackTests = []unpackTest{
201201
IntOne *big.Int
202202
}{big.NewInt(1)},
203203
},
204+
{
205+
def: `[{"type":"bool"}]`,
206+
enc: "",
207+
want: false,
208+
err: "abi: attempting to unmarshall an empty string while arguments are expected",
209+
},
210+
{
211+
def: `[{"type":"bytes32","indexed":true},{"type":"uint256","indexed":false}]`,
212+
enc: "",
213+
want: false,
214+
err: "abi: attempting to unmarshall an empty string while arguments are expected",
215+
},
216+
{
217+
def: `[{"type":"bool","indexed":true},{"type":"uint64","indexed":true}]`,
218+
enc: "",
219+
want: false,
220+
},
204221
}
205222

206223
// TestLocalUnpackTests runs test specially designed only for unpacking.

0 commit comments

Comments
 (0)