-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtool_create_bruteforce.py
70 lines (62 loc) · 2.42 KB
/
tool_create_bruteforce.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import argparse
import sys
from web3 import Web3
from utils import get_profile, init_log, say
from tx import send_transaction, confirm_transactions
from evm_table import all_bytecode_combinations
ap = argparse.ArgumentParser()
ap.add_argument('-p', '--profile', required=True, help="Profile to use")
ap.add_argument('-e', '--eth', required=True, help="Eth to fund each sender")
ap.add_argument('-c', '--confirm', required=True, help="N txs to confirm")
ap.add_argument(
'-f', '--from', required=False, default=None,
help="Start from that bytecode")
ap.add_argument(
'-t', '--to', required=False, default=None, help="End on that bytecode")
args = vars(ap.parse_args())
node_url, chain_id, funded_key, bridge_ep, bridge_addr, l1_ep, \
l1_funded_key, _ = \
get_profile(args['profile'])
init_log(args['profile'], tool='bruteforce')
w = Web3(Web3.HTTPProvider(node_url))
sender = w.eth.account.from_key(str(funded_key))
eth_amount = int(args['eth'])
confirm_each = int(args['confirm'])
_from = args['from']
_to = args['to']
account = w.eth.account.create()
tx_hashes = send_transaction(
ep=node_url, sender_key=funded_key, eth_amount=eth_amount,
receiver_address=account.address, wait='last'
)
say(f"Created account, address={account.address} and balance={eth_amount}ETH")
nonce = 0
for i in range(1, 4):
bytecodes = all_bytecode_combinations(i, start=_from, end=_to)
print(f"Number of bytecodes with {i} byte(s): {len(bytecodes)}")
n_txs = 0
for data in bytecodes:
tx_hashes = send_transaction(
ep=node_url, sender_key=account.key.hex(), gas=299999, data=data,
sc_create=True, wait=False, nonce=nonce
)
# say(f"Transaction with data={data} and nonce={nonce} sent")
n_txs += 1
if n_txs and (n_txs % confirm_each == 0):
receipts = \
confirm_transactions(
ep=node_url, tx_hashes=tx_hashes, timeout=120)
if receipts:
block = int(receipts[0].get('blockNumber'), 16)
status = int(receipts[0].get('status'), 16)
say(
f"Mined tx data={data} nonce={nonce} "
f"block={block} status={status}"
)
else:
say(
f"ERROR: Transaction with data {data} and nonce {nonce} "
"not confirmed"
)
sys.exit(1)
nonce += 1