Deposit allows for stealing underlying tokens from TruefiProvider, IdleProvider, YearnProvider, BetaProvider, CompoundProvider and AaveProvider balances
The deposit functions in several provider contracts accept a user-supplied underlying token address and amount, then use the contract's own balance of that token to mint yield-bearing tokens, which are sent to the caller. An attacker can supply a fake token that reports a balance increase without actually transferring funds, causing the provider to use its own holdings of a real underlying token to mint tokens for the attacker.
TruefiProvider, IdleProvider, YearnProvider deposit() accept both underlying and yield bearing tokens from user and allow for stealing all underlying tokens from contract balances whenever there is a real yield bearing token for it.
Vulnerability Detail
Consider the following, for TruefiProvider case:
Attacker needs to supply fake pre-cooked _uToken, real _tToken, and _amount = IERC20(real_uToken).balanceOf(address(this)).
Fake _uToken will report exactly _amount balance increase after safeTransferFrom() call.
TruefiProvider will join real _tToken with all balance of its own, and send all the proceeds to msg.sender.
Impact
Any underlying tokens for which there is a market can be stolen from Provider balance.
Even if all these contracts aren't supposed to hold balances, there are a spectre of cases when they end up possessing some meaningful funds (accumulated residuals, additional rewards supplied from the markets, user operational mistakes), which are attributed to protocol users, but can be stolen this way.
Same with BetaProvider deposit(), fake _uToken can just report current real underlying token balance of BetaProvider and real _bToken minted from that is sent to msg.sender:
Same with CompoundProvider deposit(), fake _uToken can just report current real underlying token balance and real _cToken minted from that is send to msg.sender:
Same with AaveProvider deposit(), fake _uToken reports current real underlying token balance of AaveProvider, real _aToken deposits it on behalf of msg.sender:
One way is maintaining a whitelist mapping {underlying token -> yield bearing token -> acceptance flag}. The flag for the pair used in a call is then required to proceed.
Also, a balance check for token that is sent to a user can be useful: for attacker to benefit the token that is sent to them has to be real, so another approach is controlling its balance of the contract before and after the operation, and require that no loss of the initial balance took place.
A version of that is implemented in CompoundProvider's withdraw(), where real token balance ends up controlled, as an example:
no real issue cause provider never has a balance of the underlying
hrishibhat
Given that the providers can hold some funds through secondary rewards or other operations mistakes, loss of these funds is not considered a valid high/medium based on Sherlock rules.
Considering this issue as low
dmitriia
Escalate for 10 USDC
The only requirements for token to be stolen is that it should have the market for itself. I.e. it can be a reward token that is distributed to Provider that performs the deposits, but there should be a market for it in the same Provider.
This condition is actually satisfied in Beta Finance case.
There are BETA rewards distributed to stablecoin markets on mainnet:
As mentioned in 360 comments, there is a shortcoming of the current design, that treats Vault as the destination of reward tokens, while it is Provider address interacting with the markets and Vault address has literally no link with the pools, so if the additional non-underlying rewards are due, they be due to the Provider's address.
It is assumed that govToken should end up being on the Vault balance:
This way the reward portion of the yield for the whole Vault can be stolen fully, as it will sit on the BetaProvider balance in the form of BETA tokens and there is a market for these tokens in Beta Finance, so this looks like valid high severity and needs to be fixed.
sherlock-admin
Escalate for 10 USDC
The only requirements for token to be stolen is that it should have the market for itself. I.e. it can be a reward token that is distributed to Provider that performs the deposits, but there should be a market for it in the same Provider.
This condition is actually satisfied in Beta Finance case.
There are BETA rewards distributed to stablecoin markets on mainnet:
As mentioned in 360 comments, there is a shortcoming of the current design, that treats Vault as the destination of reward tokens, while it is Provider address interacting with the markets and Vault address has literally no link with the pools, so if the additional non-underlying rewards are due, they be due to the Provider's address.
It is assumed that govToken should end up being on the Vault balance:
This way the reward portion of the yield for the whole Vault can be stolen fully, as it will sit on the BetaProvider balance in the form of BETA tokens and there is a market for these tokens in Beta Finance, so this looks like valid high severity and needs to be fixed.
You've created a valid escalation for 10 USDC!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
hrishibhat
Escalation accepted
Considering issues #359 and #360 duplicates of this issue.
These issues point to different ways in which the rewards in the provider can be stolen.
However, considering the fact that derby protocol optimizes yield, this issue points towards the fact that the provider could eventually end up with some additional rewards/gov tokens from different protocols(which is not expected) and they can be lost/stolen.
Considering this issue a valid high in this case.
Note:
@sjoerdsommen care must be taken while adding code to sweep these additional rewards to avoid attacks mentioned in this issue and its duplicates.
sherlock-admin
Escalation accepted
Considering issues #359 and #369 duplicates of this issue.
These issues point to different ways in which the rewards in the provider can be stolen.
However, considering the fact that derby protocol optimizes yield, this issue points towards the fact that the provider could eventually end up with some additional rewards/gov tokens from different protocols(which is not expected) and they can be lost/stolen.
Considering this issue a valid high in this case.
Note:
@sjoerdsommen care must be taken while adding code to sweep these additional rewards to avoid attacks mentioned in this issue and its duplicates.
This issue's escalations have been accepted!
Contestants' payouts and scores will be updated according to the changes made on this issue.
hrishibhat
Note:
The primary reason for considering the 3 issues collectively is that they identify the additional rewards being collected in these providers which is not originally intended.
So being able to steal them is not a primary issue because these providers were not supposed to have any underlying balance in the first place.
This is a subjective decision in this case after further discussion & consideration, and cannot be referenced for future contests.
However, Sherlock will consider addressing such scenarios in the judging guide going forward.
The original report as published on Sherlock, by hyh. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The deposit functions trust the user-supplied underlying token address and amount without validating that the token is legitimate or that the contract's own balance of the real underlying token is not used.
Impact
Any underlying tokens for which there is a market can be stolen from the provider's balance, though the providers are not supposed to hold balances and such funds would only be present due to residuals, rewards, or mistakes.
What the attacker needed
Provider holds a balance of a real underlying token; A market exists for that token in the same provider; Attacker can deploy a fake ERC20 token
The fix
The deposit functions should maintain a whitelist mapping of allowed underlying token to yield-bearing token pairs, and optionally check that the contract's balance of the token sent to the user does not decrease.
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.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
These provider contracts let users deposit tokens to earn yield. The deposit function checks that the user's token balance increased by the amount they claim, but it does not verify that the token is legitimate. An attacker can create a fake token that lies about the balance increase, so the contract thinks the user deposited funds when they did not. The contract then uses its own real tokens to mint yield tokens for the attacker, stealing from the contract's balance.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.