Gas costs will likely result in any fees sent to the Splitter being economically unviable to recover.
Each NFT mint creates a separate fee window in the Splitter contract, so royalties must be claimed one window at a time. Because claiming each window costs gas, collection owners will likely lose money unless a single sale's fees outweigh the cost of claiming them.
Originally disclosed on Code4rena
Submitted by TomFrenchBlockchain
Impact
Collection owners will likely lose money by claiming fees unless the fees from a single NFT sale outweighs the cost of claiming it (not guaranteed).
Proof of Concept
Consider a new Collection with a RoyaltyVault and Splitter set and a nonzero mint fee.
When calling mintToken, the _handlePayment function is called https://github.com/code-423n4/2022-03-joyn/blob/c9297ccd925ebb2c44dbc6eaa3effd8db5d2368a/core-contracts/contracts/CoreCollection.sol#L161-L163
This will transfer the minting fee to the RoyaltyVault contract.
On each transfer of an NFT within the collection (for instance in the _mint call which occurs directly after calling _handlePayment), the Collection contract will call sendToSplitter on the RoyaltyVault:
This function will forward the collection owners’ portion of the minting on to the Splitter contract but another important thing to note is that we call Splitter.incrementWindow.
This results in the fees newly deposited into the Splitter contract being held in a separate “window” to the fees from previous or later mints and need to be claimed separately. Remember that this process happens on every NFT sale so the only funds which will be held in this window will be the minting fees for this particular mint.
From this we can see that the claim function will only claim the fraction of the fees which are owed to the caller from a single NFT mint.
Note that we can attempt to claim from multiple windows in a single transaction using claimForAllWindow but as the name suggests it performs an unbounded loop trying to claim all previous windows (even ones which have already been claimed!) and it is likely that with a new window for every NFT sold this function will exceed the gas limit (consider an 10k token collection resulting in trying to do 10k SSTOREs at 20k gas each.), leaving us to claim each window individually with claim.
We’re then forced to claim the royalties from each NFT sold one by one, having to send huge numbers of calls to claim incurring the base transaction cost many times over and performing many ERC20 transfers when we could have just performed one.
Compound on this that this needs to be repeated by everyone included in the split, multiplying the costs of claiming.
Medium risk as it’s gas inefficiency to the point of significant value leakage where collection owners will lose a large fraction of their royalties.
Recommended Mitigation Steps
It doesn’t seem like the “window” mechanism does anything except raise gas costs to the extent that it will be very difficult to withdraw fees so it should be removed.
sofianeOuafir (Joyn) confirmed and commented:
This is a very fair point and we’ll consider fixing this issue.
deluca-mike (judge) commented:
Aside from the very valid points made by the warden, it seems that the heavy functions called from the
_beforeTokenTransferalso create a lot of friction for the NFT owners. Might make more sense to have royalty splitting happen asynchronously from NFT transfers (i.e. let the cost of splitting be the burden of royalty stakeholders, not NFT holders).If NFT transferring becomes too costly, someone could make a “de-joyn” contract which can “re-tokenize” NFTs sent to it, so that they can be transferred without having to worry about
_beforeTokenTransfer(or royalties, for that matter).See Recommended Mitigation Steps in #37 for more info.
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 Splitter contract opens a new claim window on every NFT transfer instead of pooling fees, and its claim-all function loops over every past window without a bound, so fees can only be recovered one window at a time.
Impact
Collection owners will likely lose a large fraction of their royalties because claiming each window costs more gas than the fees it holds, and every participant in the split pays this cost separately.
What the attacker needed
A collection with a royalty vault and splitter; a nonzero mint fee; many NFT mints or sales
The fix
The window mechanism should be removed so fees accumulate in one pool that can be claimed in a single transaction.
How it was found
- Mint an NFT in a collection that has a royalty vault and splitter with a nonzero mint fee.
- The mint fee is transferred to the royalty vault.
- The vault forwards the owners' share to the splitter and opens a new window.
- The owner tries to claim, but each claim only covers one window.
- The claim-all function loops over all windows and is likely to exceed the gas limit.
- The owner must claim each window individually, paying base transaction costs many times.
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 someone mints an NFT, a small fee is set aside for the collection owner. The contract stores each fee in its own separate pot, and the owner has to pay a transaction fee (gas) to open each pot. If each pot holds only a tiny amount, the cost of opening it is higher than the money inside, so the owner effectively loses money.
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.