-
Notifications
You must be signed in to change notification settings - Fork 91
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
Add 1wei tolerance for bad token detection #2892
Conversation
if balance_after_in | ||
< computed_balance_after_in | ||
.checked_sub(U256::one()) | ||
.unwrap_or_default() | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is equivalent
if balance_after_in | |
< computed_balance_after_in | |
.checked_sub(U256::one()) | |
.unwrap_or_default() | |
{ | |
if balance_after_in < computed_balance_after_in.saturating_sub(U256::one()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lg. Not sure how easy would be to write a unit test to confirm behaviour.
The first idea I had was to create a forked e2e test that tries to trade the problematic token. But TBH I wouldn't worry about it given that we execute these code paths A LOT and the unit test confirms the token is okay now. |
There is an integration test, which has a token that was bad before and is now supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Description
This is a pretty hacky PR, but given that we didn't manage to get rid of bad token detection in the last quarter and it's not clear when we will find the ressources for it, I feel the impact this change can have may be worth its ugliness.
There are a lot of tokens (e.g. stETH, eUSD, oETH, etc.) whose transfer logic is based on "shares" (cf. eUSD transfer implementation). The logic to convert shares into token amounts requires a division which can lead to off by one error:
Relevant solidity code
Consider the following example:
Transferring 3 eUSD would lead to transferring 1 share (3 * 50 / 100). After the transfer the user therefore has 5 shares = 10 eUSD (5 * 100 / 50) which is not in line with our expectation (8 + 3 = 11). This 1 wei discrepency is causing the bad token detector to fire.
Changes
How to test
Not sure if this warrants an e2e test in and of itself (I assume it will be quite involved to deploy the token as in the example)? For now I would rely on the existing unit tests. In particular
now shows
0x0aacfbec6a24756c20d41914f2caba817c0d8521
as supported 💪