code-423n4 / 2021-10-tempus-findings

0 stars 0 forks source link

for loop with _TOTAL_TOKENS #36

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

pauliax

Vulnerability details

Impact

The loop here is not really necessary as _TOTAL_TOKENS is a constant of 2 so there is always just 1 iteration: for (uint256 i = 1; i < _TOTAL_TOKENS; ++i) { uint256 currentBalance = balances[i]; if (currentBalance > maxBalance) { chosenTokenIndex = i; maxBalance = currentBalance; } }

Recommended Mitigation Steps

Consider if you want to reduce gas usage by eliminating this loop here but taking the risk that _TOTAL_TOKENS will not be updated to a different value.

RedFox20 commented 2 years ago

I think this is a nice small cleanup for the code, it looks much simpler with this fix. Fixed in https://github.com/tempus-finance/tempus-protocol/pull/379