Skip to content

All supplied WETH to Aave as a deposit by a Strategy will be irrecoverable. #41

Open

Description

@c4-bot-1

Lines of code

https://github.com/code-423n4/2024-05-bakerfi/blob/main/contracts/core/strategies/StrategyLeverage.sol#L562-L566

Vulnerability details

Impact

WETH supplied to Aave will be lost.

Proof of Concept

When a strategy pays debt on Aave it does a swap of the withdrawn collateral from Aave in exchange for WETH. After the swap is completed, it checks if there are any weth leftovers after the swap, if so, it deposits them back. The problem with this approach is that the strategy doesn't have any means to pull WETH out of Aave, the strategy is only capable of withdrawing the collateral from Aave, but not WETH.

function _payDebt(uint256 debtAmount, uint256 fee) internal {
  ...

  //@audit-info => output represents the received amount of WETH for the swap
  uint256 output = _swap(
      ISwapHandler.SwapParams(
          ierc20A(),
          wETHA(),
          ISwapHandler.SwapType.EXACT_OUTPUT,
          amountIn,
          debtAmount + fee,
          _swapFeeTier,
          bytes("")
      )
  );

  //@audit-info => Checks if there are any WETH leftovers
  // When there are leftovers from the swap, deposit then back
  uint256 wethLefts = output > (debtAmount + fee) ? output - (debtAmount + fee) : 0;

  //@audit-issue => If any leftover WETH, it deposits them onto Aave!
  //@audit-issue => Once the WETH is deposited in Aave, the Strategy won't be able to pull it out.
  if (wethLefts > 0) {
      _supply(wETHA(), wethLefts);
  }
  emit StrategyUndeploy(msg.sender, debtAmount);
}

The strategy uses the StrategyAAVEv3._withdraw() function to withdraw an asset from Aave, but, in the places where this function is called, the only assets requested to be withdrawn is the Collateral.

Tools Used

Manual Audit

Recommended Mitigation Steps

Instead of supplying the wethLefts, use the excess WETH to repay more WETH debt on Aave, in this way, those extra WETHs won't be lost on Aave because the strategy doesn't have any means to withdraw them.

  • By using the extra WETH to repay more debt, the loan to value is brought down even to a healtier level.
function _payDebt(uint256 debtAmount, uint256 fee) internal {
  ...
  ...
  ...

  //@audit => Instead of supplying WETH to Aave, use it to repay more debt
  if (wethLefts > 0) {
-     _supply(wETHA(), wethLefts);
+     _repay(wETHA(), wethLefts);
  }
  emit StrategyUndeploy(msg.sender, debtAmount);
}

Assessed type

Context

Activity

  1. added
    2 (Med Risk)Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
    bugSomething isn't working
    on Jun 2, 2024
  2. added a commit that references this issue on Jun 2, 2024
  3. added
    primary issueHighest quality submission among a set of duplicates
    on Jun 5, 2024
  4. c4-judge commented on Jun 5, 2024

    @c4-judge

    0xleastwood marked the issue as primary issue

  5. added
    sponsor confirmedSponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
    on Jun 7, 2024
  6. c4-judge commented on Jun 12, 2024

    @c4-judge

    0xleastwood marked the issue as selected for report

  7. added
    selected for reportThis submission will be included/highlighted in the audit report
    on Jun 12, 2024
  8. ickas commented on Jun 18, 2024

    @ickas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    2 (Med Risk)Assets not at direct risk, but function/availability of the protocol could be impacted or leak value🤖_38_groupAI based duplicate group recommendation🤖_primaryAI based primary recommendationM-01bugSomething isn't workingprimary issueHighest quality submission among a set of duplicatesselected for reportThis submission will be included/highlighted in the audit reportsponsor confirmedSponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions