Answer the question
In order to leave comments, you need to log in
Does anyone see a vulnerability in this smart contract?
Hello. There is a solidity smart contract for Ethereum. Task: find a vulnerability.
contract SimpleToken{
mapping(address => uint) public balances;
/// Buy token at the price of 1ETH/token.
function buyToken() payable {
balances[msg.sender]+=msg.value / 1 ether;
}
/**
* @dev Send token.
* @param _recipient The recipient.
* @param _amount The amount to send.
*/
function sendToken(address _recipient, uint _amount) {
require(balances[msg.sender]!=0); // You must have some tokens.
balances[msg.sender]-=_amount;
balances[_recipient]+=_amount;
}
}
Answer the question
In order to leave comments, you need to log in
I would check like this: require(balances[msg.sender]>=_amount);
Because the sender, in theory, could send more than he has, if he has at least some coins.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question