Created
April 28, 2022 13:59
-
-
Save drgorillamd/95877ea75479e57853f9035892359a91 to your computer and use it in GitHub Desktop.
Cost difference of delegatecall with returned value or mutex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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