Incorrect calculation when rate changes in _ongoingDebtScaledOf
The function assumes a constant rate throughout the entire period from snapshotTime
to block.timestamp
. However, if there was a rate change during this period, the calculation will be incorrect because it:
Only uses the current rate (_streams[streamId].ratePerSecond
)
Applies this rate to the entire period
Ignores the historical rate that was active for part of the period
Time: [Start]---------------[End]
Rate: 100 tokens/second (constant)
Period: 100 seconds
Debt: 100 * 100 = 10,000 tokens
Time: [Start]-----[Rate Change]-----[End]
Rate: 100 tokens/s -> 200 tokens/s
Period: 50s at 100/s + 50s at 200/s
Expected: (50 * 100) + (50 * 200) = 15,000 tokens
Actual: 100s * 200 = 20,000 tokens (incorrect)
The total debt will be wrong if any rate changes occurred. Users might withdraw incorrect amounts. Protocol-wide accounting will be inaccurate
Manual Review
Track all rate changes in a period
Calculate debt separately for each sub-period
Sum up the total correctly accounting for different rates
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.