eth-abi icon indicating copy to clipboard operation
eth-abi copied to clipboard

Decode input data with bad padding

Open ArielTM opened this issue 1 year ago • 3 comments

We want to decode input data sent to old contracts compiled using solc 0.5.16. In some of the transactions, an address parameter was sent with a none empty padding:

pragma solidity >=0.5.0;

contract TestContract {
    function testInner(address addr) public pure returns(address) {
        return addr;
    }

    function test() public view returns(address) {
        (bool success, bytes memory data) = address(this).staticcall(hex"21803c550000000000000000000022221111111111111111111111111111111111111111");
        require(success, "test error");
        address ret_addr = abi.decode(data, (address));
        return ret_addr;
    }
}

Compiling this with solc 0.5.16 and calling test() will return 0x1111111111111111111111111111111111111111 Compiling this with solc 0.8.24 and calling test() will result in revert.

We want to be able to decode the input data in python without checking for empty padding (strict=False does not apply for fixed length parameters). How can we do this?

ArielTM avatar Feb 14 '24 13:02 ArielTM

Why not just compile it with an older compiler version?

pacrob avatar Jul 01 '24 16:07 pacrob

The above contract is just an example. We want to decode historic transactions to already deployed contacts

ArielTM avatar Jul 01 '24 16:07 ArielTM