Skip to content
Smart contracts Audit finding Advanced

Too few rewards paid over periods in Furnace and StRSR

The report claims that the reward calculation in Furnace and StRSR incorrectly composes rewards over multiple periods, potentially paying out too little. The attacker could exploit this to receive fewer rewards than expected, but the claim was disputed and later deemed invalid by the judge.

Franfran Follow

Originally disclosed on Code4rena

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.

Proof of Concept

Taken from the comments, we can write the formula of the next rewards payout as:

with n = (i+1) > 0, n is the number of periods
rewards{0} = rsrRewards()
payout{i+1} = rewards{i} * payoutRatio
rewards{i+1} = rewards{i} - payout{i+1}
rewards{i+1} = rewards{i} * (1 - payoutRatio)

Generalization: $u_{i+1} = u_{i} * (1 - r)$

It’s a geometric mean whose growth rate is (1 - r).

Calculation of the sum:

You can play with the graph here.

For a practical example, let’s 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. Let’s 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, that’s

$S = 5 * 0.1² + 5 * 0.1 + 5$ $S = 5.55$

If we do the same calculation with the sum formula

$S' = 4.995$

Recommended Mitigation Steps

Rather than dividing by 1 (1e18 from the Fixed library), divide it by the ratio.

// Furnace.sol
// Paying out the ratio r, N times, equals paying out the ratio (1 - (1-r)^N) 1 time.
uint192 payoutRatio = FIX_ONE.minus(FIX_ONE.minus(ratio).powu(numPeriods));

uint256 amount = payoutRatio * lastPayoutBal / ratio;
// StRSR.sol
uint192 payoutRatio = FIX_ONE - FixLib.powu(FIX_ONE - rewardRatio, numPeriods);

// payout: {qRSR} = D18{1} * {qRSR} / r
uint256 payout = (payoutRatio * rsrRewardsAtLastPayout) / rewardRatio;

tbrent (Reserve) disputed and commented:

I think there is a mistake in the math here, possibly arising from the fact that rsrRewards() doesn’t correspond to how much rewards has been handed out, but how much is available to be handed out.

I don’t understand why the warden is computing the sum of u_i. If u_0 is the value of rsrRewards() at time 0, and u_1 is the value of rsrRewards() at time 1, why is the sum of u_i for all i interesting? This is double-counting balances, since only some of u_i is handed out each time.

As the number of payouts approach infinity, the total amount handed out approaches u_0.

0xean (judge) commented:

Would be good to get the warden to comment here during QA - will see if we can have that occur to clear up the difference in understanding.

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:

I want to apologize that I missed the fact that no response was given during QA and currently believe this issue to be invalid.

Franfran (warden) commented:

Hey friends, sorry for not hopping into the discussion earlier! My reasoning was that if the staker’s rewards doesn’t compound over time, then there is no reason for them to stay in the pool and not harvest the rewards, which is a costly process if they would have to harvest each cycle.


The original report as published on Code4rena, by Franfran. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely a misunderstanding of how the reward calculation works, as the project team explained that the formula correctly computes the payout based on available rewards, not a cumulative sum.

Impact

The report claimed that rewards could be underpaid, but the project team disputed this and the judge later deemed the issue invalid, so no actual impact was confirmed.

What the attacker needed

None

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This report is about a smart contract that pays rewards over time. The author thought the maths for calculating rewards over several periods was wrong, but the project team explained that the formula was actually correct and the judge agreed it was not a real bug.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Franfran

View all

14 more disclosed reports, best first.

More from Reserve Core

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.