# Incorrect address is used as spender for ERC20 permit signature verification

LoopFi's TransferAction passes `to` instead of the contract as spender when verifying ERC20 permit signatures, reverting increaseLever when called via PRBProxy delegatecall.

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

**Target:** PositionAction/TransferAction proxy (Solidity, ERC20 permit)
**Root cause:** safePermit() verifies the EIP-2612 signature using `to` as spender, but under delegatecall via PRBProxy `to` is the PositionAction contract while the actual spender is the proxy address, so the recovered signer mismatches.
**Steps:**
1. Build LeverParams with primarySwap recipient = address(positionAction) and permitParams of ApprovalType.PERMIT.
2. Sign permit with spender = address(userProxy) via PermitMaker.getPermitTransferFromSignature.
3. Call userProxy.execute(positionAction.increaseLever(leverParams, USDC, 20000 ether, user, permitParams)).
4. Observe revert `EIP2612: invalid signature` because safePermit uses `to` (positionAction) as spender, not userProxy.
**How found:** Code reading of TransferAction._transferFrom: noticed safePermit's spender argument is `to` rather than address(this); realized under PRBProxy delegatecall `self`/`to` differs from address(this), breaking permit verification.
**Insight:** In proxy/delegatecall architectures, address(this) is the proxy while the implementation's own address is a different value; any signature check using a caller-supplied or `to` address as spender will mismatch the signer's intended spender.

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

**Foundry test proving permit spender mismatch reverts**

```
function test_increaseLeverWithInvalidPermission() public {
        uint256 upFrontUnderliers = 20_000 ether;
        uint256 borrowAmount = 70_000 ether;
        uint256 amountOutMin = 69_000 ether;

        deal(address(USDC), user, upFrontUnderliers);

        // build increase lever params
        address[] memory assets = new address[](2);
        assets[0] = address(underlyingToken);
        assets[1] = address(USDC);

        LeverParams memory leverParams = LeverParams({
            position: address(userProxy),
            vault: address(vault),
            collateralToken: address(USDC),
            primarySwap: SwapParams({
                swapProtocol: SwapProtocol.UNIV3,
                swapType: SwapType.EXACT_IN,
                assetIn: address(underlyingToken),
                amount: borrowAmount,
                limit: amountOutMin,
                recipient: address(positionAction),
                deadline: block.timestamp + 100,
                args: abi.encode(weightedPoolIdArray, assets)
            }),
            auxSwap: emptySwap,
            auxAction: emptyPoolActionParams
        });

        PermitParams memory permitParams;

        uint256 deadline = block.timestamp + 100;
        //@audit-info the spender is userProxy
        (uint8 v, bytes32 r, bytes32 s) = PermitMaker.getPermitTransferFromSignature(
            address(USDC),
            address(userProxy),
            20_000 ether,
            0,
            deadline,
            0x12341234
        );
        permitParams = PermitParams({
            approvalType: ApprovalType.PERMIT,
            approvalAmount: 20_000 ether,
            nonce: 0,
            deadline: deadline,
            v: v,
            r: r,
            s: s
        });

        // call increaseLever
        vm.startPrank(user);
        //@audit-info revert due to invalid signature because `to` is used as `spender` to verify the signature, 
        //@audit-info while `to` inside the function `increaseLever()` is address(positionAction) instead of `userProxy`
        vm.expectRevert("EIP2612: invalid signature");
        userProxy.execute(
            address(positionAction),
            abi.encodeWithSelector(
                positionAction.increaseLever.selector,
                leverParams,
                address(USDC),
                20_000 ether,
                address(user),
                permitParams
            )
        );
        vm.stopPrank();
    }
```

