Skip to content

Instantly share code, notes, and snippets.

@cwhinfrey
Created October 17, 2019 02:30
Show Gist options
  • Save cwhinfrey/ef136b3b2ecb4f1223f3820e20a1d707 to your computer and use it in GitHub Desktop.
Save cwhinfrey/ef136b3b2ecb4f1223f3820e20a1d707 to your computer and use it in GitHub Desktop.
BasicProxy.sol
pragma solidity ^0.5.0;
contract BasicProxy {
address public implementation = 0xB6Eb4245eF5626E3505c6223D3157FCE3CE8d0AE;
function () external payable {
address target = implementation;
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize)
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas, target, 0, calldatasize, 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize)
switch result
// delegatecall returns 0 on error.
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