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

kaysoft - Loss of ETH when user deposits stEth or WETH but msg.value is not zero #39

Closed
sherlock-admin3 opened this issue Jun 27, 2024 · 0 comments
Labels
Excluded Excluded by the judge without consulting the protocol or the senior Non-Reward This issue will not receive a payout Sponsor Disputed The sponsor disputed this issue's validity

Comments

@sherlock-admin3
Copy link
Contributor

sherlock-admin3 commented Jun 27, 2024

kaysoft

Medium

Loss of ETH when user deposits stEth or WETH but msg.value is not zero

Summary

When a user tries to deposit stEth or WETH token but msg.value is greater than zero the ETH will be lost to the DepositWrapper.sol contract.

Vulnerability Detail

The deposit function accepts deposits of ETH, stETH, WETH and wstETh which are finally converted to wstETH. When a user tries to deposit any of stETH, WETH and wstETh, there is no check to ensure that msg.value sent along with the transaction is zero. This could cause users to lose ETH to the DepositWrapper.sol smart contract when trying to deposit.

File: DepositWrapper.sol
function deposit(
        address to,
        address token,
        uint256 amount,
        uint256 minLpAmount,
        uint256 deadline
    ) external payable returns (uint256 lpAmount) {
        address wrapper = address(this);
        address sender = msg.sender;
        address[] memory tokens = vault.underlyingTokens();
        if (tokens.length != 1 || tokens[0] != wsteth)
            revert InvalidTokenList();
        if (amount == 0) revert InvalidAmount();
        if (token == steth) {
            IERC20(steth).safeTransferFrom(sender, wrapper, amount);
            amount = _stethToWsteth(amount);
        } else if (token == weth) {
            IERC20(weth).safeTransferFrom(sender, wrapper, amount);
            amount = _wethToWsteth(amount);
        } else if (token == address(0)) {
            if (msg.value != amount) revert InvalidAmount();
            amount = _ethToWsteth(amount);
        } else if (wsteth == token) {
            IERC20(wsteth).safeTransferFrom(sender, wrapper, amount);
        } else revert InvalidToken();

        IERC20(wsteth).safeIncreaseAllowance(address(vault), amount);
        uint256[] memory amounts = new uint256[](1);
        amounts[0] = amount;
        (, lpAmount) = vault.deposit(to, amounts, minLpAmount, deadline);
        uint256 balance = IERC20(wsteth).balanceOf(wrapper);
        if (balance > 0) IERC20(wsteth).safeTransfer(sender, balance);
        emit DepositWrapperDeposit(sender, token, amount, lpAmount, deadline);
    }

Impact

Loss of ETH when user deposits stEth or WETH but msg.value is not zero

Code Snippet

https://github.com/sherlock-audit/2024-06-mellow/blob/main/mellow-lrt/src/utils/DepositWrapper.sol#L42C5-L75C6

Tool used

Manual Review

Recommendation

Consider validating that msg.value == 0 when a user tries to deposit either stEth or WETH tokens this way:

File: DepositWrapper.sol
function deposit(
        address to,
        address token,
        uint256 amount,
        uint256 minLpAmount,
        uint256 deadline
    ) external payable returns (uint256 lpAmount) {
        address wrapper = address(this);
        address sender = msg.sender;
        address[] memory tokens = vault.underlyingTokens();
        if (tokens.length != 1 || tokens[0] != wsteth)
            revert InvalidTokenList();
        if (amount == 0) revert InvalidAmount();

++   if (token != address(0)) {
++       require(msg.value == 0, "Loss of Ether");
++    }
        if (token == steth) {
            IERC20(steth).safeTransferFrom(sender, wrapper, amount);
            amount = _stethToWsteth(amount);
        } else if (token == weth) {
            IERC20(weth).safeTransferFrom(sender, wrapper, amount);
            amount = _wethToWsteth(amount);
        } else if (token == address(0)) {
            if (msg.value != amount) revert InvalidAmount();
            amount = _ethToWsteth(amount);
        } else if (wsteth == token) {
            IERC20(wsteth).safeTransferFrom(sender, wrapper, amount);
        } else revert InvalidToken();

        IERC20(wsteth).safeIncreaseAllowance(address(vault), amount);
        uint256[] memory amounts = new uint256[](1);
        amounts[0] = amount;
        (, lpAmount) = vault.deposit(to, amounts, minLpAmount, deadline);
        uint256 balance = IERC20(wsteth).balanceOf(wrapper);
        if (balance > 0) IERC20(wsteth).safeTransfer(sender, balance);
        emit DepositWrapperDeposit(sender, token, amount, lpAmount, deadline);
    }
@sherlock-admin2 sherlock-admin2 changed the title Proper Sepia Toad - stEth:transferFrom() transfers 1-2 wei less than the actual amount Loss of ETH when user deposits stEth or WETH but msg.value is not zero 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 Loss of ETH when user deposits stEth or WETH but msg.value is not zero Attractive Vanilla Shark - Loss of ETH when user deposits stEth or WETH but msg.value is not zero Jul 6, 2024
@github-actions github-actions bot closed this as completed Jul 6, 2024
@github-actions github-actions bot added the Excluded Excluded by the judge without consulting the protocol or the senior label Jul 6, 2024
@sherlock-admin3 sherlock-admin3 changed the title Attractive Vanilla Shark - Loss of ETH when user deposits stEth or WETH but msg.value is not zero kaysoft - Loss of ETH when user deposits stEth or WETH but msg.value is not zero Jul 15, 2024
@sherlock-admin3 sherlock-admin3 added the Non-Reward This issue will not receive a payout label Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Excluded Excluded by the judge without consulting the protocol or the senior 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

1 participant