Skip to content
Business logic Audit finding Intermediate

LeverageManager closeFee is only collected for pTKN, which can be easily bypassed

The LeverageManager contract only charges a close fee on pTKN tokens returned to the user, not on borrowedTKN tokens. An attacker can bypass the fee by swapping most or all pTKN to borrowedTKN during the leverage removal process.

ZoA Follow with ck, pashap9990 and 1 other

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/485

Found by

ZoA, ck, pashap9990, pkqs90

Summary

LeverageManager closeFee is only collected for pTKN, which can be easily bypassed.

Root Cause

First we need to understand the workflow of removeLeverage in LeverageManager.

  1. Borrow _borrowAssetAmt underlying token from flashloan source.
  2. Repay these tokens to FraxlendPair.
  3. Withdraw collateral (aspTKN) to borrowedTKN and pTKN. If borrowedTKN is not enough to repay the flashloan, swap pTKN to borrowedTKN.
  4. Repay flashloan.
  5. Send leftover borrowedTKN and pTKN back to position owner.

In step 5, a closeFee is charged. However, this is charged only for pTKN. Users can easily bypass this if he swaps most or all of pTKN to borrowedTKN in step 3. This can be set by setting a large _podSwapAmtOutMin for the pTKN -> borrowedTKN swap.

https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/lvf/LeverageManager.sol#L1

Solidity
    function callback(bytes memory _userData) external override workflow(false) {
        IFlashLoanSource.FlashData memory _d = abi.decode(_userData, (IFlashLoanSource.FlashData));
        (LeverageFlashProps memory _posProps,) = abi.decode(_d.data, (LeverageFlashProps, bytes));

        address _pod = positionProps[_posProps.positionId].pod;

        require(_getFlashSource(_posProps.positionId) == _msgSender(), "A2");

        if (_posProps.method == FlashCallbackMethod.ADD) {
            uint256 _ptknRefundAmt = _addLeveragePostCallback(_userData);
            if (_ptknRefundAmt > 0) {
                IERC20(_pod).safeTransfer(_posProps.owner, _ptknRefundAmt);
            }
        } else if (_posProps.method == FlashCallbackMethod.REMOVE) {
            (uint256 _ptknToUserAmt, uint256 _pairedLpToUser) = _removeLeveragePostCallback(_userData);
            if (_ptknToUserAmt > 0) {
                // if there's a close fee send returned pod tokens for fee to protocol
@>              if (closeFeePerc > 0) {
                    uint256 _closeFeeAmt = (_ptknToUserAmt * closeFeePerc) / 1000;
                    IERC20(_pod).safeTransfer(feeReceiver, _closeFeeAmt);
                    _ptknToUserAmt -= _closeFeeAmt;
                }
                IERC20(_pod).safeTransfer(_posProps.owner, _ptknToUserAmt);
            }
            // @audit-bug: closeFee is not charged for borrowedTKN.
            if (_pairedLpToUser > 0) {
@>              IERC20(_getBorrowTknForPod(_posProps.positionId)).safeTransfer(_posProps.owner, _pairedLpToUser);
            }
        } else {
            require(false, "NI");
        }
    }

    function _swapPodForBorrowToken(
        address _pod,
        address _targetToken,
        uint256 _podAmt,
        uint256 _targetNeededAmt,
        uint256 _podSwapAmtOutMin
    ) internal returns (uint256 _podRemainingAmt) {
        IDexAdapter _dexAdapter = IDecentralizedIndex(_pod).DEX_HANDLER();
        uint256 _balBefore = IERC20(_pod).balanceOf(address(this));
        IERC20(_pod).safeIncreaseAllowance(address(_dexAdapter), _podAmt);
@>      _dexAdapter.swapV2SingleExactOut(
            _pod, _targetToken, _podAmt, _podSwapAmtOutMin == 0 ? _targetNeededAmt : _podSwapAmtOutMin, address(this)
        );
        _podRemainingAmt = _podAmt - (_balBefore - IERC20(_pod).balanceOf(address(this)));
    }

Internal pre-conditions

N/A

External pre-conditions

N/A

Attack Path

User can set a large _podSwapAmtOutMin so most of the pTKN is swapped to borrowTKN, to bypass closeFee.

Impact

User can bypass closeFee when removing leverage.

PoC

N/A

Mitigation

Also charge closeFee for leftover borrowedTKN.

The original report as published on Sherlock, by ZoA. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

The close fee is applied only to the pTKN amount returned to the user, while the borrowedTKN amount is transferred without any fee deduction.

Impact

Users can bypass the close fee when removing leverage, reducing protocol revenue.

What the attacker needed

A leveraged position; ability to call removeLeverage

The fix

The close fee should also be charged on the leftover borrowedTKN amount.

How it was found

  1. Call removeLeverage with a large _podSwapAmtOutMin to swap most pTKN to borrowedTKN.
  2. The contract repays the flashloan and sends leftover borrowedTKN and pTKN to the user.
  3. The close fee is charged only on the pTKN portion, so the fee is largely bypassed.

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.

When you remove leverage, the contract gives you back two types of tokens: pTKN and borrowedTKN. It takes a small fee only from the pTKN part. By swapping most of your pTKN into borrowedTKN before the fee is taken, you can avoid paying most of the fee.

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 ZoA

View all

5 more disclosed reports, best first.

More from Peapods

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.