Refunds can be bricked by triggering OOG (out of gas) in DepositManager
The refund function in DepositManager iterates over an unbounded list of deposits, which can be made arbitrarily large, causing out-of-gas errors and preventing any refunds from being processed. An attacker could permanently lock funds in the contract.
clems4ever Follow with HollaDieWaldfee, 0x52 and 26 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-openq-judging/issues/77
Found by
clems4ever, HollaDieWaldfee, 0x52, HonorLt, unforgiven, rvierdiiev, chainNue, GimelSec, Jeiwan, ak1, seyni, kiki_dev, Robert, KingNFT, eyexploit, carrot, ltyu, jkoppel, bin2chen, holyhansss, 0xdeadbeef, TrungOre, hake, yixxas, MyFDsYours, Atarpara, joestakey, imare, ctf_sec
Summary
The DepositManager contract is in charge of refunding tokens from the individual bounties. This function ends up running a for loop over an unbounded array. This array can be made to be sufficiently large to exceed the block gas limit and cause out-of-gas errors and stop the processing of any refunds.
Vulnerability Detail
The function refundDeposit() in DepositManager.sol is responsible for handling refunds, through the following snippet of code,
https://github.com/sherlock-audit/2023-02-openq/blob/main/contracts/DepositManager/Implementations/DepositManagerV1.sol#L152-L181
We are here interested in the line
https://github.com/sherlock-audit/2023-02-openq/blob/main/contracts/DepositManager/Implementations/DepositManagerV1.sol#L171-L172
which calculates available funds. If we check the function getLockedFunds(), we see it run a for loop
https://github.com/sherlock-audit/2023-02-openq/blob/main/contracts/Bounty/Implementations/BountyCore.sol#L333-L352
This loop is running over the list of ALL deposits. The deposit list is unbounded, since there are no checks for such limits in the receiveFunds() function. This can result in a very long list, causing out-of-gas errors when making refund calls.
Impact
Inability to withdraw funds. Can be forever locked into the contract.
Code Snippet
Tool used
Manual Review
Recommendation
Put a bound on the function receiveFunds to limit the number of deposits allowed.
Discussion
FlacoJones
Confirmed. Will fix by requiring funder == issuer and implementing a simple deposit volume greater than/less than token balance after claims
FlacoJones
https://github.com/OpenQDev/OpenQ-Contracts/pull/117 and https://github.com/OpenQDev/OpenQ-Contracts/pull/116
jacksanford1
Lead Senior Watson comment on PR #116:
Changes look good. Requires that funder is the issuer. This prevents a whole host of potential exploits in exchange for closing the otherwise open funding model.
Lead Senior Watson comment on PR #117:
Changes look good. The refund logic has been simplified to match the newly simplified funding logic.
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 refund logic iterates over an unbounded array of deposits without any limit on its size.
Impact
Refunds cannot be processed, potentially locking funds in the contract forever.
What the attacker needed
Attacker can add many deposits
The fix
The project fixed it by requiring the funder to be the issuer and simplifying the refund logic to match the new funding model.
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 function that processes refunds loops over every deposit ever made. If there are too many deposits, the loop takes more gas than a block allows, so the transaction always fails. This means nobody can get their refunds, and the money stays stuck.
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.