Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StraawHaat - Redundant check in emergencyWithdraw() makes the function almost unusable #270

Closed
sherlock-admin4 opened this issue Jun 27, 2024 · 0 comments
Labels
Non-Reward This issue will not receive a payout Sponsor Disputed The sponsor disputed this issue's validity

Comments

@sherlock-admin4
Copy link
Contributor

sherlock-admin4 commented Jun 27, 2024

StraawHaat

Medium

Redundant check in emergencyWithdraw() makes the function almost unusable

Summary

Redundant check in emergencyWithdraw() makes the function almost unusable. This is because the function will almost always cancel the request instead of withdrawing the users' funds:

        if (timestamp > request.deadline) {
            _cancelWithdrawalRequest(sender);
            return actualAmounts;
        }

Vulnerability Detail

The emergencyWithdraw function allows users to withdraw their share of the vault's assets in an emergency situation.

    function emergencyWithdraw(
        uint256[] memory minAmounts,
        uint256 deadline
    )
        external
        nonReentrant
        checkDeadline(deadline)
        returns (uint256[] memory actualAmounts)
    {
        uint256 timestamp = block.timestamp;
        address sender = msg.sender;
        if (!_pendingWithdrawers.contains(sender)) revert InvalidState();
        WithdrawalRequest memory request = _withdrawalRequest[sender];

        if (timestamp > request.deadline) {
            _cancelWithdrawalRequest(sender);
            return actualAmounts;
        }

According to the configuration, 90 days must pass to use this function:

        if (
            request.timestamp + configurator.emergencyWithdrawalDelay() >
            timestamp
        ) revert InvalidState();
require(setup.configurator.emergencyWithdrawalDelay() == 90 days);

But before this check there is a completely unnecessary check which will cancel the request:

        if (timestamp > request.deadline) {
            _cancelWithdrawalRequest(sender);
            return actualAmounts;
        }

This check cancels the withdrawal request if the current timestamp is greater than the request deadline. That is, when a user makes a withdrawal request he chooses by what time(deadline) he wants it to be executed. Almost never it will be more than 90 days.

Any value below configurator.emergencyWithdrawalDelay will enter the above code check and cancel the withdraw request.

This means that if an emergency happens, instead of users withdrawing their funds, the request will be cancelled.

Impact

The function is almost unusable. In the event of an emergency, instead of users saving their funds, the request will be canceled, and they may lose them.

Code Snippet

https://github.com/sherlock-audit/2024-06-mellow/blob/main/mellow-lrt/src/Vault.sol#L384-L387

Tool used

Manual Review

Recommendation

Remove the following check:

        if (timestamp > request.deadline) {
            _cancelWithdrawalRequest(sender);
            return actualAmounts;
        }

Duplicate of #57

@sherlock-admin3 sherlock-admin3 changed the title Prehistoric Snowy Corgi - deposit() in DepositWrapper causes multiple reverts to due unhandled conversion of stETH to wstETH Redundant check in emergencyWithdraw() makes the function almost unusable Jun 28, 2024
@sherlock-admin3 sherlock-admin3 added the Sponsor Disputed The sponsor disputed this issue's validity label Jun 30, 2024
@github-actions github-actions bot changed the title Redundant check in emergencyWithdraw() makes the function almost unusable Stale Hickory Goblin - Redundant check in emergencyWithdraw() makes the function almost unusable Jul 6, 2024
@github-actions github-actions bot closed this as completed Jul 6, 2024
@github-actions github-actions bot added the Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label label Jul 6, 2024
@sherlock-admin3 sherlock-admin3 changed the title Stale Hickory Goblin - Redundant check in emergencyWithdraw() makes the function almost unusable StraawHaat - Redundant check in emergencyWithdraw() makes the function almost unusable Jul 15, 2024
@sherlock-admin3 sherlock-admin3 added Non-Reward This issue will not receive a payout and removed Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Non-Reward This issue will not receive a payout Sponsor Disputed The sponsor disputed this issue's validity
Projects
None yet
Development

No branches or pull requests

2 participants