Wild Credit contest - WatchPug's results

Decentralized lending protocol with isolated lending pairs.

General Information

Platform: Code4rena

Start Date: 23/09/2021

Pot Size: $50,000 USDC

Total HM: 5

Participants: 14

Period: 7 days

Judge: ghoulsol

Total Solo HM: 3

Id: 32

League: ETH

Wild Credit

Findings Distribution

Researcher Performance

Rank: 1/14

Findings: 4

Award: $19,617.17

🌟 Selected for report: 4

🚀 Solo Findings: 1

Findings Information

🌟 Selected for report: 0xRajeev

Also found by: WatchPug

Labels

bug
duplicate
3 (High Risk)

Awards

5947.4124 USDC - $5,947.41

External Links

Handle

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-09-wildcredit/blob/c48235289a25b2134bb16530185483e8c85507f8/contracts/LendingPair.sol#L660-L684

In _supplyCreditUni(), the calculation of the collateral value of tokenB supply is using _priceB instead of _priceA, which can lead to undercollateralized loans.

  function _supplyCreditUni(
    address _account,
    address _returnToken,
    uint    _priceA,
    uint    _priceB,
    uint    _colFactorA,
    uint    _colFactorB
  ) internal view returns(uint) {

    if (uniPosition[_account] > 0) {

      (uint amountA, uint amountB) = uniV3Helper.positionAmounts(uniPosition[_account], _priceA, _priceB);

      uint supplyA = _convertTokenValues(tokenA, _returnToken, amountA, _priceA, _priceB);
      uint supplyB = _convertTokenValues(tokenB, _returnToken, amountB, _priceB, _priceB);

      uint creditA = supplyA * _colFactorA / 100e18;
      uint creditB = supplyB * _colFactorB / 100e18;

      return (creditA + creditB);

    } else {
      return 0;
    }
  }

Impact

Undercollateralized debts cannot be liquidated and it leads to bad debts to the protocol.

An attacker can deposit a small sum of collateral asset and borrow a rather large amount of asset, essentially steal funds from the protocol.

Proof of Concept

Given:

  • tokenA is BTC, tokenB is USDC;
  • Price of BTC is 5000 USDC;
  • The collateral factor is 80%.

An attacker can:

  1. Deposit a Uni v3 position of 0 BTC and 500 USDC;
  2. The miscalculation made the protocol believes that the attacker has 500 BTC worth of collateral;
  3. Borrow 400 BTC.

The attacker steals ~399.9 BTC from the protocol.

Recommendation

Consider changing to:

uint supplyB = _convertTokenValues(tokenB, _returnToken, amountB, _priceB, _priceA);

#0 - talegift

2021-10-03T04:01:13Z

Duplicate #70

Findings Information

🌟 Selected for report: WatchPug

Labels

bug
3 (High Risk)
disagree-with-severity
sponsor-confirmed

Awards

13216.4719 USDC - $13,216.47

External Links

Handle

WatchPug

Vulnerability details

When the liquidator is trying to liquidate a undercolldarezed loan by calling liquidateAccount(), it calls _unwrapUniPosition() -> uniV3Helper.removeLiquidity() -> positionManager.decreaseLiquidity().

However, when the Uni v3 position has 0 liquidity, positionManager.decreaseLiquidity() will fail.

See: https://github.com/Uniswap/v3-periphery/blob/main/contracts/NonfungiblePositionManager.sol#L265

Based on this, a malicious user can escaped liquidation by depositing a Uni v3 position with 0 liquidity.

Impact

Undercollateralized debts cannot be liquidated and it leads to bad debts to the protocol.

A malicious user can take advantage of this by creating long positions on the collateral assets and take profit on the way up, and keep taking more debt out of the protocol, while when the price goes down, the debt can not be liquidated and the risks of bad debt are paid by the protocol.

Proof of Concept

  1. A malicious user deposits some collateral assets and borrow the max amount of debt;
  2. The user deposits a Uni v3 position with 0 liquidity;
  3. When the market value of the collateral assets decreases, the liquadation will fail as positionManager.decreaseLiquidity() reverts.

Recommendation

Check if liquidity > 0 when removeLiquidity.

#0 - talegift

2021-10-03T04:39:11Z

Valid issue. Good catch.

Severity should be lowered to 2 as it doesn't allow direct theft of funds and the loss would only occur under specific external conditions.

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

https://docs.code4rena.com/roles/wardens/judging-criteria#estimating-risk-tl-dr

#1 - ghoul-sol

2021-10-12T04:28:40Z

To my understanding, bad position would affect the whole protocol and a loss would have to be paid by other participans which means funds can be drained. For that reason, I'm keeping high risk.

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter