# PhiFactory:claim potentially causing loss of funds if mintFee changed beforehand

PhiFactory.claim forwards mintFee as msg.value to external merkleClaim/signatureClaim without validating user's msg.value, so excess ETH is unrefunded and underpayment drains factory balance.

- Payout: Audit contest
- Severity: medium
- Program: Phi
- Found by: pep7siup
- Disclosed: 2024-10-07
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-08-phi-findings/issues/109
- Library page: https://bugbountylibrary.com/r/c4%3A2024-08-phi%3AM-03
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:business-logic vuln:fee-bypass

**Target:** PhiFactory.claim payable mint flow (Solidity/EVM)
**Root cause:** claim() computes mintFee and forwards it as value to external this.merkleClaim/signatureClaim, overriding the caller's msg.value; the original msg.value is never validated or refunded.
**Steps:**
1. Create art with mintFee; user calls `phiFactory.claim{value: mintFee + 0.1 ether}(data)`; excess 0.1 ETH stays in factory.
2. Attacker calls `phiFactory.claim{value: 0}(data2)` for another art; factory forwards mintFee from its own balance.
3. Assert factory balance decreased by mintFee, confirming protocol loss.
**How found:** Code reading of claim() noting the external call forwards mintFee rather than msg.value, and that external (not public) call overrides msg.value so refund logic in merkleClaim/signatureClaim never sees the original value.
**Exploitation:** Attacker mints with zero msg.value while factory holds residual ETH from overpaying users; the forwarded mintFee is paid from the factory's balance, draining it.
**Insight:** When a payable function forwards a computed fee via an external self-call, the inner call's msg.value replaces the outer one—check that the outer msg.value is validated/refunded, and that residual contract balance can't subsidize underpayers.

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

**claim forwards mintFee without validating msg.value**

```
uint256 mintFee = getArtMintFee(artId, quantity_);
    283: =>             this.merkleClaim{ value: mintFee }(proof, claimData, mintArgs, leafPart_); 
    284:        } else if (art.verificationType.eq("SIGNATURE")) {
        ...
    304:    }

Similarly, this external call to `this.signatureClaim` forwards the `mintFee` value of ETH without validating it against `msg.value`.

- Found in [src/PhiFactory.sol at Line 300](https://github.com/code-423n4/2024-08-phi/blob/main/src/PhiFactory.sol#L300)

    264:    function claim(bytes calldata encodeData_) external payable {
        ...
    299:            uint256 mintFee = getArtMintFee(artId, quantity_);
    300: =>             this.signatureClaim{ value: mintFee }(signature_, claimData, mintArgs);
```

