Question about ERC20 burn function

Hello Guys,

in the ERC20 contract _burn() function you are using an unchecked block to exclude the balance update from overflow/underflow checking by the solc.

Why do you do this? Is this to save gas and because you made sure with the require-check above that underflow cannot happen?

I am trying to understand what was the reasoning for adding this unchecked block and I would appreciate if you could shed some light on that for me.

Thank you and best regards
Daniel

    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            **_balances[account] = accountBalance - amount;**
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

It's because overflow is already checked in the previous line:

        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");

Does it save gas to put it in an unchecked block?

Yes, it omits the redundant overflow checking code.