Solidity
為什麼在最新開放的 zeppelin erc20 轉賬中,餘額和要求檢查不在未檢查的功能範圍內?
如果由於檢查 mint 功能而無法在此傳輸中上溢/下溢,那麼為什麼這 2 行 (236/237) 不在未檢查欄位內?
這兩行不執行算術運算,因此將它們移動到
unchecked
塊內不會帶來任何好處。也許它會使程式碼更難閱讀:uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by // decrementing then incrementing. _balances[to] += amount; }