Eggstravaganza

First Flight #37
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: high
Valid

Security Vulnerability in NFT Deposit Function: Access Control and Approval Issues

Summary

This function, depositEggToVault, allows a player to deposit their egg (NFT) into the Egg Vault. But there’s a potential problem with security that could allow someone to exploit it.

Vulnerability Details

  • ** Lack of proper access control:** The function only checks if the player is the owner of the egg. But it doesn’t have any extra protections, like ensuring only certain people (the actual player) can call this function. This can lead to bad actors potentially exploiting it if other parts of the system aren’t secure.

  • NFT Transfer Approval: The player must first approve the NFT for transfer. This is important because without the approval, the contract can’t transfer the NFT. But if a player forgets or doesn't do it, the function won't work properly.

Impact

Potential exploit: If there's no proper protection, someone could trick the system and steal the NFT by taking advantage of the weak points in the code.

The main risk is that a player could lose control of their NFT if there’s a mistake in the process, or if the contract is manipulated by a malicious user.

Tools Used

Manual code review.

Recommendations

  • Add proper access control: Use a method like require(msg.sender == owner) to make sure only the person who owns the egg (NFT) can deposit it into the vault.

  • Ensure approval is in place: Always make sure the player approves the contract to transfer the NFT before calling the depositEggToVault function. This will ensure the transfer happens smoothly.

    function depositEggToVault(uint256 tokenId) external {
    require(eggNFT.ownerOf(tokenId) == msg.sender, "You are not the owner of this egg");
    // Ensure the player has approved the contract to transfer their NFT
    eggNFT.transferFrom(msg.sender, address(eggVault), tokenId);
    eggVault.depositEgg(tokenId, msg.sender);
    }
Updates

Lead Judging Commences

m3dython Lead Judge about 2 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Frontrunning Vulnerability DepositEgg

Front-running depositEgg allows deposit ownership hijacking.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.