Skip to content
Business logic Audit finding Intermediate

decreaseLever uses incorrect position address when withdrawing

The decreaseLever function of the Position4626 contract withdraws collateral from the contract's own address rather than from the position passed in by the caller. Because the collateral sits in that position, the withdrawal always reverts, so decreasing leverage is impossible for Position4626 vaults.

hash Follow with 0xAlix2, pkqs90 and 1 other

Originally disclosed on Code4rena

Submitted by hash, also found by 0xAlix2, pkqs90, and nnez

decreaseLever will always revert for Position4626 associated vaults.

Proof of Concept

When decreasing lever, the control is passed over to the actual implementation contract for the flashLoan execution:

    function decreaseLever(
        LeverParams calldata leverParams,
        uint256 subCollateral,
        address residualRecipient
    ) external onlyDelegatecall {

       ....

        // @audit execution passed to the implementation contract by setting it as the callback
        // take out credit flash loan
        IPermission(leverParams.vault).modifyPermission(leverParams.position, self, true);
        uint loanAmount = leverParams.primarySwap.amount;
        flashlender.creditFlashLoan(
            ICreditFlashBorrower(self),
            loanAmount,
            abi.encode(leverParams, subCollateral, residualRecipient)
        );
        IPermission(leverParams.vault).modifyPermission(leverParams.position, self, false);

Inside the onCreditFlashLoan call, it attempts to withdraw the collateral of the passed in position by the passed in subCollateral amount:

    function onCreditFlashLoan(
        address /*initiator*/,
        uint256 /*amount*/,
        uint256 /*fee*/,
        bytes calldata data
    ) external returns (bytes32) {

        // sub collateral and debt
        ICDPVault(leverParams.vault).modifyCollateralAndDebt(
            leverParams.position,
            address(this),
            address(this),
            0,
            -toInt256(subDebt)
        );

        // withdraw collateral and handle any CDP specific actions
        // @audit should withdraw `subCollateral` amount from `leverParams.position`
=>      uint256 withdrawnCollateral = _onDecreaseLever(leverParams, subCollateral);

But the _onDecreaseLever function of the Position4626 contract is flawed as it attempts to withdraw the collateral from its own address instead of the passed in position:

    function _onDecreaseLever(
        LeverParams memory leverParams,
        uint256 subCollateral
    ) internal override returns (uint256 tokenOut) {
        // @audit attempts to withdraw from address(this) rather than leverParams.position
=>      uint256 withdrawnCollateral = ICDPVault(leverParams.vault).withdraw(address(this), subCollateral);

Since the collateral is actually present in the passed in position, this attempt to withdraw will cause the call to revert.

Recommended Mitigation Steps

Inside _onDecreaseLever, withdraw from leverParams.position instead.

Koolex (judge) increased severity to High

amarcu (LoopFi) confirmed


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

The override of _onDecreaseLever passes the contract's own address to the vault's withdraw call instead of the position address supplied in the parameters.

Impact

Decreasing leverage always reverts for Position4626 vaults, so that functionality is unavailable; the text does not claim any loss of funds.

What the attacker needed

A Position4626 vault; a position holding collateral

The fix

The withdrawal inside _onDecreaseLever should use the position address from the parameters rather than the contract's own address.

How it was found

  1. Call decreaseLever with a Position4626 vault and a position holding collateral.
  2. The call is delegated to the implementation contract, which starts a credit flash loan.
  3. In the flash loan callback, the code calls the Position4626 version of _onDecreaseLever.
  4. That function asks the vault to withdraw from its own address, which holds no collateral, so the call reverts.

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.

A smart contract here is meant to take collateral out of a user's position when they reduce their borrowing. Instead it tried to take the collateral out of its own account, which holds none of it. The withdrawal therefore failed every time, so that feature simply did not work.

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 hash

View all

27 more disclosed reports, best first.

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.