doesn’t check the underflow/overflow like a prior version from 0.7
tl;dr: "unchecked" exists in order to save gas
If you use array, you should use unchecked keyword.
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++;
}
}