Skip to content
Business logic Audit finding Intermediate

Swap token can be traded as fake base token

The swap function does not verify that the base token is one of the allowed base tokens, so an attacker can pass a fake base token and manipulate the pool's accounting. This can lead to incorrect swap results, loss of funds for liquidity providers, and potential theft of tokens from the pool.

Vader Protocol contest

Originally disclosed on Code4rena

The Pools.swap function does not check if base is one of the base tokens. One can transfer tokens to the pool and set base=token and call swap(token, token, member, toBase=false)

The _actualInput = getAddedAmount(base, token); will return the token amount added but use the ratio compared to the base reserve calcSwapOutput(_actualInput=tokenInput, mapToken_baseAmount[token], mapToken_tokenAmount[token]); = tokenIn / baseAmount * tokenAmount which yields a wrong swap result.

It breaks the accounting for the pool as tokens are transferred in, but the base balance is increased (and token balance decreased). LPs cannot correctly withdraw again, and others cannot correctly swap again.

Another example scenario is that the token pool amount can be stolen. Send tokenIn=baseAmount of tokens to the pool and call swap(base=token, token, member, toBase=false). Depending on the price of token relative to base this could be cheaper than trading with the base tokens.

Recommend checking that base is either USDV or VADER.

strictly-scarce (vader) confirmed:

Valid, funds can be lost

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

This breaks the pool's accounting, preventing liquidity providers from withdrawing correctly and other users from swapping correctly; in some scenarios, tokens can be stolen from the pool.

What the attacker needed

Ability to call the swap function; Possession of some tokens to transfer

The fix

The swap function should check that the base token is either USDV or VADER.

How it was found

  1. Transfer tokens to the pool.
  2. Call swap with base set to the token itself and toBase set to false.
  3. Observe that the swap output is calculated using the token amount but the base reserve, leading to incorrect results.

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.

A swap function lets users trade one token for another. It relies on a 'base' token to calculate exchange rates. The bug is that the function doesn't check if the base token is legitimate. An attacker can pretend a different token is the base, which tricks the system into giving wrong amounts and can drain funds.

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 from Vader Protocol 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.