Skip to content

Commit

Permalink
dkg: ensure number of commitments (#2007)
Browse files Browse the repository at this point in the history
Addresses OBOL-01, closes #1999.

category: bug
ticket: #1999
  • Loading branch information
gsora authored and LukeHackett12 committed Apr 11, 2023
1 parent 46c6bb4 commit b40a61f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dkg/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func Run(ctx context.Context, conf Config) (err error) {
}
peerMap[p.ID] = nodeIdx
}
tp := newFrostP2P(tcpNode, peerMap, key)
tp := newFrostP2P(tcpNode, peerMap, key, def.Threshold)

log.Info(ctx, "Waiting to connect to all peers...")

Expand Down
13 changes: 10 additions & 3 deletions dkg/frostp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
)

// newFrostP2P returns a p2p frost transport implementation.
func newFrostP2P(tcpNode host.Host, peers map[peer.ID]cluster.NodeIdx, secret *k1.PrivateKey) *frostP2P {
func newFrostP2P(tcpNode host.Host, peers map[peer.ID]cluster.NodeIdx, secret *k1.PrivateKey, threshold int) *frostP2P {
var (
round1CastsRecv = make(chan *pb.FrostRound1Casts, len(peers))
round1P2PRecv = make(chan *pb.FrostRound1P2P, len(peers))
Expand Down Expand Up @@ -72,9 +72,16 @@ func newFrostP2P(tcpNode host.Host, peers map[peer.ID]cluster.NodeIdx, secret *k

for _, cast := range msg.Casts {
if int(cast.Key.SourceId) != peers[pID].ShareIdx {
return errors.New("invalid round 2 cast source ID")
return errors.New("invalid round 1 cast source ID")
} else if cast.Key.TargetId != 0 {
return errors.New("invalid round 2 cast target ID")
return errors.New("invalid round 1 cast target ID")
}

if len(cast.Commitments) != threshold {
return errors.New("invalid amount of commitments in round 1",
z.Int("received", len(cast.Commitments)),
z.Int("expected", threshold),
)
}
}

Expand Down

0 comments on commit b40a61f

Please sign in to comment.