11package keeper
22
33import (
4- "bytes"
5- "encoding/hex"
6-
7- "github.com/btcsuite/btcd/btcutil/psbt"
8-
94 errorsmod "cosmossdk.io/errors"
105 sdkmath "cosmossdk.io/math"
116 sdk "github.com/cosmos/cosmos-sdk/types"
127
13- "github.com/sideprotocol/side/bitcoin/crypto/schnorr"
148 "github.com/sideprotocol/side/x/lending/types"
159)
1610
1711// HandleLiquidationSignatures handles the liquidation signatures
12+ // Assume that signatures have already been verified
1813func (k Keeper ) HandleLiquidationSignatures (ctx sdk.Context , loanId string , signatures []string ) error {
1914 if ! k .HasLoan (ctx , loanId ) {
2015 return types .ErrLoanDoesNotExist
@@ -30,34 +25,14 @@ func (k Keeper) HandleLiquidationSignatures(ctx sdk.Context, loanId string, sign
3025 return types .ErrLiquidationSignaturesAlreadyExist
3126 }
3227
33- p , _ := psbt .NewFromRawBytes (bytes .NewReader ([]byte (dlcMeta .LiquidationCet .Tx )), true )
34- if len (signatures ) != len (p .Inputs ) {
35- return errorsmod .Wrap (types .ErrInvalidSignatures , "mismatched signature number" )
36- }
37-
38- script , _ := hex .DecodeString (dlcMeta .MultisigScript )
39- dcmPubKey , _ := hex .DecodeString (loan .DCM )
40-
41- for i , input := range p .Inputs {
42- sigHash , err := types .CalcTapscriptSigHash (p , i , input .SighashType , script )
43- if err != nil {
44- return err
45- }
46-
47- sigBytes , _ := hex .DecodeString (signatures [i ])
48-
49- if ! schnorr .Verify (sigBytes , sigHash , dcmPubKey ) {
50- return types .ErrInvalidSignature
51- }
52- }
53-
5428 dlcMeta .LiquidationCet .DCMSignatures = signatures
5529 k .SetDLCMeta (ctx , loanId , dlcMeta )
5630
5731 return nil
5832}
5933
6034// handleDefaultLiquidationSignatures handles the default liquidation signatures
35+ // Assume that signatures have already been verified
6136func (k Keeper ) handleDefaultLiquidationSignatures (ctx sdk.Context , loanId string , signatures []string ) error {
6237 if ! k .HasLoan (ctx , loanId ) {
6338 return types .ErrLoanDoesNotExist
@@ -73,27 +48,6 @@ func (k Keeper) handleDefaultLiquidationSignatures(ctx sdk.Context, loanId strin
7348 return types .ErrLiquidationSignaturesAlreadyExist
7449 }
7550
76- p , _ := psbt .NewFromRawBytes (bytes .NewReader ([]byte (dlcMeta .DefaultLiquidationCet .Tx )), true )
77- if len (signatures ) != len (p .Inputs ) {
78- return errorsmod .Wrap (types .ErrInvalidSignatures , "mismatched signature number" )
79- }
80-
81- script , _ := hex .DecodeString (dlcMeta .MultisigScript )
82- dcmPubKey , _ := hex .DecodeString (loan .DCM )
83-
84- for i , input := range p .Inputs {
85- sigHash , err := types .CalcTapscriptSigHash (p , i , input .SighashType , script )
86- if err != nil {
87- return err
88- }
89-
90- sigBytes , _ := hex .DecodeString (signatures [i ])
91-
92- if ! schnorr .Verify (sigBytes , sigHash , dcmPubKey ) {
93- return types .ErrInvalidSignature
94- }
95- }
96-
9751 dlcMeta .DefaultLiquidationCet .DCMSignatures = signatures
9852 k .SetDLCMeta (ctx , loanId , dlcMeta )
9953
0 commit comments