rust

抽象级别

  • hardcode
  • parameter
  • generic
  • trait
  • GAT
  • HRTB (Hight Rank Trait Bounds)
  • macro

petgraph

套利流程

[] 获取所有交易对信息常驻内存,提供模拟引擎接口,完整的各个uniswap clone版本的clone版本

[] 通过add/remove/swap sync event更新对应交易对信息

[] 监视pending交易,通过模拟引擎接口,simulate用户交易,更新模拟信息

[] 选取更新交易对的五级hops和常用待监视交易对,查询cycles,使用图算法寻找最优套利路径

[] 计算是否盈利

[] backrunning用户交易,使用多个bot同时发送交易,提高成功率

[] 更新合约,一个成功,其他失败,失败的确保GAS费耗费最少

[] 多线程方式,同步信息或者协程方式,mpmc

Ref

frontrun

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0|start    | 2022-11-23T04:12:47.612879Z  INFO fetch_tx_1: block_bot::util::transaction: https://bscscan.com/tx/0x7976930b8f1d29645532c8962b09bbe6d777e452b809c3560a96d2198995374d GasPrice: 5000000000, GasLimit: 1470804, nonce: 819, from: 0xa15bcf6695aa600bd19deafbda74a0e02b225b96, to: Some(0x9d3a168cf3a54bae225471fc061a77e49c741751)
0|start | 2022-11-23T04:12:47.612926Z INFO fetch_tx_1: block_bot::util::transaction: v_debt: 0x57a5297f2cb2c0aac9d554660acd6d385ab50c6b, borrower: 0x8c2d68ada55f6d602b612c36ce63bc6f3a0d0aef, repay_amount: 1125708341278038872, v_collateral: 0x882c173bc7ff3b7786ca16dfed3dfffb9ee7847b
0|start | 2022-11-23T04:12:47.896680Z INFO fetch_tx_1: block_bot::util::transaction: 🚀
0|start | 2022-11-23T04:12:48.442698Z INFO fetch_tx_1: block_bot::util::transaction: https://bscscan.com/tx/0xc0f590ec8d17e251e04826d280f35cc3de127c23554a1e6f6fbc64442d987723 GasPrice: 8098552296, GasLimit: 6500000, nonce: 48, from: 0xb99bcff726fe908c72aad3edced34414da2ff6eb, to: Some(0xd22cd4d5fb86d727962ddd1f166458bf408935dd)
0|start | 2022-11-23T04:12:48.444101Z INFO fetch_tx_1: block_bot::util::transaction: duplicate data_hash: 12973895815296091427, nonce: 842
0|start | 2022-11-23T04:12:48.745966Z INFO fetch_tx_1: block_bot::util::transaction: 🚀🚀🚀
0|start | 2022-11-23T04:12:49.591421Z INFO fetch_tx_1: block_bot::util::transaction: https://bscscan.com/tx/0xe55d54b10f6de14722463abbb05229d7e46e6d2dfcaaf4efa2937626cb398be2 GasPrice: 9047218091, GasLimit: 6500000, nonce: 48, from: 0xb99bcff726fe908c72aad3edced34414da2ff6eb, to: Some(0xd22cd4d5fb86d727962ddd1f166458bf408935dd)
0|start | 2022-11-23T04:12:49.592859Z INFO fetch_tx_1: block_bot::util::transaction: duplicate data_hash: 12973895815296091427, nonce: 843
0|start | 2022-11-23T04:12:50.318527Z INFO fetch_tx_1: block_bot::util::transaction: 🚀🚀🚀
0|start | 2022-11-23T04:12:51.023612Z INFO fetch_tx_1: block_bot::util::transaction: https://bscscan.com/tx/0xb83925d4deed8d893e0cf1a0372d581eb449d1319e1fabdf6553652352c62ee9 GasPrice: 10114748706, GasLimit: 6500000, nonce: 48, from: 0xb99bcff726fe908c72aad3edced34414da2ff6eb, to: Some(0xd22cd4d5fb86d727962ddd1f166458bf408935dd)
0|start | 2022-11-23T04:12:51.023963Z INFO fetch_tx_1: block_bot::util::transaction: duplicate data_hash: 12973895815296091427, nonce: 843
0|start | 2022-11-23T04:12:51.348030Z INFO fetch_tx_1: block_bot::util::transaction: 🚀🚀🚀
0|start | 2022-11-23T04:12:52.026233Z INFO fetch_tx_1: block_bot::util::transaction: https://bscscan.com/tx/0xd6a864ef7a7924a61144bf57dc3e99e4adbe10be28b456fdb87af39e27763f76 GasPrice: 7606230453, GasLimit: 6500000, nonce: 709, from: 0xc1403efe15c651a32a11e0fdb469edc8c47d2b07, to: Some(0xd22cd4d5fb86d727962ddd1f166458bf408935dd)
0|start | 2022-11-23T04:12:52.026750Z INFO fetch_tx_1: block_bot::util::transaction: duplicate data_hash: 12973895815296091427, nonce: 844
0|start | 2022-11-23T04:12:52.310967Z INFO fetch_tx_1: block_bot::util::transaction: 🚀🚀🚀
0|start | 2022-11-23T04:12:52.746616Z INFO fetch_tx_1: block_bot::util::transaction: https://bscscan.com/tx/0x1cbd1967c140cf2245db101554b290d5821913b00d4287438be6de5dc74fd016 GasPrice: 11319513236, GasLimit: 6500000, nonce: 48, from: 0xb99bcff726fe908c72aad3edced34414da2ff6eb, to: Some(0xd22cd4d5fb86d727962ddd1f166458bf408935dd)
0|start | 2022-11-23T04:12:52.747074Z INFO fetch_tx_1: block_bot::util::transaction: duplicate data_hash: 12973895815296091427, nonce: 844
0|start | 2022-11-23T04:12:52.987014Z INFO fetch_tx_1: block_bot::util::transaction: https://bscscan.com/tx/0xf68164edb47cd4b9ed7caa18cb8db76e0e35ad21c45941b77252539c544f5dc4 GasPrice: 9081188499, GasLimit: 6500000, nonce: 709, from: 0xc1403efe15c651a32a11e0fdb469edc8c47d2b07, to: Some(0xd22cd4d5fb86d727962ddd1f166458bf408935dd)
0|start | 2022-11-23T04:12:53.038995Z INFO fetch_tx_1: block_bot::util::transaction: 🚀🚀🚀
0|start | 2022-11-23T04:12:53.039049Z INFO fetch_tx_1: block_bot::util::transaction: duplicate data_hash: 12973895815296091427, nonce: 845
0|start | 2022-11-23T04:12:53.353545Z INFO fetch_tx_1: block_bot::util::transaction: 🚀🚀🚀

winnner: 监测到4个pending

1 ok, 1 error

sender: 0xb99bcff726fe908c72aad3edced34414da2ff6eb
winner
position: 4

other’s failed tx:
sender: 0xc1403efe15c651a32a11e0fdb469edc8c47d2b07,监测到2个pending
failed
position: 12

my failed tx: 7个交易,替换3个(842,843,844),失败4个(842,843,844,845),期望成功1个(842),其他都替换为成功的。
4 errors
failed1
position: 6
failed2
position: 7

next block:
failed1
position: 0
failed2
position: 1

exploit1

poc

[MEV contract] 0xee85d50607ed2d1413eabf789eca6f138a9c362f
为可升级合约,实现地址为:0x037f09d32E1e3AC52a295aE856C17C42d7DEFE83
调用了另一个0x83EF20c2eA6BEd52a62b34BfB3f559DDE4441E65合约

decompiler

decompiler

msg.sender: 0xa1d2b3c7c64b2746370cd8f6e81af7d4cb3fbb1c

input:
0xb11ad16900000000000000000000000000000000000000000000000000000000000000600000000000000000000000001610bc33319e9398de5f57b33a5b184c806ad21700000000000000000000000000000000000000000000000045963237b717b40000000000000000000000000000000000000000000000000000000000000000010000000000000000000000009abfe8921d32eac9fea6669e25344e2c97182757

0xb11ad169
0000000000000000000000000000000000000000000000000000000000000060 address[], borrowers
0000000000000000000000001610bc33319e9398de5f57b33a5b184c806ad217 # vDot
00000000000000000000000000000000000000000000000045963237b717b400 # dot price
0000000000000000000000000000000000000000000000000000000000000001 # borrowers.length
0000000000000000000000009abfe8921d32eac9fea6669e25344e2c97182757 # borrower

borrower: 0x9abfe8921d32eac9fea6669e25344e2c97182757
vDot: 0x1610bc33319e9398de5f57b33a5b184c806ad217 不再使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
getAssetsIn
getAccountSnapshot*
getUnderlyingPrice*
mintedVAIs
underlying
liquidateCalculateSeizeTokens
exchangeRateStored
liquidationIncentiveMantissa
pcs.getAmountsOut
mdex.getAmountsOut
swap
pancakeCall
approve
liquidateBorrow
transfer

trace

mev-analyzer

poc1
flashswap: WBNB -> BTCB -> vCake -> BUSD

input

0xa5bb9219
00000000000000000000000086ac3974e2bd0d60825230fa6f355ff11409df5c # vCollateral: vCake
000000000000000000000000882c173bc7ff3b7786ca16dfed3dfffb9ee7847b # vDebt: vBTC
0000000000000000000000009c2323b8a57da0bd3cbe325c7f4db05cbb896dbd # borrower
0000000000000000000000000000000000000000000000000004c8b3c57ccfc5 # borrow amount
000000000000000000000000e9e7cea3dedca5984780bafc599bd69add087d56 # token repay

vTokenCollateral vCake
vDebt vBTC
borrower
repay token BUSD

trace