Iterations over all tiers in recordMintBestAvailableTier can render system unusable
A function that picks the best tier for a mint loops over every tier, so with many tiers a payment with a large leftover amount can run out of gas and always revert. This could block payments and, per the judge, also break redemptions that loop over tiers.
Submitted by Lambda, also found by brgltd
JBTiered721DelegateStore.recordMintBestAvailableTier potentially iterates over all tiers to find the one with the highest contribution floor that is lower than _amount. When there are many tiers, this loop can always run out of gas, which will cause some transactions (the ones that have a high _leftoverAmount within _processPayment) to always revert. The (implicit) limit for the number of tiers is 2^16 - 1, so it is possible that this happens in practice.
Proof Of Concept
Let’s say that 1,000 tiers are registered for a project. Small payments without a leftover amount or a small amount will be succesfully processed by _processPayment, because _mintBestAvailableTier is either not called or it is called with a small amount, meaning that recordMintBestAvailableTier will exit the loop early (when it is called with a small amount). However, if a payment with a large leftover amount (let’s say greater than the highest contribution floor) is processed, it is necessary to iterate over all tiers, which will use too much gas and cause the processing to revert.
Recommended Mitigation Steps
Use a binary search (which requires some architectural changes) for determining the best available tier. Then, the gas usage grows logarithmically (instead of linear with the current design) with the number of tiers, meaning that it would only be ~16 times higher for 65535 tiers as for 2 tiers.
drgorillamd (Juicebox DAO) commented on duplicate issue #226:
Disagree with:
Over time maxTierIdOf for a nft address gets large due to several increments
There is no several increments outside of adding new tiers by the project owner (this is similar to adding new token in an erc1155 - there is no such check in, for instance, OZ https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol), this is a project owner choice, not faulty logic.
Picodes (judge) commented on duplicate issue #226:
User funds could be at stake as
redeemParamswould revert because of the for loop intotalRedemptionWeight. A limit value would be indeed a good safeguard.
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 tier selection uses a linear scan over all tiers instead of a bounded or logarithmic search, so gas cost grows with the number of tiers.
Impact
Payments with a large leftover amount could always revert, and the judge noted user funds could be at stake because redemptions would also revert.
What the attacker needed
Project owner registers many tiers; payment with large leftover amount
The fix
The report recommends replacing the linear scan with a binary search so gas grows logarithmically, and the judge suggests adding a limit on the number of tiers.
How it was found
- Register a large number of tiers for a project, for example 1,000.
- Send a payment whose leftover amount is larger than the highest contribution floor.
- The contract must scan every tier to find the best one, uses too much gas, and the transaction reverts.
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 is a program on a blockchain, and every operation costs 'gas', a small fee. If a single transaction uses more gas than the network allows, it fails and is undone. Here a lookup walks through every tier one by one, so a project with many tiers can make some payments impossible to complete.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.