When the value of the post-loop increment/decrement is not stored or used in any calculations, the prefix increment/decrement operators (++i/--i) cost less gas PER LOOP than the postfix increment/decrement operators (i++/i--)
Proof of Concept
There are 27 instances of this issue in the repository:
Handle
IllIllI
Vulnerability details
Impact
When the value of the post-loop increment/decrement is not stored or used in any calculations, the prefix increment/decrement operators (
++i
/--i
) cost less gas PER LOOP than the postfix increment/decrement operators (i++
/i--
)Proof of Concept
There are 27 instances of this issue in the repository:
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/XOLE.sol#L362
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/dex/eth/EthDexAggregatorV1.sol#L48
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/dex/eth/UniV2Dex.sol#L59
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/dex/eth/UniV3Dex.sol#L75
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/dex/bsc/UniV2ClassDex.sol#L60
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/dex/bsc/BscDexAggregatorV1.sol#L46
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/lib/DexData.sol#L89
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/lib/DexData.sol#L114
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/lib/DexData.sol#L139
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/periphery/QueryHelper.sol#L69
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/periphery/QueryHelper.sol#L112
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/periphery/QueryHelper.sol#L225
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/OpenLevV1.sol#L52
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/gov/GovernorAlpha.sol#L202
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/gov/GovernorAlpha.sol#L228
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/gov/GovernorAlpha.sol#L280
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/gov/GovernorAlpha.sol#L307
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/test/MockTaxToken.sol#L187
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/test/MockTaxToken.sol#L287
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/farming/FarmingPools.sol#L126
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/farming/FarmingPools.sol#L132
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/farming/FarmingPools.sol#L164
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/ControllerV1.sol#L303
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/ControllerV1.sol#L375
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/Airdrop.sol#L64
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/OLETokenLock.sol#L33
https://github.com/code-423n4/2022-01-openleverage/blob/main/openleverage-contracts/contracts/OpenLevV1Lib.sol#L260
Tools Used
Code inspection
Recommended Mitigation Steps
Use
++i
rather thani++
in all places