doesn’t check the underflow/overflow like a prior version from 0.7

tl;dr: "unchecked" exists in order to save gas

the features of unchecked

  1. don’t use the default overflow/underflow features from solidity 0.8 ~
  2. If you use this unchecked, you can save your gas fee

If you use array, you should use unchecked keyword.

Screen Shot 2022-08-06 at 15.41.55.png

https://ethereum.stackexchange.com/questions/113221/what-is-the-purpose-of-unchecked-in-solidity


gas optimization

for (uint256 i = 0; i < distributions.length; ) {
            if (distributions[i].beneficiary == _beneficiary) return true;
						// check under/over flow when executing i++ 
            unchecked {
                ++i;
            }
        }

https://moralis.io/gas-optimizations-in-solidity-top-tips/

This code must not use unchecked. it has underflow/overflow error….

pragma solidity 0.7.0;

contract ChangeBalance {
    uint8 public balance;

    function decrease() public {
        balance--;
    }

    function increase() public {
        balance++;
    }
}