Submitted by Franfran
https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/p1/Furnace.sol#L77-L79
https://github.com/reserve-protocol/protocol/blob/df7ecadc2bae74244ace5e8b39e94bc992903158/contracts/p1/StRSR.sol#L509-L512
https://github.com/reserve-protocol/protocol/blob/946d9b101dd77275c6cbfe0bfe9457927bd221a9/contracts/p1/StRSR.sol#L490-L493
For two instances in the codebase (Furnace and StRSR), the composed rewards calculation seems to be wrong.
How the rewards are working in these two snippets is that we are first measuring how much period or rewardPeriod occured since the last payout and calculating in only one step the rewards that should be distributed over these periods. In other words, it is composing the ratio over periods.
Taken from the comments, we can write the formula of the next rewards payout as:
Generalization:
$u\_{i+1} = u\_{i} * (1 - r)$
Its a geometric mean whose growth rate is (1 - r).
Calculation of the sum:

You can play with the graph here.
For a practical example, lets say that our rsrRewardsAtLastPayout is 5, with a rewardRatio of 0.9.
If we had to calculate our compounded rewards, from the formula given by the comments above, we could calculate manually for the first elements. Lets take the sum for n = 3:
$S = u\_{2} + u\_{1} + u\_{0}$
$u\_{2} = u\_{1} * (1-0.9)$
$u\_{1} = u\_{0} * (1-0.9)$
$u\_{0} = rsrRewardsAtLastPayout$
So,
$S = u\_{0} * (1-0.9) * (1-0.9) + u\_{0} * (1-0.9) + u\_{0}$
For the values given above, thats
$S = 5 * 0.1 + 5 * 0.1 + 5$
$S = 5.55$
If we do the same calculation with the sum formula

$S' = 4.995$
Rather than dividing by 1 (1e18 from the Fixed library), divide it by the ratio.
tbrent (Reserve) disputed and commented:
0xean (judge) commented:
Please note: the following comment and re-assessment took place after judging and awarding were finalized. As such, this report will leave this finding in its originally assessed risk category as it simply reflects a snapshot in time.
0xean (judge) commented:
Franfran (warden) commented:
