Missing maxNumberOfKeys checks in shareKey and grantKey
The shareKey and grantKey functions mint new keys without checking the lock's maxNumberOfKeys limit, unlike the purchase function. An attacker could mint more keys than intended, though the protocol team stated that for grantKey this is intentional and only confirmed the issue for shareKey.
Submitted by kenzo
More keys can be minted than maxNumberOfKeys since shareKey and grantKey do not check if the lock is sold out.
Impact
More keys can be minted than intended.
Proof of Concept
In both shareKey and grantKey, if minting a new token, a new token is simply minted (and _totalSupply increased) without checking it against maxNumberOfKeys. This is unlike purchase, which has the notSoldOut modifier.
shareKey: https://github.com/code-423n4/2021-11-unlock/blob/main/smart-contracts/contracts/mixins/MixinTransfer.sol#L83:#L84 Both functions call _assignNewTokenId which does not check maxNumberOfKeys.
https://github.com/code-423n4/2021-11-unlock/blob/main/smart-contracts/contracts/mixins/MixinKeys.sol#L311:#L322 So you can say that _assignNewTokenId is actually the root of the error, and this is why I am submitting this as 1 finding and not 2 (for grantKey/shareKey).
Recommended Mitigation Steps
Add a check to _assignNewTokenId that will revert if we need to record a new key and maxNumberOfKeys has been reached.
julien51 (Unlock Protocol) confirmed and commented:
This is actually intentional. We want the lock manager to be able to grant keys even if the lock is sold out. Note that the lock manager could also increase the supply if they needed anyway. However, we should take that into account in the
shareKeyflow so I’ll mark as confirmed for that flow.
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
The internal function _assignNewTokenId, used by shareKey and grantKey, does not verify that the total supply is below maxNumberOfKeys before minting a new token.
Impact
More keys could be minted than the lock's maximum, potentially diluting key value or breaking intended supply limits; the protocol team confirmed this for shareKey but stated grantKey's behaviour is intentional.
What the attacker needed
Access to shareKey or grantKey function
The fix
Add a check in _assignNewTokenId that reverts when a new key would exceed maxNumberOfKeys, or at least apply this check in the shareKey flow.
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 lock has a maximum number of keys it can sell. Two functions that create new keys skip the check that enforces this limit, so more keys can be created than allowed. The team said one of these functions is meant to bypass the limit, but the other one should not.
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.