Closed code423n4 closed 1 year ago
Summary Statement The main gas improvements found come from seperating conditions rather than using the binary operation &&.
Using nested if statements saves 3 gas per &&.
/contracts/JBTiered721DelegateStore.sol Line(s): 664, 668, 678, 1050
664: if (_i != 0 && _tierToAdd.contributionFloor < _tiersToAdd[_i - 1].contributionFloor) 668: if (_flags.lockVotingUnitChanges && _tierToAdd.votingUnits != 0) 678: if (_flags.lockManualMintingChanges && _tierToAdd.allowManualMint) 1050: if (_isManualMint && !_storedTier.allowManualMint) revert CANT_MINT_MANUALLY();
Example: from
if (_i != 0 && _tierToAdd.contributionFloor < _tiersToAdd[_i - 1].contributionFloor) { //Inner code }
to
if (_i != 0) { if (_tierToAdd.contributionFloor < _tiersToAdd[_i - 1].contributionFloor) { //Inner code } }
The EVM operates 32 bytes at a time. Changing uint8 to uint256 unless used for variable packing will reduce gas costs.
uint8
uint256
/contracts/libraries/JBIpfsDecoder.sol Line(s): 48
48: uint8 digitlength = 1;
Note: The parameter of _trunctate will also have to change
_trunctate
2 - invalid, 1 is below 100 gas overall
Picodes marked the issue as grade-c
Gas Report
Optimizations found [2]
Summary Statement The main gas improvements found come from seperating conditions rather than using the binary operation &&.
[G-01] Use nested if instead of && ⓘ
Findings:
Using nested if statements saves 3 gas per &&.
/contracts/JBTiered721DelegateStore.sol Line(s): 664, 668, 678, 1050
Example: from
to
[G-02] Unless Used for Variable Packing uint8 May Be More Expensive Than Using uint256 ⓘ
The EVM operates 32 bytes at a time. Changing
uint8
touint256
unless used for variable packing will reduce gas costs.Findings:
/contracts/libraries/JBIpfsDecoder.sol Line(s): 48
Note: The parameter of
_trunctate
will also have to change