Attackers can call UToken.redeem() and drain the funds in assetManager
The redeem function in UToken does not check whether the calculated uTokenAmount is zero, allowing an attacker to redeem underlying tokens without burning any uTokens. An attacker could repeatedly call redeem with a small amountOut to drain funds from assetManager.
Source: https://github.com/sherlock-audit/2023-02-union-judging/issues/12
Found by
chaduke
Summary
Attackers can call UToken.redeem() and drain the funds in assetManager, taking advantage of the following vulnerability: due to round error, it is possible that uTokenAmount = 0; the redeem()function does not check whether uTokenAmount = 0 and will redeem the amount of underlyingAmount even when zero uTokens are burned.
Vulnerability Detail
Consider the following attack scenario:
-
Suppose
exchangeRate = 1000 WAD, that is each utoken exchanges for 1000 underlying tokens. -
Attacker B calls
redeem(0, 999), then the else-part of the following code will get executed:
if (amountIn > 0) {
// We calculate the exchange rate and the amount of underlying to be redeemed:
// uTokenAmount = amountIn
// underlyingAmount = amountIn x exchangeRateCurrent
uTokenAmount = amountIn;
underlyingAmount = (amountIn * exchangeRate) / WAD;
} else {
// We get the current exchange rate and calculate the amount to be redeemed:
// uTokenAmount = amountOut / exchangeRate
// underlyingAmount = amountOut
uTokenAmount = (amountOut * WAD) / exchangeRate;
underlyingAmount = amountOut;
}
-
we have
uTokenAmount = 999*WAD/1000WAD = 0, andunderlyingAmount = 999. -
Since
redeeem()does not check whetheruTokenAmount = 0and the function will proceed. When finished, the attacker will get 999 underlying tokens, but burned no utokens. He stole 999 underlying tokens. -
The attacker can accomplish draining the
assetMangerby writing a malicious contract/function using a loop to runredeem(0, exchangeRate/WAD-1)multiple times (as long as not running of gas) and will be able to steal more funds in one SINGLE transaction. Running this transaction a few times will drainassetManagereasily. This attack will be successful whenexchangeRate/WAD-1 > 0. Here we need to consider thatexchangeRatemight change due to the decreasing oftotalReeemable. So in each iteration, when we callredeem(0, exchangeRate/WAD-1), the second argument is recalculated.
Impact
An attacker can keep calling redeem() and drain the funds in assetManager.
Code Snippet
Tool used
Remix
Manual Review
Recommendation
Revise redeem() so that it will revert when uTokenAmount = 0.
Discussion
kingjacob
points valid, but not easy to increase exchangeRate exponentially. becasue exchangeRate starts from 1e18, 10x of exchangeRate means UToken value, by accruing interests, has increased 10x comparing to the underlying DAI. and the attack can profit 9 DAI in that case)
hrishibhat
Agree with the Sponsor on the severity of the issue as exchangeRate cannot be increase exponentially. Considering this a valid medium.
kingjacob
https://github.com/unioncredit/union-v2-contracts/pull/113
dmitriia
Looks ok
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
Impact
An attacker could drain the funds in assetManager, but the sponsor notes that increasing the exchange rate exponentially is not easy, limiting the profit.
What the attacker needed
ExchangeRate/WAD-1 > 0; attacker can call redeem repeatedly
The fix
The redeem function should be revised to revert when uTokenAmount is zero.
How it was found
- Assume the exchange rate is 1000 WAD (each uToken equals 1000 underlying tokens).
- Attacker calls redeem with amountIn=0 and amountOut=999.
- The contract calculates uTokenAmount = (999 * WAD) / 1000 WAD = 0 and underlyingAmount = 999.
- Since uTokenAmount is zero, no uTokens are burned, but the attacker receives 999 underlying tokens.
- The attacker can repeat this in a loop, recalculating amountOut each time, to drain assetManager.
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.
When you redeem tokens, the contract calculates how many uTokens you must burn to get the underlying tokens. Due to rounding, this calculation can result in zero uTokens needed, but the contract still sends you the underlying tokens. An attacker can exploit this to get free tokens, potentially draining the contract's funds.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.