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.
_balances[token] Leading to DoSThe deposit() function updates _balances[token] and _totalValue upon a successful transfer:
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.
If an administrator deposits such a token, _balances[token] could reach type(uint256).max, making any further deposit attempt revert due to arithmetic limitations.
This would effectively prevent any further deposits or updates to _totalValue, leading to a denial of service.
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.
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.
Manual Code Review
Read Balance Before and After Transfers:
Instead of relying on amount, update _balances[token] by calculating the actual transferred amount:
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.