Last active
February 1, 2023 16:18
-
-
Save bartubozkurt/b8dcb04c4bdcff55f23ad9475600de03 to your computer and use it in GitHub Desktop.
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
/* Bad */ | |
contract SendEth{ | |
mapping(address => uint256) public balanceOf; | |
function withdraw(address user, uint256 numTokens) public { | |
require(balanceOf[user] >= numTokens); | |
balanceOf[user] -= numTokens; | |
user.transfer(numTokens * 1 ether); | |
} | |
} | |
/* Better */ | |
contract SendEth{ | |
mapping(address => uint256) public balanceOf; | |
function withdraw(address user, uint256 numTokens) public { | |
require(user == msg.sender); // add** | |
require(balanceOf[user] >= numTokens); | |
balanceOf[user] -= numTokens; | |
user.transfer(numTokens * 1 ether); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment