Skip to content
Business logic Audit finding Intermediate

VaderPoolV2 incorrectly calculates the amount of IL protection to send to LPs

VaderPoolV2 incorrectly calculates the amount of impermanent loss (IL) protection to send to liquidity providers (LPs). It pays out IL expressed in USDV as if it were VADER, assuming a 1:1 exchange rate, so LPs could receive substantially more or less VADER than the actual IL they experienced.

TomFrenchBlockchain Follow

Originally disclosed on Code4rena

Submitted by TomFrenchBlockchain

Impact

The VaderReserve pays out IL from VaderPoolV2 LPs expressed in USDV with VADER (assuming a 1:1 exchange rate)

Proof of Concept

From the TwapOracle, it can be seen that VaderPoolV2 is intended to be deployed with USDV as its nativeAsset:

All the pairs in VaderPoolV2 are then USDV:TKN where TKN is some other token, exactly which is irrelevant in this case.

VaderPoolV2 offers IL protection where any IL is refunded from the VaderReserve

https://github.com/code-423n4/2021-11-vader/blob/3a43059e33d549f03b021d6b417b7eeba66cf62e/contracts/dex-v2/pool/VaderPoolV2.sol#L258-L268

The VaderReserve holds a balance of VADER tokens which will be used to pay out this protection.

https://github.com/code-423n4/2021-11-vader/blob/3a43059e33d549f03b021d6b417b7eeba66cf62e/contracts/reserve/VaderReserve.sol#L76-L90

The IL experienced by the LP is calculated in VaderMath.calculateLoss

https://github.com/code-423n4/2021-11-vader/blob/3a43059e33d549f03b021d6b417b7eeba66cf62e/contracts/dex/math/VaderMath.sol#L73-L93

This is the core of the issue. From the variable names it’s clear that this is written with the assumption that it is work on units of VADER whereas it is provided amounts in terms of USDV. Checking VaderRouterV2 we can see that we pass the output of this calculation directly to the reserve in order to claim VADER.

If an LP experienced 100 USDV worth of IL, instead of claiming the equivalent amount of VADER they would receive exactly 100 VADER as there’s no handling of the exchange rate between USDV and VADER.

As VADER and USDV are very unlikely to trade at parity LPs could get sustantially more or less than the amount of IL they experienced.

Recommended Mitigation Steps

Add handling for the conversion rate between VADER and USDV using a tamper resistant oracle (TwapOracle could potentially fulfil this role).

SamSteinGG (Vader) confirmed

The original report as published on Code4rena, by TomFrenchBlockchain. 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 IL calculation in VaderMath.calculateLoss assumes amounts are in VADER, but it is given amounts in USDV, and the result is passed directly to the reserve without converting between USDV and VADER.

Impact

LPs could receive substantially more or less VADER than the IL they experienced, depending on the VADER/USDV exchange rate.

What the attacker needed

LP has experienced impermanent loss; VADER/USDV exchange rate is not 1:1

The fix

The code should be fixed to convert the IL amount from USDV to VADER using a tamper-resistant oracle, such as TwapOracle.

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.

Liquidity providers (LPs) put tokens into a pool and can suffer impermanent loss (IL) when the price of the tokens changes. The project promises to refund that loss from a reserve of VADER tokens. But the code calculates the loss in USDV (a stablecoin) and then pays out the same number in VADER, ignoring the exchange rate between the two tokens. So LPs might get too much or too little VADER.

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 TomFrenchBlockchain

View all

28 more disclosed reports, best first.

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.