DOS in the claimWithdraw function due to an incorrect check of the lastFinalizedRequestId in the EEtherAdapter.sol
The claimWithdraw function in EEtherAdapter.sol uses an incorrect comparison operator when checking the lastFinalizedRequestId, causing it to revert for valid withdrawal requests. This prevents users from claiming their withdrawals, leading to a denial of service and a permanent increase in totalQueueEth.
Source: https://github.com/sherlock-audit/2024-05-napier-update-judging/issues/55
Found by
Drynooo, KupiaSec, blutorque, merlin, whitehair0330
Summary
The claimWithdrawal function has an incorrect check of lastFinalizedRequestId, which lead to a DOS vulnerability in the EEtherAdapter.claimWithdraw function.
if (_requestId < ETHERFI_WITHDRAW_NFT.lastFinalizedRequestId()) revert RequestInQueue();
Vulnerability Detail
Let's discuss how WithdrawRequestNFT handles withdrawal request IDs. When requestWithdraw is called, the nextRequestId is increased by one.
uint256 requestId = nextRequestId++;
For a user to successfully call the claimWithdraw function, the admin of WithdrawRequestNFT must call finalizeRequests with our requestId:
function finalizeRequests(uint256 requestId) external onlyAdmin {
lastFinalizedRequestId = uint32(requestId);
}
So, if a requestId is created and the admin finalizes our request id, then the user will be able to claim the withdrawal amount.
However, the issue lies in the fact that EEtherAdapter.claimWithdrawal checks whether _requestId >= ETHERFI_WITHDRAW_NFT.lastFinalizedRequestId(), otherwise the call will fail.
if (_requestId < ETHERFI_WITHDRAW_NFT.lastFinalizedRequestId()) revert RequestInQueue();
However, when we examine the WithdrawRequestNFT.claimWithdrawal function, we see a completely different check:
require(tokenId < nextRequestId, "Request does not exist");
--> require(tokenId <= lastFinalizedRequestId, "Request is not finalized");
require(ownerOf(tokenId) != address(0), "Already Claimed");
From this, we can conclude that a user will only be able to call the claimWithdrawal function when requestId = lastFinalizedRequestId; otherwise, the call will fail.
Now, if we examine WithdrawRequestNFT on Etherscan, we can obtain the following information as of the report writing time:
nextRequestId = 19059
lastFinalizedRequestId = 18833
There are many finalized withdrawals that have not been claimed: 18832, 18831, 18741 etc
Most importantly, the admin calls lastFinalizedRequestId for each request ID, and the user can claim the withdrawal request ID later, meaning the main condition is that tokenId <= lastFinalizedRequestId.
This will result in a situation where if the admin calls lastFinalizedRequestId with our request ID and then with the next one, we will never be able to claim the withdrawal by this request ID.
Impact
Users will not lose their shares or receive the expected ETH, but this will impact EEtherAdapter as a whole because the totalQueueEth will be increased by the requested withdrawal amount, and it will not be possible to decrease it due to the DOS of the claimWithdraw function.
As EEtherAdapter is not an upgradable smart contract, I consider this issue to be of high severity.
Code Snippet
src/adapters/etherfi/EETHAdapter.sol#L63
Tool used
Manual Review
Recommendation
Consider removing this check altogether, or you can implement it exactly as EtherFi does:
-if (_requestId < ETHERFI_WITHDRAW_NFT.lastFinalizedRequestId()) revert RequestInQueue();
+if (_requestId > ETHERFI_WITHDRAW_NFT.lastFinalizedRequestId()) revert RequestInQueue();
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/napierfi/napier-v1/pull/222
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.
How it worked
Root cause
The check uses `<` instead of `<=` when comparing the request ID to lastFinalizedRequestId, so it reverts for requests that are actually finalized.
Impact
Users cannot claim their withdrawals, and the totalQueueEth in EEtherAdapter increases permanently, potentially locking funds.
What the attacker needed
User has a withdrawal request; admin finalizes the request
The fix
The check should be changed to use `>` instead of `<`, or removed entirely, as was done in the referenced fix.
How it was found
- A user requests a withdrawal, which creates a request ID.
- The admin finalizes that request ID by calling finalizeRequests.
- The user calls claimWithdraw, but the function reverts because the check uses `<` instead of `<=`.
- The admin finalizes a later request ID, making the user's request ID less than lastFinalizedRequestId, so the user can never claim.
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 function that lets users claim their withdrawn funds has a bug in a check. The check uses the wrong comparison, so it blocks legitimate claims. This means users cannot get their money back, and the contract's accounting gets stuck.
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.