Submitted by CryptoCraze, also found by adriro, kaden, sashik_eth, 0xfusion, 0xDING99YA, parlayan_yildizlar_takimi, fs0c, xmxanuel, Inspex, sinarette, 0xNineDec, Banditx0x, nobody2018, ladboy233, azhar and orion.
An attacker can steal all tokens of users that use FeeWrapper.
There is no way to distinguish between users that use FeeWrapper. For example, if a user called RubiconRouter
through the FeeWrapper, then the msg.sender in RubiconRouter would be the address of FeeWrapper, instead
of the address of the user. This will cause all offers to be owned by FeeWrapper.
This means that a malicious attacker can call FeeWrapper and impersonate another user, then withdraw their tokens
on their behalf. Here is an example of the flow of events that could occur:
As seen in the FeeWrapper, its possible for anyone to make the FeeWrapper call any function of any contract with any arguments, through rubicall. For example, we can call offer and cancel (of RubiconMarket) and even transfer/transferFrom (of any ERC20 token) on its behalf.
This exploit has a victim and an attacker, the victim invests his tokens through some 3rd party that uses the FeeWrapper
by creating an offer. Then the attacker calls the FeeWrapper directly, and cancels the victims offer, taking all his
tokens.
We modified the fee-wrapper.ts test. The setup is almost identical, only we added a victim and an attacker, and
modified the pepeFinance to use our example 3rd party.
And we created Some3rdPartyProtocol.sol, which is almost identical to Test3rdPartyProtocol.sol, but uses RubiconMarket directly.
If you run the test, youll see the following output:
To emphasize the problem, well also show that theres a problem in the example given with Test3rdPartyProtocol.sol. Theres another bug making it impossible to cancel offers through the FeeWrapper, because the FeeWrapper is
not capable of accepting eth.
The following test is an exploit using the given Test3rdPartyProtocol.sol which cancels an offer made by another user. Currently, user cancel doesnt work because FeeWrapper doesnt have a payable fallback function. This exploit will work when the payable function is added, resulting in stolen funds.
Just to be clear, currently, an honest user making an offer cant cancel their own offer.
We added the following test to fee-wrapper.ts that shows this exploit:
We recommend converting the FeeWrapper to be a library, instead of a standalone contract (i.e. it shouldnt have an address) and making the rubicall function private. That way, all the logic of the FeeWrapper can be used by 3rd parties, but no one can call the FeeWrapper directly.
Also, we think FeeWrapper functions should have a reentry guard.
daoio (Rubicon) confirmed
HickupHH3 (judge) commented:
