Skip to content

Commit

Permalink
chore: fixing the handling equivocated votes (ethereum-optimism#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis authored Aug 7, 2023
1 parent 8644ca7 commit e6bdb89
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions service/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"sync"
"sync/atomic"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/lightningnetwork/lnd/signal"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -146,29 +145,28 @@ func (r *rpcServer) AddFinalitySignature(ctx context.Context, req *proto.AddFina
return nil, err
}

var localPrivKey *btcec.PrivateKey
res := &proto.AddFinalitySignatureResponse{TxHash: txHash}

// if privKey is not empty, then this BTC validator
// has voted for a fork and will be slashed
if privKey != nil {
localPrivKey, err = r.app.getBtcPrivKey(v.KeyName)
res.ExtractedSkHex = privKey.Key.String()

localPrivKey, err := r.app.getBtcPrivKey(v.KeyName)
if err != nil {
return nil, err
}
}

res := &proto.AddFinalitySignatureResponse{
TxHash: txHash,
ExtractedSkHex: privKey.Key.String(),
}

localSkHex := localPrivKey.Key.String()
localSkNegateHex := localPrivKey.Key.Negate().String()
if res.ExtractedSkHex == localSkHex {
res.LocalSkHex = localSkHex
} else if res.ExtractedSkHex == localSkNegateHex {
res.LocalSkHex = localSkNegateHex
} else {
return nil, fmt.Errorf("the validator's BTC private key is extracted but does not match the local key,"+
"extrated: %s, local: %s, local-negated: %s",
res.ExtractedSkHex, localSkHex, localSkNegateHex)
localSkHex := localPrivKey.Key.String()
localSkNegateHex := localPrivKey.Key.Negate().String()
if res.ExtractedSkHex == localSkHex {
res.LocalSkHex = localSkHex
} else if res.ExtractedSkHex == localSkNegateHex {
res.LocalSkHex = localSkNegateHex
} else {
return nil, fmt.Errorf("the validator's BTC private key is extracted but does not match the local key,"+
"extrated: %s, local: %s, local-negated: %s",
res.ExtractedSkHex, localSkHex, localSkNegateHex)
}
}

return res, nil
Expand Down

0 comments on commit e6bdb89

Please sign in to comment.