The Treasury.sol contract allows any actor to deposit arbitrary ERC-20 tokens. This introduces a critical issue because these tokens directly affect _totalValue, which is tracked and updated when deposits and withdrawals occur. A malicious entity could exploit this mechanism to front-run deposits and push _totalValue to type(uint256).max, making all future deposits revert and effectively causing a denial of service (DoS) attack on the treasury.
The deposit() function increases _totalValue by the deposited amount:
A malicious ERC-20 token can be designed to return true for all transferFrom() calls without actually transferring tokens.
The attacker front-runs legitimate deposits by calling deposit() with:
This forces _totalValue to reach its maximum possible value.
Once _totalValue == type(uint256).max, all future deposits will revert due to Solidity's built-in overflow protection.
A threat actor deploys a malicious ERC-20 token that does not enforce actual transfers but always returns true on transferFrom().
They repeatedly front-run deposit transactions, maxing out _totalValue.
Any legitimate deposit attempt fails because adding any amount would exceed type(uint256).max, triggering a revert.
The treasury contract becomes permanently unusable as no further deposits can be made.
Denial of Service (DoS): The treasury contract is rendered inoperable as deposits become impossible.
Protocol Disruption: Users and protocol functions relying on treasury deposits will fail.
Manual Code Review
Use Checked Arithmetic:
Ensure _totalValue + amount does not exceed type(uint256).max before updating _totalValue.
Example fix:
Restrict Token Deposits:
Implement a whitelist for allowed ERC-20 tokens to prevent deposits from non-standard or malicious tokens.
Ensure deposited tokens conform to expected behavior by validating their balance and transfer logic.
Cap Maximum Deposit Amounts:
Introduce a reasonable upper limit for deposits to prevent excessive values from being processed.
Example:
By implementing these mitigations, the Treasury contract can safeguard against front-running DoS attacks and ensure the integrity of fund management operations.
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.