Core Contracts

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

unchecked return value

Summary

Treasury.sol:: deposit Treasury.sol::withdraw

The transferFrom function is called to transfer tokens from the caller (msg.sender) to the Treasury contract:

The transfer function is called to transfer tokens from the Treasury contract to the recipient:

Vulnerability Details

Both the deposit and withdraw functions contain unchecked return values for ERC20 transferFrom and transfer calls

IERC20(token).transferFrom(msg.sender, address(this), amount);
IERC20(token).transfer(recipient, amount);

Impact

  • Silent Failures: If the transferFrom or transfer call fails, the contract will not revert, and the failure will go unnoticed.

  • State Inconsistency: The contract updates its state (e.g., _balances and _totalValue) assuming the transfer was successful, but if the transfer fails, the state will be incorrect.

  • Funds Loss: In the withdraw function, if the transfer fails, the tokens will not be sent to the recipient, but the contract will reduce the balance, effectively losing the tokens.

Tools Used

Manual Review

Recommendations

To fix this issue, you should always check the return value of transfer and transferFrom. Here are the recommended fixes:

  • Use SafeERC20 Library
    The contract already imports the SafeERC20 library, which provides safeTransfer and safeTransferFrom functions that revert if the transfer fails. Replace the transfer and transferFrom calls with safeTransfer and safeTransferFrom:

IERC20(token).safeTransfer(recipient, amount);
  • Manually Check the Return Value
    If you prefer not to use SafeERC20, you can manually check the return value of transfer and transferFrom:

bool success = IERC20(token).transferFrom(msg.sender, address(this), amount);
if (!success) revert TransferFailed();
_balances[token] += amount;
_totalValue += amount;
  • Add a Custom Error
    Define a custom error for failed transfers:

error TransferFailed();
Updates

Lead Judging Commences

inallhonesty Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

[INVALID] SafeERC20 not used

LightChaser Low-60

Support

FAQs

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