Return to site
Return to site

Bug Deep Dive #8

Incorrect rounding direction in geometric pool ask_exact_amount_out allows theft of funds - $7467

· Bug Deep Dive
Section image

Usually these findings are at most lows and and have 1000 dups, but this was not the case. Why? the truncation was hidden and you had to do the math to verify it is exploitable (gas fees can be bigger than the mistake).

Alfa: next time you spot a rounding error, do the math. And also, languages that are not Solidity are like Solidity in 2022 in terms of knowledge lol.

More specifically on this issue, there is an incorrect rounding direction in geometric pool ask_exact_amount_out, which allows theft of funds via multiple swaps..

Section image

The interesting thing about this finding is that the bug is not in checked_div_dec_floor() (well it is but it is not exploitable there, difference is on the decimal part only), but is input_amount.into_int(), which completely removes the decimal part.

So, consider a scenario BTC-USDC pool where 1 sat unit of BTC = 1999 units of USDC. An attacker can execute a swap with exact amount out 1999 units of USDC which translates to 1.999 sat of BTC.

As a result of the bug above, the attacker can obtain 1999 units of USDC while paying 1 sats of BTC every swap (actual price: 1000 units of USDC per 1 sat of BTC). Eventually this can accumulate with multiple swaps to drain the BTC pool.

Conclusion

This finding would earn you $7467, which is honestly huge, if this was solidity it would have way more dups, even if this is a particularity of the into_int() operation. Do what you want with this information.

Section image

Full Report

Subscribe
Previous
Bug Deep Dive #7
Next
Bug Deep Dive #9
 Return to site
Cookie Use
We use cookies to improve browsing experience, security, and data collection. By accepting, you agree to the use of cookies for advertising and analytics. You can change your cookie settings at any time. Learn More
Accept all
Settings
Decline All
Cookie Settings
Necessary Cookies
These cookies enable core functionality such as security, network management, and accessibility. These cookies can’t be switched off.
Analytics Cookies
These cookies help us better understand how visitors interact with our website and help us discover errors.
Preferences Cookies
These cookies allow the website to remember choices you've made to provide enhanced functionality and personalization.
Save