Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lcfr-eth authored May 22, 2023
1 parent 1c01602 commit af8f535
Showing 1 changed file with 129 additions and 32 deletions.
161 changes: 129 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# FlashbotsBundler
# Flashbots Bundler

A react app for building FlashBots Bundles for token rescues.
An "easy-to-use" react app for building FlashBots Bundles for token rescues.

[Live App Here](https://bundler.lcfr.io)

contracts/transferHelper.sol : small contract to faciliate bulk transferring ERC721 tokens.
[0x422970f74bfa2e403df107fd1de22cd4185d9117](https://etherscan.io/address/0x422970f74bfa2e403df107fd1de22cd4185d9117)
contracts/transferHelper.sol : A small yul contract to faciliate bulk transferring ERC721 tokens effeciently.
[0xbcf192495e2ff497c34f872b27ae0ea21e6a7874](https://etherscan.io/address/0xbcf192495e2ff497c34f872b27ae0ea21e6a7874)

This app works by adding a FlashBots RPC that caches multiple transactions into a Bundle to be sent to a
Flashbots relay.
Expand All @@ -14,49 +14,146 @@ Flashbots relay.
[Understanding Bundles](https://docs.flashbots.net/flashbots-auction/searchers/advanced/understanding-bundles)
[Transaction Caching](https://docs.flashbots.net/flashbots-protect/rpc/bundle-cache)

### The counter-attack flow is:
1) Transfer ETH from a clean wallet to the compromised wallet in one transaction.
### Why
Most of the apps/programs allowing Flashbots bundles are still too hard for users to use.

[The ScaffoldEth](https://github.com/scaffold-eth/scaffold-eth/tree/flashbots-bundler) code this was based off of was ineffecient for transferring large amounts of tokens such as ENS collectors who own 100+ tokens.

[Python examples](https://github.com/lcfr-eth/ENSPublic/blob/main/ENSRescuer/rescuer.py) require knowledge of python etc.

[Other node based examples](https://github.com/Arachnid/flashbots-ens-rescue/blob/master/src/index.ts) didn't take into account large token ownership and max bundle size

2) Identify the NFT Contract address your tokens are from. For example ENS is 0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85.

3) Call SetApprovalForAll on the collection contract to approve your new-unhacked address to transfer your tokens.
### IMPORTANT:

4) Call SetApprovalForAll on the collection contract to approve the TransferHelper contract to enable bulk transferring of the tokens.
When connected to the Flashbots RPC it will display a 100ETH balance.
This is for gas calculations etc but cant be spent (obviously).
![FBRPC](./public/Screen%20Shot%202023-05-22%20at%2010.10.25%20AM.png)

5) Call the TransferHelper contract from the clean address you approved previously with the TokenIds you wish to transfer.
When submitting transactions to a bundle you have to set a custom <b>Priority Fee</b> in MetaMask advanced gas settings. This has to be done for EVERY transaction you submit to the bundle.

### Usage Notes
![FEE](./public/Screen%20Shot%202023-05-22%20at%2010.17.46%20AM.png)

Currently usage requires 2 separate bundles if you wish to batch transfer all your NFTs/Tokens in a single transfer.
This is because of the way MM simulates transactions before submitting.
A good tip is usually 5-20 GWEI.

Since the approval for the transferHelper is not executed on-chain at the time of building the bundle the approval check will fail and MM will give the high gas cost since it detects
the revert.
![FEE2](./public/Screen%20Shot%202023-05-22%20at%2010.18.25%20AM.png)

We work around this by creating one bundle to send ETH + setApprovals and execute it so the MM simulation passes
then we can create a second bundle to bundle transfer transactions and execute it.
### Generalized ENS/ERC721 counter sweeper flow:

IMPORTANT: When submitting transactions to the bundle you have to set a custom MaxPriorityFeePerGas in the MM advanced/custom gas settings. This has to be done for EVERY transaction you submit to the bundle.
!! This only applies to ERC721 collections.
!! Read below for ERC20 & ERC1155.

A good tip is usually 5-20 GWEI.
Things you will need:

### Usage
The ENS collection address: 0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85.
A list of all your name's tokenIds. Not just names but the tokenIds.
This can be obtained from:
[The ENS Subgraph](https://thegraph.com/hosted-service/subgraph/ensdomains/ens)
[EnsVision](https://ens.vision)
[OpenSea](https://opensea.io)
[Etherscan](https://etherscan.io)

1) Create a new Bundle/BundleUUID
2) Click to add & swap to the Bundler RPC. Note If on Mobile you need to add the RPC manually and change to it.
3) Enter a new clean-unhacked address you wish to give permission to transfer tokens from the hacked address.
4) Click to approve the address entered
5) Click to approve the TransferHelper contract
6) Submit the first bundle.
A clean unhacked address with ETH to fund transactions and receive tokens.

Now batch transfer your tokens in the next step:
Fund the hacked wallet with names + Set needed approvals with a Bundle.

1) Create a new Bundle/BundleUUID
2) Click to add & swap to the Bundler RPC. Note If on Mobile you need to add the RPC manually and change to it.
3) Click the transfer Tab and enter up to 25 tokenIds and click "Add to Bundle"
4) Repeat until all tokenIds are added with as many transactions as needed.
5) Click Submit Bundle
1) Click the "New Bundle" tab to generate a new bundle uuid + Swith to the provided RPC.
2) Click the "Send ETH" tab.
3) Connect a clean unhacked wallet to the dapp in metamask to fund the transactions from.
4) Enter the hacked wallets address to send funds to.
5) Click the button to estimate cost.
6) Copy the cost for two approvals to the amount box below.
7) Click Send to add the transaction to the bundle.
8) Click the "Set NFT Approvals" tab.
9) Connect the hacked wallet address to the dapp in metamask.
10) Enter the NFT collection address.
11) Enter the hacked wallet (that your connected from) address.
12) Enter your unhacked wallet address to give the permission to transfer the tokens.
13) Click to add the first setApproval transaction to the bundle.
14) Click to add the second setApproval transaction to the bundle.
15) Click the "Submit Bundle" tab to submit the first bundle when finished adding approvals.

Transfer Names/Nfts

1) Optional: You can change back to Ethereum Mainnet in metamask RPC now and skip adding additional tip in metamask.
2) Click the Transfer NFTs tab.
3) Connect to the dapp in metamask with the unhacked address you entered previously that has funds to cover gas.
4) Enter the NFT Collection address (should be pre-filled).
5) Enter the hacked address that holds the tokens to transfer.
6) Enter the unhacked address to receive tokens that you should be connected from (should be pre-filled).
7) Enter the tokenIds below. One per line.
8) Click "add the transaction to bundle" to execute the transaction without any bundle.
9) Optional: If still connected to the Flashbots RPC click the "Submit Bundle" tabe.

### ERC1155

1) Click the "New Bundle" tab to generate a new bundle uuid + Swith to the provided RPC.
2) Click the "Send ETH" tab.
3) Connect a clean unhacked wallet to the dapp in metamask to fund the transactions from.
4) Enter the hacked wallets address to send funds to.
5) Click the button to estimate cost.
6) Copy the value to the Amount field below.
7) Click the "Click to send eth" button to add the transaction to the bundle.
8) Change to the hacked wallet address in MetaMask.
9) Click the "Transfer NFTs" tab.
10) Enter the ERC1155 token contract address.
11) Enter the hacked wallets address.
12) Enter the unhacked receiver wallet address.
13) Enter the tokenIds one per line
14) Click "Click to add transaction to bundle" to add to bundle.
15) Click the "Submit Bundle" tab to submit the bundle with two transactions.

### ERC20

1) Click the "New Bundle" tab to generate a new bundle uuid + Swith to the provided RPC.
2) Click the "Send ETH" tab.
3) Connect a clean unhacked wallet to the dapp in metamask to fund the transactions from.
4) Enter the hacked wallets address to send funds to.
5) Click the button to estimate cost.
6) Copy the value to the Amount field below.
7) Click the "Click to send eth" button to add the transaction to the bundle.
8) Change to the hacked wallet address in MetaMask.
9) Click the "ERC20 Tokens" tab.
10) Enter the ERC20 token contracts address.
11) Optional: Click to get the balanced owned by the hacked address.
12) Click the button "Click to transfer full balance" to add the transaction to the bundle.
13) Click the "Submit Bundle" tab to submit the bundle with two transactions.


### Technical

ERC1155 tokens have a built in batch transfer function to transfer multiple tokens in the same transaction.

ERC721 tokens lack such functionality. In order to batch transfer a large quantity of ERC721 tokens it requires a utility contract to batch the calls together.

The UI detects if a supplied token contract is ERC721 or ERC1155. If the token contract is an ERC1155 contract then the UI will utilize the built in safeBatchTransferFrom() method.

This also means a bundle only requires two transactions and no approvals. One transaction to fund the safeBatchTransferFrom and another transaction to call the safeBatchTransferFrom call.

This is similar to rescuing ERC20 tokens. ERC20 tokens also only require two transactions in a single bundle as well. One transaction to fund the transfer call and then the actual transfer call/transaction.

In contrast if the token contract is ERC721 then it requires two setApprovalForAll transactions to batch transfer the tokens using the transferProxy utility contract.

### Additional Notes

When submitting bundles you will see an alert screen to let you know it was submitted:

![submitted](public/Screen%20Shot%202023-05-21%20at%201.51.37%20PM.png)

Your bundle might not be included in a block the first time you submit it. An alert will inform you if your bundle was not mined:
![submitted2](public/Screen%20Shot%202023-05-21%20at%201.26.31%20PM.png)

If this happens then click the "Submit Bundle" tab and submit the bundle again.

Its possible it might take multiple submissions.

When your bundle is included you will see an alert like this:
![submitted3](public/Screen%20Shot%202023-05-21%20at%202.03.52%20PM.png)

Currently the UI will check if the transactions were mined for +10 blocks from the block its submitted on.


If you forget to add the Priority Tip to a transaction in a bundle you will need to reset the wallet state and start over again by generating a new bundle uuid in the "New Bundle" tab.

### Thanks
[Austin Griffith](https://twitter.com/austingriffith) and co for the [ScaffoldETH](https://github.com/scaffold-eth/scaffold-eth) repo for the original leg work and pretty CSS.
Expand Down

1 comment on commit af8f535

@vercel
Copy link

@vercel vercel bot commented on af8f535 May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.