# PositionAction20._onWithdraw and PositionPendle20._onWithdraw also returns token amount in wrong scale

CDPVault.withdraw returns amount in wad scale, but PositionAction20/Pendle._onWithdraw treat it as token scale, so withdrawals revert for non-18-decimal collateral.

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

**Target:** CDPVault / PositionAction20 / PositionActionPendle withdraw proxy
**Root cause:** CDPVault.withdraw converts amount to tokenScale but returns tokenAmount in wad scale; the proxy _onWithdraw callers assume the return is in collateral token decimals and use it directly for safeTransfer.
**Steps:**
1. Collateral has 8 decimals; user calls withdraw with amount=1e8.
2. CDPVault.withdraw does wdiv(amount, tokenScale) and returns tokenAmount in wad (1e18).
3. PositionAction20._onWithdraw returns that 1e18 to _withdraw.
4. _withdraw calls IERC20.safeTransfer(collateralizer, 1e18), exceeding balance of 1e8.
5. Transfer reverts with insufficient funds.
**How found:** Code reading of CDPVault.withdraw return scale versus proxy _onWithdraw consumers; noticed mismatch when collateral decimals deviate from 18.
**Insight:** When a vault function both accepts and returns amounts, verify the return scale matches what downstream proxy/action layers assume; decimal conversions at boundaries are a recurring source of revert/DoS in lending wrappers.

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

**CDPVault.withdraw returns wad-scaled tokenAmount**

```
function withdraw(address to, uint256 amount) external whenNotPaused returns (uint256 tokenAmount) {
    tokenAmount = wdiv(amount, tokenScale);
    int256 deltaCollateral = -toInt256(tokenAmount);
    modifyCollateralAndDebt({
        owner: to,
        collateralizer: msg.sender,
        creditor: msg.sender,
        deltaCollateral: deltaCollateral,
        deltaDebt: 0
    });
}
```

**PositionAction20._onWithdraw returns wrong scale**

```
function _onWithdraw(address vault, address position, address /*dst*/, uint256 amount) internal override returns (uint256) {
    return ICDPVault(vault).withdraw(position, amount); <-- return in wad scale
}
```

**PositionActionPendle._onWithdraw returns wrong scale**

```
function _onWithdraw(address vault, address position, address /*dst*/, uint256 amount) internal override returns (uint256) {
    return ICDPVault(vault).withdraw(address(position), amount); <-- return in wad scale
}
```

