Skip to content
Business logic Audit finding Advanced

Forget to check “Some manifolds contracts of ERC-2981 return (address(this), 0) when royalties are not defined” in 3rd priority - MarketFees.sol

The royalty lookup in the third priority path of MarketFees.sol did not ignore a zero royalty amount, so a contract returning (address(this), 0) was treated as a valid recipient. An attacker could cause sale proceeds to be sent to the market contract itself, where the funds become stuck.

KIntern_NA Follow

Originally disclosed on Code4rena

Submitted by KIntern_NA, also found by bin2chen and Lambda

Wrong return of cretorShares and creatorRecipients can make real royalties party can’t gain the revenue of sale.

Proof of concept

Function getFees() firstly call to function internalGetImmutableRoyalties to get the list of creatorRecipients and creatorShares if the nftContract define ERC2981 royalties.

try implementationAddress.internalGetImmutableRoyalties(nftContract, tokenId) returns (
  address payable[] memory _recipients,
  uint256[] memory _splitPerRecipientInBasisPoints
) {
  (creatorRecipients, creatorShares) = (_recipients, _splitPerRecipientInBasisPoints);
} catch // solhint-disable-next-line no-empty-blocks
{
  // Fall through
}

In the 1st priority it check the nftContract define the function royaltyInfo or not. If yes, it get the return value receiver and royaltyAmount. In some manifold contracts of erc2981, it return (address(this), 0) when royalties are not defined. So we ignore it when the royaltyAmount = 0

  try IRoyaltyInfo(nftContract).royaltyInfo{ gas: READ_ONLY_GAS_LIMIT }(tokenId, BASIS_POINTS) returns (
    address receiver,
    uint256 royaltyAmount
  ) {
    // Manifold contracts return (address(this), 0) when royalties are not defined
    // - so ignore results when the amount is 0
    if (royaltyAmount > 0) {
      recipients = new address payable[](1);
      recipients[0] = payable(receiver);
      splitPerRecipientInBasisPoints = new uint256[](1);
      // The split amount is assumed to be 100% when only 1 recipient is returned
      return (recipients, splitPerRecipientInBasisPoints);
    }

In the same sense, the 3rd priority (it can reach to 3rd priority when function internalGetImmutableRoyalies fail to return some royalties) should check same as the 1st priority with the royaltyRegistry.getRoyaltyLookupAddress. But the 3rd priority forget to check the case when royaltyAmount == 0.

  try IRoyaltyInfo(nftContract).royaltyInfo{ gas: READ_ONLY_GAS_LIMIT }(tokenId, BASIS_POINTS) returns (
    address receiver,
    uint256 /* royaltyAmount */
  ) {
    recipients = new address payable[](1);
    recipients[0] = payable(receiver);
    splitPerRecipientInBasisPoints = new uint256[](1);
    // The split amount is assumed to be 100% when only 1 recipient is returned
    return (recipients, splitPerRecipientInBasisPoints);
  }

It will make function _distributeFunds() transfer to the wrong creatorRecipients (for example erc2981 return (address(this), 0), market will transfer creator revenue to address(this) - market contract, and make the fund freeze in contract forever).

This case just happen when

  • nftContract doesn’t have any support for royalties info
  • overrideContract which was fetched fromroyaltyRegistry.getRoyaltyLookupAddress(nftContract) implements both function getRoyalties and royaltyInfo but doesn’t support royaltyInfo by returning (address(this), 0).

Recommended Mitigation Steps

Add check if royaltyAmount > 0 or not in 3rd priority.

HardlyDifficult (Foundation) confirmed and commented:

This was a great catch. We will be making the recommended change.

Medium risk seems correct as this is a form of potentially leaking value.

We agree that any contract returning (address(this), 0) should be treated as no royalties defined instead of paying to address(this).

HickupHH3 (judge) commented:

Yes, agree that zero royalty amount check is missing for 3rd priority.


The original report as published on Code4rena, by KIntern_NA. 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

Impact

Creator royalties could be sent to the market contract and become permanently stuck, though this only happens with a specific combination of contracts.

What the attacker needed

NFT contract has no royalty support; Override contract returns (address(this), 0)

The fix

The third-priority lookup should check that the royalty amount is greater than zero before accepting the recipient, and the project said it would make this change.

How it was found

  1. The NFT contract has no royalty support, so the first two royalty lookups fail.
  2. The royalty registry returns an override contract that implements both getRoyalties and royaltyInfo.
  3. That override contract's royaltyInfo returns the market contract address with a zero amount.
  4. The third-priority lookup accepts this as a valid recipient without checking the amount.
  5. The distribution function sends the creator's share to the market contract, where it is frozen.

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 NFT is sold, the marketplace asks the NFT contract who should receive a creator fee. Some contracts answer with their own address and a fee of zero to mean 'no fee'. The marketplace code in one place forgot to ignore that zero-fee answer, so it sent the creator's money to the marketplace contract instead of the real creator, and the money could not be taken out.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by KIntern_NA

View all

21 more disclosed reports, best first.

More from Foundation Exhibition, Scheduling & Early Access Solo Audit by Lambda

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.