Solidity: Delegate call does not detect uint function

Created on 13 Nov 2017  路  2Comments  路  Source: ethereum/solidity

Let me explain by giving an example

 contract A {
    uint public n=10;

    function setN(uint _n){
        n=30;
    }

    function() payable {
        n=40;
    }
}

contract B {
    uint public n=30;
    address public addr;
    function b(address _addr) {
        addr=_addr;
    }
    function set(uint _n){
        addr.delegatecall(bytes4(sha3("setN(uint)")), _n); 
    }
} 

delegatecall should call setN of contract A instead fallback function is called as function signature is not matching.
It calls setN if the code is addr.delegatecall(bytes4(sha3("setN(uint256)")), _n) instead of just uint.

Most helpful comment

@chriseth Hello! What do you mean by proper libraries here?

All 2 comments

You have to use the "long form" uint256 for the signature. Having said that: We plan to remove this use of delegatecall. Please use proper libraries instead.

@chriseth Hello! What do you mean by proper libraries here?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chriseth picture chriseth  路  3Comments

bshastry picture bshastry  路  3Comments

Dohtar1337 picture Dohtar1337  路  4Comments

ddeclerck picture ddeclerck  路  3Comments

AnthonyAkentiev picture AnthonyAkentiev  路  3Comments