Skip to content

AMM TPS test for ZKsync Era, Polygon zkEVM, and OP Mainnet

Notifications You must be signed in to change notification settings

bogatyy/rollup-amm-tps-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AMM TPS test for ZKsync Era, Polygon zkEVM, and OP Mainnet

Our goal was to benchmark maximal transaction throughput (TPS) for ZKsync Era, Polygon zkEVM and OP Mainnet. We settled on the time-tested AMM test, i.e. measuring the TPS via the number of token swaps through a Uniswap V2 AMM style pool. Using the AMM test as a reasonable apples-to-apples comparison was popularized by Dragonfly Research; see also discussion by Georgios (Paradigm) against non-specific TPS, plus here.

This repository includes scripts designed for executing predefined WETH -> CAKE V2 swaps simultaneously from multiple accounts. Additionally, it contains helper scripts to analyze blockchain performance metrics post-execution.

The overall TPS (transactions per second) is calculated by dividing the total number of transactions sent by the total time in seconds between the moments the first and last transactions were included (last_block_timestamp - first_block_timestamp).

Results

ZKsync Era Results

  • From 100 different accounts, 20 V2-swaps were sent by each in parallel
  • We used the official WS RPC for sending transactions
  • 2000 transactions total, split across 10 IP addresses to avoid RPC limits
  • It took 11s for all transactions to be included with overall throughput of 181.8 tx/s
  • On-chain data: 11 blocks from 36612894 to 36612904 are almost exclusively our swaps

ZKSync Era results

Polygon zkEVM Results

  • From 100 different accounts, 20 V2-swaps were sent by each in parallel
  • We have not been able to find an official Polygon zkEVM WS RPC. Thus, we used the paid version of WS API on dRPC.org, as the fastest we could find https://chainlist.org/chain/1101
  • 2000 transactions total, split across 10 IP addresses to avoid RPC limits
  • It took 372s for all transactions to be included with relatively steady TPS of 5.4 tx/s
  • On-chain data: 131 blocks from 13686722 to 13686852 are almost exclusively our swaps

Polygon zkEVM results

Optimism OP Mainnet Results

  • Estimating OP Mainnet throughput with confidence is easier
  • For Optimism Mainnet, the block size is 30M gas, block time is 2 seconds, and an average AMM trade requires roughly 105k gas. Thus the maximum possible TPS on Optimism Mainnet is roughly 30M / 2sec / 105k ~= 142.8 tx/s
  • We obtained this TPS in practice: blocks between 121963262 and 121963269

Technical Details

High-Level Overview:

  • blockchain.py: Manages addresses and endpoints for specified chain IDs. This class is extendable for tps-tests on other chains, though it is crucial to ensure that any newly added tokens possess sufficient V2 liquidity for trading.
  • prepare.py: Implements the logic to fund accounts (derived from a mnemonic) with ETH. It also handles wrapping and approving ETH for the SmartRouter to spend.
  • tps_test.py: Executes a specified number of WETH -> CAKE swaps via a websocket RPC endpoint from each account concurrently.
  • logs_parser.py: Analyzes the logs by organizing swap transactions based on the time they were sent, identifying the corresponding block for each transaction, organizing these blocks, and finally calculating the TPS to provide insights into the dynamics of transaction inclusion and blockchain performance.

Suggested TPS-test setup:

  1. Fund 100 accounts with 0.002 ETH (prepare.py)
  2. Wrap 0.00000005 WETH for each account (prepare.py)
  3. Approve spending 1 WETH for SmartRouter for each account (prepare.py)
  4. Run 10 instances of tps_test.py from different IPs. This can be achieved by operating the script on 10 distinct servers or by setting up iptables rules to alternate source IPs based on the user.
    You can configure sending accounts by specifying -n flag:
    tps_test.py -n 0 2>&1 | tee logs/tps00.log // will send swaps from accounts #0...#9
    tps_test.py -n 1 2>&1 | tee logs/tps01.log // will send swaps from accounts #10...#19
    ...
    tps_test.py -n 9 2>&1 | tee logs/tps09.log // will send swaps from accounts #90...#99
    To synchronize start times, the script include logic to delay execution until the next 5-minute mark. For example, if a script launches at 15:02:34, it will commence at 15:05:00.
  5. Combine all tps0*.log into tps.log by running cat tps0{0..9}.log > tps.log
  6. Create swaps.log using logs_parser.py - the list of all sorted transactoins (example)
  7. Create tps-results.log using logs_parser.py - the list of blocks and final TPS result (example)

Recent TPS Results:

  • zkSync Era Mainnet: 181.8 txs/s (Date: 14 June 2024, spent in swap tx fees: ~0.007 ETH) [tps-results]
  • Optimism Mainnet: 142.8 tx/s (Date: 27 June 2024, spent in swap tx fees: ~0.0007 ETH) [tps-results]
  • Polygon zkEVM Mainnet: 5.4 txs/s (Date: 25 June 2024, spent in swap tx fees: ~0.042 ETH) [tps-results]

About

AMM TPS test for ZKsync Era, Polygon zkEVM, and OP Mainnet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages