Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad address of function type #14

Closed
charles-liu opened this issue Mar 3, 2022 · 0 comments
Closed

Bad address of function type #14

charles-liu opened this issue Mar 3, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@charles-liu
Copy link
Contributor

The address of a function type loses the first byte after ABI encoding.

pragma soliditypp ^0.8.0;

contract A {
    function add(uint a, uint b, function(uint) external callback) external {
        if (callback.address != address(0)) {
            // the callback.address is broken here (lose the first byte)
            callback(a + b);
        }
    }
}

contract B {
    A contractA;
    uint public data;

    constructor (address addr) {
        contractA = A(addr);
    }

    function test() external {
        // the following assert is ok
        require(this.callback_onAdd.address == address(this));
        contractA.add(1, 2, this.callback_onAdd);
    }

    function callback_onAdd(uint result) external {
        require(msg.sender == address(contractA));
        data = result;
    }
}

Cause: It's an address format issue, a Vite addresse has 168 bits rather than 160 bits like Ethereum.

@charles-liu charles-liu added the bug Something isn't working label Mar 3, 2022
@charles-liu charles-liu self-assigned this Mar 3, 2022
charles-liu added a commit that referenced this issue Mar 3, 2022
fix: fix bad address of function type. close #14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant