Skip to content

Instantly share code, notes, and snippets.

@sibelius
Last active March 4, 2022 14:46
Show Gist options
  • Save sibelius/cc7a8e7a52752b533a1f2aec752bca05 to your computer and use it in GitHub Desktop.
Save sibelius/cc7a8e7a52752b533a1f2aec752bca05 to your computer and use it in GitHub Desktop.
Delegate function call to another smart contract implementation
pragma solidity ^0.5.0;
contract DelegateProxy {
address internal implementation;
function() external payable {
address addr = implementation;
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), addr, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 { revert(0, returndatasize()) }
default { return(0, returndatasize()) }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment