Skip to content

Commit

Permalink
fix: do not break on 0x0 code
Browse files Browse the repository at this point in the history
  • Loading branch information
Otto-AA committed Jul 23, 2024
1 parent ad812a0 commit 6e9f9fc
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 607 deletions.

Large diffs are not rendered by default.

62 changes: 32 additions & 30 deletions tests/integration/snapshots/snap_test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,63 @@
"types": ["balance"],
}

snapshots["test_tod_attack_miner_e2e num_candidates"] = 157
snapshots["test_tod_attack_miner_e2e num_candidates"] = 163

snapshots["test_tod_attack_miner_e2e stats"] = {
"accesses": {"balance": 4663, "code": 2248, "nonce": 4332, "storage": 8239},
"candidates": 157,
"accesses": {"balance": 4721, "code": 2301, "nonce": 4385, "storage": 8500},
"candidates": 163,
"candidates_filters": {
"candidates": {
"before_filters": 2195,
"final": 157,
"original_without_same_value": 264234,
"before_filters": 2222,
"final": 163,
"original_without_same_value": 264455,
},
"filtered": {
"block_producers": 786,
"block_window": 62,
"block_producers": 784,
"block_window": 63,
"codes": 0,
"indirect_dependencies_quick": 47,
"indirect_dependencies_recursive": 38,
"limited_collisions_per_address": 208,
"limited_collisions_per_code_family": 2,
"limited_collisions_per_code_hash": 2,
"nonces": 658,
"indirect_dependencies_quick": 55,
"indirect_dependencies_recursive": 43,
"limited_collisions_per_address": 213,
"limited_collisions_per_code_family": 1,
"limited_collisions_per_code_hash": 7,
"nonces": 659,
"recipient_eth_transfer": 61,
"same_sender": 174,
"same_sender": 173,
},
},
"candidates_transactions_unique": 235,
"collision_addresses_unique": 70,
"collisions": {"balance": 63, "storage": 172},
"collisions_before_filters": {"balance": 1526, "nonce": 879, "storage": 710},
"candidates_transactions_unique": 240,
"collision_addresses_unique": 73,
"collisions": {"balance": 64, "storage": 175},
"collisions_before_filters": {"balance": 1533, "nonce": 879, "storage": 766},
"frequencies": {
"candidates_transactions": [(2, 79), (1, 156)],
"candidates_transactions": [(3, 3), (2, 80), (1, 157)],
"collisions_addresses": [
(10, 11),
(6, 2),
(5, 5),
(4, 4),
(3, 3),
(2, 18),
(10, 10),
(9, 1),
(7, 1),
(6, 1),
(5, 2),
(4, 6),
(3, 6),
(2, 19),
(1, 27),
],
},
"samples": {
"candidates_transactions_frequent": [
("0x367b13927c05d804d67b2809daade8baba114e6d5a0f2d95cf7318ffdb656f97", 2),
("0xbc0dca6b2bb6d8089d16824a3abc89c38f39af5af5edeeab534734c6db6f0ef9", 3),
("0x83f080e05913644ae70103139509caf246066d8111d432db8a5afe954b6a05e7", 3),
("0x618f4b0392ac8ee3cb3c447c6dbe1ec4b472e8e49d302a393fd23e6d36164ec6", 3),
("0x767e0cc6d695c96fb2b7be8a28f075c5a0729cdd646e3892230a6138a33925df", 2),
("0x4fa5690f54408827f28253342d0bf8c616b9377a9917ab7706be23c79079df9a", 2),
("0x7d98a6b0fa1b22bdd88bbaed71178105c121010dae17a6d96084e7576c055316", 2),
("0x5406c057c0fecf3d9ca3a200f9c8f58a10d57c2b732df59c5607b45412f40af6", 2),
],
"collision_addresses_frequent": [
("0x0ec68c5b10f21effb74f2a5c61dfe6b08c0db6cb", 10),
("0x3328f7f4a1d1c57c35df56bbf0c9dcafca309c49", 10),
("0x7777777f279eba3d3ad8f4e708545291a6fdba8b", 10),
("0x8390a1da07e376ef7add4be859ba74fb83aa02d5", 10),
("0x8fa3b4570b4c96f8036c13b64971ba65867eeb48", 10),
("0x916b2aff900d06c526b4935f999462b65f1a24fe", 10),
],
},
"state_diffs": {"balance": 2577, "code": 3, "nonce": 880, "storage": 2594},
Expand Down
9 changes: 8 additions & 1 deletion tod_attack_miner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import psycopg

from tod_attack_miner.db.db import DB
from tod_attack_miner.db.filters import (
get_filters_duplicate_limits,
get_filters_except_duplicate_limits,
)
from tod_attack_miner.miner.miner import Miner

from tod_attack_miner.rpc.rpc import RPC
Expand Down Expand Up @@ -48,6 +52,9 @@ def main():
miner.fetch(int(args.from_block), int(args.to_block))
miner.compute_skelcodes()
miner.find_collisions()
miner.filter_candidates(args.window_size)
miner.filter_candidates(
get_filters_except_duplicate_limits(25)
+ get_filters_duplicate_limits(10)
)
print(f"Found {miner.count_candidates()} candidates")
print(json.dumps(miner.get_stats()))
2 changes: 2 additions & 0 deletions tod_attack_miner/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,5 +470,7 @@ def hash_code(code: str) -> str:

def code_skeleton_hash(code: str) -> str:
code_without_prefix = code[2:]
if code_without_prefix == "0":
code_without_prefix = ""
skelcode = skeletize(bytes.fromhex(code_without_prefix)).hex()
return hash_code(skelcode)
4 changes: 2 additions & 2 deletions tod_attack_miner/fetcher/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def fetch_block_range(rpc: RPC, db: DB, block_range: BlockRange):
)
):
bar.set_postfix_str(f"block {block_number}")
rpc.fetch_block_with_transactions(block_number)
block = rpc.fetch_block_with_transactions(block_number)
prestates = rpc.fetch_prestates(block_number)
state_diffs = rpc.fetch_state_diffs(block_number)

db.insert_block(rpc.fetch_block_with_transactions(block_number))
db.insert_block(block)
for i, prestate in enumerate(prestates):
db.insert_prestate(block_number, i, prestate)
for i, state_diff in enumerate(state_diffs):
Expand Down

0 comments on commit 6e9f9fc

Please sign in to comment.