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

recursiveEth - Potential 1-2 Wei Loss in Token Transfers Due to Integer Division and Rounding #163

Closed
sherlock-admin4 opened this issue Jun 27, 2024 · 6 comments
Labels
Escalation Resolved This issue's escalations have been approved/rejected Non-Reward This issue will not receive a payout Sponsor Disputed The sponsor disputed this issue's validity

Comments

@sherlock-admin4
Copy link
Contributor

sherlock-admin4 commented Jun 27, 2024

recursiveEth

High

Potential 1-2 Wei Loss in Token Transfers Due to Integer Division and Rounding

Summary

The deposit function that allows users to deposit tokens into a vault. The function specifically handles Wsteth (wrapped staked Ether) and converts other tokens (stETH, WETH, ETH) to Wsteth if necessary. A potential vulnerability arises from the integer division and rounding down during token transfers, which may result in a 1-2 wei discrepancy. This discrepancy can become significant over time, especially as the stETH/share rate increases.

Vulnerability Detail

  if (token == steth) {
            IERC20(steth).safeTransferFrom(sender, wrapper, amount);
            amount = _stethToWsteth(amount);

This function is used to deposit stETH to vault, however it doesn't take into account that stETH is a special token when it comes to it's transfer logic, navigating to lido's official docs, where during transfers the amount that actually gets sent is actually a bit less than what has been specified in the transaction. More can be read on the "1-2 wei corner case" issue from lidofinance/core#442.

This would mean that protocol would then overvalue the amount of assets that get transferred in, which would make protocol over-evaluate the value of steth.

Impact

Code Snippet

https://github.com/sherlock-audit/2024-06-mellow/blob/main/mellow-lrt/src/utils/DepositWrapper.sol#L55
Some Example:-
sherlock-audit/2024-05-sophon-judging#30
sherlock-audit/2024-05-sophon-judging#63

Tool used

Manual Review

Recommendation

To mitigate this vulnerability, consider using transferShares instead of direct balance transfers. or Apply the balance check

 if (token == steth) {
+        uint256 balanceBefore = IERC20(stETH).balanceOf(address(this));
            IERC20(steth).safeTransferFrom(sender, wrapper, amount);
+        uint256 receivedAmount =  (IERC20(stETH).balanceOf(address(this)) - balanceBefore);
        receivedAmount = _stethToWsteth(receivedAmount );

@sherlock-admin2 sherlock-admin2 changed the title Uneven Mango Ferret - Potential Silent Failure in delegateCall Function Due to Unchecked Delegate Call Result Potential 1-2 Wei Loss in Token Transfers Due to Integer Division and Rounding 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 Potential 1-2 Wei Loss in Token Transfers Due to Integer Division and Rounding Uneven Mango Ferret - Potential 1-2 Wei Loss in Token Transfers Due to Integer Division and Rounding 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 Uneven Mango Ferret - Potential 1-2 Wei Loss in Token Transfers Due to Integer Division and Rounding recursiveEth - Potential 1-2 Wei Loss in Token Transfers Due to Integer Division and Rounding 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
@recursiveEth
Copy link

Escalate
issue number is #163, the loss of 1-2 WEI is not a low/invalid issue, the same issue has been considered in past audits as well thank you

@sherlock-admin3
Copy link
Contributor

Escalate
issue number is #163, the loss of 1-2 WEI is not a low/invalid issue, the same issue has been considered in past audits as well thank you

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

@sherlock-admin4 sherlock-admin4 added the Escalated This issue contains a pending escalation label Jul 16, 2024
@z3s
Copy link
Collaborator

z3s commented Jul 16, 2024

Same as #181

@WangSecurity
Copy link

I believe the report is incorrect. This issue doesn't lead to 1-2 wei loss and contracts believing they have more funds. The issue results in reverts and the function not being able to proceed since the balance is less than it's expected, leading to revert and DOS of deposit functionality.

Hence, I believe this report is not sufficient duplicate and the escalation will be rejected. I'll review the #299 issue, since it may have been judged incorrectly, but this report will be deduplicated either way.

@WangSecurity
Copy link

Result:
Invalid
Unique

@sherlock-admin2 sherlock-admin2 removed the Escalated This issue contains a pending escalation label Jul 19, 2024
@sherlock-admin3 sherlock-admin3 added the Escalation Resolved This issue's escalations have been approved/rejected label Jul 19, 2024
@sherlock-admin4
Copy link
Contributor Author

Escalations have been resolved successfully!

Escalation status:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Escalation Resolved This issue's escalations have been approved/rejected 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

6 participants