Adversary can lock every deposit forever by making a deposit with _expiration = type(uint256).max
A depositor can set an expiration value so large that adding it to the deposit time overflows, causing the refund calculation to always revert. This permanently blocks all refunds for that bounty.
GimelSec Follow with clems4ever, KingNFT and 5 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-openq-judging/issues/362
Found by
GimelSec, clems4ever, KingNFT, Robert, 0x52, bin2chen, 0xdeadbeef, TrungOre
Summary
DepositMangerV1 allows the caller to specify _expiration which specifies how long the deposit is locked. An adversary can specify a deposit with _expiration = type(uint256).max which will cause an overflow in the BountyCore#getLockedFunds subcall and permanently break refunds.
Vulnerability Detail
DepositManagerV1#fundBountyToken allows the depositor to specify an _expiration which is passed directly to BountyCore#receiveFunds.
BountyCore stores the _expiration in the expiration mapping.
When requesting a refund, getLockedFunds returns the amount of funds currently locked. The line to focus on is depositTime[depList[i]] + expiration[depList[i]]
An adversary can cause getLockedFunds to always revert by making a deposit in which depositTime[depList[i]] + expiration[depList[i]] > type(uint256).max causing an overflow. To exploit this the user would make a deposit with _expiration = type(uint256).max which will cause a guaranteed overflow. This causes DepositMangerV1#refundDeposit to always revert breaking all refunds.
Submitting as high risk because when combined with payout breaking methods it will result in all deposited tokens being stuck forever.
Impact
Adversary can permanently break refunds
Code Snippet
Tool used
Manual Review
Recommendation
Add the following check to DepositMangerV1#fundBountyToken:
+ require(_expiration <= type(uint128).max)
Discussion
FlacoJones
Overflow check: https://github.com/OpenQDev/OpenQ-Contracts/pull/129
Funder == Issuer: https://github.com/OpenQDev/OpenQ-Contracts/pull/116
jacksanford1
Lead Senior Watson comment on PR #129:
Fix looks good. _expiraiton is now limited to prevent overflows and trapped funds
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.
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 did not limit the user-supplied expiration value, so adding it to the deposit timestamp could overflow and make the refund calculation revert.
Impact
All refunds for the affected bounty are permanently blocked, and combined with other payout issues all deposited tokens could be stuck forever.
What the attacker needed
Ability to make a deposit on a bounty
The fix
The contract was fixed by adding a check that the expiration does not exceed the maximum value of a 128-bit unsigned integer.
How it was found
- Call fundBountyToken with an expiration set to the maximum possible unsigned integer value.
- The contract stores this expiration for the deposit.
- When any refund is requested, getLockedFunds adds the deposit time and expiration, which overflows and reverts.
- As a result, refundDeposit always reverts and no refunds can be processed.
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.
Smart contracts store numbers with a fixed maximum size. If you add two numbers and the result is too big to fit, the calculation can fail or wrap around. Here, a user could choose an expiration date so far in the future that adding it to the deposit time overflowed, making the refund function crash every time it ran.
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.