Why are all the absolutely-safe operations wrapped in an unchecked block?

I'm being a bit of a nerd here and reading openzeppelin's ERC20 smart contract implementation:

I noticed this. What's the point of having unchecked blocks if we're fully sure that the operation is safe? Is this a performance enhancement?

Solidity 0.8.0 added under/overflow checks by default (prior to that most code used the SafeMath lib). The unchecked tells the compiler not to add those checks. It's a gas saving enhancement (and performance in the sense that gas == amount of work done)

1 Like

Thanks, yes that makes total sense.