Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nino #60

Open
wants to merge 45 commits into
base: dev
Choose a base branch
from
Open

nino #60

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d1e51ec
Don't check stanford certificate
Feb 5, 2022
f880357
Merge pull request #1 from 1337samuels/bugfix/fix_certificate_for_make
1337samuels Feb 5, 2022
35a429e
Added ImprovedHB for two nodes
tomerfri Feb 5, 2022
e17fb50
Runs our test, weird our_start.sh
1337samuels Feb 5, 2022
11c996e
Now really added our_start.sh
1337samuels Feb 5, 2022
0ce8e2e
Merge remote-tracking branch 'origin/feature/time_honeybadger_test' i…
tomerfri Feb 5, 2022
f41fe90
Use logs and test normally
1337samuels Feb 5, 2022
4054dad
Merge remote-tracking branch 'origin/feature/time_honeybadger_test' i…
tomerfri Feb 5, 2022
3272ff2
Amazing logging
1337samuels Feb 5, 2022
2baf481
Move files
1337samuels Feb 5, 2022
e5f31e1
Merge remote-tracking branch 'origin/feature/time_honeybadger_test' i…
tomerfri Feb 5, 2022
9fd838d
Correct log file name
1337samuels Feb 5, 2022
037cc6f
Remove redundant logs
1337samuels Feb 5, 2022
ab001df
Split tests
tomerfri Feb 5, 2022
9840722
Merge remote-tracking branch 'origin/feature/time_honeybadger_test' i…
tomerfri Feb 5, 2022
7cb8979
Revert print removals
1337samuels Feb 7, 2022
af7e5b9
Merge pull request #2 from 1337samuels/feature/time_honeybadger_test
1337samuels Feb 7, 2022
dc0f428
Merge branch 'dev' into improvedHB
1337samuels Feb 7, 2022
5a562e1
Initial commit, test 2 different node sizes
1337samuels Feb 7, 2022
e2f6abb
added permuted HB
tomerfri Feb 7, 2022
e525f70
Move HB logic to utils.py
1337samuels Feb 7, 2022
abcf8e2
added debug prints and removing messages from transaction_buffer
tomerfri Feb 7, 2022
bc97454
Updated params
1337samuels Feb 7, 2022
98fd39c
Finish tests
1337samuels Feb 7, 2022
4488cf2
Merge pull request #4 from 1337samuels/feature/test_different_params
1337samuels Feb 7, 2022
10d5cdd
merged params
tomerfri Feb 7, 2022
2851aea
Merge branch 'improvedHB' of https://github.com/1337samuels/HoneyBadg…
tomerfri Feb 7, 2022
5dea0d3
Merge branch 'improvedHB' into feature/permutedHB
tomerfri Feb 7, 2022
e96eb35
changed to sort lexicographically
tomerfri Feb 7, 2022
2b6fbb0
Tests run and have a meaning
1337samuels Feb 7, 2022
5e4c1a0
Store and log results properly
1337samuels Feb 7, 2022
a0df03b
Merge pull request #5 from 1337samuels/feature/permutedHB
1337samuels Feb 8, 2022
2458d25
Parametrized tests
1337samuels Feb 8, 2022
f462e38
Added analyze_results.py
1337samuels Feb 8, 2022
2770395
Change gevent use
doras100p Feb 9, 2022
4bd8221
Change gevent use
doras100p Feb 9, 2022
709c48a
Fixed hanging
doras100p Feb 9, 2022
8e7d575
Some impovements but nothing works
doras100p Feb 10, 2022
159c2b0
Update
doras100p Feb 14, 2022
76dc732
Merge pull request #7 from 1337samuels/debugStuc
1337samuels Feb 14, 2022
8363680
Merge pull request #6 from 1337samuels/feature/run_tests_seperately
1337samuels Feb 14, 2022
8c802e4
Run both tests
1337samuels Feb 14, 2022
d7d053b
All tests pass and are analyzed!
1337samuels Feb 14, 2022
b2fde9b
Merge pull request #8 from 1337samuels/feature/test_throughput
1337samuels Feb 21, 2022
ea1bf97
Merge pull request #3 from 1337samuels/improvedHB
1337samuels Feb 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
# IDE junk files
.idea/*
*.pyc
*~
#*#
tmp*
ec2/logs/*
ec2/logs_old/*
ec2/hosts
*_keys
*.keys

# Unit test / coverage reports
.cache
logs/
*__pycache__*
.coverage
.coverage.*
coverage.xml
htmlcov/
.pytest_cache

# Sphinx documentation
docs/_build/
*.pyc
important_logs/
backup_tests/
our_srcs/__pycache__/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENV B 16

RUN apt-get update && apt-get -y install bison flex libgmp-dev libmpc-dev

RUN wget https://crypto.stanford.edu/pbc/files/pbc-0.5.14.tar.gz
RUN wget --no-check-certificate https://crypto.stanford.edu/pbc/files/pbc-0.5.14.tar.gz
RUN tar -xvf pbc-0.5.14.tar.gz
RUN cd pbc-0.5.14 && ./configure && make && make install

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ If the above went all well, you should be setup for developing
## License
This is released under the CRAPL academic license. See ./CRAPL-LICENSE.txt
Other licenses may be issued at the authors' discretion.


### Our added documentation
# To watch log results being written live
```bash
grep -v DEBUG logs/`ls -t logs | head -n 1`
```
4 changes: 2 additions & 2 deletions experiments/honest_party_test_EC2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python
__author__ = 'aluex'
from gevent import monkey
from gevent import monkey, sleep
monkey.patch_all()

from gevent.queue import *
Expand Down Expand Up @@ -267,7 +267,7 @@ def toBeScheduled():
finally:
print "Consensus Finished"

s = sched.scheduler(time.time, time.sleep)
s = sched.scheduler(time.time, sleep)

time_now = time.time()
delay = options.delaytime - time_now
Expand Down
3 changes: 2 additions & 1 deletion experiments/run_local_tor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__author__ = 'aluex'

import subprocess32 as subprocess
from gevent import sleep
import time
def runOnTransaction(N, t, Tx):
retry = True
Expand All @@ -15,7 +16,7 @@ def runOnTransaction(N, t, Tx):
retry = False
except subprocess.TimeoutExpired:
retry = True
time.sleep(2)
sleep(2)
q = subprocess.check_output(['python', 'process.py', 'msglog.TorMultiple'])
print N, t, Tx, q.replace('\n', ' ')

Expand Down
2 changes: 2 additions & 0 deletions honeybadgerbft/core/binaryagreement.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from gevent import monkey
monkey.patch_all()
import gevent
from gevent.event import Event

Expand Down
5 changes: 5 additions & 0 deletions honeybadgerbft/core/commonsubset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from gevent import monkey
monkey.patch_all()
import gevent


from our_srcs.consts import *
from logging import getLogger; logger=getLogger(LOGGER_NAME)

def commonsubset(pid, N, f, rbc_out, aba_in, aba_out):
"""The BKR93 algorithm for asynchronous common subset.

Expand Down
88 changes: 74 additions & 14 deletions honeybadgerbft/core/honeybadger.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from collections import namedtuple
from enum import Enum

from gevent import monkey
monkey.patch_all()
import gevent
from gevent.queue import Queue
import hashlib
import random

from honeybadgerbft.core.commoncoin import shared_coin
from honeybadgerbft.core.binaryagreement import binaryagreement
from honeybadgerbft.core.reliablebroadcast import reliablebroadcast
from honeybadgerbft.core.commonsubset import commonsubset
from honeybadgerbft.core.honeybadger_block import honeybadger_block
from honeybadgerbft.exceptions import UnknownTagError
from our_srcs.consts import *
from logging import getLogger; logger=getLogger(LOGGER_NAME)


class BroadcastTag(Enum):
Expand Down Expand Up @@ -43,6 +48,8 @@ def broadcast_receiver_loop(recv_func, recv_queues):
broadcast_receiver(recv_func, recv_queues)




class HoneyBadgerBFT():
r"""HoneyBadgerBFT object used to run the protocol.

Expand All @@ -64,7 +71,7 @@ class HoneyBadgerBFT():
:param recv:
"""

def __init__(self, sid, pid, B, N, f, sPK, sSK, ePK, eSK, send, recv):
def __init__(self, sid, pid, B, N, f, sPK, sSK, ePK, eSK, send, recv, amount=-1):
self.sid = sid
self.pid = pid
self.B = B
Expand All @@ -76,19 +83,28 @@ def __init__(self, sid, pid, B, N, f, sPK, sSK, ePK, eSK, send, recv):
self.eSK = eSK
self._send = send
self._recv = recv
self.amount = amount

self.round = 0 # Current block number
self.transaction_buffer = []
self._per_round_recv = {} # Buffer of incoming messages
self.messages_seen = set()
self.bytes_sent = 0

def submit_tx(self, tx):
"""Appends the given transaction to the transaction buffer.

:param tx: Transaction to append to the buffer.
"""
print('submit_tx', self.pid, tx)
self.transaction_buffer.append(tx)

def get_bytes_sent(self):
"""Returns the ammount of non empty messages sent"""
return self.bytes_sent

def _prepare_transaction_buffer(self):
pass

def run(self):
"""Run the HoneyBadgerBFT protocol."""

Expand All @@ -113,15 +129,25 @@ def _recv():
# round and will stop participating!

self._recv_thread = gevent.spawn(_recv)

while True:
# For each round...
r = self.round
logger.debug(str(self.pid) + f" round number: {self.round}")
logger.debug(str(self.pid) + f" transaction buffer with len: {len(self.transaction_buffer)}")
if r not in self._per_round_recv:
self._per_round_recv[r] = Queue()

# Select all the transactions (TODO: actual random selection)
tx_to_send = self.transaction_buffer[:self.B]
self._prepare_transaction_buffer()
if len(self.transaction_buffer):
tx_to_send = self.transaction_buffer[:self.B]
logger.debug(str(self.pid) + f"Chosen tx_to_send for {self.pid} is {tx_to_send[0][:40]}")
for t in tx_to_send:
self.bytes_sent += len(t)

else:
tx_to_send = ['']
logger.debug(str(self.pid) + f"EEEEE transaction_buffer for id {self.pid}: {[t[:40] for t in self.transaction_buffer]}")

# TODO: Wait a bit if transaction buffer is not full

Expand All @@ -133,14 +159,21 @@ def _send(j, o):
send_r = _make_send(r)
recv_r = self._per_round_recv[r].get
new_tx = self._run_round(r, tx_to_send[0], send_r, recv_r)
print('new_tx:', new_tx)
for msg_recvd in new_tx:
if msg_recvd != b'':
logger.debug(str(self.pid) + f'Node id {self.pid} got from his friends: {msg_recvd[:40]}')
self.messages_seen.add(msg_recvd)

# Remove all of the new transactions from the buffer
self.transaction_buffer = [_tx for _tx in self.transaction_buffer if _tx not in new_tx]
self.transaction_buffer = [_tx for _tx in self.transaction_buffer if _tx not in [t.decode('utf-8') for t in new_tx] and _tx not in tx_to_send]
logger.debug(str(self.pid) + f"New transaction buffer after getting messages for id {self.pid}: {[t[:40] for t in self.transaction_buffer]}")

self.round += 1 # Increment the round
if self.round >= 3:
break # Only run one round for now
# if not self.transaction_buffer:
logger.debug(f"{self.pid} Up to now: {len(set(self.messages_seen))} out of {self.amount}")
if len(set(self.messages_seen)) == self.amount:
logger.debug(str(self.pid) + f" finished with rounds: {self.round}")
break

def _run_round(self, r, tx_to_send, send, recv):
"""Run one protocol round.
Expand Down Expand Up @@ -174,7 +207,6 @@ def broadcast(o):
rbc_outputs = [Queue(1) for _ in range(N)]

my_rbc_input = Queue(1)
print(pid, r, 'tx_to_send:', tx_to_send)

def _setup(j):
"""Setup the sub protocols RBC, BA and common coin.
Expand Down Expand Up @@ -222,30 +254,58 @@ def rbc_send(k, o):
# N instances of ABA, RBC
for j in range(N):
_setup(j)

# One instance of TPKE
def tpke_bcast(o):
"""Threshold encryption broadcast."""
broadcast(('TPKE', 0, o))

tpke_recv = Queue()

# One instance of ACS
acs = gevent.spawn(commonsubset, pid, N, f, rbc_outputs,
[_.put_nowait for _ in aba_inputs],
[_.get for _ in aba_outputs])

recv_queues = BroadcastReceiverQueues(
ACS_COIN=coin_recvs,
ACS_ABA=aba_recvs,
ACS_RBC=rbc_recvs,
TPKE=tpke_recv,
)
gevent.spawn(broadcast_receiver_loop, recv, recv_queues)

_input = Queue(1)
_input.put(tx_to_send)
return honeybadger_block(pid, self.N, self.f, self.ePK, self.eSK,
_input.get,
acs_in=my_rbc_input.put_nowait, acs_out=acs.get,
tpke_bcast=tpke_bcast, tpke_recv=tpke_recv.get)


def permute_list(lst, index):
return lst[index:] + lst[:index]

def sha256(s):
return hashlib.sha256(s.encode()).digest().hex()

def distance(frac):
def dist(s):
return abs(int((2**256) * frac) - int.from_bytes(hashlib.sha256(s.encode()).digest(), 'big'))
return dist

class ImprovedHoneyBadgerBFT(HoneyBadgerBFT):
def _prepare_transaction_buffer(self):
self.transaction_buffer = sorted(self.transaction_buffer, key=sha256, reverse=(self.pid%2 == 1))

class PermutedHoneyBadgerBFT(HoneyBadgerBFT):
def _prepare_transaction_buffer(self):
self.transaction_buffer = sorted(self.transaction_buffer, key=sha256)
self.transaction_buffer = permute_list(self.transaction_buffer, int((self.pid / self.N) * self.N))
logger.debug("permutating")

class RandomizedHoneyBadgerBFT(HoneyBadgerBFT):
def _prepare_transaction_buffer(self):
self.transaction_buffer = random.sample(self.transaction_buffer, len(self.transaction_buffer))

class DistanceHoneyBadgerBFT(HoneyBadgerBFT):
def _prepare_transaction_buffer(self):
self.transaction_buffer = sorted(self.transaction_buffer, key=distance(self.pid / self.N))
logger.debug("permutating with distance")

5 changes: 2 additions & 3 deletions honeybadgerbft/core/honeybadger_block.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from ..crypto.threshenc import tpke
import os
from our_srcs.consts import *
from logging import getLogger; logger=getLogger(LOGGER_NAME)


def serialize_UVW(U, V, W):
Expand Down Expand Up @@ -70,7 +72,6 @@ def honeybadger_block(pid, N, f, PK, SK, propose_in, acs_in, acs_out, tpke_bcast
share = SK.decrypt_share(*tkey)
# share is of the form: U_i, an element of group1
my_shares.append(share)

tpke_bcast(my_shares)

# Receive everyone's shares
Expand All @@ -82,7 +83,6 @@ def honeybadger_block(pid, N, f, PK, SK, propose_in, acs_in, acs_out, tpke_bcast
print('Received a duplicate decryption share from', j)
continue
shares_received[j] = shares

assert len(shares_received) >= f+1
# TODO: Accountability
# If decryption fails at this point, we will have evidence of misbehavior,
Expand All @@ -100,5 +100,4 @@ def honeybadger_block(pid, N, f, PK, SK, propose_in, acs_in, acs_out, tpke_bcast
plain = tpke.decrypt(key, ciph)
decryptions.append(plain)
# print 'Done!', decryptions

return tuple(decryptions)
7 changes: 4 additions & 3 deletions misc/includeTransaction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__author__ = 'aluex'

from gevent import Greenlet
from gevent import monkey
monkey.patch_all()
from gevent import Greenlet, sleep
from gevent.queue import Queue, Empty
from bkr_acs import acs
from utils import mylog, MonitoredInt, callBackWrap, greenletFunction, \
Expand Down Expand Up @@ -321,7 +322,7 @@ def listener():
broadcast(eval(msg)) # now the msg is something we mannually send
mylog("timestampB (%d, %lf)" % (pid, time.time()), verboseLevel=-2)
if len(transactionCache) < B: # Let's wait for many transactions. : )
time.sleep(0.5)
sleep(0.5)
print "Not enough transactions", len(transactionCache)
continue

Expand Down
Loading