Beebots.TradeValid() Will Erroneously Return True When Maker Is Set To Address(0) and makerIds Are Set To The TokenIds of Unminted Beebot NFTs
The Beebots contract's signature verification returns true when the signer is the zero address, and unminted NFTs are treated as owned by the zero address. An attacker could call tradeValid with maker set to the zero address and makerIds of unminted tokens to make the function erroneously return true.
Larva Labs Meebits
Originally disclosed on Code4rena
Beebots.TradeValid() will erroneously return true when maker is set to address(0) and makerIds are set to the tokenIds of unminted beebot NFTs.
Beebots.verify() returns true no matter what signature is given when signer is set to address(0). This means that BeeBots.tradeValid() will erroneously return true when maker is set to address(0).
Finally, before an NFT has even been minted at all, it is assumed to have an owner of address(0) due to the idToOwner mapping being initialized to zero for all uninitialized slots, so an attacker can call tradeValid() with maker set to address(0) and makerIds set to the tokenIds of any unminted nftIds, and tradeValid() will erroneously return true.
-
(1)
Beebots.verify()returns true no matter what signature is given when signer is set toaddress(0).- (1a)
BeeBots.verify()does not check to ensure that signer is notaddress(0). - (1b) This is a problem because
ecrecoverfails silently if the signature does not match and returns zero. - (1c) So if an attacker passes in
address(0)as the signer, then verify will return true no matter what signature is provided, sinceecrecoverwill returnaddress(0), and the signer isaddress(0), so verify will pass. - (1d) This means that
BeeBots.tradeValid()will erroneously return true when maker is set toaddress(0).
- (1a)
-
(2) Before an NFT has even been minted at all, it is assumed to have an owner of
address(0)due to theidToOwnermapping being initialized to zero for all uninitialized slots- (2a) Solidity initializes all mappings to 0 for all slots that have not yet been set.
- (2b) So for any NFT ID that has not yet been minted, the corresponding owner in the mapping
BeeBots.idToOwnerisaddress(0), even though that NFT should not even exist. - (2c) This means that an attacker can call
tradeValid()with maker set toaddress(0)and makerIds set to any unminted nftIds, andtradeValid()will erroneously return true.
(1) Recommend adding this check to Beebots.verify(): require(signer != address(0), "Cannot verify signatures from 0x0");
(2) Recommend adding this check to Beebots.tradeValid(): require(maker != address(0), "Maker 0x0 not allowed");
dangerousfood (Meebits) commented:
Wow, this exploit is absolutely stunning.
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 fails to reject the zero address as a signer and treats unminted token IDs as owned by the zero address.
Impact
An attacker could make tradeValid return true for unminted tokens, potentially enabling invalid trades.
What the attacker needed
None
The fix
The report recommends adding checks to reject address(0) in both verify and tradeValid.
How it was found
- Call tradeValid with maker set to address(0).
- Set makerIds to the tokenIds of unminted NFTs.
- Observe that tradeValid returns true.
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 checks signatures to prove who approved a trade. If the expected signer is the special zero address, the check always passes because the recovery function returns zero on failure. Also, unminted tokens appear to be owned by the zero address. So an attacker can pretend a trade is valid for tokens that do not exist yet.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.