forked from jonahar/lightning-systemic-attack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_attack_simulation_scripts.py
63 lines (54 loc) · 2.09 KB
/
generate_attack_simulation_scripts.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
import json
import os
from commands_generator.commands_generator import generate_attack_file
from paths import LN
num_sending_nodes = 10
num_receiving_nodes = num_sending_nodes
num_victims = 10
blockmaxweight = 4_000_000
simulation_num = 1
payments_per_channel = int(483 * 2) # increase number of payments a little bit because some payments randomly fail
num_channels = num_sending_nodes * num_victims
script_name = f"steal-attack-{num_channels}-channels-blockmaxweight={blockmaxweight}"
# first we generate topology. sending-node ids start with 1, receiving-node ids
# start with 3, victim ids start with 4 (only a convention we use here, not required)
sending_node_ids = [f"1{i}" for i in range(1, num_sending_nodes + 1)]
receiving_node_ids = [f"3{i}" for i in range(1, num_receiving_nodes + 1)]
victim_node_ids = [f"4{i}" for i in range(1, num_victims + 1)]
topology = {}
for sending_node_id in sending_node_ids:
topology[sending_node_id] = {
"client": "c-lightning",
"evil": True,
"peers": victim_node_ids,
"type": "attacker-sending",
}
for receiving_node_id in receiving_node_ids:
topology[receiving_node_id] = {
"client": "c-lightning",
"evil": True,
"peers": [],
"type": "attacker-receiving",
}
for victim_node_id in victim_node_ids:
topology[victim_node_id] = {
"client": "lnd",
"peers": receiving_node_ids,
"type": "victim",
}
topology_filename = f"topology-{num_sending_nodes}-{num_victims}-{num_receiving_nodes}.json"
topology_fullpath = os.path.join(LN, "topologies", topology_filename)
with open(topology_fullpath, mode="w") as f:
json.dump(topology, f, sort_keys=True, indent=4)
outfile = os.path.join(LN, "simulations", f"{script_name}.sh")
datadir = os.path.join(LN, "simulations", f"{script_name}")
generate_attack_file(
topology_file=topology_fullpath,
simulation_number=simulation_num,
bitcoin_blockmaxweight=blockmaxweight,
payments_per_channel=payments_per_channel,
amount_msat=11000000,
datadir=datadir,
block_time_sec=300, # 5 minutes
outfile=outfile,
)