Open code423n4 opened 2 years ago
0 is less efficient than != 0 for uint in require condition 9 gas
Use custom errors Not useful without explanation
Variables that could be set immutable 5 * 2100 -> 10500
Use uint256 instead of bool 3 gas I believe
Cache block.timestamp + GRACE_PERIOD to activated[_token]
Would save 3 gas on withdraw
Unchecked safe math would save 40 gas
float multiplication optimization Not exactly sure if it will save more than just using unchecked, in lack of math / poc will give it 20 gas
Gas Saved 10575
Report is short and sweet, I appreciate it
> 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/
Variables that could be set immutable
https://github.com/code-423n4/2022-02-concur/blob/72b5216bfeaa7c52983060ebfc56e72e0aa8e3b0/contracts/USDMPegRecovery.sol#L24
https://github.com/code-423n4/2022-02-concur/blob/72b5216bfeaa7c52983060ebfc56e72e0aa8e3b0/contracts/StakingRewards.sol#L19
Use uint256 instead of bool
Use uint(1) instead of bool(true) to save gas by avoiding masking ops https://github.com/code-423n4/2022-02-concur/blob/72b5216bfeaa7c52983060ebfc56e72e0aa8e3b0/contracts/Shelter.sol#L17
Cache
block.timestamp + GRACE_PERIOD
toactivated[_token]
Since we are only interested in
activated[_token] + GRACE_PERIOD
, might as well cache it when we call activate. https://github.com/code-423n4/2022-02-concur/blob/72b5216bfeaa7c52983060ebfc56e72e0aa8e3b0/contracts/Shelter.sol#L38Unchecked safe math
https://github.com/code-423n4/2022-02-concur/blob/72b5216bfeaa7c52983060ebfc56e72e0aa8e3b0/contracts/USDMPegRecovery.sol#L95
can be changed to
assuming user.usdm always <= total.usdm
similarly
can be changed to
float multiplication optimization
can be applied to floating multiplication such as in https://github.com/code-423n4/2022-02-concur/blob/72b5216bfeaa7c52983060ebfc56e72e0aa8e3b0/contracts/ConvexStakingWrapper.sol#L180