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

xKeywordx - [H-1] DepositWrapper::deposit function will revert because it will be off by 1-2 wei in the case of stETH deposits. #74

Closed
sherlock-admin3 opened this issue Jun 27, 2024 · 2 comments
Labels
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

xKeywordx

High

[H-1] DepositWrapper::deposit function will revert because it will be off by 1-2 wei in the case of stETH deposits.

Summary

According to Lido's official docs, there is a known issue called the 1-2 wei corner case. Internally, stETH transfers are converted to shares so if a user transfers 1e18 of stETH, the actual amount received by the protocol will be 0.99e18. You can see a description of the issue here.

Vulnerability Detail

The DepositWrapper::deposit function assumes that the amount parameter passed in by the function caller will be the actual amounts deposited in the protocol. In the case of stETH this will generally not be true because of the rounding that takes place during transfers.

Impact

The transaction will revert when the internal _stethToWsteth function will call the wrap function because the balance of the contract will be amount - 1 instead of amount.

When the function caller transfers stETH from him to the contract, the actual amount will be amount - 1, and when the DepositWrapper contract calls the wrap function, it will attempt to transfer amount from the contract to Lido, and it will revert because it has fewer tokens in it.

Code Snippet

    /// @inheritdoc IDepositWrapper
    function deposit(...) external payable returns (uint256 lpAmount) {
//..
//..
        if (token == steth) {
//@audit | the actual amount transferred here will be off by 1-2 wei
>           IERC20(steth).safeTransferFrom(sender, wrapper, amount);
>           amount = _stethToWsteth(amount);
        } else if (token == weth) {
//..
//..
    }

    function _stethToWsteth(uint256 amount) private returns (uint256) {
        IERC20(steth).safeIncreaseAllowance(wsteth, amount);
//@audit | the below line will revert because the actual amount held by the contract is `amount - 1`
>       IWSteth(wsteth).wrap(amount);
        return IERC20(wsteth).balanceOf(address(this));
    }

Tool used

Manual Review

Recommendation

Check the actual balance before and after stETH transfer in order to make sure that the protocol registers the right amount.

    /// @inheritdoc IDepositWrapper
    function deposit(...) external payable returns (uint256 lpAmount) {
//..
//..
        if (token == steth) {
+           uint256 balanceBefore = IERC20(stETH).balanceOf(address(this);
            IERC20(steth).safeTransferFrom(sender, wrapper, amount);
+           uint256 balanceAfter = IERC20(stETH).balanceOf(address(this);
+           uint256 actualAmount = balanceAfter - balanceBefore ;
-           amount = _stethToWsteth(amount);
+          amount = _stethToWsteth(actualAmount );
        } else if (token == weth) {
//..
//..
}

Duplicate of #299

@sherlock-admin4 sherlock-admin4 changed the title Suave Felt Fly - [H-2] - DoS attack to prevent the processWithdrawals call from the SimpleDVTStakingStrategy contract. [H-1] DepositWrapper::deposit function will revert because it will be off by 1-2 wei in the case of stETH deposits. 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 [H-1] DepositWrapper::deposit function will revert because it will be off by 1-2 wei in the case of stETH deposits. Suave Felt Fly - [H-1] DepositWrapper::deposit function will revert because it will be off by 1-2 wei in the case of stETH deposits. 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 Suave Felt Fly - [H-1] DepositWrapper::deposit function will revert because it will be off by 1-2 wei in the case of stETH deposits. xKeywordx - [H-1] DepositWrapper::deposit function will revert because it will be off by 1-2 wei in the case of stETH deposits. 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
@xKeywordx
Copy link

Escalate
This exact issue was credited as a High in the Sophon Farming contest on Sherlock. I don't understand why it is invalid in this contest. sherlock-audit/2024-05-sophon-judging#63

@sherlock-admin3
Copy link
Contributor Author

Escalate
This exact issue was credited as a High in the Sophon Farming contest on Sherlock. I don't understand why it is invalid in this contest. sherlock-audit/2024-05-sophon-judging#63

The escalation could not be created because you are not exceeding the escalation threshold.

You can view the required number of additional valid issues/judging contest payouts in your Profile page,
in the Sherlock webapp.

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