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

Ironsidesec - Many cases stEth.transferFrom will transfer 1-2 less way, which would result in revert in consequent functions, because of not enough balance #82

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

Ironsidesec

Medium

Many cases stEth.transferFrom will transfer 1-2 less way, which would result in revert in consequent functions, because of not enough balance

Summary

This issue is about 1 or 2 wei less transferred on steth.safeTransferfrom.

Also, there is another issue on steth.submit and wsteth.wrap which has a different impact and root cause than this.
This issue's root cause and fix are on steth.transferFrom and balance before/after checks.

Previous issues :

  1. EgisSecurity - Many cases stEth::transferFrom will transfer 1-2 less way, which would result in revert in consequent functions, because of not enough balance 2024-05-sophon-judging#63
  2. Account's stETH balance getting lower on 1 or 2 wei due to rounding down integer math lidofinance/core#442

Vulnerability Detail

The issue occurs in 2 functions with different impacts.

  1. Issue on DepositWrapper.deposit, when converting from stETH to wstETH in L64-L65 below, if 1 eth is transferFrom called, it will pull 1eth - 1 or 2 wei less. And when the code block goes into _stethToWsteth which further calls wstETH.wrap which will revert due to less amount. That is, calling wrap(1 steth) but we have 1 steth - 1wei, so it reverts when wrapping. Look at https://github.com/lidofinance/lido-dao/blob/5fcedc6e9a9f3ec154e69cff47c2b9e25503a78a/contracts/0.6.12/WstETH.sol#L57

  2. The second issue on Vault.deposit(), which calls stETH.transferfrom, which pulls 1 or 2 wei less amount which will deflate the share value on every deposit and messes the accounting. The current depositcallback doesn't care about the actualAmounts array which holds the 1 steth values instead of 1steth - 1 wei actual value. If deposit callbacks does any accounting on this actualAmounts, then the impact will increase.

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

File: 2024-06-mellow/mellow-lrt/src/utils/DepositWrapper.sol

46:     function deposit() external payable returns (uint256 lpAmount) {
... SNIP ...

59:         if (token == steth) {
60:             IERC20(steth).safeTransferFrom(sender, wrapper, amount);
62:             amount = _stethToWsteth(amount);
63:         } else if (token == weth) {
64:   >>>>      IERC20(weth).safeTransferFrom(sender, wrapper, amount);
65:   >>>>      amount = _wethToWsteth(amount);
66:         } else if (token == address(0)) {

... SNIP ...

76:         (, lpAmount) = vault.deposit(to, amounts, minLpAmount, deadline);
80:     }

https://github.com/sherlock-audit/2024-06-mellow/blob/26aa0445ec405a4ad637bddeeedec4efe1eba8d2/mellow-lrt/src/Vault.sol#L329-L332

File: 2024-06-mellow/mellow-lrt/src/Vault.sol

308:     function deposit()
... SNIP ...
318:     {
... SNIP ...

364:    >>>>     IERC20(tokens[i]).safeTransferFrom( 
365:                 msg.sender,
366:                 address(this),
367:                 amount
368:             );
371:         }

Impact

Reverts on DepositWrapper.deposit. so DOS most times. Also wrong accounting on Vault.deposit() messing the share value, i.e, mints 1 mellowToken for 1 wsteth - 2 wei deposit.

Code Snippet

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

https://github.com/sherlock-audit/2024-06-mellow/blob/26aa0445ec405a4ad637bddeeedec4efe1eba8d2/mellow-lrt/src/Vault.sol#L329-L332

Tool used

Manual Review

Recommendation

Use lido recommendation to utilize transferShares function, so the amount is realistic, or implement Fee on transfer approach, which compares the balance before and after the transfer.

Duplicate of #299

@sherlock-admin2 sherlock-admin2 added Low/Info A Low/Info severity issue Non-Reward This issue will not receive a payout labels Jun 27, 2024
@sherlock-admin2 sherlock-admin2 changed the title Mini Coral Chameleon - Inconsistent function name and logic in requireProposerOrAcceptor modifier Many cases stEth.transferFrom will transfer 1-2 less way, which would result in revert in 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 Many cases stEth.transferFrom will transfer 1-2 less way, which would result in revert in consequent functions, because of not enough balance Beautiful Teal Kookaburra - Many cases stEth.transferFrom will transfer 1-2 less way, which would result in revert in consequent functions, because of not enough balance 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
@z3s z3s removed the Low/Info A Low/Info severity issue label Jul 15, 2024
@sherlock-admin3 sherlock-admin3 changed the title Beautiful Teal Kookaburra - Many cases stEth.transferFrom will transfer 1-2 less way, which would result in revert in consequent functions, because of not enough balance Ironsidesec - Many cases stEth.transferFrom will transfer 1-2 less way, which would result in revert in consequent functions, because of not enough balance Jul 15, 2024
@sherlock-admin3 sherlock-admin3 removed the Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label label 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

3 participants