I'm wondering why it always reverts when I delegatecall
a non-payable function from a payable
context when the msg.value
is not 0
.
Simple code below:
contract Trial {
function magicNumber42() public returns (uint256){
return 42;
}
}
function tryDelegate(address number_contract) payable public {
(bool success, bytes memory data) = number_contract.delegatecall(abi.encodeWithSignature("magicNumber42()"));
require(success, "failed");
number = abi.decode(data, (uint256));
}
When I call tryDelegate
with a non-zero value it reverts but succeeds when no value attached. Is it by design? In the meantime staticcall
doesn't seem to have this problem.