You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The for loop has no overflow risk of i. Use an unchecked block to save gas.
Proof of Concept
IndexLogic.sol
39: for (uint i; i < assets.length(); ++i) {
60: for (uint i; i < inactiveAssets.length(); ++i) {
102: for (uint i; i < length; ++i) {
125: for (uint i; i < length + inactiveAssets.length(); ++i) {
TrackedIndexReweightingLogic.sol
37: for (uint i; i < assets.length(); ++i) {
66: for (uint i; i < assets.length(); ++i) {
TopNMarketCapReweightingLogic.sol
37: for (uint i; i < assets.length(); ++i) {
51: for (uint _i; _i < diff.assetCount; ++_i) {
104: for (uint i; i < _inactiveAssets.length; ++i) {
ManagedIndex.sol
30: for (uint i; i < _assets.length; ++i) {
TopNMarketCapIndex.sol
48: for (uint i; i < _assets.length; ++i) {
BaseIndex.sol
78: for (uint i; i < _assets.length; ++i) {
UniswapV2PathPriceOracle.sol
34: for (uint i = 0; i < path.length - 1; i++) {
49: for (uint i = 0; i < path.length - 1; i++) {
TrackedIndex.sol
35: for (uint i; i < _assets.length; ++i) {
ManagedIndexReweightingLogic.sol
38: for (uint i; i < assets.length(); ++i) {
50: for (uint i; i < _updatedAssets.length; ++i) {
96: for (uint i; i < _inactiveAssets.length; ++i) {
Recommendation
Use unchecked blocks to avoid overflow checks, or use ++i rather than i++ if you don't use unchecked blocks.
for (uint256 i = 0; i < length; ) {
...
unchecked {
++i;
}
}
The text was updated successfully, but these errors were encountered:
Save gas in for loops by unchecked arithmetic
The for loop has no overflow risk of
i
. Use an unchecked block to save gas.Proof of Concept
Recommendation
Use
unchecked
blocks to avoid overflow checks, or use++i
rather thani++
if you don't use unchecked blocks.The text was updated successfully, but these errors were encountered: