Created
July 21, 2018 18:29
-
-
Save vasa-develop/415a17c709d804a4d351485cd1b7c981 to your computer and use it in GitHub Desktop.
DO NOT USE THIS CODE. THIS CODE IS USED TO DEMONSTRATE A VULNERABILITY IN A SOLIDITY CODE.
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
contract EtherGame { | |
uint public payoutMileStone1 = 3 ether; | |
uint public mileStone1Reward = 2 ether; | |
uint public payoutMileStone2 = 5 ether; | |
uint public mileStone2Reward = 3 ether; | |
uint public finalMileStone = 10 ether; | |
uint public finalReward = 5 ether; | |
mapping(address => uint) redeemableEther; | |
// users pay 0.5 ether. At specific milestones, credit their accounts | |
function play() public payable { | |
require(msg.value == 0.5 ether); // each play is 0.5 ether | |
uint currentBalance = this.balance + msg.value; | |
// ensure no players after the game as finished | |
require(currentBalance <= finalMileStone); | |
// if at a milestone credit the players account | |
if (currentBalance == payoutMileStone1) { | |
redeemableEther[msg.sender] += mileStone1Reward; | |
} | |
else if (currentBalance == payoutMileStone2) { | |
redeemableEther[msg.sender] += mileStone2Reward; | |
} | |
else if (currentBalance == finalMileStone ) { | |
redeemableEther[msg.sender] += finalReward; | |
} | |
return; | |
} | |
function claimReward() public { | |
// ensure the game is complete | |
require(this.balance == finalMileStone); | |
// ensure there is a reward to give | |
require(redeemableEther[msg.sender] > 0); | |
redeemableEther[msg.sender] = 0; | |
msg.sender.transfer(redeemableEther[msg.sender]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment