Skip to content

Instantly share code, notes, and snippets.

@pertsev
Created July 3, 2018 19:48
Show Gist options
  • Save pertsev/7b839682954aa2a1d814554c13783e99 to your computer and use it in GitHub Desktop.
Save pertsev/7b839682954aa2a1d814554c13783e99 to your computer and use it in GitHub Desktop.
contract Sender {
function contractFallbackHack(address _to, uint value, bytes _data)
private
returns(bool)
{
return _to.call(abi.encodeWithSignature("onTokenTransfer(address,uint256,bytes)", msg.sender, value, _data));
}
function transferAndCallHack(address _to, uint value, bytes _data)
external returns (bool)
{
if(isContract(_to)){
return contractFallbackHack(_to, value, _data);
}
return true;
}
function isContract(address _addr)
private
view
returns (bool)
{
uint length;
assembly { length := extcodesize(_addr) }
return length > 0;
}
}
contract Recipient {
address public who;
uint public value;
bytes public data;
function () payable {
revert();
}
function onTokenTransfer(address _who, uint256 _value, bytes _data) returns(bool) {
who = _who;
value = _value;
data = _data;
return true;
}
}
contract Recipient2 {
address public who;
function () payable {
revert();
}
}
contract Recipient3 {
address public who;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment