-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfdry_weighted_sim_v3.py
More file actions
131 lines (113 loc) · 5.28 KB
/
Copy pathfdry_weighted_sim_v3.py
File metadata and controls
131 lines (113 loc) · 5.28 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""
v3: Supermajority model. Slash requires:
1. Minimum quorum of total FDRY-weighted feedback
2. >67% of weighted feedback is negative
"""
import numpy as np
np.random.seed(42)
FDRY_SUPPLY = 1_000_000
MONTHS = 24
def simulate(n_honest_ix=15, n_honest_con=100, n_atk=0, atk_type="",
atk_fdry=10000, routes_per=500, quorum=50000, supermajority=0.67):
agents = []
routes = []
rid = 0
ix_fdry = (FDRY_SUPPLY * 0.4) / n_honest_ix
con_fdry = (FDRY_SUPPLY * 0.3) / n_honest_con
for i in range(n_honest_ix):
agents.append({'id':i,'fdry':ix_fdry,'ix':True,'mal':False})
for _ in range(routes_per):
routes.append({'id':rid,'owner':i,'working':True}); rid+=1
for i in range(n_honest_con):
agents.append({'id':n_honest_ix+i,'fdry':con_fdry,'ix':False,'mal':False})
for i in range(n_atk):
aid = n_honest_ix+n_honest_con+i
is_ix = atk_type in ['self_inflate','cartel']
agents.append({'id':aid,'fdry':atk_fdry,'ix':is_ix,'mal':True})
if is_ix:
for _ in range(routes_per):
routes.append({'id':rid,'owner':aid,'working':True}); rid+=1
total_fdry = sum(a['fdry'] for a in agents)
atk_pct = sum(a['fdry'] for a in agents if a['mal'])/total_fdry*100
false_slashes = 0; honest_slashed = 0; legit_slashes = 0
for month in range(MONTHS):
for r in routes:
if r['working'] and np.random.random() < 0.0375:
r['working'] = False
# Honest maintain
for r in routes:
if not r['working']:
ix = next((a for a in agents if a['id']==r['owner']),None)
if ix and not ix['mal']: r['working']=True
for r in routes:
wpos=0.0; wneg=0.0
# Honest consumers
for a in agents:
if a['mal'] or a['ix']: continue
if np.random.random() < 150/len(routes):
if r['working']: wpos+=a['fdry']
else: wneg+=a['fdry']
# Honest indexers (not own)
for a in agents:
if a['mal'] or not a['ix'] or a['id']==r['owner']: continue
if np.random.random() < 60/len(routes):
if r['working']: wpos+=a['fdry']
else: wneg+=a['fdry']
# Attackers
for a in agents:
if not a['mal']: continue
if atk_type=="sabotage" and r['owner']==0:
wneg+=a['fdry']
elif atk_type=="self_inflate" and r['owner']==a['id']:
wpos+=a['fdry']
elif atk_type=="cartel":
if any(a2['mal'] and a2['id']==r['owner'] for a2 in agents):
wpos+=a['fdry']
elif r['owner']==0:
wneg+=a['fdry']
total_w = wpos+wneg
if total_w >= quorum and wneg/total_w >= supermajority:
ix = next((a for a in agents if a['id']==r['owner']),None)
if ix and ix['fdry']>0:
slash=0.01*ix['fdry']; ix['fdry']-=slash
if ix['mal']: pass
else:
honest_slashed+=slash
if r['working']: false_slashes+=1
else: legit_slashes+=1
quality = sum(1 for r in routes if r['working'])/len(routes)
return {'quality':quality,'false':false_slashes,'legit':legit_slashes,
'honest_lost':honest_slashed,'atk_pct':atk_pct}
def run(name,**kw):
r=simulate(**kw)
s="YES ⚠️" if r['false']>0 else "NO ✓"
print(f" {name:<50} q={r['quality']:.3f} false={r['false']:<5} legit={r['legit']:<5} "
f"honest_lost={r['honest_lost']:>8,.0f} atk={r['atk_pct']:.1f}% {s}")
print("="*110)
print("FDRY-WEIGHTED v3: SUPERMAJORITY MODEL")
print("Slash requires: quorum ≥ Q of total weighted feedback AND ≥67% negative")
print("="*110)
print(f"\nFDRY: 1M supply | 15 honest indexers (26.7K each) | 100 consumers (3K each)")
print("\n--- BASELINE ---")
run("Healthy equilibrium")
print("\n--- SABOTAGE (quorum=50K, supermajority=67%) ---")
run("1% saboteur (10K)",n_atk=1,atk_type="sabotage",atk_fdry=10000)
run("5% saboteur (50K)",n_atk=1,atk_type="sabotage",atk_fdry=50000)
run("20% saboteur (200K)",n_atk=1,atk_type="sabotage",atk_fdry=200000)
run("50% saboteur (500K)",n_atk=1,atk_type="sabotage",atk_fdry=500000)
print("\n--- CARTEL 3x (quorum=50K, supermajority=67%) ---")
run("3% cartel (10K each)",n_atk=3,atk_type="cartel",atk_fdry=10000)
run("15% cartel (50K each)",n_atk=3,atk_type="cartel",atk_fdry=50000)
run("30% cartel (100K each)",n_atk=3,atk_type="cartel",atk_fdry=100000)
print("\n--- SELF-INFLATE (quorum=50K, supermajority=67%) ---")
run("1% inflate (10K)",n_atk=1,atk_type="self_inflate",atk_fdry=10000)
run("20% inflate (200K)",n_atk=1,atk_type="self_inflate",atk_fdry=200000)
print("\n--- QUORUM SENSITIVITY (50K saboteur) ---")
for q in [10000,25000,50000,100000,200000]:
run(f"quorum={q:>7,}",n_atk=1,atk_type="sabotage",atk_fdry=50000,quorum=q)
print("\n--- SUPERMAJORITY SENSITIVITY (50K saboteur, quorum=50K) ---")
for sm in [0.51,0.60,0.67,0.75,0.80,0.90]:
run(f"supermajority={sm:.0%}",n_atk=1,atk_type="sabotage",atk_fdry=50000,supermajority=sm)
print("\n" + "="*110)
print("SUMMARY")
print("="*110)