Skip to content
Business logic Audit finding Intermediate

In PositionActionPendle::_onDecreaseLever , tokenOut is implemented incorrectly

The PositionActionPendle contract's _onDecreaseLever function fails to return the withdrawn token amount when the auxiliary action arguments are empty, leading to incorrect accounting. An attacker could potentially exploit this to cause a denial of service or incorrect state, but the flow may always revert due to parameter settings.

minglei-wang-3570 Follow with zhaojohnson, lian886 and 1 other

Originally disclosed on Code4rena

Submitted by minglei-wang-3570, also found by zhaojohnson, lian886, and 0xc0ffEE

The function PositionActionPendle::_onDecreaseLever is a hook to decrease lever by withdrawing collateral from the CDPVault. But the current implementation is wrong if leverParams.auxAction.args.length is 0, _onWithdraw is called here, but the tokenOut still returns 0.

    function _onDecreaseLever(
        LeverParams memory leverParams,
        uint256 subCollateral
    ) internal override returns (uint256 tokenOut) {
@>      _onWithdraw(leverParams.vault, leverParams.position, address(0), subCollateral);

        if (leverParams.auxAction.args.length != 0) {
            bytes memory exitData = _delegateCall(
                address(poolAction), abi.encodeWithSelector(poolAction.exit.selector, leverParams.auxAction)
            );

@>          tokenOut = abi.decode(exitData, (uint256));
        }
    }

The tokenOut accounting will be incorrect if the leverParams.auxAction.args.length is 0.

Proof of Concept

We can see that the function PositionActionPendle::_onDecreaseLever returns the tokenOut on successful withdraw.

    function _onDecreaseLever(
        LeverParams memory leverParams,
        uint256 subCollateral
    ) internal override returns (uint256 tokenOut) {
        _onWithdraw(leverParams.vault, leverParams.position, address(0), subCollateral);

        if (leverParams.auxAction.args.length != 0) {
            bytes memory exitData = _delegateCall(
                address(poolAction), abi.encodeWithSelector(poolAction.exit.selector, leverParams.auxAction)
            );

            tokenOut = abi.decode(exitData, (uint256));
        }
    }

But in the above implementation, The tokenOut accounting will be incorrect if the leverParams.auxAction.args.length is 0.

The implementation properly handled in the function PositionAction4626::_onDecreaseLever() as the tokenOut is return even if leverParams.auxAction.args.length is 0.

    function _onDecreaseLever(
        LeverParams memory leverParams,
        uint256 subCollateral
    ) internal override returns (uint256 tokenOut) {
        // withdraw collateral from vault
        uint256 withdrawnCollateral = ICDPVault(leverParams.vault).withdraw(address(this), subCollateral);

        // withdraw collateral from the ERC4626 vault and return underlying assets
@>       tokenOut = IERC4626(leverParams.collateralToken).redeem(withdrawnCollateral, address(this), address(this));

        if (leverParams.auxAction.args.length != 0) {
            bytes memory exitData = _delegateCall(
                address(poolAction),
                abi.encodeWithSelector(poolAction.exit.selector, leverParams.auxAction)
            );

            tokenOut = abi.decode(exitData, (uint256));
        }
    }

Recommended Mitigation Steps

Handle the edge case properly like PositionAction4626::_onDecreaseLever() and return tokenOut if leverParams.auxAction.args.length is 0.

Assessed type

Token-Transfer

amarcu (LoopFi) confirmed and commented:

The flow will always revert because of how the parameters are set. We will make the update to always revert with a custom message for the case where the auxSwap is not defined. Maybe this can be re-evaluated as a medium.

Koolex (judge) decreased severity to Medium and commented:

Medium, since it is an edge case.


The original report as published on Code4rena, by minglei-wang-3570. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Likely, the function only sets tokenOut inside the conditional block, so when the condition is false, tokenOut remains zero instead of being set to the withdrawn amount.

Impact

The incorrect tokenOut value could lead to incorrect accounting, but the flow will always revert because of how the parameters are set, limiting the impact.

What the attacker needed

AuxAction.args.length is 0

The fix

The function should be updated to handle the edge case by returning the withdrawn amount when the auxiliary action arguments are empty, similar to PositionAction4626.

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.

This is a smart contract bug where a function that should return the amount of tokens withdrawn sometimes returns zero instead. That means the system's record of tokens is wrong, which could break other parts of the contract that rely on that number.

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 from LoopFi

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.