In the MinimumVarianceUpdateRule contract's _getWeights function, there are loops that rely on a loop variable i. The issue arises because the loop variable i is not properly initialized before each loop. Instead, it is declared once at the function level and reused across multiple loops without resetting it to zero. This can lead to loops not executing as intended, resulting in incomplete calculations.
The loop variable i is declared once at the function-level scope: uint i;. It is used in multiple loops without being reinitialized between them. After the first loop finishes, i equals _prevWeights.length. The condition for the next loop i < _prevWeights.length is no longer satisfied, so the loop doesn't execute.
See the first loop above. Since i is declared at the function level and not reinitialized here, it starts with its current value. At the beginning of the first loop, i is 0 (since it's a new function call).
The loop runs as long as i < _prevWeights.length. i is incremented in each iteration via ++i. When i reaches _prevWeights.length, the loop exits.
After the first loop, i equals _prevWeights.length.
The second loop can be seen above. i is not reinitialized, so it remains at _prevWeights.length. The loop condition i < _prevWeights.length evaluates to false (since i == _prevWeights.length). The loop body is not executed at all. All calculations intended to be performed in the second loop are skipped.
The second loop is crucial as it calculates the final adjusted weights and stores them in newWeightsConverted.
Note: similar issue can be found in ChannelFollowingUpdateRule.sol::_getWeights. I don't want to Belabor the point with another report on the similar issue
The newWeightsConverted array remains uninitialized or contains default values (likely zeros).
The function returns incorrect weight values. The final weights are incorrect because the necessary calculations in the second loop are never performed
Manual Review
Initialize i Before Each Loop: Ensure that i starts at 0 for each loop by declaring it within the loop's scope.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.