code-423n4 / 2021-11-vader-findings

0 stars 0 forks source link

Potential economic attack that exploits IL coverage #217

Closed code423n4 closed 3 years ago

code423n4 commented 3 years ago

Handle

WatchPug

Vulnerability details

The current implementation of Vader protocol provides impermanent loss coverage calculated as below:

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

function calculateLoss(
    uint256 originalVader,
    uint256 originalAsset,
    uint256 releasedVader,
    uint256 releasedAsset
) public pure returns (uint256 loss) {
    //
    // TODO: Vader Formula Differs https://github.com/vetherasset/vaderprotocol-contracts/blob/main/contracts/Utils.sol#L347-L356
    //

    // [(A0 * P1) + V0]
    uint256 originalValue = ((originalAsset * releasedVader) /
        releasedAsset) + originalVader;

    // [(A1 * P1) + V1]
    uint256 releasedValue = ((releasedAsset * releasedVader) /
        releasedAsset) + releasedVader;

    // [(A0 * P1) + V0] - [(A1 * P1) + V1]
    if (originalValue > releasedValue) loss = originalValue - releasedValue;
}

An attacker may exploit this by adding liquidity and manipulating the price of the pool (with flash loans) to get IL coverage from the protocol.

PoC

Given:

The attacker can:

  1. Add liquidity with 1M USDV and 10 BTC;
  2. 30 days later, do the following in one transaction:
    1. borrow a flash loan of 200 BTC, swap 20 BTC to USDV, repeat for 10 times;
    2. current reserves: 189055 USDV and 210 BTC, current loss: 630,891 USDV;
    3. remove all liquidity, repay flash loan, profit for the coveredLoss = 630,891 * 30 / 365 = 52k USDV.
SamSteinGG commented 3 years ago

Duplicate #31