contracts/v1/FiatTokenV1.sol:136: require(_amount > 0, "FiatToken: mint amount not greater than 0");
contracts/v1/FiatTokenV1.sol:368: require(_amount > 0, "FiatToken: burn amount not greater than 0");
contracts/v2/FiatTokenV2.sol:143: require(_amount > 0, "FiatToken: mint amount not greater than 0");
contracts/v2/FiatTokenV2.sol:378: require(_amount > 0, "FiatToken: burn amount not greater than 0");
> 0
is less efficient than!= 0
for uint in require conditionRef: https://twitter.com/GalloDaSballo/status/1485430908165443590
Use custom errors
Solidity ^0.8.4 allow the use of custom errors to optimize gas usage. https://blog.soliditylang.org/2021/04/21/custom-errors/
Unnecessary checks
Don't think this risk justisfy the additional gas cost https://github.com/code-423n4/2022-02-jpyc/blob/cfc018384dd1d71febaa57f0576cb51f5d9c7e07/contracts/v1/FiatTokenV1.sol#L245 https://github.com/code-423n4/2022-02-jpyc/blob/cfc018384dd1d71febaa57f0576cb51f5d9c7e07/contracts/v2/FiatTokenV2.sol#L253
Use uint instead of bool
Instead of bool(true), we can use uint(1) instead. This save us around 27 gas each time whitelist is checked. https://github.com/code-423n4/2022-02-jpyc/blob/cfc018384dd1d71febaa57f0576cb51f5d9c7e07/contracts/v2/FiatTokenV2.sol#L62
to
and
accordingly
Unchecked safe math
This is safe because individual balance cannot > totalSupply https://github.com/code-423n4/2022-02-jpyc/blob/cfc018384dd1d71febaa57f0576cb51f5d9c7e07/contracts/v1/FiatTokenV1.sol#L145 https://github.com/code-423n4/2022-02-jpyc/blob/cfc018384dd1d71febaa57f0576cb51f5d9c7e07/contracts/v2/FiatTokenV2.sol#L152
This is safe becuase of the prior
value <= allowed[from][msg.sender]
check https://github.com/code-423n4/2022-02-jpyc/blob/cfc018384dd1d71febaa57f0576cb51f5d9c7e07/contracts/v1/FiatTokenV1.sol#L276 https://github.com/code-423n4/2022-02-jpyc/blob/cfc018384dd1d71febaa57f0576cb51f5d9c7e07/contracts/v2/FiatTokenV2.sol#L286This is safe because of the prior
value <= balances[from]
check https://github.com/code-423n4/2022-02-jpyc/blob/cfc018384dd1d71febaa57f0576cb51f5d9c7e07/contracts/v1/FiatTokenV1.sol#L316 https://github.com/code-423n4/2022-02-jpyc/blob/cfc018384dd1d71febaa57f0576cb51f5d9c7e07/contracts/v2/FiatTokenV2.sol#L326Safe after reorder since individual balance cannot > totalSupply https://github.com/code-423n4/2022-02-jpyc/blob/cfc018384dd1d71febaa57f0576cb51f5d9c7e07/contracts/v1/FiatTokenV1.sol#L371 https://github.com/code-423n4/2022-02-jpyc/blob/cfc018384dd1d71febaa57f0576cb51f5d9c7e07/contracts/v2/FiatTokenV2.sol#L381