Skip to content

Instantly share code, notes, and snippets.

@phunguyen19
Created July 29, 2024 01:54
Show Gist options
  • Save phunguyen19/e4f1f1b7bc8f678e83f414d60183d044 to your computer and use it in GitHub Desktop.
Save phunguyen19/e4f1f1b7bc8f678e83f414d60183d044 to your computer and use it in GitHub Desktop.
Example Ethereum Smart Contract Arithmetic Over/Underflow attack
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