-
Notifications
You must be signed in to change notification settings - Fork 4
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
0xHabanero - LP Token amounts may be miscalculated due to DepositWrapper:: deposit()
not handling stETH 1-2 wei corner case
#115
Comments
DepositWrapper
do not take into acount the 1-2wei corner case for stEth tranfser leading to possible DoS of depositsDepositWrapper:: deposit()
not handling stETH 1-2 wei corner case
DepositWrapper:: deposit()
not handling stETH 1-2 wei corner caseDepositWrapper:: deposit()
not handling stETH 1-2 wei corner case
DepositWrapper:: deposit()
not handling stETH 1-2 wei corner caseDepositWrapper:: deposit()
not handling stETH 1-2 wei corner case
This bug causes a miscalculation of funds in the common 1-2 Wei corner case. As seen in past finding here, as well as here, this has been recognized as a valid, high finding in past contests. In this case, the situation is the exact same; the protocol has not correctly accounted for the 1-2 wei corner case, creating a protocol malfunction. |
Escalate |
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. |
Same as #181 I answered there. |
@z3s totally wrong, txn will revert in |
The comment above is correct, the report is wrong and this issue won't lead to miscalculation of the LP token amounts, cause the deposit would just revert in this case. Hence, this issue is not correct and cannot be a sufficient duplicate cause it doesn't identify a valid medium impact. Planning to reject the escalation and leave the issue as it is. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Both comments are hidden due to being off-topic. The escalation is not resolved yet, and I'll take the necessary changes when the escalation will be resolved. @0xHabanero be more respectful, the other Watson didn't say anything bad and we're professionals, so have to behave professionally. |
Understood @WangSecurity, apologies if I came off as disrespectful @IlIlHunterlIlI it was not my intention. |
For the finding itself @WangSecurity , I am not seeing how .wrap() would revert? Could you possibly tell me/show me the LOC where this would take place? Thank you! |
@WangSecurity Upon further review I see where this revert would take place and understand your decision to invalidate. Thanks. |
Result: |
Escalations have been resolved successfully! Escalation status:
|
0xHabanero
High
LP Token amounts may be miscalculated due to
DepositWrapper:: deposit()
not handling stETH 1-2 wei corner caseSummary
As seen in the Lido official docs here, there is a very common edge case where sending steth (staked ETH) often results in 1-2 wei being left in the sender account during a transaction. This means that the true amount sent is slightly smaller than what is given as an argument in
deposit
. While theDepositWrapper:: deposit()
attempts to handle any leftover wsteth by making sure that any remaining amount of wsteth in the contract is sent back to the sender, the main vulnerability lies in the wayamount
is calculated inDepositWrapper::deposit()
.Vulnerability Detail
As can be seen in the code above,
amount
is being converted to wsteth after the transfer takes place, and is later being used for the vault deposit/LP token calculation. The issue with this is that in the likely 1-2 wei remainder case, the true amount being transferred is slightly smaller than what the argumentamount
equals. For example, if 1 eth is the amount to be deposited usingDepositWrapper
,amount
will equal 1 eth. However, the true transfer amount is actually slightly less (.99e18 or a little less). As a result, the LP token amount will be calculated based on a 1 eth deposit, when in reality it is slightly less than 1 eth. This causes the user to receive LP tokens for 1 eth worth of deposit, while getting to keep their 1-2 wei that was "lost."This shows how it is not only a vulnerability, but could be exploited by a user as a way to receive more LP Tokens than deserved, while still keeping the difference amount
Impact
Miscalculation of deposit token amount will inflate amount of LP tokens given to users who deposit stETH
Code Snippet
(https://github.com/sherlock-audit/2024-06-mellow/blob/main/mellow-lrt/src/utils/DepositWrapper.sol/?plain=1#L42)
Tool used
Manual Review
Recommendation
Since the initial balance of the wrapper will always be 0, something like the code below can give a more accurate calculation for the amount
As we can see, this calculates amount transferred using the balance of wrapper. This means even if 1-2 wei less is transferred due to this edge case, the LP token amount will be calculated using the exact and correct amount, further mitigating any potential exploitations or risks.
Alternatively, Lido's
transferShares
can be used to calculate amount more accurately.The text was updated successfully, but these errors were encountered: