Skip to content
Business logic Audit finding Intermediate

PositionAction4626.sol#_onWithdraw should withdraw from position CDPVault position instead of address(this)

The ERC4626 position action withdrew collateral from the proxy contract itself rather than from the CDPVault position address passed in, unlike the sibling position action contracts. This meant the proxy could not perform withdrawals on behalf of positions other than its own, breaking the intended cross-position functionality.

pkqs90 Follow with pkqs90 and zhaojohnson

Originally disclosed on Code4rena

Submitted by pkqs90, also found by pkqs90 and zhaojohnson

In PositionAction4626, the _onWithdraw should withdraw the token from position CDPVault position. However, currently it withdraws from address(this). This is inconsistent to the parent contract PositionAction.sol, which specifically states the operation should handle the position address.

Also, in contrast, we can check the PositionAction20 contract, it withdraws from the position address.

PositionAction4626.sol:

    function _onWithdraw(address vault, address /*position*/, address dst, uint256 amount) internal override returns (uint256) {
>       uint256 collateralWithdrawn = ICDPVault(vault).withdraw(address(this), amount);

        // if collateral is not the dst token, we need to withdraw the underlying from the ERC4626 vault
        address collateral = address(ICDPVault(vault).token());
        if (dst != collateral) {
            collateralWithdrawn = IERC4626(collateral).redeem(collateralWithdrawn, address(this), address(this));
        }

        return collateralWithdrawn;
    }

PositionAction20.sol:

    function _onWithdraw(address vault, address position, address /*dst*/, uint256 amount) internal override returns (uint256) {
>       return ICDPVault(vault).withdraw(position, amount);
    }

PositionAction.sol:

    /// @notice Hook to withdraw collateral from CDPVault, handles any CDP specific actions
    /// @param vault The CDP Vault
>   /// @param position The CDP Vault position
    /// @param dst Token the caller expects to receive
    /// @param amount The amount of collateral to deposit [wad]
    /// @return Amount of collateral (or dst) withdrawn [CDPVault.tokenScale()]
    function _onWithdraw(address vault, address position, address dst, uint256 amount) internal virtual returns (uint256);

Recommended Mitigation Steps

-       uint256 collateralWithdrawn = ICDPVault(vault).withdraw(address(this), amount);
+       uint256 collateralWithdrawn = ICDPVault(vault).withdraw(position, amount);

amarcu (LoopFi) confirmed

Koolex (judge) commented:

Please elaborate on the impact, will re-evaluate in PJQA.

pkqs90 (warden) commented:

@Koolex - The proxy supports depositing/withdrawing collateral from positions other than the proxy itself. An example can be found in unit tests, where a user creates a position for another address (aliceProxy).

The issue here is that for PositionAction4626, it only supports actions on the vault of the sender proxy, and not any other address. To make a comparison, both PositionAction20 and PositionActionPendle supports it, only PositionAction4626 lack this functionality.

    function test_deposit_to_an_unrelated_position() public {
        // create 2nd position
        address alice = vm.addr(0x45674567);
        PRBProxy aliceProxy = PRBProxy(payable(address(prbProxyRegistry.deployFor(alice))));

        uint256 depositAmount = 10_000 ether;

        deal(address(token), user, depositAmount);

        CollateralParams memory collateralParams = CollateralParams({
            targetToken: address(token),
            amount: depositAmount,
            collateralizer: address(user),
            auxSwap: emptySwap // no entry swap
        });

        vm.prank(user);
        token.approve(address(userProxy), depositAmount);

        vm.prank(user);
        userProxy.execute(
            address(positionAction),
            abi.encodeWithSelector(
                positionAction.deposit.selector,
                address(aliceProxy),
                address(vault),
                collateralParams,
                emptyPermitParams
            )
        );

        (uint256 collateral, uint256 debt, , , , ) = vault.positions(address(aliceProxy));

        assertEq(collateral, depositAmount);
        assertEq(debt, 0);
    }

Koolex (judge) commented:

Stays as-is.


The original report as published on Code4rena, by pkqs90. 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 withdraw call hardcoded address(this) instead of using the position parameter supplied to the hook.

Impact

Withdrawals through this contract only work for the sender's own proxy position, so the proxy cannot withdraw collateral from other positions, unlike the other position action contracts.

What the attacker needed

A proxy position other than the caller's own

The fix

The withdraw call should pass the position address rather than address(this); the team confirmed the issue.

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 proxy contract lets a user act on a vault on their behalf. The code that handles withdrawals was told which position to take collateral from, but it ignored that and took it from the proxy's own balance instead. That means actions aimed at someone else's position would not work as designed.

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