Skip to content

Commit 24ac038

Browse files
committed
improve participant field
1 parent afa021e commit 24ac038

File tree

7 files changed

+231
-202
lines changed

7 files changed

+231
-202
lines changed

api/side/btcbridge/btcbridge.pulsar.go

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

proto/side/btcbridge/btcbridge.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ message DKGParticipant {
123123
string moniker = 1;
124124
// the operator address of the corresponding validator
125125
string operator_address = 2;
126-
// the consensus address of the corresponding validator
127-
string consensus_address = 3;
126+
// the consensus public key of the corresponding validator
127+
string consensus_pubkey = 3;
128128
}
129129

130130
enum DKGRequestStatus {

x/btcbridge/keeper/tss.go

Lines changed: 13 additions & 2 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"
@@ -169,13 +170,23 @@ func (k Keeper) IterateDKGCompletionRequests(ctx sdk.Context, id uint64, cb func
169170
// InitiateDKG initiates the DKG request by the specified params
170171
func (k Keeper) InitiateDKG(ctx sdk.Context, participants []*types.DKGParticipant, threshold uint32, vaultTypes []types.AssetType, enableTransfer bool, targetUtxoNum uint32) (*types.DKGRequest, error) {
171172
for _, p := range participants {
172-
consAddress, _ := sdk.ConsAddressFromHex(p.ConsensusAddress)
173+
valAddr, _ := sdk.ValAddressFromBech32(p.OperatorAddress)
173174

174-
validator, err := k.stakingKeeper.GetValidatorByConsAddr(ctx, consAddress)
175+
validator, err := k.stakingKeeper.GetValidator(ctx, valAddr)
175176
if err != nil {
176177
return nil, errorsmod.Wrap(types.ErrInvalidDKGParams, "non validator")
177178
}
178179

180+
pubKey, err := validator.ConsPubKey()
181+
if err != nil {
182+
return nil, err
183+
}
184+
185+
pubKeyBytes, _ := base64.StdEncoding.DecodeString(p.ConsensusPubkey)
186+
if !bytes.Equal(pubKeyBytes, pubKey.Bytes()) {
187+
errorsmod.Wrap(types.ErrInvalidDKGParams, "incorrect consensus public key")
188+
}
189+
179190
if validator.Status != stakingtypes.Bonded {
180191
return nil, errorsmod.Wrap(types.ErrInvalidDKGParams, "validator not bonded")
181192
}

x/btcbridge/types/btcbridge.pb.go

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

x/btcbridge/types/expected_keepers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ type BankKeeper interface {
3636

3737
// StakingKeeper defines the expected staking keeper used to retrieve validator (noalias)
3838
type StakingKeeper interface {
39+
GetValidator(ctx context.Context, addr sdk.ValAddress) (stakingtypes.Validator, error)
3940
GetValidatorByConsAddr(ctx context.Context, consAddr sdk.ConsAddress) (stakingtypes.Validator, error)
4041
}

x/btcbridge/types/msg_initiate_dkg.go

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

33
import (
4+
"encoding/base64"
5+
46
errorsmod "cosmossdk.io/errors"
7+
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
58
sdk "github.com/cosmos/cosmos-sdk/types"
69
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
710
)
@@ -29,15 +32,15 @@ func (m *MsgInitiateDKG) ValidateBasic() error {
2932
return errorsmod.Wrap(err, "invalid operator address")
3033
}
3134

32-
if _, err := sdk.ConsAddressFromHex(p.ConsensusAddress); err != nil {
33-
return errorsmod.Wrap(err, "invalid consensus address")
35+
if pubKey, err := base64.StdEncoding.DecodeString(p.ConsensusPubkey); err != nil || len(pubKey) != ed25519.PubKeySize {
36+
return errorsmod.Wrap(err, "invalid consensus public key")
3437
}
3538

36-
if participants[p.ConsensusAddress] {
39+
if participants[p.ConsensusPubkey] {
3740
return errorsmod.Wrap(ErrInvalidDKGParams, "duplicate participant")
3841
}
3942

40-
participants[p.ConsensusAddress] = true
43+
participants[p.ConsensusPubkey] = true
4144
}
4245

4346
if len(m.VaultTypes) == 0 {

x/btcbridge/types/tss.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,30 @@ package types
22

33
import (
44
"crypto/ed25519"
5+
"encoding/base64"
56
"encoding/binary"
67
"encoding/hex"
78
"reflect"
89

910
"github.com/cometbft/cometbft/crypto"
11+
"github.com/cometbft/cometbft/crypto/tmhash"
1012
)
1113

14+
// MustGetConsensusAddr gets the hex-encoded consensus address from the given consensus public key
15+
// Panic if any error occurs
16+
func MustGetConsensusAddr(consPubKey string) string {
17+
pubKey, err := base64.StdEncoding.DecodeString(consPubKey)
18+
if err != nil {
19+
panic(err)
20+
}
21+
22+
return hex.EncodeToString(tmhash.SumTruncated(pubKey))
23+
}
24+
1225
// ParticipantExists returns true if the given address is a participant, false otherwise
1326
func ParticipantExists(participants []*DKGParticipant, consAddress string) bool {
1427
for _, p := range participants {
15-
if p.ConsensusAddress == consAddress {
28+
if MustGetConsensusAddr(p.ConsensusPubkey) == consAddress {
1629
return true
1730
}
1831
}

0 commit comments

Comments
 (0)