Created
March 30, 2020 17:26
-
-
Save viraj124/632af424c39c9a2892479b54ea8c6dea to your computer and use it in GitHub Desktop.
This file contains hidden or 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.5.7; | |
contract Execute { | |
function execute(address _target, bytes memory _data) | |
public | |
payable | |
returns (bytes32 response) | |
{ | |
require(_target != address(0)); | |
// call contract in current context | |
assembly { | |
let succeeded := delegatecall(sub(gas, 5000), _target, add(_data, 0x20), mload(_data), 0, 32) | |
response := mload(0) // load delegatecall output | |
switch iszero(succeeded) | |
case 1 { | |
// throw if delegatecall failed | |
revert(0, 0) | |
} | |
} | |
} | |
function() external payable {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment