Skip to content

Commit

Permalink
python: Let chilldkg have its own DKGOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
real-or-random committed Jul 7, 2024
1 parent 8210949 commit 38c727f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,23 @@ public key.
- `ThresholdError` - If `1 <= t <= len(hostpubkeys)` does not hold.
- `OverflowError` - If `t >= 2^32` (so `t` cannot be serialized in 4 bytes).

#### DKGOutput Tuples

```python
class DKGOutput(NamedTuple):
secshare: Optional[bytes]
threshold_pubkey: bytes
pubshares: List[bytes]
```

Holds the outputs of a DKG session.

*Attributes*:

- `secshare` - Secret share of the participant (or `None` for coordinator)
- `threshold_pubkey` - Senerated threshold public key representing the group
- `pubshares` - Public shares of the participants

#### participant\_step1

```python
Expand Down
23 changes: 20 additions & 3 deletions python/chilldkg_ref/chilldkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from secp256k1ref.util import int_from_bytes, bytes_from_int

from .vss import VSS, VSSCommitment
from .simplpedpop import DKGOutput
from . import encpedpop
from .util import (
BIP_TAG,
Expand Down Expand Up @@ -271,6 +270,22 @@ def params_id(params: SessionParams) -> bytes:
return params_id


# This is really the same definition as in simplpedpop and encpedpop. We repeat
# it here only to have its docstring in this module.
class DKGOutput(NamedTuple):
"""Holds the outputs of a DKG session.
Attributes:
secshare: Secret share of the participant (or `None` for coordinator)
threshold_pubkey: Senerated threshold public key representing the group
pubshares: Public shares of the participants
"""

secshare: Optional[bytes]
threshold_pubkey: bytes
pubshares: List[bytes]


RecoveryData = NewType("RecoveryData", bytes)


Expand Down Expand Up @@ -429,12 +444,13 @@ def participant_step2(
(params, idx, enc_state) = state1
enc_cmsg, enc_secshares = cmsg1

dkg_output, eq_input = encpedpop.participant_step2(
enc_dkg_output, eq_input = encpedpop.participant_step2(
enc_state, hostseckey, enc_cmsg, 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.
eq_input += b"".join([bytes_from_int(int(share)) for share in enc_secshares])
dkg_output = DKGOutput._make(enc_dkg_output) # Convert to chilldkg.DKGOutput type
state2 = ParticipantState2(params, eq_input, dkg_output)
sig = certeq_participant_step(hostseckey, idx, eq_input)
pmsg2 = ParticipantMsg2(sig)
Expand Down Expand Up @@ -520,10 +536,11 @@ def coordinator_step1(
params_validate(params)
(hostpubkeys, t) = params

enc_cmsg, dkg_output, eq_input, enc_secshares = encpedpop.coordinator_step(
enc_cmsg, enc_dkg_output, eq_input, enc_secshares = encpedpop.coordinator_step(
[pmsg1.enc_pmsg for pmsg1 in pmsgs1], t, hostpubkeys
)
eq_input += b"".join([bytes_from_int(int(share)) for share in enc_secshares])
dkg_output = DKGOutput._make(enc_dkg_output) # Convert to chilldkg.DKGOutput type
state = CoordinatorState(params, eq_input, dkg_output)
cmsg1 = CoordinatorMsg1(enc_cmsg, enc_secshares)
return state, cmsg1
Expand Down
2 changes: 1 addition & 1 deletion python/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def simulate_encpedpop(seeds, t) -> List[Tuple[simplpedpop.DKGOutput, bytes]]:

def simulate_chilldkg(
seeds, t
) -> List[Tuple[simplpedpop.DKGOutput, chilldkg.RecoveryData]]:
) -> List[Tuple[chilldkg.DKGOutput, chilldkg.RecoveryData]]:
n = len(seeds)

hostpubkeys = []
Expand Down

0 comments on commit 38c727f

Please sign in to comment.