Malicious user can grief withdrawing users via VUSD reentrancy
The VUSD contract's withdrawal processing sends the withdrawn gas token to the user's address using a low-level call, which triggers the recipient's receive function. An attacker could deploy a malicious contract that, upon receiving the gas token, immediately deposits and withdraws again, thereby lengthening the withdrawal queue and forcing other users to spend more gas to process their withdrawals.
0x3e84fa45 Follow with 0x52
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-04-hubble-exchange-judging/issues/153
Found by
0x3e84fa45, 0x52
Summary
VUSD#processWithdraw makes a call to withdrawal.usr to send the withdrawn gas token. processWithdrawals is the only nonreentrant function allowing a user to create a smart contract that uses it's receive function to deposit then immediately withdraw to indefinitely lengthen the withdrawal queue and waste large amounts of caller gas.
Vulnerability Detail
while (i < withdrawals.length && (i - start) < maxWithdrawalProcesses) {
Withdrawal memory withdrawal = withdrawals[i];
if (reserve < withdrawal.amount) {
break;
}
(bool success, bytes memory data) = withdrawal.usr.call{value: withdrawal.amount}("");
if (success) {
reserve -= withdrawal.amount;
To send the withdrawn gas token to the user VUSD#processWithdrawals utilizes a call with no data. When received by a contract this will trigger it's receive function. This can be abused to continually grief users who withdraw with no recurring cost to the attacker. To exploit this the attacker would withdraw VUSD to a malicious contract. This contract would deposit the received gas token then immediately withdraw it. This would lengthen the queue. Since the queue is first-in first-out a user would be forced to process all the malicious withdrawals before being able to process their own. While processing them they would inevitably reset the grief for the next user.
NOTE: I am submitting this as a separate issue apart from my other two similar issues. I believe it should be a separate issue because even though the outcome is similar the root cause is entirely different. Those are directly related to the incorrect call parameters while the root cause of this issue is that both mintWithReserve and withdraw/withdrawTo lack the reentrant modifier allowing this malicious reentrancy.
Impact
Malicious user can maliciously reenter VUSD to grief users via unnecessary gas wastage
Code Snippet
Tool used
Manual Review
Recommendation
Add the nonreentrant modifer to mintWithReserve withdraw and withdrawTo
Discussion
asquare08
Will add the nonreentrant modifer to mintWithReserve withdraw and withdrawTo
ctf-sec
To exploit this the attacker would withdraw VUSD to a malicious contract. This contract would deposit the received gas token then immediately withdraw it.
I put this issue and #160 together because these two issue highlight different ways of wasting gas, but they also focus on how to waste gas in external call.
Recommend checking #160 as well.
and I leave the #158 as a separate issue because the root cause is the returned call data is emitted in the contract code itself
asquare08
yes noted. #160 has slightly different cause but same effect. So the solution for all these related issues is
- don't save data in variable #158
- cap the gas limit of .call #160
- this
IAm0x52
Escalate
As the sponsor has pointed out, this is a different issue from the dupes. While the outcome of wasting gas is similar, the root cause is completely different. The root cause for this is reentrancy across functions, while the root cause of issues marked as dupes is that there is no gas limit. I suggest that this issue be separated and the dupes groped together as separate issues.
Edit: Missed #195. That and this should be considered a separate issue
sherlock-admin2
Escalate
As the sponsor has pointed out, this is a different issue from the dupes. While the outcome of wasting gas is similar, the root cause is completely different. The root cause for this is reentrancy across functions, while the root cause of issues marked as dupes is that there is no gas limit. I suggest that this issue be separated and the dupes groped together as separate issues.
Edit: Missed #195. That and this should be considered a separate issue
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
ctf-sec
See escalation https://github.com/sherlock-audit/2023-04-hubble-exchange-judging/issues/116
There are a lot of ways to consume all gas in external call (reentrancy to expand the queue size, gas token, for loop, swap, etc....), cannot count each of them as duplicates
I think grouping all these issue about wasting gas in external call to one issue make sense, root cause is gas limit not capped.
0xArcturus
Agreed with escalation,
as also mentioned in #195, the root cause of this is the lack of reentrancy guard and the withdrawals.length changing during execution. This attack can bloat the queue by reentering with a single withdraw call, while the dupes are focused on consuming gas in a single call.
hrishibhat
Result: Medium Has duplicates Agree with the escalation that this should be a separate issue along with #195
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- IAm0x52: accepted
asquare08
Fixed in this PR. The description is in the PR.
IAm0x52
Fix looks good. mintWithReserve, withdraw, and withdrawTo now use the nonreentrant modifier to prevent this exploit
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 lack of a reentrancy guard on the withdraw and withdrawTo functions, combined with the use of a low-level call to send gas tokens, allows an attacker to reenter the contract and add more withdrawals to the queue during processing.
Impact
A malicious user could repeatedly reenter VUSD to grief withdrawing users by wasting their gas, with no recurring cost to the attacker.
What the attacker needed
Attacker deploys a malicious contract; attacker initiates a withdrawal to that contract; victim processes withdrawals
The fix
The fix was to add the nonreentrant modifier to mintWithReserve, withdraw, and withdrawTo.
How it was found
- The attacker deploys a malicious contract that, upon receiving the gas token, deposits it and immediately withdraws it again.
- The attacker initiates a withdrawal from VUSD to the malicious contract.
- When a user processes withdrawals, the contract sends the gas token to the malicious contract, triggering its receive function.
- The malicious contract reenters VUSD to deposit and withdraw, adding more withdrawals to the queue.
- This lengthens the queue, forcing the user to process more withdrawals and spend more gas.
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.
When you withdraw funds from a smart contract, the contract sends you the funds by calling your address. If your address is a contract, that call runs code you control. The attacker used this to make the withdrawal queue longer each time someone processed a withdrawal, so other users had to pay more gas to get their own funds out.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.