Skip to content

Instantly share code, notes, and snippets.

@duanescarlett
Last active March 10, 2023 18:25
Show Gist options
  • Save duanescarlett/492da1d6268d25f0e15e6b8e4b97faa7 to your computer and use it in GitHub Desktop.
Save duanescarlett/492da1d6268d25f0e15e6b8e4b97faa7 to your computer and use it in GitHub Desktop.
In this tutorial I explain how overflow and unchecked works in solidity
// 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