Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Nyx - Hard-coded slippage may freeze user funds during market turbulence #289

Closed
sherlock-admin2 opened this issue Aug 29, 2023 · 6 comments
Labels
Escalation Resolved This issue's escalations have been approved/rejected Non-Reward This issue will not receive a payout

Comments

@sherlock-admin2
Copy link
Contributor

sherlock-admin2 commented Aug 29, 2023

Nyx

high

Hard-coded slippage may freeze user funds during market turbulence

Summary

If volatile market conditions happen, users can't withdraw their funds from the vault.

Vulnerability Detail

function withdraw(
        ILMPVault vault,
        address to,
        uint256 amount,
        uint256 maxSharesOut,
        bool unwrapWETH
    ) public virtual override returns (uint256 sharesOut) {
        address destination = unwrapWETH ? address(this) : to;

        sharesOut = vault.withdraw(amount, destination, msg.sender);
        if (sharesOut > maxSharesOut) {
            revert MaxSharesError();
        }

        if (unwrapWETH) {
            _processWethOut(to);
        }
    }

When the user withdraws, the user can use maxSharesOut parameter for slippage protection. There is one more slippage protection inside the withdrawing process.

uint256 actualAssets = _withdraw(assets, shares, receiver, owner);

        if (actualAssets < assets) {
            revert TooFewAssets(assets, actualAssets);
        }

If the actualAssests that returns from _withdraw() function is less than the user input assets parameter, the function will revert.
If there are not enough idle funds in the LMPVault, the rest of the funds are withdrawn from Destination Vaults.

uint256 withdrawalQueueLength = withdrawalQueue.length;
            for (uint256 i = 0; i < withdrawalQueueLength; ++i) {
                IDestinationVault destVault = IDestinationVault(withdrawalQueue[i]);
                (uint256 sharesToBurn, uint256 totalDebtBurn) = _calcUserWithdrawSharesToBurn(
                    destVault,
                    shares,
                    info.totalAssetsToPull - Math.max(info.debtDecrease, info.totalAssetsPulled),
                    totalVaultShares
                );
                if (sharesToBurn == 0) {
                    continue;
                }

                uint256 assetPreBal = _baseAsset.balanceOf(address(this));
                uint256 assetPulled = destVault.withdrawBaseAsset(sharesToBurn, address(this));

If one destination vault is not enough, funds are withdrawn from other destination vaults as well. (withdrawalQueue.length)

The problem is, let's say there are 3 destination vaults. (withdrawalQueue.length == 3)
The volatile market condition happens, and funds coming from destination vaults are less than usual.(due to swaps)
There is a chance that actualAssests won't equal user input assets parameter.

Because of too strict or hard-coded slippage, the user can't withdraw his funds and his funds are locked.

Impact

Users funds may be locked.

Code Snippet

https://github.com/sherlock-audit/2023-06-tokemak/blob/5d8e902ce33981a6506b1b5fb979a084602c6c9a/v2-core-audit-2023-07-14/src/vault/LMPVault.sol#L400-L419

https://github.com/sherlock-audit/2023-06-tokemak/blob/5d8e902ce33981a6506b1b5fb979a084602c6c9a/v2-core-audit-2023-07-14/src/vault/LMPVault.sol#L469-L480

Tool used

Manual Review

Recommendation

Pass a slippage parameter for the assets or remove the check.

Duplicate of #450

@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Sep 11, 2023
@sherlock-admin sherlock-admin changed the title Basic Cornflower Dinosaur - Hard-coded slippage may freeze user funds during market turbulence Nyx - Hard-coded slippage may freeze user funds during market turbulence Oct 3, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Oct 3, 2023
@berndartmueller
Copy link

Escalate

I do not consider this submission a duplicate of #519, which demonstrates an arithmetic underflow error rendering withdrawals impossible.

While this submission here highlights a slippage issue in https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVault.sol#L416-L418, reverting if the withdrawn assets are less than the anticipated withdrawal amount.

@sherlock-admin2
Copy link
Contributor Author

Escalate

I do not consider this submission a duplicate of #519, which demonstrates an arithmetic underflow error rendering withdrawals impossible.

While this submission here highlights a slippage issue in https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVault.sol#L416-L418, reverting if the withdrawn assets are less than the anticipated withdrawal amount.

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.

@Trumpero
Copy link
Collaborator

Trumpero commented Oct 24, 2023

This issue seems a dup of #450. withdraw function will only work as written when there isn't any slippage. Users should use redeem function to avoid reverting due to slippage of withdrawal.

@Evert0x
Copy link
Contributor

Evert0x commented Oct 24, 2023

Planning to accept escalation and duplicate with #450

@Evert0x
Copy link
Contributor

Evert0x commented Oct 27, 2023

Result:
Invalid
Duplicate of #450

Escalation is accepted even if issue is invalid as main issue was valid when the escalation was created.

@sherlock-admin sherlock-admin added Non-Reward This issue will not receive a payout and removed Reward A payout will be made for this issue labels Oct 27, 2023
@sherlock-admin2
Copy link
Contributor Author

sherlock-admin2 commented Oct 27, 2023

Escalations have been resolved successfully!

Escalation status:

@sherlock-admin sherlock-admin removed the Escalated This issue contains a pending escalation label Oct 27, 2023
@sherlock-admin2 sherlock-admin2 added the Escalation Resolved This issue's escalations have been approved/rejected label Oct 27, 2023
@sherlock-admin sherlock-admin removed the Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label label Oct 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Escalation Resolved This issue's escalations have been approved/rejected Non-Reward This issue will not receive a payout
Projects
None yet
Development

No branches or pull requests

5 participants