Core Contracts

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

DoS Vulnerability in Treasury Contract Due to Certain Token Behaviors

Summary

The Treasury.sol contract allows deposits from any ERC-20 token, which can lead to denial of service (DoS) conditions if a token unexpectedly transfers the maximum possible balance (type(uint256).max). Some legitimate tokens, such as Compound V3 tokens (e.g., cUSDCv3), exhibit this behavior where calling transferFrom() with a high value results in transferring the sender's entire balance. If an administrator deposits such a token, _balances[token] and _totalValue may become inconsistent, causing reverts and/or preventing further deposits or withdrawals.

Vulnerability Details

Incorrect _balances[token] Leading to DoS

Root Cause:

  1. The deposit() function updates _balances[token] and _totalValue upon a successful transfer:

    _balances[token] += amount;
    _totalValue += amount;
  2. Some ERC-20 tokens, including legitimate ones like cUSDCv3 from Compound V3, behave in a way where calling transferFrom() with type(uint256).max results in transferring the entire token balance of the sender.

  3. If an administrator deposits such a token, _balances[token] could reach type(uint256).max, making any further deposit attempt revert due to arithmetic limitations.

  4. This would effectively prevent any further deposits or updates to _totalValue, leading to a denial of service.

Exploit Scenario:

  • An administrator deposits a token that behaves abnormally, transferring the entire balance on large input values.

  • _balances[token] reaches type(uint256).max, causing all future deposits to revert.

  • Withdrawals and other balance-dependent operations may fail due to inconsistencies in _totalValue.

Impact

  • Denial of Service (DoS): No further deposits can be made due to the maximum limit being reached.

  • Incorrect Accounting: _totalValue no longer accurately represents the treasury’s actual holdings.

  • Potential Fund Locking: The contract could become unusable if key functions revert due to balance mismatches.

Tools Used

  • Manual Code Review

Recommendations

  1. Read Balance Before and After Transfers:

    • Instead of relying on amount, update _balances[token] by calculating the actual transferred amount:

      uint256 beforeBalance = IERC20(token).balanceOf(address(this));
      IERC20(token).transferFrom(msg.sender, address(this), amount);
      uint256 afterBalance = IERC20(token).balanceOf(address(this));
      _balances[token] += afterBalance - beforeBalance;
      _totalValue += afterBalance - beforeBalance;
  2. Whitelist Approved ERC-20 Tokens:

    • Restrict deposits to known, standard-compliant ERC-20 tokens to prevent unexpected behavior.

    • Maintain a governance-approved list of supported tokens.

By implementing these mitigations, the Treasury contract can prevent DoS attacks and ensure accurate fund accounting.

Updates

Lead Judging Commences

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Treasury::deposit increments _totalValue regardless of the token, be it malicious, different decimals, FoT etc.

Support

FAQs

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

Give us feedback!