Adversary can permanently break reward distribution for percentage tier bounties by funding bounty then refunding after competition closes
The TieredPercentageBountyV1 contract takes a snapshot of token balances when a competition closes to calculate payouts, but allows deposits to be refunded afterwards. An attacker can deposit a token (especially native MATIC) with a short expiration, then refund after closing, leaving the contract unable to pay winners and causing claims to revert permanently.
Source: https://github.com/sherlock-audit/2023-02-openq-judging/issues/266
Found by
8olidity, 0x52, HonorLt, unforgiven, chainNue, 0xbepresent, libratus, CodeFoxInc, XKET, Ruhum, seyni, Robert, ltyu, jkoppel, holyhansss, TrungOre, yixxas, ctf_sec, cccz
Summary
When closeCompetition is called for TieredPercentageBountyV1 it takes a snapshot of the current token balance. Afterwards it uses this number to calculate the payouts. When a deposit is refunded after the competition is closed then the contract won't have enough funds to pay users.
To exploit this an adversary can make a deposit for a token that has a current balance of zero using a expiration of 1 second. After the competition closes they refund their deposit. Now when the contract tries to give payouts to the winners it will try to payout a token that it no longer has any of, causing it to revert anytime someone tries to claim a payout.
Vulnerability Detail
TieredPercentageBountyV1#closeCompetition set the final fundingTotals for each token.
For each token in tokenAddresses it will send the claimedBalance to the claimant. If a deposit is refunded after the competition is closed then the contract won't have enough funds to pay users.
An adversary can exploit this by making a deposit of 100 for some token with and _expiration of 1 (second). After the competition has been closed they can refund their deposit causing the contract to be short on funds. If the user makes a deposit with an ERC20 token payouts can be re-enabled by donating to make the contract whole. The user can permanently break payouts by using native MATIC as the deposit. All bounty contracts have their receive function disabled which means the contract can't just be funded, which permanently breaks payouts.
Submitting as high because it can be combined with methods for breaking refunds to lock user funds permanently.
Impact
Adversary can permanently break TieredPercentageBounty payouts
Code Snippet
Tool used
Manual Review
Recommendation
Since TieredPercentageBounty is designed to distribute all deposits present at closing, refunds should be disabled after the competition is closed.
Discussion
FlacoJones
Valid. Will fix by removing this contract for now.
FlacoJones
https://github.com/OpenQDev/OpenQ-Contracts/pull/112
jacksanford1
Lead Senior Watson comment on PR #112:
Looks like you got everything. Will keep my eye out when reviewing the rest of the PRs for anything that might have been missed.
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 calculates payouts based on a balance snapshot at competition close but does not prevent deposits from being refunded after that point.
Impact
An adversary can permanently break TieredPercentageBounty payouts, especially by using native MATIC, as the contract cannot be refunded.
What the attacker needed
Ability to make a deposit; competition must close; deposit must be refundable after close
The fix
Refunds should be disabled after the competition is closed.
How it was found
- Make a deposit of a token with an expiration of 1 second.
- Wait for the competition to close.
- Refund the deposit after the competition is closed.
- When winners try to claim payouts, the contract lacks sufficient funds and reverts.
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 for bounties records how much money it holds when a competition ends, then uses that amount to pay winners. But it still lets people take back their deposits after the end, so the recorded amount can become wrong. An attacker can exploit this to make the contract unable to pay anyone.
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.