Created
July 29, 2024 01:54
-
-
Save phunguyen19/e4f1f1b7bc8f678e83f414d60183d044 to your computer and use it in GitHub Desktop.
Example Ethereum Smart Contract Arithmetic Over/Underflow attack
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 TimeLock { | |
mapping(address => uint) public balances; | |
mapping(address => uint) public lockTime; | |
function deposit() external payable { | |
balances[msg.sender] += msg.value; | |
lockTime[msg.sender] = now + 1 weeks; | |
} | |
function increaseLockTime(uint _secondsToIncrease) public { | |
lockTime[msg.sender] += _secondsToIncrease; | |
} | |
function withdraw() public { | |
require(balances[msg.sender] > 0); | |
require(now > lockTime[msg.sender]); | |
uint transferValue = balances[msg.sender]; | |
balances[msg.sender] = 0; | |
msg.sender.transfer(transferValue); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment