Treasury cannot claim COMP tokens & COMP tokens are stuck
The TreasuryAction contract's claimCOMPAndTransfer function uses pre- and post-balances to determine how much COMP to transfer, but anyone can claim COMP on behalf of the contract, causing the contract's balance to increase without the function's knowledge. An attacker can repeatedly claim COMP for the contract, making the contract unable to claim COMP itself and leaving the claimed COMP stuck in the contract.
Submitted by cmichel, also found by leastwood
The TreasuryAction.claimCOMPAndTransfer function uses pre- and post-balances of the COMP token to check which ones to transfer:
function claimCOMPAndTransfer(address[] calldata cTokens)
external
override
onlyManagerContract
nonReentrant
returns (uint256)
{
// Take a snasphot of the COMP balance before we claim COMP so that we don't inadvertently transfer
// something we shouldn't.
uint256 balanceBefore = COMP.balanceOf(address(this));
COMPTROLLER.claimComp(address(this), cTokens);
// NOTE: If Notional ever lists COMP as a collateral asset it will be cCOMP instead and it
// will never hold COMP balances directly. In this case we can always transfer all the COMP
// off of the contract.
uint256 balanceAfter = COMP.balanceOf(address(this));
uint256 amountClaimed = balanceAfter.sub(balanceBefore);
// NOTE: the onlyManagerContract modifier prevents a transfer to address(0) here
COMP.safeTransfer(treasuryManagerContract, amountClaimed);
// NOTE: TreasuryManager contract will emit a COMPHarvested event
return amountClaimed;
}
Note that anyone can claim COMP tokens on behalf of any address (see Comptroller.claimComp). An attacker can claim COMP tokens on behalf of the contract and it’ll never be able to claim any compound itself. The COMP claimed by the attacker are stuck in the contract and cannot be retrieved. (One can eventually get back the stuck COMP by creating a cCOMP market and then transferring it through transferReserveToTreasury.)
Recommended Mitigation Steps
Don’t use pre-and post-balances, can you use the entire balance?
jeffywu (Notional) disagreed with severity and commented:
Dispute as a high risk bug. Would categorize this as medium risk.
There is no profit to be gained by doing this from the attacker besides denial of service. The protocol could simply upgrade to regain access to the tokens. We will fix this regardless.
Very good find.
It is a tough decision if this should be classified as High or Medium severity. An exploiter cannot acquire those assets, and the contracts are upgradeable if necessary, however, I think this time I will leave it in favor of wardens who both are experienced enough and submitted this as of high severity: 3 — High: Assets can be stolen/lost/compromised directly (or indirectly if there is a valid attack path that does not have hand-wavy hypotheticals).
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The function relies on the difference between pre- and post-claim balances to determine the amount to transfer, but an attacker can increase the balance beforehand, causing the computed amount to be zero or incorrect.
Impact
An attacker can cause a denial of service by making the contract unable to claim COMP, and the claimed COMP becomes stuck in the contract, though the attacker gains no profit and the protocol could upgrade to recover the tokens.
What the attacker needed
Attacker can call claimComp for the contract
The fix
The function should transfer the entire COMP balance instead of using pre- and post-balances.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a smart contract bug where a function tries to send only the COMP tokens it just claimed by comparing the balance before and after claiming. But because anyone can trigger a claim for the contract, an attacker can make the contract's COMP balance go up without the function noticing, so the function sends zero and the extra COMP gets stuck. The attacker doesn't steal the tokens, but they block the contract from claiming its own rewards.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.