In the Treasury contract an attacker can frontrun legitimate deposits by artificially inflating the _totalValue state variable using a malicious token that can't be transfered out of the Treasury anymore. This will temporarily disrupt protocol operations and cause legitimate deposits to fail due to arithmetic overflow.
The vulnerability exists in the unprotected deposit() function where anyone can deposit any token:
Attack Path:
Attacker spots a legitimate pending transaction in the MemPool
Attacker deploys a malicious token with no value
Mints type(uint256).max tokens (or any other amount that would cause an overflow in the next deposit)
Deposits these tokens into the treasury, inflating _totalValue
Legitimate deposit will fail due to arithmetic overflow
Protocol operations depending on deposits are disrupted (i.e.: the FeeCollector sends funds to the Treasury) [https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/collectors/FeeCollector.sol#L276]
withdraw() function in the Treasury contract won't work because the token blocks all transfers
In order to run the test you need to:
Run foundryup to get the latest version of Foundry
Install hardhat-foundry: npm install --save-dev @nomicfoundation/hardhat-foundry
Import it in your Hardhat config: require("@nomicfoundation/hardhat-foundry");
Make sure you've set the BASE_RPC_URL in the .env file or comment out the forking option in the hardhat config.
Run npx hardhat init-foundry
There is one file in the test folder that will throw an error during compilation so rename the file in test/unit/libraries/ReserveLibraryMock.sol to => ReserveLibraryMock.sol_broken so it doesn't get compiled anymore (we don't need it anyways).
Create a new folder test/foundry
Paste the below code into a new test file i.e.: FoundryTest.t.sol
Run the test: forge test --mc FoundryTest -vvvv
Disrupt protocol operations (for example the FeeCollector depends on the Treasury and some functions wouldn't work anymore)
Blocks legitimate deposits
There is a withdraw functions that allows the owner of the Treasury to withdraw any deposited token but this will fail because the Malicious Token contract prevents all transfers and the Attacker can execute this Attack repeatedly. This is why I rate this high and not medium, because there is no fix for this without redeploying.
Foundry
Manual Review
Implement token whitelisting with admin control:
Restrict deposits to only come from trusted addresses (similar to whitelisting a token => whitelist the allowed addresses)
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.