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

PositionAction4626._onWithdraw withdraws from address(this) instead of the CDPVault position, so withdrawals target the wrong account and can revert or misdirect collateral.

- Payout: Audit contest
- Severity: medium
- Program: LoopFi
- Found by: pkqs90
- Disclosed: 2025-02-17
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-10-loopfi-findings/issues/13
- Library page: https://bugbountylibrary.com/r/c4%3A2024-10-loopfi%3AM-03
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:solidity technique:incomplete-fix technique:source-review vuln:accounting-error

**Target:** PositionAction4626.sol CDPVault integration
**Root cause:** _onWithdraw passes address(this) as the position to ICDPVault.withdraw instead of the actual position address, unlike the fixed _onDeposit which correctly uses position.
**Steps:**
1. Call the withdraw flow that invokes PositionAction4626._onWithdraw(vault, position, dst, amount)
2. Observe `ICDPVault(vault).withdraw(address(this), amount)` uses address(this) rather than position
3. Compare to _onDeposit which correctly passes position to ICDPVault.deposit
4. Withdrawal debits/credits the wrong position, breaking accounting or reverting
**How found:** Noticed the prior audit fix (M-35) only patched _onDeposit; code review of _onWithdraw showed the same address(this) vs position mistake remained, an incomplete-fix regression.
**Insight:** When a prior audit fix changes one function, grep sibling functions for the same wrong-argument pattern (address(this) vs the position parameter) to catch incomplete fixes.

## Proof of concept (copied exactly from the original report)

**Buggy _onWithdraw withdraws from address(this)**

```
function _onWithdraw(
        address vault,
        address /*position*/,
        address dst,
        uint256 amount
    ) internal override returns (uint256) {
        // @audit-note: This is still a bug.
@>      uint256 collateralWithdrawn = ICDPVault(vault).withdraw(address(this), amount);
```

**Recommended fix withdraws from position**

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

