Eggstravaganza

First Flight #37
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: medium
Invalid

Reentrancy Vulnerability in depositEggToVault Function

Summary
The depositEggToVault function contains a potential reentrancy vulnerability due to external calls to the NFT and Vault contracts. While the function's ordering is correct and there are no state updates after external calls, the dependency on external contracts could lead to security issues if either contract is compromised or contains vulnerabilities.

Vulnerability Details:
The depositEggToVault function performs two sequential external calls:

function depositEggToVault(uint256 tokenId) external {
require(eggNFT.ownerOf(tokenId) == msg.sender, "Not owner of this egg");
eggNFT.transferFrom(msg.sender, address(eggVault), tokenId);
eggVault.depositEgg(tokenId, msg.sender);
}

The function first transfers the NFT to the vault contract and then calls the vault's depositEgg function. While the ordering follows the Checks-Effects-Interactions pattern, the function's security depends on the trustworthiness of both external contracts.

Root Cause:
The vulnerability stems from the following factors:

  1. External Contract Dependencies:

    • The function relies on the security of the EggstravaganzaNFT contract

    • The function depends on the security of the EggVault contract

    • Both contracts must maintain proper security standards

  2. Trust Model:

    • The implementation assumes both external contracts are secure

    • No validation of external contract behavior is performed

    • Success of external calls is not verified


Impact
If either the NFT or Vault contracts are compromised or contain vulnerabilities:

  1. Potential Consequences:

    • Unauthorized NFT transfers

    • Inconsistent vault state

    • Loss of user assets


Tools Used:
Foundry


PoC

Using Foundry, we can demonstrate the potential vulnerability:
```solidity
// Foundry test script
function test_depositEggToVault() public {
// Setup
uint256 tokenId = 1;
vm.prank(user1);
// Test normal operation
vm.expectRevert("Not owner of this egg");
eggHunt.depositEggToVault(tokenId);
// Test with valid owner
vm.prank(user2);
eggHunt.depositEggToVault(tokenId);
// Verify state changes
assertEq(eggVault.getEggOwner(tokenId), user2);
}

Recommended Mitigation

  1. Immediate Fixes:

    • Add return value checking for external calls

    • Implement event emissions for state changes

    • Add input validation for token IDs

  2. Long-term Solutions:

    • Document trust assumptions about external contracts

    • Implement monitoring for external contract changes

    • Consider using a reentrancy guard if needed


  • Add fuzz testing for edge cases

  • Implement property-based testing

Updates

Lead Judging Commences

m3dython Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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