Submitted by KingNFT, also found by joestakey, cducrest, Neon2835, 0xWaitress, koxuan and J4de.
When users buy() from RubiconMarket, their spend is rounded down. Tokens with small decimals, such as WBTC and GUSD, are vulnerable to rounding error attack. Attackers can exploit it to get risk free profit.
The issue arises on L319 of buy(), we can see calculation of spend is rounded down:
The following test cases show how attackers can exploit it to get profit:
The given market parameters and test result for Case 1:
From the log, we can see a 19% profit in one attack. The absolute profit value is about 0.029 USDC, though it is small, but Optimism confirms transactions instantly, attackers can submit huge number of transactions such as 1M to get 29,000 USDC profit.
One point needs to be pointed out, market parameters other than L1 gas prices are consistent with the actual normal situations. The 4 Gwei L1 gas price is a a relatively low price, and its a key condition to make the attack be profitable. But this scenario can actually happen, here are some instances when a gas price drops below 4 Gwei.
The given market parameters and test result for Case 2:
For the GUSD pair, we can see even on a normal 20 Gwei L1 gas price condition, the attack profit rate is 88%. The absolute profit value in one attack is about 2.8 USDC. Similarly, attackers can submit huge number of transactions to make a significant profit.
Calculation of spend should be rounded up.
daoio (Rubicon) acknowledged and commented via duplicate issue #1142:
HickupHH3 (judge) commented via duplicate issue #1142:
HickupHH3 (judge) commented:
