Skip to content
Business logic Audit finding Advanced

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.

cmichel Follow

Originally disclosed on Code4rena

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 totalSupplyAmount by calling accrue(token0) and accrue(token1) afterwards.
  • call withdraw and receive a larger amount of tokens for the newly minted shares due to the increase in totalSupplyAmount from accrue (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:

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.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. This huge amount will capture the protocol’s debt accrual in the next steps.
  • 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.
  • 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.

ghoul-sol (judge) commented:

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.

The original report as published on Code4rena, by cmichel. 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 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

  1. Create a Uniswap V3 position.
  2. Get flashloans for both tokens to provide lots of liquidity for this position.
  3. Call `positionManager.decreaseLiquidity` such that the entire liquidity is removed and stored (but not collected yet) in the position’s `tokensOwed0/1` fields
  4. Deposit it to WildCredit’s lending pair using `depositUniPosition`
  5. Call `uniClaimDeposit` to mint a huge amount of NFT supply shares.
  6. 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.

More by cmichel

View all

196 more disclosed reports, best first.

More from Wild Credit contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.