In case Distributor.setDistribution use, revenue from rToken RevenueTrader and rsr token RevenueTrader should be distributed
The Distributor contract's distribution settings can be changed at any time, but revenue already sent to RevenueTrader contracts is not redistributed immediately. If the distribution is changed to give a zero share to a destination, tokens held in RevenueTrader may become stuck because the distribute function will not send them to that destination.
Originally disclosed on Code4rena
Submitted by rvierdiiev
In case Distributor.setDistribution use, revenue from rToken RevenueTrader and rsr token RevenueTrader should be distributed. Otherwise wrong distribution will be used.
Proof of Concept
BackingManager.forwardRevenue function sends revenue amount to the rsrTrader and rTokenTrader contracts, according to the distribution inside Distributor contract. For example it can 50%/50%. In case if we have 2 destinations in Distributor: strsr and furnace, that means that half of revenue will be received by strsr stakers as rewards.
This distribution can be changed at any time.
The job of RevenueTrader is to sell provided token for a tokenToBuy and then distribute it using Distributor.distribute function. There are 2 ways of auction that are used: dutch and gnosis. Dutch auction will call RevenueTrader.settleTrade, which will initiate distribution. But Gnosis trade will not do that and user should call distributeTokenToBuy manually, after auction is settled.
The problem that I want to discuss is next.
Suppose, that governance at the beginning set distribution as 50/50 between 2 destinations: strsr and furnace. And then later forwardRevenue sent some tokens to the rsrTrader and rTokenTrader. Then, when trade was active to exchange some token to rsr token, Distributor.setDistribution was set in order to make strsr share to 0, so now everything goes to Furnace only. As result, when trade will be finished in the rsrTrader and Distributor.distribute will be called, then those tokens will not be sent to the strsr contract, because their share is 0 now. They will be stuck inside rsrTrader.
Another problem here is that strsr holders should receive all revenue from the time, where they distribution were created. What i mean is if in time 0, rsr share was 50% and in time 10 rsr share is 10%, then BackingManager.forwardRevenue should be called for all tokens that has surplus, because if that will be done after changing to 10%, then strsr stakers will receive less revenue.
Tools Used
VsCode
Recommended Mitigation Steps
You need to think how to guarantee fair distribution to the strsr stakers, when distribution params are changed.
tbrent (Reserve) confirmed and commented:
This is a good find. The mitigation we have in mind is adding a new function to the
RevenueTraderthat allows anyone to transfer a registered ERC20 back to theBackingManager, as long as the current distribution for thattokenToBuyis 0%.
Distribute revenue in
setDistribution. PR: https://github.com/reserve-protocol/protocol/pull/878
Status: Mitigation error. Full details in reports from 0xA5DF and rvierdiiev - and also shared below in the Mitigation Review section.
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 the distribution logic does not account for revenue that was forwarded under a previous distribution configuration, so changing the distribution can leave funds stranded in RevenueTrader contracts.
Impact
Tokens could become stuck in the RevenueTrader contract, and stakers may receive less revenue than they are owed.
What the attacker needed
Governance can change distribution; revenue forwarded before change; trade active during change
The fix
The mitigation was to add a function to RevenueTrader that allows anyone to transfer a registered ERC20 back to BackingManager when the current distribution for that tokenToBuy is 0%, and later to distribute revenue in setDistribution, but the mitigation had an error.
How it was found
- Governance sets distribution to 50% for strsr and 50% for furnace.
- BackingManager.forwardRevenue sends tokens to rsrTrader and rTokenTrader.
- A trade is started to exchange some token for rsr token.
- While the trade is active, Distributor.setDistribution is called to set strsr share to 0%.
- The trade finishes and Distributor.distribute is called, but the strsr share is now 0%, so tokens remain stuck in rsrTrader.
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.
A smart contract splits revenue between recipients according to percentages that can be updated. If the percentages change after some money has already been set aside for a recipient, that money might not be sent because the new percentage is zero. This report points out that the money can get stuck in the contract.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.