for (uint256 i = 0; i < cTokenAddresses.length;) {
if (sources[i] != address(0)) {
require(msg.sender == admin, "Only the admin or guardian can clear the aggregators");
}
unchecked{
i++
}
}
Please provide summary with total gas savings for these proposed changes in terms of contract calls and deployment costs. Please provide relevant sources to substantiate submissions wherever possible.
TITLE (Gas savings )
ISSUE 1 VARIABLES SHOULD BE IMMUTABLE
https://github.com/LodestarFinance/lodestar-token-fix/blob/8807ec57f88b96421e97b0011833897ac48b4bb6/contracts/TokenFIx.sol#L11-L12
The following variables should be market as immutable because they are initialized in the constructor and can't be changed after:
SEVERITY (either high or medium, see the rules)
Gas
A LINK TO THE GITHUB ISSUE
https://github.com/LodestarFinance/lodestar-token-fix/blob/8807ec57f88b96421e97b0011833897ac48b4bb6/contracts/TokenFIx.sol#L11-L12
SOLUTION
IERC20 public immutable oldToken; IERC20 public immutable newToken;
ISSUE 2 FOR LOOP OPTIMAZATION
https://github.com/LodestarFinance/lodestar-protocol/blob/807a166179ca5be52039d39316844d2a420eabce/contracts/Oracle/PriceOracleProxyETH.sol#L237
Add an unchecked keyword to the i++ on the for loop
SEVERITY (either high or medium, see the rules)
Gas
A LINK TO THE GITHUB ISSUE
https://github.com/LodestarFinance/lodestar-protocol/blob/807a166179ca5be52039d39316844d2a420eabce/contracts/Oracle/PriceOracleProxyETH.sol#L237
https://github.com/LodestarFinance/plvglp-oracle/blob/b9e78d6bfb119ee1703a7e97d283a1e1dcf25046/contracts/plvGLPOracle.sol#L99
SOLUTION
ISSUE 3 DON'T INITIALIZE VARIABLES TO 0
[https://github.com/LodestarFinance/lodestar-token-fix/blob/8807ec57f88b96421e97b0011833897ac48b4bb6/contracts/TokenFIx.sol#L11-L12
Should not have uint i = 0 instead uint i
SEVERITY (either high or medium, see the rules)
Gas
A LINK TO THE GITHUB ISSUE
https://github.com/LodestarFinance/plvglp-oracle/blob/b9e78d6bfb119ee1703a7e97d283a1e1dcf25046/contracts/plvGLPOracle.sol#L92
SOLUTION
for (uint256 i; i < latestIndexing; i++) { sum += HistoricalIndices[i].recordedIndex; }
ISSUE 4 USE REVERT INSTEAD OF REQUIRE
(https://github.com/LodestarFinance/lodestar-protocol/blob/807a166179ca5be52039d39316844d2a420eabce/contracts/Oracle/PriceOracleProxyETH.sol#L219)
SEVERITY (either high or medium, see the rules)
Gas
A LINK TO THE GITHUB ISSUE
https://github.com/LodestarFinance/lodestar-protocol/blob/807a166179ca5be52039d39316844d2a420eabce/contracts/Oracle/PriceOracleProxyETH.sol#L219
SOLUTION