Use Custom Error instead of Revert String to Save Gas
Custom error from solidity 0.8.4 are cheaper than revert strings, custom error are defined using the error statement can use inside and outside the contract.
Consider making some constants as non-public to save gas
Reducing from public to private or internal can save gas when a constant isn’t used outside of its contract. I suggest changing the visibility from public to internal or private.
> 0 is less efficient than != 0 for unsigned integers
!= 0 costs less gas compared to > 0 for unsigned integers in require statements with the optimizer enabled (6 gas)
While it may seem that > 0 is cheaper than !=, this is only true without the optimizer enabled and outside a require statement. If you enable the optimizer at 10k AND you’re in a require statement, this will save gas.
Custom error from solidity 0.8.4 are cheaper than revert strings, custom error are defined using the
error
statement can use inside and outside the contract.source https://blog.soliditylang.org/2021/04/21/custom-errors/
i suggest replacing revert error strings with custom error
POC :
https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VeAssetDepositor.sol#L54 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VeAssetDepositor.sol#L60 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VeAssetDepositor.sol#L69 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VeAssetDepositor.sol#L132 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L124 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L130 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L136 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L146 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L163 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L169 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L179 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L194 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L226 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L231 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L244 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L261 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L262 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L309 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L326 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L350 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L352 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L360 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L448 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L458 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L468 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L477 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L485 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L498 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L570 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L604 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#L122 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#L123 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#L124 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#L132 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#L173 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#L196 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#L215 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#L301 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VE3DRewardPool.sol#L135 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VE3DRewardPool.sol#L136 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VE3DRewardPool.sol#L135 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VE3DRewardPool.sol#L210 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VE3DRewardPool.sol#L234 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VE3DRewardPool.sol#L253 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VE3DRewardPool.sol#L342 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L63 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L69 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L78 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L84 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L92 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L110 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L128 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L139 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L151 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L159 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L167 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L173 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L186 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L211 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L225 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L257 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L263 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L279 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VeTokenMinter.sol#L42 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VeTokenMinter.sol#L49
Reducing from
public
toprivate
orinternal
can save gas when a constant isn’t used outside of its contract. I suggest changing the visibility frompublic
tointernal
orprivate
.POC :
https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L33
> 0
is less efficient than!= 0
for unsigned integers!= 0
costs less gas compared to> 0
for unsigned integers in require statements with the optimizer enabled (6 gas)While it may seem that
> 0
is cheaper than!=
, this is only true without the optimizer enabled and outside a require statement. If you enable the optimizer at 10k AND you’re in a require statement, this will save gas.source : https://twitter.com/gzeon/status/1485428085885640706
I suggest changing
> 0
with!= 0
POC :
https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VeAssetDepositor.sol#L132 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#L196 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/BaseRewardPool.sol#L215 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VE3DRewardPool.sol#L210 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VE3DRewardPool.sol#L234 https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VE3DRewardPool.sol#L253