Created
June 22, 2016 05:16
-
-
Save PeterBorah/a325e76370f2a22f4a57db8c68c30c75 to your computer and use it in GitHub Desktop.
This file contains 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 TokenWithInvariants { | |
mapping(address => uint) public balanceOf; | |
uint public totalSupply; | |
modifier checkInvariants { | |
_ | |
if (this.balance < totalSupply) throw; | |
} | |
function deposit(uint amount) checkInvariants { | |
// intentionally vulnerable | |
balanceOf[msg.sender] += amount; | |
totalSupply += amount; | |
} | |
function transfer(address to, uint value) checkInvariants { | |
if (balanceOf[msg.sender] >= value) { | |
balanceOf[to] += value; | |
balanceOf[msg.sender] -= value; | |
} | |
} | |
function withdraw() checkInvariants { | |
// intentionally vulnerable | |
uint balance = balanceOf[msg.sender]; | |
if (msg.sender.call.value(balance)()) { | |
totalSupply -= balance; | |
balanceOf[msg.sender] = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment