Submitted by CryptoCraze.
An attacker can steal all funds in RubiconRouter by abusing an error in the token to repay the user in the functions maxBuyAllAmount and maxSellAllAmount (and possibly others).
Please note that the vulnerability exists in the version of RubiconRouter in production and was missed in the C4 audit for Rubicon v1.
The function maxBuyAllAmount is used to allow a user to trade using their entire balance of buy_gem. The user transfers the funds to the router and then RubiconMarket is used to find the best offers and execute them. After the trades are performed, the router intends to forward the resulting amount back to the user. Due to a bug, the token used for this transfer is buy_gem again, instead of pay_gem as seen in the same function.
This mismatch allows an attacker to steal all funds stored in the router using the following steps:
Attached is a POC which performs this flow:
For this POC, please include the following lines in ProtocolDeployment.t.sol:
The exploit is performed by the following function:
The output of this test shows that funds were stolen from the router:
The final transfers in maxBuyAllAmount and maxSellAllAmount (see RubiconRouter.sol#L355 and RubiconRouter.sol#L374) should use pay_gem instead of buy_gem.
bghughes (Rubicon) confirmed
HickupHH3 (judge) commented:
