-
-
Save karlfloersch/437c8f9a3eaa239fca4499ae276aff66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Batch exit strategy (known as a checkpoint in our model): | |
# 1) input is a bytes string of all exits | |
# 2) merklize all of the exits | |
# 3) store the root hash as a batch exit | |
exit_bytes = 64 # Each exit we store 14 bytes for start, 14 bytes for end, and 4 bytes for block number | |
cd_gas_per_byte = 68 | |
gas_per_sstore = 20000 | |
gas_cost_of_merkle_root = gas_per_sstore | |
cd_gas_per_exit = cd_gas_per_byte * exit_bytes | |
total_gas_in_block = 8000000 | |
def sha3_gas(num_bytes): | |
num_words = num_bytes // 32 | |
return 30 + 6 * num_words | |
sha3_gas_of_one_hash = sha3_gas(32) | |
gas_for_one_set_of_exits = sha3_gas(exit_bytes) + cd_gas_per_exit + sha3_gas_of_one_hash | |
# Note: Added `sha3_gas_of_one_hash` gas cost per exit because merkle tree hash cost is 2x number of leaves | |
total_exits_in_block = ((total_gas_in_block - gas_cost_of_merkle_root) / gas_for_one_set_of_exits) | |
print('total exits in block:', total_exits_in_block) | |
print('gas per exit:', total_gas_in_block / total_exits_in_block) | |
eth_block_time = 14 | |
print('avg exits per second', total_exits_in_block//eth_block_time) | |
# Results: | |
# total exits in block: 1801.354401805869 | |
# gas per exit: 4441.102756892231 | |
# avg exits per second 128.0 | |
# Note: For optimistic rollup, assuming all eth blocks are filled, the `*max* safe tps = (dispute_period/halt_time) * tps` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment