Skip to content

Commit 6842b7b

Browse files
committed
Add demo of attack on BA liveness
issue: amiller/HoneyBadgerBFT#59
1 parent 09fec40 commit 6842b7b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

test/demo_attack_issue59.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import random
2+
3+
import gevent
4+
from gevent.queue import Queue
5+
from pytest import mark
6+
7+
8+
@mark.demo
9+
def test_issue59_attack_demo(mocker, monkeypatch):
10+
from .byzantine import byz_ba_issue_59, broadcast_router
11+
from .test_binaryagreement import _make_coins
12+
from honeybadgerbft.core import binaryagreement
13+
14+
def mocked_conf_message_receiver(**kwargs):
15+
pass
16+
17+
def mocked_conf_phase_handler(**kwargs):
18+
return kwargs['values']
19+
20+
monkeypatch.setattr(
21+
binaryagreement, 'handle_conf_messages', mocked_conf_message_receiver)
22+
monkeypatch.setattr(
23+
binaryagreement, 'wait_for_conf_values', mocked_conf_phase_handler)
24+
25+
N = 4
26+
f = 1
27+
seed = None
28+
sid = 'sidA'
29+
rnd = random.Random(seed)
30+
sends, recvs = broadcast_router(N)
31+
threads = []
32+
inputs = []
33+
outputs = []
34+
35+
coins_seed = rnd.random()
36+
coins = _make_coins(sid+'COIN', N, f, coins_seed)
37+
38+
for i in range(4):
39+
inputs.append(Queue())
40+
outputs.append(Queue())
41+
42+
byz_thread = gevent.spawn(byz_ba_issue_59, sid, 3, N, f, coins[3],
43+
inputs[3].get, outputs[3].put_nowait, sends[3], recvs[3])
44+
threads.append(byz_thread)
45+
46+
for i in (2, 0, 1):
47+
t = gevent.spawn(binaryagreement.binaryagreement, sid, i, N, f, coins[i],
48+
inputs[i].get, outputs[i].put_nowait, sends[i], recvs[i])
49+
threads.append(t)
50+
51+
inputs[0].put(0) # A_0
52+
inputs[1].put(0) # A_1
53+
inputs[2].put(1) # B
54+
inputs[3].put(0) # F (x)
55+
56+
for i in range(N):
57+
outputs[i].get()

0 commit comments

Comments
 (0)