Skip to content

Decode input data with bad padding #227

@ArielTM

Description

@ArielTM

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions