Minting and redeeming will break for fully minted tiers with reserveRate != 0 and reserveRate / MaxReserveRate tokens burned
A calculation of how many reserve tokens remain mintable can fall below the number already minted once a fully minted tier starts being burned, causing an arithmetic underflow. Because minting and redeeming both call this function, all minting and redeeming of the NFTs becomes impossible.
Submitted by 0x52
Minting and redeeming become impossible.
Proof of Concept
uint256 _numberOfNonReservesMinted = _storedTier.initialQuantity -
_storedTier.remainingQuantity -
_reserveTokensMinted;
uint256 _numerator = uint256(_numberOfNonReservesMinted * _storedTier.reservedRate);
uint256 _numberReservedTokensMintable = _numerator / JBConstants.MAX_RESERVED_RATE;
if (_numerator - JBConstants.MAX_RESERVED_RATE * _numberReservedTokensMintable > 0)
++_numberReservedTokensMintable;
return _numberReservedTokensMintable - _reserveTokensMinted;
The lines above are taken from JBTiered721DelegateStore#_numberOfReservedTokensOutstandingFor and used to calculate and return the available number of reserve tokens that can be minted. Since the return statement doesn’t check that _numberReservedTokensMintable >= _reserveTokensMinted, it will revert under those circumstances. The issue is that there are legitimate circumstances in which this becomes false. If a tier is fully minted then all reserve tokens are mintable. When the tier begins to redeem, _numberReservedTokensMintable will fall under _reserveTokensMinted, permanently breaking minting and redeeming. Minting is broken because all mint functions directly call _numberOfReservedTokensOutstandingFor. Redeeming is broken because the redeem callback (JB721Delegate#redeemParams) calls _totalRedemtionWeight which calls _numberOfReservedTokensOutstandingFor.
Example:
A tier has a reserveRate of 100 (1/100 tokens reserved) and an initialQuantity of 10000. We assume that the tier has been fully minted, that is, _reserveTokensMinted is 100 and remainingQuantity = 0. Now we begin burning the tokens. Let’s run through the lines above after 100 tokens have been burned (remainingQuantity = 100):
_numberOfNonReservedMinted = 10000 - 100 - 100 = 9800
_numerator = 9800 * 100 = 980000
_numberReservedTokensMintable = 980000 / 10000 = 98
Since _numberReservedTokensMintable < _reserveTokensMinted the line will underflow and revert.
JBTiered721DelegateStore#_numberOfReservedTokensOutstandingFor will now revert every time it is called. This affects all minting functions as well as totalRedemptionWeight. Since those functions now revert when called, it is impossible to mint or redeem anymore NFTs.
Recommended Mitigation Steps
Add a check before returning:
+ if (_reserveTokensMinted > _numberReservedTokensMintable) {
+ return 0;
+ }
return _numberReservedTokensMintable - _reserveTokensMinted;
mejango (Juicebox DAO) confirmed
The root cause seems to be that there is no tracking of reserve tokens burnt.
mejango (Juicebox DAO) commented:
@Trust fair. this would require extra storage to track which tokenIDs were minted as reserves. could be a nice-to-have, and also used to prevent this issue.
Without tracking the number of burnt tokens, the mitigation suggested by the warden avoids the underflow so solves the main issue, which is that minting and redeeming break
Accounting for
numberOfBurnedReservesFormay help fixing the math but the underflow would still be possible if only non reserve tokens are burned
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 contract does not track reserve tokens that have been burned, so the recalculated mintable reserve count can drop below the already-minted reserve count and the subtraction underflows.
Impact
Minting and redeeming of the NFTs become permanently impossible for that tier once enough tokens are burned.
What the attacker needed
A tier with reserveRate != 0; tier fully minted; tokens burned
The fix
The suggested mitigation returns zero when the minted reserve count exceeds the mintable figure, avoiding the underflow; the judge noted this solves the main issue, though tracking burned reserves would fix the maths more fully.
How it was found
- Start with a tier that has a reserve rate and has been fully minted, so all reserve tokens exist.
- Burn some of the tier's tokens so the remaining quantity falls.
- Call a mint or redeem function, which recalculates the outstanding reserve tokens.
- Observe the subtraction underflow and the call revert.
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.
Each tier sets aside a share of tokens as 'reserves'. The contract works out how many reserves are still available by subtracting reserves already made from a figure recalculated from tokens still outstanding. When people burn tokens, that recalculated figure shrinks below what was already made, so the subtraction goes negative and the code stops with an error. Every mint and redeem then fails.
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.