Open code423n4 opened 1 year ago
uint256 i;
uint256 i = 0;
contracts/libraries/JBIpfsDecoder.sol: L49 L68 L76 L84
contracts/JBTiered721Delegate.sol: L143-L152
contracts/libraries/JBIpfsDecoder.sol: L68 L76 L84
contracts/JBTiered721DelegateStore.sol: L1108
contracts/JBTiered721DelegateStore.sol: L827
contracts/abstract/JB721Delegate.sol: L206 L311 L323
contracts/libraries/JBIpfsDecoder.sol: L22 L44 L74 L82
contracts/libraries/JBBitmap.sol: L29 L59
contracts/JBTiered721DelegateDeployer.sol: L71
contracts/JBTiered721DelegateStore.sol: L628 L1091 L1227
contracts/JBTiered721Delegate.sol: L205 L208 L210 L211 L264 L290 L480 L598 L652 L789
contracts/JB721TieredGovernance.sol: L147 L313
contracts/JB721GlobalGovernance.sol: L55
contracts/JBTiered721DelegateProjectDeployer.sol: L72 L73 L109 L110 L152 L191 L218
x < y + 1
x <= y
contracts/JB721TieredGovernance.sol: L133
contracts/JBTiered721DelegateStore.sol: L903
uint
require(x != 0)
require(x > 0)
contracts/libraries/JBIpfsDecoder.sol: L57
contracts/JBTiered721DelegateStore.sol: L1254
constant
immutable
contracts/JBTiered721Delegate.sol: L48
payable
contracts/JBTiered721Delegate.sol: L370 L402 L418
i++
unchecked
contracts/libraries/JBIpfsDecoder.sol: L49 L51 L68 L76
contracts/JBTiered721Delegate.sol: L341 L355
Picodes marked the issue as grade-b
1. Explicitly assingning default values to variables is a waste of gas
Use
uint256 i;
instead ofuint256 i = 0;
contracts/libraries/JBIpfsDecoder.sol: L49 L68 L76 L84
2. Cache storage variables in function call stack to save gas
contracts/JBTiered721Delegate.sol: L143-L152
3. Prefix incrementing and decrementing costs around 6 gas less than the postfix ones
e.g. ++var is cheaper than var++
contracts/libraries/JBIpfsDecoder.sol: L68 L76 L84
contracts/JBTiered721DelegateStore.sol: L1108
4. use x = x + y instead of x+= y
contracts/JBTiered721DelegateStore.sol: L827
5. Calldata is cheaper than memory for function input
contracts/abstract/JB721Delegate.sol: L206 L311 L323
contracts/libraries/JBIpfsDecoder.sol: L22 L44 L74 L82
contracts/libraries/JBBitmap.sol: L29 L59
contracts/JBTiered721DelegateDeployer.sol: L71
contracts/JBTiered721DelegateStore.sol: L628 L1091 L1227
contracts/JBTiered721Delegate.sol: L205 L208 L210 L211 L264 L290 L480 L598 L652 L789
contracts/JB721TieredGovernance.sol: L147 L313
contracts/JB721GlobalGovernance.sol: L55
contracts/JBTiered721DelegateProjectDeployer.sol: L72 L73 L109 L110 L152 L191 L218
6. Use
x < y + 1
in stead ofx <= y
contracts/JB721TieredGovernance.sol: L133
contracts/JBTiered721DelegateStore.sol: L903
7. When comparing variables of type
uint
, userequire(x != 0)
instead ofrequire(x > 0)
contracts/libraries/JBIpfsDecoder.sol: L57
contracts/JBTiered721DelegateStore.sol: L1254
8. Use
constant
andimmutable
for constantscontracts/JBTiered721Delegate.sol: L48
9. Consider marking functions as
payable
if there is no risk of sending value through themThis change will save gas each time a function is called
contracts/JBTiered721Delegate.sol: L370 L402 L418
10. Place
i++
in anunchecked
blocks in for-loopscontracts/libraries/JBIpfsDecoder.sol: L49 L51 L68 L76
contracts/JBTiered721Delegate.sol: L341 L355