Closed code423n4 closed 2 years ago
https://github.com/code-423n4/2022-02-nested/blob/main/contracts/FeeSplitter.sol#L318
Manual review
Consider caching length before the for loop.
uint256 shareholdersLength = shareholders.length for (uint256 i; i < shareholdersLength; ++i) { ... }
6 occurences in FeeSplitter.sol
9 occurences in NestedFactory.sol
1 occurences in NestedRecords.sol
3 occurences in OperatorResolver.sol
2 occurences in MixinOperatorResolver.sol
Change i++ to ++i
i++
++i
Especially present in for loop index assignment.
Remove default value assignments.
1 and 2 already surfaced in the previous audit, they were disputed on #32 of this audit.
My personal judgments:
Gas Savings
---------------------------------------------------------------------------
1 - Accessing array length in for loop can be optimized by caching in local variable in order to save SLOAD op per spin of the loop
https://github.com/code-423n4/2022-02-nested/blob/main/contracts/FeeSplitter.sol#L318
Tools Used
Manual review
Recommended Mitigation Steps
Consider caching length before the for loop.
---------------------------------------------------------------------------
2 - Using pre-increment (++i) instead of post-increment (i++) can save gas
6 occurences in FeeSplitter.sol
9 occurences in NestedFactory.sol
1 occurences in NestedRecords.sol
3 occurences in OperatorResolver.sol
2 occurences in MixinOperatorResolver.sol
Tools Used
Manual review
Recommended Mitigation Steps
Change
i++
to++i
---------------------------------------------------------------------------
3 - Assigning default values costs unnecessary gas.
Especially present in for loop index assignment.
6 occurences in FeeSplitter.sol
9 occurences in NestedFactory.sol
1 occurences in NestedRecords.sol
3 occurences in OperatorResolver.sol
2 occurences in MixinOperatorResolver.sol
Tools Used
Manual review
Recommended Mitigation Steps
Remove default value assignments.
---------------------------------------------------------------------------