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

saidam017 - ether that deposited trough _processEthIn is not considered inside router's mint and deposit operations #276

Closed
sherlock-admin opened this issue Aug 29, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Aug 29, 2023

saidam017

high

ether that deposited trough _processEthIn is not considered inside router's mint and deposit operations

Summary

LMPVaultRouterBase's mint and deposit function allow users to use native eth for deposit/mint to LMPVault. However, the deposited native eth is not considered when calling pullToken. This will cause the mint and deposit functions to break if users use native eth, or worse can cause user charged more than necessary and the extra weth will stuck inside the router.

Vulnerability Detail

These are mint and deposit functions inside LMPVaultRouterBase :

https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVaultRouterBase.sol#L23-L41

    function mint(
        ILMPVault vault,
        address to,
        uint256 shares,
        uint256 maxAmountIn
    ) public payable virtual override returns (uint256 amountIn) {
        // handle possible eth
        _processEthIn(vault);

        IERC20 vaultAsset = IERC20(vault.asset());
        uint256 assets = vault.previewMint(shares);
        pullToken(vaultAsset, assets, address(this));
        vaultAsset.safeApprove(address(vault), assets);

        amountIn = vault.mint(shares, to);
        if (amountIn > maxAmountIn) {
            revert MaxAmountError();
        }
    }

https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVaultRouterBase.sol#L44-L57

    function deposit(
        ILMPVault vault,
        address to,
        uint256 amount,
        uint256 minSharesOut
    ) public payable virtual override returns (uint256 sharesOut) {
        // handle possible eth
        _processEthIn(vault);

        IERC20 vaultAsset = IERC20(vault.asset());
        pullToken(vaultAsset, amount, address(this));

        return _deposit(vault, to, amount, minSharesOut);
    }

It can be observed that both functions are payable and will handle the deposited eth using _processEthIn's internal function :

https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVaultRouterBase.sol#L111-L122

    function _processEthIn(ILMPVault vault) internal {
        // if any eth sent, wrap it first
        if (msg.value > 0) {
            // if asset is not weth, revert
            if (address(vault.asset()) != address(weth9)) {
                revert InvalidAsset();
            }

            // wrap eth
            weth9.deposit{ value: msg.value }();
        }
    }

the eth provided will deposited to get weth token, this weth will be stored inside router as the caller of weth.deposit. However, inside pullToken token operations, it will try to get users funds equal to amount or assets and not considering the deposited weth :

https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/utils/PeripheryPayments.sol#L53-L56

    function pullToken(IERC20 token, uint256 amount, address recipient) public payable {
        // @audit - this will cause user to transfer more than it should if already providing eth
        token.safeTransferFrom(msg.sender, recipient, amount);
    }

After that, it will call _deposit also without considering the extra deposited native eth.

Impact

This could lead to 2 possible scenario :

  1. First, user try to deposit/mint using native eth, and not have the weth balance or not previously give approval of weth to router. The operation will always revert when try to call pullToken, mint and deposit function simply broken.
  2. The more severe impact is when user try to deposit/mint using native eth, have enough weth balance equal to amount or assets and previously given approval of weth router (give max approval for instance). The user will charged twice than expected (from native eth and his weth) and the extra weth will be stuck inside router or taken by another users that trigger _processWethOut.

The likeliness of this happening is high and potentially risking user's funds.

Code Snippet

https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVaultRouterBase.sol#L23-L41
https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVaultRouterBase.sol#L44-L57
https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVaultRouterBase.sol#L111-L122

Tool used

Manual Review

Recommendation

Fix _processEthIn so it will return value that will be considered inside pullToken function ( decrease the required weth transferred from user by the deposited native eth).

Duplicate of #1

@github-actions github-actions bot added High A valid High severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Sep 11, 2023
@sherlock-admin2 sherlock-admin2 changed the title Rural Saffron Dinosaur - ether that deposited trough _processEthIn is not considered inside router's mint and deposit operations saidam017 - ether that deposited trough _processEthIn is not considered inside router's mint and deposit operations Oct 3, 2023
@sherlock-admin2 sherlock-admin2 added the Reward A payout will be made for this issue label Oct 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

2 participants