Last active
February 2, 2023 11:03
-
-
Save bartubozkurt/b09366ac42eae611fd98a384017cd5fa 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 */ | |
pragma solidity =0.4.11; | |
contract Bad { | |
mapping(address => uint256) balances; | |
function badWithdraw(uint256 amounts) public { | |
require(amounts <= balances[msg.sender]); | |
balances[msg.sender] -= amounts; | |
(bool success, bytes memory data) = msg.sender.call{value: amounts}(""); | |
require(success); | |
} | |
} | |
/* Better */ | |
pragma solidity =0.8.0; // only version change | |
contract Good { | |
mapping(address => uint256) balances; | |
function badWithdraw(uint256 amounts) public { | |
require(amounts <= balances[msg.sender]); | |
balances[msg.sender] -= amounts; | |
(bool success, bytes memory data) = msg.sender.call{value: amounts}(""); | |
require(success); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment