Skip to content

Commit

Permalink
python: investigate error directly
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasnick committed Dec 18, 2024
1 parent ad4ae90 commit fe66c7a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 8 additions & 19 deletions python/chilldkg_ref/chilldkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
)

Expand Down
6 changes: 3 additions & 3 deletions python/chilldkg_ref/encpedpop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/chilldkg_ref/simplpedpop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion python/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions python/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit fe66c7a

Please sign in to comment.