Skip to content
Business logic Audit finding Intermediate

getAddedAmount can return wrong results

The getAddedAmount function returns incorrect results when called with a token that is neither VADER/USDV nor the pool, because it subtracts the token's balance from a stored amount for a different token. An attacker can call sync with a token whose balance is less than the stored amount for another token, corrupting the accounting and enabling token swaps without payment.

Vader Protocol contest

Originally disclosed on Code4rena

The getAddedAmount function only works correctly when called with (VADER/USDV, pool) or (pool, pool). However, when called with (token, pool) where token is neither VADER/USDV/pool, it returns the wrong results:

  1. It gets the token balance
  2. And subtracts it from the stored mapToken_tokenAmount[_pool] amount which can be that of a completely different token

Anyone can break individual pairs by calling sync(token1, token2) where the token1 balance is less than mapToken_tokenAmount[token2]. This will add the difference to mapToken_tokenAmount[token2] and break the accounting and result in a wrong swap logic.

Furthermore, this can also be used to swap tokens without having to pay anthing with swap(token1, token2, member, toBase=false).

Recommend adding a require statement in the else branch that checks that _token == _pool.

strictly-scarce (vader) confirmed:

Valid, funds can be lost

strictly-scarce (vader) commented:

Would bundle this issue with: https://github.com/code-423n4/2021-04-vader-findings/issues/205

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

Funds can be lost, and an attacker could swap tokens without paying.

What the attacker needed

Ability to call sync and swap functions

The fix

A require statement should be added in the else branch to check that _token == _pool.

How it was found

  1. Call sync(token1, token2) where token1 balance is less than mapToken_tokenAmount[token2].
  2. This adds the difference to mapToken_tokenAmount[token2] and breaks accounting.
  3. Use swap(token1, token2, member, toBase=false) to swap tokens without paying anything.

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 where a function that calculates added amounts uses the wrong token's stored balance. By calling a sync function with mismatched tokens, an attacker can make the contract think more tokens were added than actually were, which messes up swap calculations and lets them swap without paying.

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.