Skip to content
Business logic Audit finding Advanced

AutoCompoundingPodLp does not work for advanced self-lending pods with podded fTKN as pairedLpTKN

pkqs90 Follow

Originally disclosed on Sherlock

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

Found by

pkqs90

Summary

AutoCompoundingPodLp does not work for advanced self-lending pods with podded fTKN as pairedLpTKN.

Root Cause

First, let's see how the autocompounding process works: 1) swap rewardTKN -> pairedLpTKN, 2) swap a portion (roughly half) of pairedLpTKN -> pTKN, 3) add pairedLpTKN, pTKN to UniV2 LP, 4) stake LP token to spTKN.

This is supposed to also work for self-lending pods. There are two kinds of self-lending pods. The first is the regular one, where the pairedLpTKN for a pod is a fraxlend paired fTKN. However, there is also an "advanced feature", so the pairedLpTKN is a podded fTKN (which makes it a pfTKN). This can be seen in LeverageManager.sol contract when initializing a leverage position.

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

Solidity
    /// @notice The ```initializePosition``` function initializes a new position and mints a new position NFT
    /// @param _pod The pod to leverage against for the new position
    /// @param _recipient User to receive the position NFT
    /// @param _overrideLendingPair If it's a self-lending pod, an override lending pair the user will use
@>  /// @param _hasSelfLendingPairPod bool Advanced implementation parameter that determines whether or not the self lending pod's paired LP asset (fTKN) is podded as well
    function initializePosition(
        address _pod,
        address _recipient,
        address _overrideLendingPair,
        bool _hasSelfLendingPairPod
    ) external override returns (uint256 _positionId) {
        _positionId = _initializePosition(_pod, _recipient, _overrideLendingPair, _hasSelfLendingPairPod);
    }

Now, going back to autocompounding. In step 1, if the pod was a self-lending pod, the rewardTKN -> pairedLpTKN swap is non-trivial, because the liquidity may not be good. So it first swaps rewardTKN to the underlying token, then processes it to the pairedLpTKN.

For a normal self-lending pod, this works well (e.g. swap to USDC, then convert to fUSDC). However, for a podded fTKN as pairedLpTKN, this is not supported. We can see in details how the swap is handled in _tokenToPairedLpToken() function.

https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/AutoCompoundingPodLp.sol#L213

Solidity
    function _tokenToPodLp(address _token, uint256 _amountIn, uint256 _amountLpOutMin, uint256 _deadline)
        internal
        returns (uint256 _lpAmtOut)
    {
@>      uint256 _pairedOut = _tokenToPairedLpToken(_token, _amountIn);
        if (_pairedOut > 0) {
            uint256 _pairedFee = (_pairedOut * protocolFee) / 1000;
            if (_pairedFee > 0) {
                _protocolFees += _pairedFee;
                _pairedOut -= _pairedFee;
            }
            _lpAmtOut = _pairedLpTokenToPodLp(_pairedOut, _deadline);
            require(_lpAmtOut >= _amountLpOutMin, "M");
        }
    }

    function _tokenToPairedLpToken(address _token, uint256 _amountIn) internal returns (uint256 _amountOut) {
        address _pairedLpToken = pod.PAIRED_LP_TOKEN();
        address _swapOutputTkn = _pairedLpToken;
        if (_token == _pairedLpToken) {
            return _amountIn;
        } else if (maxSwap[_token] > 0 && _amountIn > maxSwap[_token]) {
            _amountIn = maxSwap[_token];
        }

        // if self lending pod, we need to swap for the lending pair borrow token,
        // then deposit into the lending pair which is the paired LP token for the pod

        // @audit-bug: This does not support podded fTKN.
@>      if (IS_PAIRED_LENDING_PAIR) {
            _swapOutputTkn = IFraxlendPair(_pairedLpToken).asset();
        }

        address _rewardsToken = pod.lpRewardsToken();
        if (_token != _rewardsToken) {
            _amountOut = _swap(_token, _swapOutputTkn, _amountIn, 0);
            if (IS_PAIRED_LENDING_PAIR) {
                _amountOut = _depositIntoLendingPair(_pairedLpToken, _swapOutputTkn, _amountOut);
            }
            return _amountOut;
        }
        uint256 _amountInOverride = _tokenToPairedSwapAmountInOverride[_rewardsToken][_swapOutputTkn];
        if (_amountInOverride > 0) {
            _amountIn = _amountInOverride;
        }
        uint256 _minSwap = 10 ** (IERC20Metadata(_rewardsToken).decimals() / 2);
        _minSwap = _minSwap == 0 ? 10 ** IERC20Metadata(_rewardsToken).decimals() : _minSwap;
        IERC20(_rewardsToken).safeIncreaseAllowance(address(DEX_ADAPTER), _amountIn);
        try DEX_ADAPTER.swapV3Single(
            _rewardsToken,
            _swapOutputTkn,
            REWARDS_POOL_FEE,
            _amountIn,
            0, // _amountOutMin can be 0 because this is nested inside of function with LP slippage provided
            address(this)
        ) returns (uint256 __amountOut) {
            _tokenToPairedSwapAmountInOverride[_rewardsToken][_swapOutputTkn] = 0;
            _amountOut = __amountOut;

            // if this is a self-lending pod, convert the received borrow token
            // into fTKN shares and use as the output since it's the pod paired LP token

            // @audit-bug: This does not support podded fTKN.
@>          if (IS_PAIRED_LENDING_PAIR) {
                _amountOut = _depositIntoLendingPair(_pairedLpToken, _swapOutputTkn, _amountOut);
            }
        } catch {
            _tokenToPairedSwapAmountInOverride[_rewardsToken][_swapOutputTkn] =
                _amountIn / 2 < _minSwap ? _minSwap : _amountIn / 2;
            IERC20(_rewardsToken).safeDecreaseAllowance(address(DEX_ADAPTER), _amountIn);
            emit TokenToPairedLpSwapError(_rewardsToken, _swapOutputTkn, _amountIn);
        }
    }

Internal pre-conditions

N/A

External pre-conditions

N/A

Attack Path

N/A

Impact

AutoCompoundingPodLP does not work for advanced self-lending pods. This essentially means the LVF feature for advanced self-lending pods don't work at all.

PoC

N/A

Mitigation

Add support for the feature.

The original report as published on Sherlock, by pkqs90. 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.

What is known

A medium-severity business logic bug in Peapods. Sherlock made it public on 12 March 2025. Found in the 749 audit contest (finding M-22).

About Business logic

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

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 pkqs90

View all

25 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.