Skip to content
Smart contracts Audit finding Intermediate

ERC2981 royalties discrepancy with strategy

The Edition contract's setFeeStrategy and publish functions update the strategy's royaltyBps but do not update ERC2981's internal royalty value, causing a discrepancy between the stored royaltyBps and the royaltyInfo returned by ERC2981. This could lead to incorrect royalty payments after updates.

ComposableSecurity Follow with cducrest-brainbot and sammy

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-04-titles-judging/issues/144

Found by

ComposableSecurity, cducrest-brainbot, sammy

Summary

In Edition.sol, functions that set the value of works[tokenId].strategy which includes works[tokenId].strategy.royaltyBps do not set ERC2981's internal token royalty value.

Vulnerability Detail

The function setFeeStrategy() sets the public mapping value works[tokenId_].strategy which may update the roylatyBps value but does not call _setTokenRoyalty(...):

Solidity
    function setFeeStrategy(uint256 tokenId_, Strategy calldata strategy_) external {
        if (msg.sender != works[tokenId_].creator) revert Unauthorized();
        works[tokenId_].strategy = FEE_MANAGER.validateStrategy(strategy_);  // @audit does not set royalties
    }

Similarly, the publish() function to create a new work sets the strategy but does not call _setTokenRoyalty():

Solidity
    function publish(
        address creator_,
        uint256 maxSupply_,
        uint64 opensAt_,
        uint64 closesAt_,
        Node[] calldata attributions_,
        Strategy calldata strategy_,
        Metadata calldata metadata_
    ) external override onlyRoles(EDITION_MANAGER_ROLE) returns (uint256 tokenId) {
        tokenId = ++totalWorks;

        _metadata[tokenId] = metadata_;
        works[tokenId] = Work({
            creator: creator_,
            totalSupply: 0,
            maxSupply: maxSupply_,
            opensAt: opensAt_,
            closesAt: closesAt_,
            strategy: FEE_MANAGER.validateStrategy(strategy_)
        });

        Node memory _node = node(tokenId);
        for (uint256 i = 0; i < attributions_.length; i++) {
            // wake-disable-next-line reentrancy, unchecked-return-value
            GRAPH.createEdge(_node, attributions_[i], attributions_[i].data);
        }

        emit Published(address(this), tokenId);
    } 

This latter case may be less of a problem since TitlesCore calls edition_.setRoyaltyTarget() right after publishing a new work. However it remains a problem if publishers are expected to interact directly with Edition and not only through TitlesCore

Impact

The value returned by works[tokenId].strategy.royaltyBps and ERC2981.royaltyInfo(tokenId, salePrice) will not be coherent. Users may expect to set a certain royalty bps while the value is not updated. Core values used for royalty payments may become incorrect after updates.

Code Snippet

https://github.com/vectorized/solady/blob/main/src/tokens/ERC2981.sol

https://github.com/sherlock-audit/2024-04-titles/blob/d7f60952df22da00b772db5d3a8272a988546089/wallflower-contract-v2/src/editions/Edition.sol#L368-L371

https://github.com/sherlock-audit/2024-04-titles/blob/d7f60952df22da00b772db5d3a8272a988546089/wallflower-contract-v2/src/editions/Edition.sol#L121

Tool used

Manual Review

Recommendation

Call _setTokenRoyalty(tokenId, FeeManager.feeReceiver(address(this), tokenId), works[tokenId].strategy.royaltyBps); at the end of setFeeStrategy().

Discussion

pqseags

This is valid and should be fixed

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/titlesnyc/wallflower-contract-v2/pull/1

sherlock-admin2

The Lead Senior Watson signed off on the fix.

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

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 setFeeStrategy and publish functions update the strategy mapping but fail to call _setTokenRoyalty to synchronise ERC2981's internal royalty state.

Impact

The royaltyBps stored in the strategy and the royaltyInfo returned by ERC2981 may become inconsistent, potentially causing incorrect royalty payments after updates.

What the attacker needed

Creator calls setFeeStrategy; or publisher calls publish directly

The fix

The protocol team fixed this issue by calling _setTokenRoyalty at the end of setFeeStrategy.

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.

This report is about a smart contract that manages digital editions and royalties. When the creator changes the royalty percentage, the contract updates one record but forgets to update another record that actually determines how much royalty is paid. So the two records disagree, and the creator might not receive the intended royalty amount.

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 ComposableSecurity

View all

6 more disclosed reports, best first.

More from TITLES Publishing Protocol

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.