Hack Analysis Decoding Rabby’s Smart Contract Vulnerability

neptunemutual · November 06, 2024 · 9 hits

Rabby became the victim of a smart contract exploit resulting a total loss of $200,000.

TL;DR

On October 11, 2022, Rabby was the victim of a smart contract exploit in which the hacker stole 114 ETH worth $146,000 and 179 BNB worth $48,500, totaling a loss of ~$200,000.

Introduction to Rabby

Rabby is a browser-based open source Ethereum cryptocurrency wallet. It is built and maintained by the DeBank team and is intended to provide a smooth multi-chain experience for DeFi users.

Vulnerability Assessment

The root cause of the vulnerability is the contract's token exchange function, which was called externally via the functionCallWithValue function in the OpenZeppelin Address library.

Steps Step 1: The attacker address can be found here, alongside one of the attack transaction. Step 2: The exploitable contract that enables the swap feature had previously been audited, however it appeared that the vulnerability was undetected. Step 3: The interface for users to swap tokens in a given DEX router is provided by the RabbyRouter contract. When the source token is address(0), it intends to buy tokens with Ether. It was revealed that there was an existence of a redundant Ether transfer. Step 4: In the dexRouter, the _swap() routine is used to complete the token swap from the srcToken to the dstToken.

Step 5: When the srcToken is Ether (srcToken == address(0)), the Ether value is token in the transaction's msg.value. Step 6: However, there was a redundant Ether transfer, which transferred the specified amount of Ether from the current contract to the contract itself.

Step 7: There were also no validation techniques, require(amount == msg.value) to ensure that the srcToken amount was exactly the same as msg.value. Step 8: The _swap function thus calls the dexRouter(token) address using functionCallWithValue function.

Step 9: A user can pass in the target contract and the call data, however the contract does not validate the user-passed arguments, which causes an arbitrary external call issue. This is what the attacker takes advantage of to steal money from users who have approved the swap contract. Step 10: All of the stolen money has been deposited into Tornado Cash by the attacker.

Aftermath

The team has stated that they are currently looking for the stolen assets and that they will provide users with a satisfactory resolution within a week. They advised users to rescind all prior approvals for Rabby Swap contracts on all chains.

How to prevent such an attack vector

This exploit could have been avoided using proper validation techniques to ensure that the any external call to the contracts were restricted.

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.