Skip to content

Commit

Permalink
Add TODOs from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
real-or-random committed Mar 20, 2024
1 parent 636fffd commit 519fc4e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions reference/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def chilldkg_finalize(
# TODO Make this a subroutine of chilldkg_finalize, which should output the backup.
# The backup must be written to permanent storage before using the dkg_output,
# so it should be coupled with dkg_finalize.
# TODO Fix Any type
def chilldkg_backup(state2: ChillDKGStateR2, cert: bytes) -> Any:
eta = state2[1]
return (eta, cert)
Expand All @@ -127,6 +128,8 @@ async def chilldkg(
chan.send(eq_round1)
cert = await chan.receive()
dkg_output = chilldkg_finalize(state2, cert)
# TODO We should probably not just return None here but raise instead.
# Raising a specific exception is also better for testing.
if dkg_output is None:
return None

Expand Down
2 changes: 2 additions & 0 deletions reference/secp256k1ref/ecdh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


def ecdh_raw(seckey: bytes, pubkey: bytes):
"""TODO"""
x = Scalar.from_bytes(seckey)
assert x != 0
Y = GE.from_bytes_compressed(pubkey)
Expand All @@ -13,5 +14,6 @@ def ecdh_raw(seckey: bytes, pubkey: bytes):


def ecdh_libsecp256k1(seckey: bytes, pubkey: bytes):
"""TODO"""
Z = ecdh_raw(seckey, pubkey)
return hashlib.sha256(Z.to_bytes_compressed().digest())
1 change: 1 addition & 0 deletions reference/secp256k1ref/secp256k1.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def sqrt(self):


class Scalar(APrimeFE):
"""TODO Docstring"""
SIZE = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141


Expand Down
15 changes: 7 additions & 8 deletions reference/simplpedpop.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,16 @@ def signer_pre_finalize(
for i in range(n):
if i == idx:
# No need to check our own pop.
# TODO Should we include a simple bytes comparison as defense-in-depth?
continue
if coms_to_secrets[i].infinity:
# TODO This branch can go away once we add real serializations.
# If the serialized pubkey is infinity, pop_verify will simply fail.
raise InvalidContributionError(i, "Participant sent invalid commitment")
else:
if not pop_verify(pops[i], coms_to_secrets[i].to_bytes_xonly(), i):
raise InvalidContributionError(
i, "Participant sent invalid proof-of-knowledge"
)
# This can be optimized: We serialize the coms_to_secrets[i] here, but
# pop_verify/schnorr_veriy will need to deserialize it again, which
# involves computing a square root to obtain the y coordinate.
if not pop_verify(pops[i], coms_to_secrets[i].to_bytes_xonly(), i):
raise InvalidContributionError(
i, "Participant sent invalid proof-of-knowledge"
)
vss_commitment = assemble_sum_vss_commitment(
coms_to_secrets, coms_to_nonconst_terms, t, n
)
Expand Down
2 changes: 2 additions & 0 deletions reference/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def kdf(seed: bytes, tag: str, extra_input: bytes = b"") -> bytes:
return tagged_hash_bip_dkg(tag + "KDF ", seed + extra_input)


# TODO Document in all functions what exceptions they can raise

class InvalidContributionError(Exception):
def __init__(self, signer, error):
self.signer = signer
Expand Down

0 comments on commit 519fc4e

Please sign in to comment.