Skip to content
Business logic Audit finding Intermediate

NonUSTStrategy.sol Improper handling of swap fees allows attacker to steal funds from other users

The NonUSTStrategy contract swaps deposited assets into UST but does not charge the swap fee to the depositor, instead spreading it across all vault users. An attacker can provide most of the liquidity in the swap pool, deposit a large amount to generate fees, and then withdraw, capturing the majority of the fees paid by other users.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

https://github.com/code-423n4/2022-01-sandclock/blob/a90ad3824955327597be00bb0bd183a9c228a4fb/sandclock/contracts/strategy/NonUSTStrategy.sol#L66-L69

NonUSTStrategy will swap the deposited non-UST assets into UST before depositing to EthAnchor. However, the swap fee is not attributed to the depositor correctly like many other yield farming vaults involving swaps (ZapIn).

An attacker can exploit it for the swap fees paid by other users by taking a majority share of the liquidity pool.

Root Cause

The swap fee of depositing is not paid by the depositor but evenly distributed among all users.

Proof of Concept

Given:

  • A NonUST vault and strategy is created for FRAX;
  • The liquidity in FRAX-UST curve pool is relatively small (<$1M).

The attacker can do the following:

  1. Add $1M worth of liquidity to the FRAX-UST curve pool, get >50% share of the pool;
  2. Deposit 1M FRAX to the vault, get a depositAmount of 1M;
  3. The strategy will swap 1M FRAX to UST via the curve pool, paying a certain amount of swap fee;
  4. Withdraw all the funds from the vault.
  5. Remove the liquidity added in step 1, profit from the swap fee. (A majority portion of the swap fee paid in step 3 can be retrieved by the attacker as the attacker is the majority liquidity provider.)

If the vault happens to have enough balance (from a recent depositor), the attacker can now receive 1M of FRAX.

A more associated attacker may combine this with issue #160 and initiate a sandwich attack in step 3 to get even higher profits.

As a result, all other users will suffer fund loss as the swap fee is essentially covered by other users.

Recommendation

Consider changing the way new shares are issued:

  1. Swap from Vault asset (eg. FRAX) to UST in deposit();
  2. Using the UST amount out / total underlying UST for the amount of new shares issued to the depositor.

In essence, the depositor should be paying for the swap fee and slippage.

CrisBRM (Sandclock) confirmed and disagreed with severity:

This is only an issue if we support low liquidity Curve pools We are also adding slippage control as per some other issue which would cause massive transfers using low liquidity pools to revert, fully mitigating this. Likelihood of this happening would also be quite low given that profitability would go down tremendously as curve LPs would move to that pool in order to capture higher base fees, dissuading the attacker from continuing.

That being said, I do agree that the curve swap fee (0.04%) should be paid by each individual depositor.

dmvt (judge) changed severity and commented:

This requires a number of external factors to line up just right. It is a medium risk according to the definition provided by Code4rena.

2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.

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

Impact

Other users could lose funds because the swap fee is effectively covered by them, though the attacker's profit depends on low liquidity and the protocol may add slippage controls that mitigate the attack.

What the attacker needed

Low liquidity in the swap pool; attacker provides majority liquidity; vault has sufficient balance

The fix

The depositor should pay the swap fee and slippage by swapping to UST first and then issuing shares based on the UST amount received.

How it was found

  1. Add a large amount of liquidity to the FRAX-UST curve pool to get more than 50% share.
  2. Deposit a large amount of FRAX to the vault.
  3. The strategy swaps the deposited FRAX to UST via the curve pool, paying a swap fee.
  4. Withdraw all funds from the vault.
  5. Remove the liquidity added in step 1 to profit from the swap fee.

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 deposit money into a vault, the vault sometimes trades your deposit for another token. That trade costs a small fee. Normally the person depositing should pay that fee, but here the fee is shared by everyone in the vault. An attacker can make the trade happen and then collect most of the fee themselves, so other users lose a little money.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Sandclock 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.