Skip to content
Business logic Audit finding Intermediate

MarketFees : Seller referrer fee can underflow

The fee calculation in MarketFees subtracts a seller referrer fee from the seller or creator revenue without checking that the fee is smaller than that revenue. With certain valid fee settings, the subtraction underflows and the sale reverts, so legitimate sales cannot complete.

Foundation Exhibition, Scheduling & Early Access Solo Audit by Lambda

Originally disclosed on Code4rena

In MarketFees._getFees, the sellerReferrerFee is deducted from creatorRev or sellerRev (depending on if the sale is primary / secondary):

      if (sellerReferrerTakeRateInBasisPoints != 0) {
        sellerReferrerFee = (price * sellerReferrerTakeRateInBasisPoints) / BASIS_POINTS;

        // Subtract the seller referrer fee from the seller revenue so we do not double pay.
        if (sellerRev == 0) {
          // If the seller revenue is 0, this is a primary sale where all seller revenue is attributed to the "creator".
          creatorRev -= sellerReferrerFee;
        } else {
          sellerRev -= sellerReferrerFee;
        }
      }

sellerReferrerTakeRateInBasisPoints can be up to 5,000 (50%), because the exhibition take rate (which is the only case when a non-zero value is passed) needs to be smaller than MAX_TAKE_RATE. On the other hand, it is only enforced that the protocol fee plus the creator royalty percentage is smaller than 100%:

    if (
      protocolFeeInBasisPoints < BASIS_POINTS / BUY_REFERRER_FEE_DENOMINATOR ||
      protocolFeeInBasisPoints + BASIS_POINTS / CREATOR_ROYALTY_DENOMINATOR >= BASIS_POINTS
    ) {
      /* If the protocol fee is invalid, revert:
       * Protocol fee must be greater than the buy referrer fee since referrer fees are deducted from the protocol fee.
       * The protocol fee must leave room for the creator royalties.
       */
      revert NFTMarketFees_Invalid_Protocol_Fee();
    }

Because of that, there are valid settings where the calculation will underflow, leading to sales that do not succeed. For instance, we can have a protocol fee of 20% and creator royalties of 35%, in which case sellerRev would be 45% of the overall price. If the exhibition take rate is then >45%, the calculation will underflow.

Link To Affected Code

https://github.com/f8n/fnd-contracts-staging/blob/c5ca7eb50e3fe3221bda49168cae8b4bbd98f4ac/contracts/mixins/shared/MarketFees.sol#L534

Recommended Mitigation Steps

There are two options to solve the problem:

  • Enforce that the protocol fee plus the creator royalty percentage is less than 50%.
  • Handle the underflow case explicitly and for instance cap the seller referrer fee if it would exceed the seller revenue.

The original report as published on Code4rena. 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 seller referrer fee is subtracted from seller or creator revenue without validating that it does not exceed that revenue, while the allowed fee ranges permit such a combination.

Impact

Valid fee configurations cause sales to revert, so affected listings cannot be sold until the fees change.

What the attacker needed

Valid fee settings, e.g. 20% protocol fee; creator royalties of 35%; exhibition take rate above 45%

The fix

The protocol fee plus creator royalty should be enforced below 50%, or the seller referrer fee should be capped so it cannot exceed the seller revenue.

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 smart contract splits each sale price between the seller, the creator and the platform. Here the code takes a referrer cut out of the seller's share, but it never checks that the cut is smaller than that share. When the cut is bigger, the maths goes negative, which the contract cannot represent, so the whole sale fails.

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 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.