code-423n4 / 2022-04-jpegd-findings

1 stars 1 forks source link

Gas Optimizations #180

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Finding: Require message too long Explanation: The require messages below can be shortened to 32 characters or fewer (as shown) to save gas.

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/tokens/JPEG.sol#L23 Change to 'JPEG: minter role needed to mint'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/tokens/StableCoin.sol#L41 Change to 'StableCoin: only minters mint'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/tokens/StableCoin.sol#L55 Change to 'StableCoin: only pausers pause'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/tokens/StableCoin.sol#L69 Change to 'StableCoin: only pausers unpause'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/NFTVault.sol#L394 Change to 'creditrate≥_liquidation_rate'

Finding: Should use custom error instead of revert string Explanation: Each line of code referenced below contains the following: revert("Cannot renounce ownership"); Using a custom error would be cheaper than the revert string.

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/farming/LPFarming.sol#L364

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/farming/yVaultLPFarming.sol#L190

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/helpers/CryptoPunksHelper.sol#L91

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/helpers/EtherRocksHelper.sol#L96

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/lock/JPEGLock.sol#L82

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/yVault/yVault.sol#L201

Finding: Should use != 0 instead of > 0 in a require statement if variable is an unsigned integer (uint) Explanation: != 0 should be used instead of > 0 where possible since > 0 costs more gas.

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/farming/LPFarming.sol#L114 Change '_rewardPerBlock > 0' to '_rewardPerBlock != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/farming/LPFarming.sol#L218 Change '_amount > 0' to '_amount != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/farming/LPFarming.sol#L239 Change '_amount > 0' to '_amount != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/farming/LPFarming.sol#L337 Change 'rewards > 0' to 'rewards != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/farming/LPFarming.sol#L354 Change 'rewards > 0' to 'rewards != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/farming/yVaultLPFarming.sol#L101 Change '_amount > 0' to '_amount != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/farming/yVaultLPFarming.sol#L118 Change '_amount > 0' to '_amount != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/farming/yVaultLPFarming.sol#L139 Change 'rewards > 0' to 'rewards != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/lock/JPEGLock.sol#L40 Change '_newTime > 0' to '_newTime != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/staking/JPEGStaking.sol#L32 Change '_amount > 0' to '_amount != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/FungibleAssetVaultForDAO.sol#L108 Change 'answer > 0' to 'answer != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/FungibleAssetVaultForDAO.sol#L142 Change 'amount > 0' to 'amount != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/FungibleAssetVaultForDAO.sol#L164 Change 'amount > 0' to 'amount != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/FungibleAssetVaultForDAO.sol#L180 Change 'amount > 0' to 'amount != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/NFTVault.sol#L278 Change '_newFloor > 0' to '_newFloor != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/NFTVault.sol#L365 Change 'pendingValue > 0' to 'pendingValue != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/NFTVault.sol#L687 Change '_amount > 0' to '_amount != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/NFTVault.sol#L764 Change '_amount > 0' to '_amount != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/NFTVault.sol#L770 Change 'debtAmount > 0' to 'debtAmount != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/NFTVault.sol#L882 Change 'position.liquidatedAt > 0' to 'position.liquidatedAt != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/NFTVault.sol#L926 Change 'position.liquidatedAt > 0' to 'position.liquidatedAt != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/yVault/strategies/StrategyPUSDConvex.sol#L334 Change 'wethBalance > 0' to 'wethBalance != 0'

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/yVault/yVault.sol#L143 Change '_amount > 0' to '_amount != 0'

Finding: Should use additional require instead of && within a require function Explanation: Using require instead of && saves gas

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/staking/JPEGStaking.sol#L45-L48 Change to: require( _amount > 0, "invalid_amount"); require( _amount <= balanceOf(msg.sender), "invalid_amount");

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/FungibleAssetVaultForDAO.sol#L93-L98 Change to: require(_creditLimitRate.denominator > 0, "invalid_amount"); //denominator can be equal to the numerator in some cases (stablecoins used as collateral) require(_creditLimitRate.denominator >= _creditLimitRate.numerator, "invalid_rate");

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/FungibleAssetVaultForDAO.sol#L194 Change to: require( _amount > 0, "invalid_amount"); require(amount <= collateralAmount, "invalid_amount");

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/NFTVault.sol#L401-L404 Change to: require(rate.denominator > 0, "invalid_amount"); require(rate.denominator >= rate.numerator, "invalid_rate");

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/yVault/yVault.sol#L99-L102 Change to: require( _rate.numerator > 0, "INVALID_AMOUNT"); require( _rate.denominator >= _rate.numerator, "INVALID_RATE");

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/vaults/yVault/strategies/StrategyPUSDConvex.sol#L181-L185 Change to: require(_performanceFee.denominator > 0, "INVALID_AMOUNT"); require(_performanceFee.denominator >= _performanceFee.numerator, "INVALID_RATE");