Created
July 21, 2018 19:59
-
-
Save vasa-develop/82759590bd44a23fd6d1344e1035fdce 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 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 FunWithNumbers { | |
uint constant public tokensPerEth = 10; | |
uint constant public weiPerEth = 1e18; | |
mapping(address => uint) public balances; | |
function buyTokens() public payable { | |
uint tokens = msg.value/weiPerEth*tokensPerEth; // convert wei to eth, then multiply by token rate | |
balances[msg.sender] += tokens; | |
} | |
function sellTokens(uint tokens) public { | |
require(balances[msg.sender] >= tokens); | |
uint eth = tokens/tokensPerEth; | |
balances[msg.sender] -= tokens; | |
msg.sender.transfer(eth*weiPerEth); // | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment