Skip to content

Commit

Permalink
python: Document (hopefully) all exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
real-or-random committed Jul 8, 2024
1 parent 7ef2a0b commit cd353b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
19 changes: 14 additions & 5 deletions python/chilldkg_ref/chilldkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
###
### Exceptions
###
# TODO Document in all public functions what exceptions they can raise


class DuplicateHostpubkeyError(ValueError):
Expand Down Expand Up @@ -395,8 +394,8 @@ def participant_step1(
ValueError: If the participant's host public key is not in argument
`hostpubkeys`.
SeedError: If the length of `seed` is not 32 bytes.
InvalidContributionError(i,...): If `hostpubkeys[i]` is not a valid
public key.
InvalidContributionError: If `hostpubkeys[i]` is not a valid public key
for some `i`, which is indicated as part of the exception.
DuplicateHostpubkeyError: If `hostpubkeys` contains duplicates.
ThresholdError: If `1 <= t <= len(hostpubkeys)` does not hold.
OverflowError: If `t >= 2**32` (so `t` cannot be serialized in 4 bytes).
Expand Down Expand Up @@ -436,7 +435,17 @@ def participant_step2(
Raises:
SeedError: If the length of `seed` is not 32 bytes.
TODO
InvalidContributionError: If `cmsg1` is invalid. This can happen if
another participant has sent an invalid message to the coordinator,
or if the coordinator has sent an invalid `cmsg1`.
Further information is provided as part of the exception, including
a hint about which party might be to blame for the problem. The hint
should not be trusted and should only be only used for debugging. In
particular, the hint may point at the wrong party, e.g., if the
coodinator is malicious or network connections are unreliable, and
as a consquence, the caller should not conclude that the party
hinted at is malicious.
"""
(hostseckey, _) = hostkeypair(seed) # SeedError if len(seed) != 32
(params, idx, enc_state) = state1
Expand Down Expand Up @@ -489,7 +498,7 @@ def participant_finalize(
Raises:
SessionNotFinalizedError: If finalizing the DKG session was not
successful from this participant's point of view (see above).
successful from this participant's point of view (see above).
"""
(params, eq_input, dkg_output) = state2
certeq_verify(params.hostpubkeys, eq_input, cmsg2.cert) # SessionNotFinalizedError
Expand Down
2 changes: 1 addition & 1 deletion python/chilldkg_ref/simplpedpop.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def participant_step2(
t, n, idx, com_to_secret = state
coms_to_secrets, sum_coms_to_nonconst_terms, pops = cmsg

# TODO Raise InvalidContributionsError when deserizaltion yields wrong lengths
# TODO Raise InvalidContributionError when deserizaltion yields wrong lengths
assert len(coms_to_secrets) == n
assert len(sum_coms_to_nonconst_terms) == t - 1
assert len(pops) == n
Expand Down
2 changes: 0 additions & 2 deletions python/chilldkg_ref/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class ThresholdError(ValueError):


class InvalidContributionError(Exception):
"""TODO"""

def __init__(self, participant: Optional[int], error: str) -> None:
self.participant = participant
self.contrib = error

0 comments on commit cd353b5

Please sign in to comment.