A donation attack of the LINK token to the StakingPool can DoS deposits if endingBalance is always higher than unusedDepositLimit
Let's have a look at the deposit function of the StakingPool:
We will be looking at this piece of code particularly:
The idea is to limit how much unused balance there is in the StakingPool. However, this can easily be used to DoS and grief a user (or multiple users) by a malicious actor.
Let's have the following scenario:
The contract’s starting balance is 0 tokens.
The unusedDepositLimit is 100 tokens.
A malicious user donates 30 tokens directly to the contract (outside the deposit function).
The contract’s starting balance is 30 tokens (from the external donation).
User calls deposit(100):
startingBalance = 30 tokens (from the donation).
The contract now has 30 + 100 = 130 tokens.
Call to _depositLiquidity:
Assume the strategies can only accept 20 tokens.
20 tokens are deposited into strategies.
110 tokens remain in the contract (leftover tokens).
After the deposit and liquidity operations, the endingBalance is 110 tokens (remaining in the contract).
Is endingBalance > startingBalance?
Yes. Ending balance = 110 tokens, and starting balance = 30 tokens. The condition 110 > 30 is true.
Is endingBalance > unusedDepositLimit?
Yes. The ending balance is 110 tokens, and the unusedDepositLimit is 100 tokens. The condition 110 > 100 is true.
Since both conditions are met, the function will revert with the error InvalidDeposit.
What is more, the malicious actor can donate the tokens only when they see the user calling deposit and front-run their transaction to DoS it.
The impact of such a vulnerability is griefing other users and DoS-ing deposits that should not be reverted.
Manual Review
Implement a system that has an internal system of counting tokens and remove usage of balanceOf to ensure that no malicious actor can DoS depositing.
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.