Rock Paper Scissors

First Flight #38
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: high
Invalid

Reentrancy Risk with Ether Transfer using call

Summary

The function uses the low-level call to transfer Ether to the admin. While call is flexible, it is vulnerable to reentrancy attacks, where an external contract could make a recursive call back into the contract, potentially altering the contract's state or draining funds.

  • Vulnerability Details

function withdrawFees(uint256 _amount) external {
require(msg.sender == adminAddress, "Only admin can withdraw fees");
uint256 amountToWithdraw = _amount == 0 ? accumulatedFees : _amount;
require(amountToWithdraw <= accumulatedFees, "Insufficient fee balance");
accumulatedFees -= amountToWithdraw;
(bool success,) = adminAddress.call{value: amountToWithdraw}("");
require(success, "Fee withdrawal failed");
emit FeeWithdrawn(adminAddress, amountToWithdraw);
}

Impact

Funds Loss: If an attacker exploits the reentrancy vulnerability, they could withdraw more funds than the intended amount, leading to a loss of Ether from the contract.

  • Security Breach: A successful reentrancy attack could compromise the integrity of the contract and its balance, affecting other users' trust in the system.

  • Reputation Damage: A breach in security could severely damage the reputation of the project or the contract owner, leading to a loss of confidence from investors or users.

Tools Used

  • Solidity: The programming language for smart contracts.

  • Reentrancy Guard: A technique used to prevent recursive function calls and mitigate reentrancy attacks.

  • call function: Used for sending Ether, but can be prone to vulnerabilities when misused in external calls.

  • ChatGPT: Assisting in reviewing the code,writing document and identifying vulnerabilities.

Recommendations

  • Implement a Reentrancy Guard: Use the noReentrancy modifier or other equivalent mechanisms to block recursive calls.

  • Prefer transfer or send over call for Ether transfers: These methods are safer in terms of reentrancy as they forward a limited amount of gas (2300 gas), preventing external contracts from making recursive calls.

Updates

Appeal created

m3dython Lead Judge about 2 months ago
Submission Judgement Published
Invalidated
Reason: Design choice
Assigned finding tags:

Owner is Trusted

m3dython Lead Judge about 2 months ago
Submission Judgement Published
Invalidated
Reason: Design choice
Assigned finding tags:

Owner is Trusted

Support

FAQs

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