Skip to content

Commit f966c04

Browse files
committed
add signing with tweak type
1 parent c0da8b1 commit f966c04

10 files changed

Lines changed: 608 additions & 1737 deletions

File tree

api/side/lending/query.pulsar.go

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

api/side/tss/tss.pulsar.go

Lines changed: 188 additions & 107 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/tss/tss.proto

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,22 @@ enum SigningStatus {
7272
enum SigningType {
7373
// SIGNING_TYPE_SCHNORR defines the common schnorr signing
7474
SIGNING_TYPE_SCHNORR = 0;
75+
// SIGNING_TYPE_SCHNORR_WITH_TWEAK defines the schnorr signing with tweak
76+
SIGNING_TYPE_SCHNORR_WITH_TWEAK = 1;
7577
// SIGNING_TYPE_SCHNORR_WITH_COMMITMENT defines the schnorr signing with commitment
76-
SIGNING_TYPE_SCHNORR_WITH_COMMITMENT = 1;
78+
SIGNING_TYPE_SCHNORR_WITH_COMMITMENT = 2;
7779
// SIGNING_TYPE_SCHNORR_ADAPTOR defines the schnorr adaptor signing
78-
SIGNING_TYPE_SCHNORR_ADAPTOR = 2;
80+
SIGNING_TYPE_SCHNORR_ADAPTOR = 3;
7981
}
8082

8183
// Signing Options
8284
message SigningOptions {
85+
// optional tweak
86+
string tweak = 1;
8387
// optional public nonce, i.e. commitment
84-
string nonce = 1;
88+
string nonce = 2;
8589
// optional adaptor point
86-
string adaptor_point = 2;
90+
string adaptor_point = 3;
8791
}
8892

8993
// Signing Request

x/lending/types/query.pb.go

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

x/liquidation/keeper/settlement.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (k Keeper) HandleSettlementSignatures(ctx sdk.Context, sender string, liqui
3535
}
3636

3737
dcmPubKey, _ := hex.DecodeString(liquidation.DCM)
38+
verificationKey := types.GetTaprootOutKey(dcmPubKey)
3839

3940
for i, input := range settlementTxPsbt.Inputs {
4041
sigHash, err := types.CalcTaprootSigHash(settlementTxPsbt, i, input.SighashType)
@@ -44,7 +45,7 @@ func (k Keeper) HandleSettlementSignatures(ctx sdk.Context, sender string, liqui
4445

4546
sigBytes, _ := hex.DecodeString(signatures[i])
4647

47-
if !schnorr.Verify(sigBytes, sigHash, dcmPubKey) {
48+
if !schnorr.Verify(sigBytes, sigHash, verificationKey) {
4849
return types.ErrInvalidSignature
4950
}
5051

x/liquidation/module/abci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ func handleCompletedLiquidations(ctx sdk.Context, k keeper.Keeper) {
5555
k.SetLiquidation(ctx, liquidation)
5656

5757
// initiate signing request via TSS
58-
k.TSSKeeper().InitiateSigningRequest(ctx, types.ModuleName, types.ToScopedId(liquidation.Id), tsstypes.SigningType_SIGNING_TYPE_SCHNORR, int32(types.SigningIntent_SIGNING_INTENT_DEFAULT), liquidation.DCM, sigHashes, nil)
58+
k.TSSKeeper().InitiateSigningRequest(ctx, types.ModuleName, types.ToScopedId(liquidation.Id), tsstypes.SigningType_SIGNING_TYPE_SCHNORR_WITH_TWEAK, int32(types.SigningIntent_SIGNING_INTENT_DEFAULT), liquidation.DCM, sigHashes, &tsstypes.SigningOptions{Tweak: ""})
5959
}
6060
}

x/liquidation/types/liquidation.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"strconv"
66
"strings"
77

8+
"github.com/btcsuite/btcd/btcec/v2/schnorr"
9+
"github.com/btcsuite/btcd/txscript"
10+
811
sdk "github.com/cosmos/cosmos-sdk/types"
912
)
1013

@@ -16,6 +19,16 @@ func GetPricePair(liquidation *Liquidation) string {
1619
return fmt.Sprintf("%s%s", strings.ToUpper(liquidation.CollateralAsset.PriceSymbol), strings.ToUpper(liquidation.DebtAsset.PriceSymbol))
1720
}
1821

22+
// GetTaprootOutKey gets the taproot output key according to the given pub key
23+
// Assume that the given pub key is valid taproot pub key
24+
func GetTaprootOutKey(pubKeyBytes []byte) []byte {
25+
pubKey, _ := schnorr.ParsePubKey(pubKeyBytes)
26+
27+
taprootOutKey := txscript.ComputeTaprootKeyNoScript(pubKey)
28+
29+
return schnorr.SerializePubKey(taprootOutKey)
30+
}
31+
1932
// ToScopedId converts the given local id to the scoped id
2033
func ToScopedId(id uint64) string {
2134
return fmt.Sprintf("%d", id)

x/tss/types/tss.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ func GetRefreshingCompletionSigMsg(id uint64, pubKeys []string) []byte {
9191
// Assume that the options match the signing type
9292
func GetSigningOption(signingType SigningType, options *SigningOptions) string {
9393
switch signingType {
94+
case SigningType_SIGNING_TYPE_SCHNORR_WITH_TWEAK:
95+
return options.Tweak
96+
9497
case SigningType_SIGNING_TYPE_SCHNORR_WITH_COMMITMENT:
9598
return options.Nonce
9699

x/tss/types/tss.pb.go

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

0 commit comments

Comments
 (0)