Treasury.sol contract can be permanently disabled by depositing a malicious token with an amount close to type(uint256).max and then making it untransferable, causing the _totalValue to remain permanently high and preventing any future deposits.
The vulnerability exists in the Treasury contract's deposit and withdraw functions:
The deposit function updates _totalValue without verifying if the token transfer was successful or if the token can be transferred out later. This allows an attacker to:
Create a malicious token(see Proof of Concept) that allows initial transfers but becomes untransferable
Mint and Deposit an amount close to type(uint256).max - 1 :
Make the token untransferable
The _totalValue remains permanently high since tokens can't be withdrawn
The withdraw function attempts to reduce _totalValue when called by a address MANAGER_ROLEbut it will fail because the tokens can't be transferred:
At this point:
_totalValue is around their max value and there’s no way to transfer the Malicious token.
deposit will revert by overflow error everytime a user wants to deposit a legitimate token.
Medium severity impact:
Treasury becomes permanently unusable
No new deposits possible due to _totalValue near maximum
Malicious tokens can't be withdrawn to reduce _totalValue
Manual review
Create and copy MaliciousToken.sol and TreasuryDoS.test.js files in the specified directory:
MaliciousToken.sol malicious token implementation:
TreasuryDoS.test.js Proof of Code:
Run the specific test:
The test output will show:
The attacker deploys a malicious token that becomes untransferable after the first transfer.
The attacker deposits an amount close to type(uint256).max - 1 for their MaliciousToken.
The token becomes untransferable, preventing withdrawals
The high _totalValue prevents any new deposits due to overflow protection
This demonstrate the ability for an attacker to force a DoS by overflowing _totalValue , making the protocol unusable
1. The main issue here is that _totalValue is a global variable, which interferes with the overall functionality of the contract.
Mitigation: Remove the global _totalValue variable and track tokens individually. This will allow Treasury.sol to maintain an independent account for each token.
2. No token validation in the deposit(address token, uint256 amount) function, which allows attackers to introduce non-standard functionalities.
Mitigation: To address this, a whitelist can be implemented to permit only specific, known tokens to interact with the protocol.
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.