def serialized_tbls_public_key_dict(tbls_public_key): from honeybadgermpc.broadcast.crypto.boldyreva import serialize return { "l": tbls_public_key.l, "k": tbls_public_key.k, "VK": serialize(tbls_public_key.VK), "VKs": [serialize(vk) for vk in tbls_public_key.VKs], }
async def get_coin(round): """Gets a coin. :param round: the epoch/round. :returns: a coin. """ # I have to do mapping to 1..l h = pk.hash_message(str((sid, round))) logger.debug( f"[{pid}] broadcast {('COIN', round, sk.sign(h))}", extra={ "nodeid": pid, "epoch": round }, ) broadcast(("COIN", round, serialize(sk.sign(h)))) return await output_queue[round].get()
async def _recv(): while True: # main receive loop logger.debug(f"[{pid}] entering loop", extra={ "nodeid": pid, "epoch": "?" }) # New shares for some round r, from sender i (i, (_, r, sig_bytes)) = await receive() sig = deserialize1(sig_bytes) logger.debug( f"[{pid}] received i, _, r, sig: {i, _, r, sig}", extra={ "nodeid": pid, "epoch": r }, ) assert i in range(n) assert r >= 0 if i in received[r]: logger.error(f"redundant coin sig received {(sid, pid, i, r)}") continue h = pk.hash_message(str((sid, r))) # TODO: Accountability: Optimistically skip verifying # each share, knowing evidence available later try: pk.verify_share(sig, i, h) except AssertionError: logger.error(f"Signature share failed! {(sid, pid, i, r)}") continue received[r][i] = sig # After reaching the threshold, compute the output and # make it available locally logger.debug( f"[{pid}] if len(received[r]) == f + 1: {len(received[r]) == f + 1}", extra={ "nodeid": pid, "epoch": r }, ) if len(received[r]) == f + 1: # Verify and get the combined signature sigs = dict(list(received[r].items())[:f + 1]) sig = pk.combine_shares(sigs) assert pk.verify_signature(sig, h) # Compute the bit from the least bit of the hash bit = hash(serialize(sig))[0] % 2 logger.debug( f"[{pid}] put bit {bit} in output queue", extra={ "nodeid": pid, "epoch": r }, ) output_queue[r].put_nowait(bit)