Supply part of the accrued debt can be stolen
The `uniClaimDeposit` function mints supply shares without first accruing the total supply, allowing an attacker to mint shares and then call `accrue` to increase the share price before withdrawing. Combined with the ability to deposit a Uniswap V3 position whose liquidity has been decreased but not collected, an attacker can steal most of the accrued `lpRate` in a single transaction.
Submitted by cmichel.
The LendingPair.uniClaimDeposit function allows the user to “collect fees” and mint new supply shares with the collected amounts.
uniClaimDeposit does not accrue tokens
However, the current total supply is not accrued in the function. This means an attacker can:
- mint shares using
uniClaimDeposit - increase the
totalSupplyAmountby callingaccrue(token0)andaccrue(token1)afterwards. - call
withdrawand receive a larger amount of tokens for the newly minted shares due to the increase intotalSupplyAmountfromaccrue(increasing the supply share price_sharesToSupply).
This would only lead to a small protocol loss if uniClaimDeposit would only collect the fees, however, combined with another flaw, one can steal almost the entire protocol lpRate each time:
uniClaimDeposit allows collecting entire liquidity instead of just fees
This has to do with the way liquidity from a Uniswap V3 position (NFT) is withdrawn:
- When calling
positionManager.decreaseLiquidity, theposition.liquidityis removed but stored in the position astokensOwed0/tokensOwed1. It is not transferred to the user. - One needs to call
positionManager.collect(params)to actually transfer out these tokens, settingtokensOwed0/1to0. (This is correctly done inUniswapV3Helper.removeLiquidity.)
An attacker can perform the following attack:
- Create a Uniswap V3 position.
- Get flashloans for both tokens to provide lots of liquidity for this position.
- Call
positionManager.decreaseLiquiditysuch that the entire liquidity is removed and stored (but not collected yet) in the position’stokensOwed0/1fields - Deposit it to WildCredit’s lending pair using
depositUniPosition - Call
uniClaimDepositto mint a huge amount of NFT supply shares. This huge amount will capture the protocol’s debt accrual in the next steps. - Call
accrueon both tokens to accrue debt and pay thelpRatepart of it to suppliers, increasingtotalSupplyAmountand thus the value of a supply share. - With the new debt added to the
totalSupplyAmount, the attacker can now withdraw their minted shares again and capture most of the new debt that was accrued, making a profit.
Impact
Combining these two issues, an attacker could steal most of the accrued lpRate in a single atomic transaction. The attacker can repeat this step capturing the supplier interest for each accrual. (The longer the market hasn’t been accrued, the bigger the profit per single attack transaction, but in the end, the attacker could perform this attack at every block or when it becomes profitable for the gas costs.)
Providing / removing Uniswap V3 liquidity does not incur fees.
The attacker’s profit is the loss of other legitimate suppliers that capture less of the newly accrued debt.
Recommendation
Accrue the debt for both tokens first in LendingPair.uniClaimDeposit.
It might also be a good idea to disallow collecting the “parked” liquidity in a token (that has been removed but not yet collected) by immediately collecting them when the NFT is deposited in depositUniPosition. I.e., call _uniCollectFees in depositUniPosition to withdraw any outstanding tokens and fees. Then mint shares with these token amounts.
talegift (Wild Credit) confirmed:
We’ll implement the suggested fix.
Suggest lowering severity to 2 as it doesn’t allow direct theft of funds and the loss would only occur under specific external conditions - long periods of not accrue interest combined with a low gas price to steal the pending interest.
It seems that the attacker can steal interest that is owed to other users but deposits are safe. For that reason I agree with sponsor to make this medium risk.
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 `uniClaimDeposit` function does not call `accrue` before minting shares, and it allows depositing a Uniswap V3 position with uncollected tokens owed.
What the attacker needed
Flashloans for both tokens; a Uniswap V3 position; low gas price; long period without accrual
The fix
The debt for both tokens should be accrued first in `LendingPair.uniClaimDeposit`, and collecting parked liquidity should be disallowed by immediately collecting tokens when the NFT is deposited.
How it was found
- Create a Uniswap V3 position.
- Get flashloans for both tokens to provide lots of liquidity for this position.
- Call `positionManager.decreaseLiquidity` such that the entire liquidity is removed and stored (but not collected yet) in the position’s `tokensOwed0/1` fields
- Deposit it to WildCredit’s lending pair using `depositUniPosition`
- Call `uniClaimDeposit` to mint a huge amount of NFT supply shares.
- Call `accrue` on both tokens to accrue debt and pay the `lpRate` part of it to suppliers, increasing `totalSupplyAmount` and thus the value of a supply share.
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 is a smart contract bug in a lending protocol. The protocol lets users deposit Uniswap V3 positions and mint shares. The function that mints shares does not update the total supply first, so an attacker can mint shares cheaply, then trigger an update that increases the share price, and finally withdraw for a profit. The attacker can also deposit a position that has been emptied of liquidity but still holds the tokens, making the minted shares huge.
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.