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

sandy - Steth::transferfrom will transfer 1-2 wei less which will result in reverting of consequent functions because of not enough balance. #239

Closed
sherlock-admin2 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-admin2
Copy link

sherlock-admin2 commented Jun 27, 2024

sandy

High

Steth::transferfrom will transfer 1-2 wei less which will result in reverting of consequent functions because of not enough balance.

Summary

Steth::transferfrom will transfer 1-2 wei less which will result in reverting of consequent functions because of not enough balance.

Vulnerability Detail

The protocol always assumes that the amount of tokens received is equal to the amount of tokens transferred. This is not the case for rebasing tokens, such as stETH, because internally they transfer shares which generally results in the received amount of tokens being lower than the requested one by a couple of wei because of rounding.

The probability of this issue appearing is very high as mentioned here: lidofinance/core#442

In the DepositWrapper contract, deposit function is used to deposit specified tokens into the vault. One of the tokens is steth which is converted to wsteth before depositing.

    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);
...

steth is then converted to wsteth here using the same amount:

    function _stethToWsteth(uint256 amount) private returns (uint256) {
        IERC20(steth).safeIncreaseAllowance(wsteth, amount);
        IWSteth(wsteth).wrap(amount);
        return IERC20(wsteth).balanceOf(address(this));
    }

The problem is if amount - 1/2 wei is passed to _stethToWsteth() function, it will revert due to insufficient funds as DepositWrapper contract doesn't hold any steth tokens.

Impact

deposit() function of DepositWrapper contract will revert resulting in all deposits reverting and contract functionality DoS. Thus, the high severity.

Code Snippet

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

Tool used

Manual Review

Recommendation

Use the actual amount of tokens received instead of the amount specified as input. This can be done by implementing amount handling like for Fee on transfer tokens, which compares the balance before and after the transfer.

Duplicate of #299

@sherlock-admin2 sherlock-admin2 changed the title Ripe Gingerbread Dog - Protocol supports stETH but doesn't consider its unique transfer logic which would lead to overvaluation of deposited assets Steth::transferfrom will transfer 1-2 wei less which will result in reverting of consequent functions because of not enough balance. 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 Steth::transferfrom will transfer 1-2 wei less which will result in reverting of consequent functions because of not enough balance. Shaggy Holographic Tuna - Steth::transferfrom will transfer 1-2 wei less which will result in reverting of consequent functions because of not enough balance. 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 Shaggy Holographic Tuna - Steth::transferfrom will transfer 1-2 wei less which will result in reverting of consequent functions because of not enough balance. sandy - Steth::transferfrom will transfer 1-2 wei less which will result in reverting of consequent functions because of not enough balance. 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