0
pragma solidity ^0.8.18;

contract One{
    address public first;
    address public second;
    address public third;


    function setaddress(address _address)public {
        third = _address;
    }

    function one(uint _num) public returns(bool) {
        (bool success,) = third.delegatecall(abi.encodeWithSignature("ceiling(uint256)",_num));
        return success;
    }

    function getfirstaddress() public view returns(address){
        return first;
    }
}

contract Two{
    uint public first;

    function ceiling(uint _num)public {
        first = _num;
    }

}

In the above code when i call the one function with some number(520786028573371803640530888255888666801131675076) it is manages to store the address that derived from the number in the address first variable which is in the slot 0. I know how the delegate call works but how the uint manages to store in the address varible.explain how this works under the hood

1 Answer 1

0

Contract Two is a library. In Solidity, libraries do not have their own state and therefore have the following limitations:

  • They do not have storage (so they cannot have changeable state variables)
  • They cannot store ether (so they cannot have a fallback function)
  • Cannot allow payable functions (since they cannot store ether)
  • Cannot inherit or be inherited
  • Cannot be destroyed (no selfdestruct() since version 0.4.20)

Since they do not have their own storage, the storage of the called contract is used. This is what is happening in your case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.