From fe66c7a27e6bdc23d067520208ffefef7a6ed38d Mon Sep 17 00:00:00 2001 From: Jonas Nick Date: Wed, 18 Dec 2024 13:36:33 +0000 Subject: [PATCH] python: investigate error directly --- README.md | 2 +- python/chilldkg_ref/chilldkg.py | 27 ++++++++------------------- python/chilldkg_ref/encpedpop.py | 6 +++--- python/chilldkg_ref/simplpedpop.py | 4 ++-- python/example.py | 2 +- python/tests.py | 6 +++--- 6 files changed, 18 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 025c6ea..197e930 100644 --- a/README.md +++ b/README.md @@ -966,7 +966,7 @@ recovery data to this participant. #### participant\_investigate ```python -def participant_investigate(blame_state: ParticipantBlameState, cinvestigation: CoordinatorInvestigationMsg) -> NoReturn +def participant_investigate(error: UnknownFaultyParticipantOrCoordinatorError, cinvestigation: CoordinatorInvestigationMsg) -> NoReturn ``` Perform a participant's blame step of a ChillDKG session. TODO diff --git a/python/chilldkg_ref/chilldkg.py b/python/chilldkg_ref/chilldkg.py index 5086995..501725c 100644 --- a/python/chilldkg_ref/chilldkg.py +++ b/python/chilldkg_ref/chilldkg.py @@ -424,10 +424,6 @@ class ParticipantState2(NamedTuple): dkg_output: DKGOutput -class ParticipantBlameState(NamedTuple): - enc_blame_state: encpedpop.ParticipantBlameState - - def participant_step1( hostseckey: bytes, params: SessionParams, random: bytes ) -> Tuple[ParticipantState1, ParticipantMsg1]: @@ -526,19 +522,12 @@ def participant_step2( params, idx, enc_state = state1 enc_cmsg, enc_secshares = cmsg1 - try: - enc_dkg_output, eq_input = encpedpop.participant_step2( - state=enc_state, - deckey=hostseckey, - cmsg=enc_cmsg, - enc_secshare=enc_secshares[idx], - ) - except UnknownFaultyParticipantOrCoordinatorError as e: - # Convert from encpedpop.ParticipantBlameState into - # chilldkg.ParticipantBlameState. - assert isinstance(e.blame_state, encpedpop.ParticipantBlameState) - blame_state = ParticipantBlameState(e.blame_state) - raise UnknownFaultyParticipantOrCoordinatorError(blame_state, e.args) from e + enc_dkg_output, eq_input = encpedpop.participant_step2( + state=enc_state, + deckey=hostseckey, + cmsg=enc_cmsg, + enc_secshare=enc_secshares[idx], + ) # Include the enc_shares in eq_input to ensure that participants agree on # all shares, which in turn ensures that they have the right recovery data. @@ -601,12 +590,12 @@ def participant_finalize( def participant_investigate( - blame_state: ParticipantBlameState, + error: UnknownFaultyParticipantOrCoordinatorError, cinvestigation: CoordinatorInvestigationMsg, ) -> NoReturn: """Perform a participant's blame step of a ChillDKG session. TODO""" encpedpop.participant_investigate( - blame_state=blame_state.enc_blame_state, + error=error, cinvestigation=cinvestigation.enc_cinvestigation, ) diff --git a/python/chilldkg_ref/encpedpop.py b/python/chilldkg_ref/encpedpop.py index 14dca85..8d71579 100644 --- a/python/chilldkg_ref/encpedpop.py +++ b/python/chilldkg_ref/encpedpop.py @@ -243,10 +243,10 @@ def participant_step2( def participant_investigate( - blame_state: ParticipantBlameState, + error: UnknownFaultyParticipantOrCoordinatorError, cinvestigation: CoordinatorInvestigationMsg, ) -> NoReturn: - simpl_blame_state, enc_secshare, pads = blame_state + simpl_blame_state, enc_secshare, pads = error.blame_state enc_partial_secshares, partial_pubshares = cinvestigation assert len(enc_partial_secshares) == len(pads) partial_secshares = [ @@ -257,7 +257,7 @@ def participant_investigate( simpl_cinvestigation = simplpedpop.CoordinatorInvestigationMsg(partial_pubshares) try: simplpedpop.participant_investigate( - simpl_blame_state, simpl_cinvestigation, partial_secshares + UnknownFaultyParticipantOrCoordinatorError(simpl_blame_state), simpl_cinvestigation, partial_secshares ) except simplpedpop.SecshareSumError as e: # The secshare is not equal to the sum of the partial secshares in the diff --git a/python/chilldkg_ref/simplpedpop.py b/python/chilldkg_ref/simplpedpop.py index 1ef9888..ee2f6d3 100644 --- a/python/chilldkg_ref/simplpedpop.py +++ b/python/chilldkg_ref/simplpedpop.py @@ -226,11 +226,11 @@ def participant_step2( def participant_investigate( - blame_state: ParticipantBlameState, + error: UnknownFaultyParticipantOrCoordinatorError, cinvestigation: CoordinatorInvestigationMsg, partial_secshares: List[Scalar], ) -> NoReturn: - n, idx, secshare, secshare_tweak, pubshare = blame_state + n, idx, secshare, secshare_tweak, pubshare = error.blame_state partial_pubshares = cinvestigation.partial_pubshares if GE.sum(*partial_pubshares) + secshare_tweak * G != pubshare: diff --git a/python/example.py b/python/example.py index 42a9c62..697a027 100755 --- a/python/example.py +++ b/python/example.py @@ -101,7 +101,7 @@ async def participant( state2, eq_round1 = participant_step2(hostseckey, state1, cmsg1) except UnknownFaultyParticipantOrCoordinatorError as e: if blame_mode: - participant_investigate(e.blame_state, cblame) + participant_investigate(e, cblame) else: # If this participant does not support blame mode, it cannot # determine which party is faulty. Re-raise UnknownFaultyPartyError diff --git a/python/tests.py b/python/tests.py index e3f696b..535a813 100755 --- a/python/tests.py +++ b/python/tests.py @@ -116,7 +116,7 @@ def simulate_simplpedpop( assert len(investigation_msgs) == len(pmsgs) try: simplpedpop.participant_investigate( - e.blame_state, investigation_msgs[i], partial_secshares + e, investigation_msgs[i], partial_secshares ) # If we're not faulty, we should blame the faulty party. except FaultyParticipantOrCoordinatorError as e: @@ -175,7 +175,7 @@ def simulate_encpedpop( investigation_msgs = encpedpop.coordinator_investigate(pmsgs) assert len(investigation_msgs) == len(pmsgs) try: - encpedpop.participant_investigate(e.blame_state, investigation_msgs[i]) + encpedpop.participant_investigate(e, investigation_msgs[i]) # If we're not faulty, we should blame the faulty party. except FaultyParticipantOrCoordinatorError as e: assert i != faulty_idx[i] @@ -224,7 +224,7 @@ def simulate_chilldkg( investigation_msgs = chilldkg.coordinator_investigate(pmsgs) assert len(investigation_msgs) == len(pmsgs) try: - chilldkg.participant_investigate(e.blame_state, investigation_msgs[i]) + chilldkg.participant_investigate(e, investigation_msgs[i]) # If we're not faulty, we should blame the faulty party. except FaultyParticipantOrCoordinatorError as e: assert i != faulty_idx[i]