An attacker can steal eggs by frontrunning the call to depositEgg function when a NFT is transfered to the vault. The NFT owner nor the transferer is verified when calling this deposit function.
The key of this issue is to frontrun the call of the function depositEgg from the EggVault contract. This operation is possible because there is no verification of ownership or transfer authorization on the egg before deposit it to the vault. We only verify if the egg has been transfered to the vault, and if the egg is already stored :
An attacker may observe when an egg (NFT) is transfered to the vault by listening transactions, or by checking the counter of eggs in the vault.
In this way, he can deposit the egg before the normal process, by specifying the tokenId and his address in the function parameters.
The egg deposited will be his own when he will withdraw the egg of the vault.
Here is a POC of the scenario :
The impact is critic because all NFTs transfered to the vault for a deposit could be stolen.
Manual review + forge test
The main objective is to protect the call of the depositEgg function by verify the permissions on the NFTs. We could do that by adding a requirement :
In doing so, we verify that the caller is indeed the owner of the NFT, or the user/contract approved by the owner to manage the repository, as the EggHuntGame contract does in the classic Eggstravaganza game operation.
Front-running depositEgg allows deposit ownership hijacking.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.