Skip to content

Instantly share code, notes, and snippets.

@wadealexc
Created November 8, 2018 12:56
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 wadealexc/b49fe88291342ddbc76e39a099a85f8f to your computer and use it in GitHub Desktop.
Save wadealexc/b49fe88291342ddbc76e39a099a85f8f to your computer and use it in GitHub Desktop.
Simple delegate-proxy implementation
pragma solidity ^0.4.24;
contract Proxy {
// Default delegatecall target
address destination;
/**
* @dev Constructor. Sets the default destination
* @param _dest The address to which this contract will forward execution
*/
constructor (address _dest) public {
destination = _dest;
}
/**
* @dev Fallback function. Delegates all execution to the default address
*/
function () external payable {
address target = destination;
assembly {
calldatacopy(0, 0, calldatasize) // Copy msg.data to memory
// Delegatecall the target, sending msg.data
let ret := delegatecall(gas, target, 0, calldatasize, 0, 0)
returndatacopy(0, 0, returndatasize) // Copy returned data to memory
// If the delegatecall failed (ret == 0), revert data.
// Otherwise, return data
switch ret
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