Skip to content

Instantly share code, notes, and snippets.

@drgorillamd
Created April 28, 2022 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drgorillamd/95877ea75479e57853f9035892359a91 to your computer and use it in GitHub Desktop.
Save drgorillamd/95877ea75479e57853f9035892359a91 to your computer and use it in GitHub Desktop.
Cost difference of delegatecall with returned value or mutex
pragma solidity 0.8.7;
interface IE {
function setN() external;
}
contract D {
uint public n;
uint private temp;
function delegatecallSetN(address _e) external { // 23347
_e.delegatecall(abi.encodeWithSelector(IE.setN.selector));
n = temp;
delete temp;
}
}
contract E {
uint public n;
uint private temp;
function setN() external {
temp = 4;
}
}
// -----------------------------------------------------
interface IG {
function setN() external returns(uint);
}
contract F {
uint public n;
function delegatecallSetN(address _e) external { // 54156
(bool success, bytes memory returnedData) = _e.delegatecall(abi.encodeWithSelector(IG.setN.selector));
n = abi.decode(returnedData, (uint));
}
}
contract G {
function setN() external returns(uint){
return 4;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment