
on hacking systematically with foundry
tl; drtoday i go over some systems i’ve created in foundry for solving blockchain security challenges. i tend to indulge myself with a pristine code organization && logic. in this particular case, i am pretty proud of my methodology for running exploits, tests, and submission scripts (you can see it for yourself, for instance, with my solution for ethernaut’s wargames). in addition, you can also find some experiments in this repository.🎶 today’s moodhttps://open.spotify.com/track/2B3D38o8GaX...

on running your own goerli validator
tl; drtoday i go over how to set a goerli validator with geth and prysm, both locally or using (docker) containerization. the code in this post is available here.🎶 today’s moodhttps://open.spotify.com/track/1sotD6Cn8aOtUsL0bd5HTJ?si=ec5ea69d52b84dbcwhy run a testnet node validatorall right, anon, if you are serious about being a blockchain leet h4xoor developoor buildoor, you gotta run your own node at some point in your life. this way, you will able to understand the many pieces of the ethe...

on cowsol, my arb solver for cow protocol
tl; drtoday i go over one of my MEV bots, cowsol, which runs arbitrage strategies for CoW protocol. set a nice soundtrack, grab your favorite beverage, and solve the puzzles with me.🎶 today’s moodhttps://open.spotify.com/track/4Y2W4zKa3q72ztbkA0r8Va?si=c79621ab86ca4b95🐮🧩 piece #1: coincidence of wants💡 the cow protocol is a fully permissionless trading protocol that uses this novel idea of batch auctions to find prices and maximize liquidity, the “coincidence of wants”.🫱🏻🫲🏽 put it si...
影森のゴーストシェル



on hacking systematically with foundry
tl; drtoday i go over some systems i’ve created in foundry for solving blockchain security challenges. i tend to indulge myself with a pristine code organization && logic. in this particular case, i am pretty proud of my methodology for running exploits, tests, and submission scripts (you can see it for yourself, for instance, with my solution for ethernaut’s wargames). in addition, you can also find some experiments in this repository.🎶 today’s moodhttps://open.spotify.com/track/2B3D38o8GaX...

on running your own goerli validator
tl; drtoday i go over how to set a goerli validator with geth and prysm, both locally or using (docker) containerization. the code in this post is available here.🎶 today’s moodhttps://open.spotify.com/track/1sotD6Cn8aOtUsL0bd5HTJ?si=ec5ea69d52b84dbcwhy run a testnet node validatorall right, anon, if you are serious about being a blockchain leet h4xoor developoor buildoor, you gotta run your own node at some point in your life. this way, you will able to understand the many pieces of the ethe...

on cowsol, my arb solver for cow protocol
tl; drtoday i go over one of my MEV bots, cowsol, which runs arbitrage strategies for CoW protocol. set a nice soundtrack, grab your favorite beverage, and solve the puzzles with me.🎶 today’s moodhttps://open.spotify.com/track/4Y2W4zKa3q72ztbkA0r8Va?si=c79621ab86ca4b95🐮🧩 piece #1: coincidence of wants💡 the cow protocol is a fully permissionless trading protocol that uses this novel idea of batch auctions to find prices and maximize liquidity, the “coincidence of wants”.🫱🏻🫲🏽 put it si...
影森のゴーストシェル
Share Dialog
Share Dialog

Subscribe to bt3gl's symposium

Subscribe to bt3gl's symposium
<100 subscribers
<100 subscribers
today i go over bdex, a tool i built that scrutinizes arbitrage cases on x*y=k AMMs on ethereum.
https://open.spotify.com/track/6BuGA3ontF6D4jluQ0DHZY?si=7e7a411cbdd241dc
The following are the resources we are fetching (but feel free to add your favorite token and pool):
WETH/DAI
Uniswap (0xa478c2975ab1ea89e8196811f51a7b7ade33eb11)
Sushiswap (0xc3d03e4f041fd4cd388c549ee2a29a9e5075882f)
Shebaswap (0x8faf958e36c6970497386118030e6297fff8d275)
Sakeswap (0x2ad95483ac838e2884563ad278e933fba96bc242)
Croswap (0x60a26d69263ef43e9a68964ba141263f19d71d51)
Let’s start by taking a look at what this tool does, and then I will share the source code with you.
Add your Alchemy API key and endpoint to a file named .env:
cp .env_example .env vim .env
Create a virtual environment:
virtualenv venv source venv/bin/activate
Install dependencies:
make install_deps
Install the CLI:
make install
You can run the CLI with:
bdex

We leverage Alchemy API endpoint eth_blockNumber_hex to get the latest block:
bdex -c
💡 The block number can be checked against ETHstat.

💡 We are crafting the checksum address string by hand without directly Keccak-256 hashing the methods and parameters.
We leverage Alchemy API endpoint eth_call to retrieve the current token balance for a specific exchange:
bdex -b TOKEN EXCHANGE

We loop over the previous method for a list of tokens and exchanges:
bdex -a

To be able to compare our results from the previous steps, we implemented an alternative way to fetch pair balances utilizing the Python web3 library:
bdex -w

💡 For this library, it's necessary to supply the contracts' ABI (in our case, for DAI and WETH, located at ./docs)
💡* A third option to verify token balances is through Etherscan tokenholdings dashboard.*
To get the current price for WETH/DAI in all exchanges (e.g., as shown in the projects' dashboards), run:
bdex -p QUANTITY TOKEN1 TOKEN2



An AMM replaces the buy and sell orders in an order book market with a liquidity pool of two assets, both valued relative to each other.
As one asset is traded for the other, the relative prices of the two assets shift, and the new market rate for both is determined.
The constant product is:
token_a_pool_size * token_b_pool_size = constant_product
All the exchanges are forks from Uniswap V2, so they all use the same price formula for trading:
market_price_token1 = token2_balance / token1_balance
For example, in a pool with 2,000,000 DAI and 1,000 WETH, the constant product is 2,000,000,000 and the market price for WETH is $2,000.
To find the buy price for a certain quantity, first, we calculate how much WETH needs to remain in balance to keep the constant product unchanged:
token1_balance_buy = constant_product / (token2_balance + quantity)
Then we calculate how much WETH goes out to keep this constant:
t1_amount_out_buy = token1_balance - token1_balance_buy
The buy price to reflect this ratio is:
buy_price = quantity / t1_amount_out_buy
To find how much we can sell a certain quantity of WETH for DAI, first, we calculate the ratio of DAI in the new pool, as we add WETH:
token2_balance_buy = constant_product / (token1_balance + quantity)
We then calculate how much DAI will go out:
t2_amount_out_buy = token2_balance + token2_balance_buy
We calculate the DAI balance reflected with the income WETH:
token1_balance_sell = constant_product / (token2_balance - quantity)
And what's the proportion of WETH in the new balance:
t1_amount_in_sell = token1_balance + token1_balance_sell
We can now calculate the sell price to reflect the balance change, keeping the constant:
sell_price = t2_amount_out_buy / t1_amount_in_sell
Run an algorithm to search for arbitrage in the supported exchanges for a certain buy quantity:
bdex -x QUANTITY



To run the arbitrage algorithm for a certain amount of minutes:
bdex -r MIN
Results are saved into results/<arbitrage_TIMESTAMP>.txt.
Here is a sample of the results running this algorithm for 100 minutes for trading 1 WETH:
{'buy_exchange': 'SUSHISWAP', 'sell_exchange': 'UNISWAP', 'arbitrage': '7.01', 'buy_price': 3475.14, 'sell_price': 3482.15} {'buy_exchange': 'SUSHISWAP', 'sell_exchange': 'SHEBASWAP', 'arbitrage': '4.27', 'buy_price': 3475.14, 'sell_price': 3479.41} {'buy_exchange': 'SHEBASWAP', 'sell_exchange': 'UNISWAP', 'arbitrage': '2.06', 'buy_price': 3480.09, 'sell_price': 3482.15} {'buy_exchange': 'CROSWAP', 'sell_exchange': 'UNISWAP', 'arbitrage': '13.06', 'buy_price': 3469.09, 'sell_price': 3482.15} {'buy_exchange': 'CROSWAP', 'sell_exchange': 'SUSHISWAP', 'arbitrage': '5.79', 'buy_price': 3469.09, 'sell_price': 3474.88} {'buy_exchange': 'CROSWAP', 'sell_exchange': 'SHEBASWAP', 'arbitrage': '10.32', 'buy_price': 3469.09, 'sell_price': 3479.41} ...



today i go over bdex, a tool i built that scrutinizes arbitrage cases on x*y=k AMMs on ethereum.
https://open.spotify.com/track/6BuGA3ontF6D4jluQ0DHZY?si=7e7a411cbdd241dc
The following are the resources we are fetching (but feel free to add your favorite token and pool):
WETH/DAI
Uniswap (0xa478c2975ab1ea89e8196811f51a7b7ade33eb11)
Sushiswap (0xc3d03e4f041fd4cd388c549ee2a29a9e5075882f)
Shebaswap (0x8faf958e36c6970497386118030e6297fff8d275)
Sakeswap (0x2ad95483ac838e2884563ad278e933fba96bc242)
Croswap (0x60a26d69263ef43e9a68964ba141263f19d71d51)
Let’s start by taking a look at what this tool does, and then I will share the source code with you.
Add your Alchemy API key and endpoint to a file named .env:
cp .env_example .env vim .env
Create a virtual environment:
virtualenv venv source venv/bin/activate
Install dependencies:
make install_deps
Install the CLI:
make install
You can run the CLI with:
bdex

We leverage Alchemy API endpoint eth_blockNumber_hex to get the latest block:
bdex -c
💡 The block number can be checked against ETHstat.

💡 We are crafting the checksum address string by hand without directly Keccak-256 hashing the methods and parameters.
We leverage Alchemy API endpoint eth_call to retrieve the current token balance for a specific exchange:
bdex -b TOKEN EXCHANGE

We loop over the previous method for a list of tokens and exchanges:
bdex -a

To be able to compare our results from the previous steps, we implemented an alternative way to fetch pair balances utilizing the Python web3 library:
bdex -w

💡 For this library, it's necessary to supply the contracts' ABI (in our case, for DAI and WETH, located at ./docs)
💡* A third option to verify token balances is through Etherscan tokenholdings dashboard.*
To get the current price for WETH/DAI in all exchanges (e.g., as shown in the projects' dashboards), run:
bdex -p QUANTITY TOKEN1 TOKEN2



An AMM replaces the buy and sell orders in an order book market with a liquidity pool of two assets, both valued relative to each other.
As one asset is traded for the other, the relative prices of the two assets shift, and the new market rate for both is determined.
The constant product is:
token_a_pool_size * token_b_pool_size = constant_product
All the exchanges are forks from Uniswap V2, so they all use the same price formula for trading:
market_price_token1 = token2_balance / token1_balance
For example, in a pool with 2,000,000 DAI and 1,000 WETH, the constant product is 2,000,000,000 and the market price for WETH is $2,000.
To find the buy price for a certain quantity, first, we calculate how much WETH needs to remain in balance to keep the constant product unchanged:
token1_balance_buy = constant_product / (token2_balance + quantity)
Then we calculate how much WETH goes out to keep this constant:
t1_amount_out_buy = token1_balance - token1_balance_buy
The buy price to reflect this ratio is:
buy_price = quantity / t1_amount_out_buy
To find how much we can sell a certain quantity of WETH for DAI, first, we calculate the ratio of DAI in the new pool, as we add WETH:
token2_balance_buy = constant_product / (token1_balance + quantity)
We then calculate how much DAI will go out:
t2_amount_out_buy = token2_balance + token2_balance_buy
We calculate the DAI balance reflected with the income WETH:
token1_balance_sell = constant_product / (token2_balance - quantity)
And what's the proportion of WETH in the new balance:
t1_amount_in_sell = token1_balance + token1_balance_sell
We can now calculate the sell price to reflect the balance change, keeping the constant:
sell_price = t2_amount_out_buy / t1_amount_in_sell
Run an algorithm to search for arbitrage in the supported exchanges for a certain buy quantity:
bdex -x QUANTITY



To run the arbitrage algorithm for a certain amount of minutes:
bdex -r MIN
Results are saved into results/<arbitrage_TIMESTAMP>.txt.
Here is a sample of the results running this algorithm for 100 minutes for trading 1 WETH:
{'buy_exchange': 'SUSHISWAP', 'sell_exchange': 'UNISWAP', 'arbitrage': '7.01', 'buy_price': 3475.14, 'sell_price': 3482.15} {'buy_exchange': 'SUSHISWAP', 'sell_exchange': 'SHEBASWAP', 'arbitrage': '4.27', 'buy_price': 3475.14, 'sell_price': 3479.41} {'buy_exchange': 'SHEBASWAP', 'sell_exchange': 'UNISWAP', 'arbitrage': '2.06', 'buy_price': 3480.09, 'sell_price': 3482.15} {'buy_exchange': 'CROSWAP', 'sell_exchange': 'UNISWAP', 'arbitrage': '13.06', 'buy_price': 3469.09, 'sell_price': 3482.15} {'buy_exchange': 'CROSWAP', 'sell_exchange': 'SUSHISWAP', 'arbitrage': '5.79', 'buy_price': 3469.09, 'sell_price': 3474.88} {'buy_exchange': 'CROSWAP', 'sell_exchange': 'SHEBASWAP', 'arbitrage': '10.32', 'buy_price': 3469.09, 'sell_price': 3479.41} ...



No activity yet