After a liquidator liquidates someone else’s position, it could cause a Denial of Service (DoS) when their own position also needs to be liquidated
Source: https://github.com/sherlock-audit/2024-06-leveraged-vaults-judging/issues/44
Found by
ZeroTrust
Summary
After a liquidator liquidates someone else’s position, it could cause a Denial of Service (DoS) when their own position also needs to be liquidated.
Vulnerability Detail
function _splitWithdrawRequest(address _from, address _to, uint256 vaultShares) internal {
WithdrawRequest storage w = VaultStorage.getAccountWithdrawRequest()[_from];
if (w.requestId == 0) return;
// Create a new split withdraw request
if (!w.hasSplit) {
SplitWithdrawRequest memory s = VaultStorage.getSplitWithdrawRequest()[w.requestId];
// Safety check to ensure that the split withdraw request is not active, split withdraw
// requests are never deleted. This presumes that all withdraw request ids are unique.
require(s.finalized == false && s.totalVaultShares == 0);
VaultStorage.getSplitWithdrawRequest()[w.requestId].totalVaultShares = w.vaultShares;
}
if (w.vaultShares == vaultShares) {
// If the resulting vault shares is zero, then delete the request. The _from account's
// withdraw request is fully transferred to _to
delete VaultStorage.getAccountWithdrawRequest()[_from];
} else {
// Otherwise deduct the vault shares
@>> w.vaultShares = w.vaultShares - vaultShares;
w.hasSplit = true;
}
// Ensure that no withdraw request gets overridden, the _to account always receives their withdraw
// request in the account withdraw slot.
WithdrawRequest storage toWithdraw = VaultStorage.getAccountWithdrawRequest()[_to];
require(toWithdraw.requestId == 0 || toWithdraw.requestId == w.requestId , "Existing Request");
// Either the request gets set or it gets incremented here.
toWithdraw.requestId = w.requestId;
toWithdraw.vaultShares = toWithdraw.vaultShares + vaultShares;
toWithdraw.hasSplit = true;
}
Here is an assumption: the requested withdrawal vaultShares are always greater than or equal to vaultSharesFromLiquidation. This assumption holds true for regular users because the requested withdrawal vaultShares represent the user’s entire vaultShares. However, this assumption does not hold for liquidators. POC: The liquidator:vaultShares 10e8 A user need to be liquidated: vaultShares 1e8, withdrawRequest.vaultShares 1e8 the vaultSharesFromLiquidation is 1e8.
- After liquidation:
The liquidator:vaultShares 11e8, withdrawRequest.vaultShares 1e8
- After sometime,The liquidator’s position need to be liquidated
the vaultSharesFromLiquidation is 2e8.
Then w.vaultShares = w.vaultShares - vaultShares; will revert()
This results in the liquidator’s position not being liquidated, leading to a loss of funds for the protocol.
Impact
This results in the liquidator’s position not being liquidated, leading to a loss of funds for the protocol.
Code Snippet
Tool used
Manual Review
Recommendation
Consider the case where w.vaultShares is less than vaultShares.
Discussion
sherlock-admin4
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
w.vaultShares = w.vaultShares - vaultShares would just revert
0502lian
Escalate This should be considered a valid issue. The report points out the specific error, the conditions under which it occurs, and the impact it has when it does.
sherlock-admin3
Escalate This should be considered a valid issue. The report points out the specific error, the conditions under which it occurs, and the impact it has when it does.
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.
mystery0x
Escalate This should be considered a valid issue. The report points out the specific error, the conditions under which it occurs, and the impact it has when it does.
It's intended to deny the call if w.vaultShares < vaultShares. What's your suggested mitigation?
0502lian
Escalate This should be considered a valid issue. The report points out the specific error, the conditions under which it occurs, and the impact it has when it does.
It's intended to deny the call if w.vaultShares < vaultShares. What's your suggested mitigation?
The Dev team did not consider the scenario where w.vaultShares < vaultShares, which is very likely to occur. It has been confirmed with the sponsor that anyone can be a liquidator.
As long as the liquidator has their own position and liquidates someone else’s position, this scenario will occur.
After this scenario occurs, the Dev team needs to consider more handling logic, which might not be solvable with just a few lines of code. So I currently don’t have a particularly good suggested mitigation
WangSecurity
Please elaborate on how this can occur:
After sometime,The liquidator’s position need to be liquidated the vaultSharesFromLiquidation is 2e8. Then w.vaultShares = w.vaultShares - vaultShares; will revert() This results in the liquidator’s position not being liquidated, leading to a loss of funds for the protocol
the vaultShares is input data, so how this situation may occur, the report just says it happens, without a sufficient explanation it is indeed possible.
0502lian
Please elaborate on how this can occur:
After sometime,The liquidator’s position need to be liquidated the vaultSharesFromLiquidation is 2e8. Then w.vaultShares = w.vaultShares - vaultShares; will revert() This results in the liquidator’s position not being liquidated, leading to a loss of funds for the protocol
the
vaultSharesis input data, so how this situation may occur, the report just says it happens, without a sufficient explanation it is indeed possible.
vaultShares is an input parameter for _splitWithdrawRequest, but it is not provided by the user. Instead, it is determined by the Notional protocol when the position needs to be liquidated, deciding how many vaultShares need to be liquidated to return to a healthy state.
In fact, most of the time, the entire vaultShares of a position need to be liquidated, and w.vaultShares is always less than the entire vaultShares (for liquidator’s position)
T-Woodward
I think this is a valid finding, although I would ask @jeffywu to confirm in case I am missing anything.
The watson is correct that we did not anticipate an account having more vaultShares than their withdrawal request. The code is designed such that accounts should either only have a withdrawal request or have no withdrawal request at all. And he is also correct that this situation could cause an inability to liquidate.
However, I'm not sure this deserves a high severity. An account can't force their way into this situation. And I don't think the watson's assertion that "this is very likely to occur" is substantiated.
Furthermore, even if they are in the situation where they have a withdrawal request + additional vaultShares I don't think there's any way that they can take advantage of it. Additional deposits will fail, and if they try to redeem the vault will only allow them to redeem their full withdraw request which would put them back in the situation they were in before they did the liquidation.
So there's no way that an account could borrow against their position and take cash out of the system knowing that they couldn't get liquidated. They would just kind of be stuck.
WangSecurity
Thank you very much, with that I agree it's medium severity. The reason is that, firstly, the attacker cannot force them into this situation, secondly, there's not real benefit for them, except not being liqudiatable when they should.
Moreover, as I understand, the regular user can end up in this situation, which would be problem for them, based on the comment above.
Planning to accept the escalation and validate with medium severity. @mystery0x @0502lian are there any additional duplicates?
brakeless-wtp
I believe it is unique.
WangSecurity
Result: Medium Unique
sherlock-admin4
Escalations have been resolved successfully!
Escalation status:
- 0502lian: accepted
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/notional-finance/leveraged-vaults/pull/88
sherlock-admin2
The Lead Senior Watson signed off on the fix.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity doS bug in Notional Leveraged Vaults: Pendle PT and Vault Incentives. Sherlock made it public on 12 July 2024. Found in the 446 audit contest (finding M-2).
About DoS
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.