Last active
March 10, 2023 18:25
-
-
Save duanescarlett/492da1d6268d25f0e15e6b8e4b97faa7 to your computer and use it in GitHub Desktop.
In this tutorial I explain how overflow and unchecked works in solidity
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
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.12; | |
contract SafeMath { | |
// uint8 public number = 255; | |
uint8 public number = 2**8 - 1; | |
function increment() public { | |
unchecked { | |
number++; | |
} | |
} | |
function decrement() public { | |
unchecked { | |
number--; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment