Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: medium
Invalid

Potential Fund Handling Vulnerability in StabilityPool.sol: Risk of Transfer Failures and Reentrancy

Summary
The StabilityPool.sol contract may contain a vulnerability related to fund withdrawals, potentially leading to transfer failures or unintended fund losses. The use of transfer() for ETH withdrawals imposes a gas limit of 2300, which can cause transactions to fail if the recipient is a smart contract with higher execution costs. Additionally, the lack of reentrancy protection could expose the contract to a potential attack vector if other conditions allow it.

Vulnerability Details

  • Issue:

    • The contract uses transfer(), which has a fixed gas limit of 2300. This can cause failures in cases where the recipient requires more gas.

    • No reentrancy protection is in place, which may be risky if combined with other vulnerabilities in the system.

  • Original Code:

function withdraw(uint256 amount) external {
require(amount <= address(this).balance, "Not enough funds");
payable(msg.sender).transfer(amount);
}
  • Problem:

    • Gas Limit Risk: If the recipient is a contract with a fallback function needing more than 2300 gas, the transfer will fail.

    • Potential Reentrancy Risk: If other vulnerabilities exist (e.g., reentrant calls modifying balances before withdrawal completes), an attacker could repeatedly withdraw funds.

Impact

  • Transaction Failures: ETH transfers may fail unexpectedly, leading to user frustration.

  • Potential Reentrancy Risk: If exploited, users could drain excess funds.

  • Loss of Trust: Unexpected behavior could undermine protocol reliability.

Tools Used

  • Manual Code Review: Identified gas limit and reentrancy concerns.

  • Solidity Security Best Practices: Cross-checked against standard security patterns.

Recommendations

  • Fix: Replace transfer() with call() for ETH withdrawals.

  • Enhancement: Use OpenZeppelin’s ReentrancyGuard to mitigate reentrancy risks.

  • Audit: Review all fund-related functions for potential security risks.

Updated Code:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract StabilityPool is ReentrancyGuard {
function withdraw(uint256 amount) external nonReentrant {
require(amount <= address(this).balance, "Not enough funds");
(bool success, ) = payable(msg.sender).call{value: amount}("");
require(success, "Transfer failed");
}
receive() external payable {}
}

Explanation

  • Use of call() instead of transfer(): Prevents gas limit issues by allowing dynamic gas allocation.

  • Added nonReentrant modifier: Ensures that reentrant calls cannot repeatedly withdraw funds.

  • Require checks: Ensures only valid transactions are processed.

Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Lack of quality

Support

FAQs

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

Give us feedback!