MyCut

First Flight #23
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Invalid

Reentrancy concerns in the `ContestManager.sol`

Description: In the context of the ContestManager.sol contract, the primary concern would arise if the Pot.sol contract (which is interacted with by ContestManager) handles Ether or interacts with other external contracts in a way that could allow reentrant calls.

Impact:

  1. Unauthorized Access: An attacker could exploit reentrancy to repeatedly call functions, potentially bypassing access controls or logic checks.

  2. State Manipulation: The contract's state could be manipulated in unexpected ways, leading to incorrect contest results or fund distribution.

  3. Financial Loss: If funds are involved, reentrancy could lead to unauthorized withdrawals or transfers.

Proof of Concept: Assuming the Pot contract has a vulnerability, here's a simplified example of how reentrancy might be exploited:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "./ContestManager.sol";
contract MaliciousContract {
ContestManager contestManager;
uint256 contestIndex;
constructor(address _contestManager, uint256 _contestIndex) {
contestManager = ContestManager(_contestManager);
contestIndex = _contestIndex;
}
// Fallback function to exploit reentrancy
fallback() external payable {
if (address(contestManager).balance >= 1 ether) {
contestManager.fundContest(contestIndex);
}
}
function attack() external {
contestManager.fundContest(contestIndex);
}
}

Recommended Mitigation:

  1. Implement Reentrancy Guards:

    1. Use OpenZeppelin's ReentrancyGuard to protect functions that could be vulnerable to reentrancy attacks.

    2. Apply the nonReentrant modifier to functions in the Pot contract that handle token transfers or external calls.

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract Pot is ReentrancyGuard {
// Example function with reentrancy protection
function distributeRewards() external nonReentrant {
// Function logic
}
}
  1. Use SafeERC20 Library:

    1. Replace direct ERC20 operations with OpenZeppelin's SafeERC20 library to handle token transfers safely.

    2. This ensures proper error handling and prevents silent failures.

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
using SafeERC20 for IERC20;
function fundContest(uint256 index) public onlyOwner {
Pot pot = Pot(contests[index]);
IERC20 token = pot.getToken();
uint256 totalRewards = contestToTotalRewards[address(pot)];
token.safeTransferFrom(msg.sender, address(pot), totalRewards);
}
  1. Add Address Validation:

    1. Ensure that addresses being assigned or used in critical operations are not address(0).

    2. Implement checks in functions to validate input addresses

Updates

Lead Judging Commences

equious Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

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