DoS: Attacker may significantly increase the cost of withdrawExcessRewards() by creating a significant number of excess receipts
An attacker can create many tiny deposits (receipts) that must all be withdrawn before the owner can call withdrawExcessRewards(), forcing the owner to spend unbounded gas. This could make the function too expensive to call.
Originally disclosed on Code4rena
Submitted by AuditsAreUS, also found by 0x52, 0xf15ers, and pedroais
An attacker may cause a DoS attack on withdrawExcessRewards() by creating a excessive number of receipts with minimal value. Each of these receipts will need to be withdrawn before the owner can call withdrawExcessRewards().
The impact is the owner would have to pay an unbounded amount of gas to withdraw() all the accounts and receive their excess funds.
Proof of Concept
withdrawExcessRewards() has the requirement that totalDepositsWei for the pool is zero before the owner may call this function as seen on line 245.
require(pool.totalDepositsWei == 0, 'Cannot withdraw until all deposits are withdrawn');
pool.totalDepositsWei is added to each time a user calls deposit(). It is increased by the amount the user deposits. There are no restrictions on the amount that may be deposited as a result a user may add 1 wei (or the smallest unit on any currency) which has negligible value.
The owner can force withdraw these accounts by calling withdraw() so long as block.timestamp > pool.endTime. They would be required to do this for each account that was created.
This could be a significant amount of gas costs, especially if the gas price has increased since the attacker originally made the deposits.
Recommended Mitigation Steps
Consider adding a minimum deposit amount for each pool that can be configured by the pool owner.
Alternatively, allow the owner to call withdrawExcessRewards() given some other criteria such as
- A fix period of time (e.g. 1 month) has passed since the end of the auction; and
- 90% of the deposits have been withdrawn
These criteria can be customised as desired by the design team.
illuzen (FactoryDAO) confirmed and commented:
Valid, will probably do minimum deposit.
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
Likely the contract allows deposits of any amount, even 1 wei, without a minimum, so an attacker can create many receipts cheaply.
Impact
The owner would have to pay an unbounded amount of gas to withdraw all the accounts and receive their excess funds.
What the attacker needed
Attacker can call deposit(); pool has an endTime
The fix
The project should add a minimum deposit amount for each pool, configurable by the pool owner.
How it was found
- Attacker calls deposit() many times with 1 wei each time, creating many receipts.
- After the pool's endTime, the owner must call withdraw() for each receipt to bring totalDepositsWei to zero.
- Only then can the owner call withdrawExcessRewards(), but the gas cost is very high.
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.
A smart contract lets people deposit money, and the owner can only take out extra funds after everyone has withdrawn. An attacker can deposit a tiny amount many times, creating many small accounts. The owner then has to close each account one by one, which costs a lot of gas (the fee paid for each transaction).
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.