Skip to content

Commit 64924a7

Browse files
committed
improve dkg completion
1 parent 8b3674a commit 64924a7

12 files changed

Lines changed: 447 additions & 440 deletions

File tree

api/side/btcbridge/btcbridge.pulsar.go

Lines changed: 72 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/side/btcbridge/tx.pulsar.go

Lines changed: 154 additions & 154 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/static/openapi.yml

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

proto/side/btcbridge/btcbridge.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ message DKGCompletionRequest {
168168
string sender = 2;
169169
// new vaults generated by DKG
170170
repeated string vaults = 3;
171-
// consensus address of the corresponding validator
172-
string consensus_address = 4;
173-
// hex encoded validator signature
171+
// participant consensus pub key
172+
string consensus_pubkey = 4;
173+
// hex encoded participant signature
174174
string signature = 5;
175175
}

proto/side/btcbridge/tx.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ message MsgCompleteDKG {
186186
uint64 id = 2;
187187
// new vaults generated by DKG
188188
repeated string vaults = 3;
189-
// consensus address of the corresponding validator
190-
string consensus_address = 4;
191-
// hex encoded validator signature
189+
// participant consensus pub key
190+
string consensus_pubkey = 4;
191+
// hex encoded participant signature
192192
string signature = 5;
193193
}
194194

x/btcbridge/keeper/msg_server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ func (m msgServer) CompleteDKG(goCtx context.Context, msg *types.MsgCompleteDKG)
298298
ctx := sdk.UnwrapSDKContext(goCtx)
299299

300300
req := &types.DKGCompletionRequest{
301-
Id: msg.Id,
302-
Sender: msg.Sender,
303-
Vaults: msg.Vaults,
304-
ConsensusAddress: msg.ConsensusAddress,
305-
Signature: msg.Signature,
301+
Id: msg.Id,
302+
Sender: msg.Sender,
303+
Vaults: msg.Vaults,
304+
ConsensusPubkey: msg.ConsensusPubkey,
305+
Signature: msg.Signature,
306306
}
307307

308308
if err := m.Keeper.CompleteDKG(ctx, req); err != nil {

x/btcbridge/keeper/tss.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package keeper
22

33
import (
44
"bytes"
5+
"encoding/base64"
56
"time"
67

78
"github.com/btcsuite/btcd/btcutil/psbt"
@@ -126,14 +127,14 @@ func (k Keeper) SetDKGCompletionRequest(ctx sdk.Context, req *types.DKGCompletio
126127
store := ctx.KVStore(k.storeKey)
127128

128129
bz := k.cdc.MustMarshal(req)
129-
store.Set(types.DKGCompletionRequestKey(req.Id, req.ConsensusAddress), bz)
130+
store.Set(types.DKGCompletionRequestKey(req.Id, req.ConsensusPubkey), bz)
130131
}
131132

132133
// HasDKGCompletionRequest returns true if the given completion request exists, false otherwise
133-
func (k Keeper) HasDKGCompletionRequest(ctx sdk.Context, id uint64, consAddress string) bool {
134+
func (k Keeper) HasDKGCompletionRequest(ctx sdk.Context, id uint64, consPubKey string) bool {
134135
store := ctx.KVStore(k.storeKey)
135136

136-
return store.Has(types.DKGCompletionRequestKey(id, consAddress))
137+
return store.Has(types.DKGCompletionRequestKey(id, consPubKey))
137138
}
138139

139140
// GetDKGCompletionRequests gets DKG completion requests by the given id
@@ -199,18 +200,18 @@ func (k Keeper) InitiateDKG(ctx sdk.Context, participants []*types.DKGParticipan
199200
}
200201

201202
// CompleteDKG completes the DKG request by the DKG participant
202-
// The DKG request will be completed when all participants submit the valid completion request before timeout
203+
// The DKG request will be finalized when all participants submit the valid completion request before timeout
203204
func (k Keeper) CompleteDKG(ctx sdk.Context, req *types.DKGCompletionRequest) error {
204205
dkgReq := k.GetDKGRequest(ctx, req.Id)
205206
if dkgReq == nil {
206207
return types.ErrDKGRequestDoesNotExist
207208
}
208209

209-
if !types.ParticipantExists(dkgReq.Participants, req.ConsensusAddress) {
210+
if !types.ParticipantExists(dkgReq.Participants, req.ConsensusPubkey) {
210211
return types.ErrUnauthorizedDKGCompletionRequest
211212
}
212213

213-
if k.HasDKGCompletionRequest(ctx, req.Id, req.ConsensusAddress) {
214+
if k.HasDKGCompletionRequest(ctx, req.Id, req.ConsensusPubkey) {
214215
return types.ErrDKGCompletionRequestExists
215216
}
216217

@@ -241,9 +242,11 @@ func (k Keeper) CompleteDKG(ctx sdk.Context, req *types.DKGCompletionRequest) er
241242
// return err
242243
// }
243244

244-
// if !types.VerifySignature(req.Signature, pubKey.Bytes(), req) {
245-
// return errorsmod.Wrap(types.ErrInvalidDKGCompletionRequest, "invalid signature")
246-
// }
245+
pubKey, _ := base64.StdEncoding.DecodeString(req.ConsensusPubkey)
246+
247+
if !types.VerifySignature(req.Signature, pubKey, req) {
248+
return errorsmod.Wrap(types.ErrInvalidDKGCompletionRequest, "invalid signature")
249+
}
247250

248251
k.SetDKGCompletionRequest(ctx, req)
249252

x/btcbridge/types/btcbridge.pb.go

Lines changed: 88 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x/btcbridge/types/keys.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@ func DKGRequestKey(id uint64) []byte {
106106
return append(DKGRequestKeyPrefix, sdk.Uint64ToBigEndian(id)...)
107107
}
108108

109-
func DKGCompletionRequestKey(id uint64, consAddress string) []byte {
110-
return append(append(DKGCompletionRequestKeyPrefix, sdk.Uint64ToBigEndian(id)...), []byte(consAddress)...)
109+
func DKGCompletionRequestKey(id uint64, consPubKey string) []byte {
110+
return append(append(DKGCompletionRequestKeyPrefix, sdk.Uint64ToBigEndian(id)...), []byte(consPubKey)...)
111111
}

x/btcbridge/types/msg_complete_dkg.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package types
22

33
import (
4+
"encoding/base64"
45
"encoding/hex"
56

67
errorsmod "cosmossdk.io/errors"
@@ -14,15 +15,15 @@ func NewMsgCompleteDKG(
1415
sender string,
1516
id uint64,
1617
vaults []string,
17-
consAddress string,
18+
consPubKey string,
1819
signature string,
1920
) *MsgCompleteDKG {
2021
return &MsgCompleteDKG{
21-
Sender: sender,
22-
Id: id,
23-
Vaults: vaults,
24-
ConsensusAddress: consAddress,
25-
Signature: signature,
22+
Sender: sender,
23+
Id: id,
24+
Vaults: vaults,
25+
ConsensusPubkey: consPubKey,
26+
Signature: signature,
2627
}
2728
}
2829

@@ -46,8 +47,13 @@ func (m *MsgCompleteDKG) ValidateBasic() error {
4647
vaults[v] = true
4748
}
4849

49-
if _, err := sdk.ConsAddressFromHex(m.ConsensusAddress); err != nil {
50-
return errorsmod.Wrap(ErrInvalidDKGCompletionRequest, "invalid consensus address")
50+
consensusPubKey, err := base64.StdEncoding.DecodeString(m.ConsensusPubkey)
51+
if err != nil {
52+
return errorsmod.Wrap(ErrInvalidDKGCompletionRequest, "failed to decode the consensus pub key")
53+
}
54+
55+
if len(consensusPubKey) != ed25519.PubKeySize {
56+
return errorsmod.Wrap(ErrInvalidDKGCompletionRequest, "incorrect consensus pub key size")
5157
}
5258

5359
sigBytes, err := hex.DecodeString(m.Signature)

0 commit comments

Comments
 (0)