Skip to content
Business logic Audit finding Intermediate

Refunding logic with multiple deposits is first mover take all

The refund logic calculates available funds as the contract's balance minus locked funds, without tracking individual deposits. When multiple deposits exist, the first depositor to request a refund can withdraw more than their fair share, potentially taking all remaining funds.

chaduke Follow with yixxas, HollaDieWaldfee and 11 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-openq-judging/issues/257

Found by

chaduke, yixxas, HollaDieWaldfee, Ruhum, MyFDsYours, Jeiwan, 0x52, joestakey, HonorLt, unforgiven, ltyu, TrungOre, ctf_sec, libratus

Summary

There is no accounting to keep track of which deposits are being used to pay bounties. This means that after all deposits have expired, the first user to refund their deposit will get more funds.

Vulnerability Detail

https://github.com/sherlock-audit/2023-02-openq/blob/main/contracts/DepositManager/Implementations/DepositManagerV1.sol#L171-L179

Available funds are simply calculated by taking the current balance of the bounty contract and subtracting the locked balance. This works well for single deposits but doesn't when there are multiple deposits from multiple funders. When this occurs it will cause a first mover take all situation.

Example: User A and User B both makes 10,000 USDC deposits to an Ongoing bounty, bringing the total funds of the bounty to 20,000 USDC. After some time the bounty is closed. By the time it's closed, it has paid out 10,000 USDC in awards leaving it with 10,000 USDC. User A and B both wait until their deposits are expired. Now User A requests a refund from his deposit. This refunds all 10,000 USDC to User A leaving none for User B. As a result, User A has effectively forced User B to pay all the awards.

Impact

Reward logic is first mover take all

Code Snippet

https://github.com/sherlock-audit/2023-02-openq/blob/main/contracts/DepositManager/Implementations/DepositManagerV1.sol#L152-L195

Tool used

Manual Review

Recommendation

Bounties should track how much has been paid and how much has been funded. When an ongoing bounty is refunded it should even split remaining funds over depositors.

Discussion

FlacoJones

Will fix by requiring funder == issuer

FlacoJones

https://github.com/OpenQDev/OpenQ-Contracts/pull/117

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.

The original report as published on Sherlock, by chaduke. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 contract does not track individual deposit amounts; it calculates available funds as the total balance minus locked funds, so refunds are not proportional to each depositor's contribution.

Impact

The first depositor to request a refund can take all remaining funds, forcing other depositors to bear the cost of awards.

What the attacker needed

Multiple depositors fund the same bounty; Bounty pays out some awards; Deposits expire; Attacker requests refund first

The fix

The refund logic was fixed by requiring that the funder is the issuer, which prevents multiple independent depositors from exploiting the refund mechanism.

How it was found

  1. Two users each deposit 10,000 USDC into an ongoing bounty.
  2. The bounty pays out 10,000 USDC in awards, leaving 10,000 USDC.
  3. Both deposits expire.
  4. The first user requests a refund and receives all 10,000 USDC, leaving nothing for the second user.

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.

In a smart contract, multiple users can deposit money. The refund function lets each user take back their deposit. But the contract doesn't remember who deposited what; it just looks at the total balance. So if two people deposited and some money was spent, the first person to ask for a refund can take more than they put in, leaving the second person with nothing.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by chaduke

View all

21 more disclosed reports, best first.

More from OpenQ

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.