Skip to content

Instantly share code, notes, and snippets.

@vasa-develop
Created July 21, 2018 19:59
Show Gist options
  • Save vasa-develop/82759590bd44a23fd6d1344e1035fdce to your computer and use it in GitHub Desktop.
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.
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