diff --git a/pkg/abi/abidecode.go b/pkg/abi/abidecode.go index 12db5fbe..72325b26 100644 --- a/pkg/abi/abidecode.go +++ b/pkg/abi/abidecode.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -127,7 +127,9 @@ func decodeABIUnsignedInt(ctx context.Context, desc string, block []byte, _, hea if headPosition+32 > len(block) { return nil, i18n.NewError(ctx, signermsgs.MsgNotEnoughBytesABIValue, component, desc) } - cv.Value = new(big.Int).SetBytes(block[headPosition : headPosition+32]) + + // When we're reading bytes, need to make sure we're reading the correct size number of bytes for the uint size + cv.Value = new(big.Int).SetBytes(block[headPosition+(32-(int(component.m/8))) : headPosition+32]) return cv, err } diff --git a/pkg/abi/abidecode_test.go b/pkg/abi/abidecode_test.go index 1f419415..0fe4cc2d 100644 --- a/pkg/abi/abidecode_test.go +++ b/pkg/abi/abidecode_test.go @@ -1,4 +1,4 @@ -// Copyright © 2022 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -1027,3 +1027,43 @@ func TestDecodeABIElementInsufficientDataTuple(t *testing.T) { _, _, err = decodeABIElement(context.Background(), "", block, 0, 0, tc.(*typeComponent).tupleChildren[0]) assert.Regexp(t, "FF22045", err) } + +func TestDecodeAddressWithNonZeroPadding(t *testing.T) { + + f := &Entry{ + Name: "approve", + Inputs: ParameterArray{ + {Type: "address"}, + {Type: "uint256"}, + {Type: "uint160"}, + {Type: "uint64"}, + {Type: "uint8"}, + }, + } + + d, err := hex.DecodeString("9028b841" + + "ffffffffffffffffffffffffab0974bbed8afc5212e951c8498873319d02d025" + // (address) 0xab0974bbed8afc5212e951c8498873319d02d025 + "ffffffffffffffffffffffffab0974bbed8afc5212e951c8498873319d02d025" + // (uint256) 0xffffffffffffffffffffffffab0974bbed8afc5212e951c8498873319d02d025 + "ffffffffffffffffffffffffab0974bbed8afc5212e951c8498873319d02d025" + // (uint160) 0xab0974bbed8afc5212e951c8498873319d02d025 + "ffffffffffffffffffffffffab0974bbed8afc5212e951c8498873319d02d025" + // ( uint64) 0x498873319d02d025 + "ffffffffffffffffffffffffab0974bbed8afc5212e951c8498873319d02d025") // ( uint8) 0x25 + assert.NoError(t, err) + + cv, err := f.DecodeCallData(d) + assert.NoError(t, err) + + address, _ := cv.Children[0].JSON() + assert.Equal(t, "\"ab0974bbed8afc5212e951c8498873319d02d025\"", string(address)) + + value, _ := cv.Children[1].JSON() + assert.Equal(t, "\"115792089237316195423570985008202854513430464469730409417913252338120266010661\"", string(value)) + + value, _ = cv.Children[2].JSON() + assert.Equal(t, "\"976448297491382722293530211171951349863068913701\"", string(value)) + + value, _ = cv.Children[3].JSON() + assert.Equal(t, "\"5298611618526187557\"", string(value)) + + value, _ = cv.Children[4].JSON() + assert.Equal(t, "\"37\"", string(value)) +} diff --git a/pkg/abi/typecomponents.go b/pkg/abi/typecomponents.go index 79c4dc42..5ba52ce5 100644 --- a/pkg/abi/typecomponents.go +++ b/pkg/abi/typecomponents.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 //