Merge pull request #2591 from rlan35/audit_fixes

fix peckshield audit issues on slashing
pull/2605/head
Rongjian Lan 5 years ago committed by GitHub
commit 0fa21786f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      consensus/votepower/roster.go
  2. 16
      core/blockchain.go
  3. 3
      staking/apr/compute.go
  4. 7
      staking/slash/double-sign.go

@ -3,10 +3,11 @@ package votepower
import (
"encoding/hex"
"encoding/json"
"github.com/harmony-one/harmony/internal/utils"
"math/big"
"sort"
"github.com/harmony-one/harmony/internal/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/bls/ffi/go/bls"
common2 "github.com/harmony-one/harmony/internal/common"

@ -2039,12 +2039,24 @@ func (bc *BlockChain) AddPendingSlashingCandidates(
pendingSlashes := append(
bc.pendingSlashes, current.SetDifference(candidates)...,
)
if l, c := len(pendingSlashes), len(current); l > maxPendingSlashes {
state, err := bc.State()
if err != nil {
return err
}
valid := slash.Records{}
for i := range pendingSlashes {
if err := slash.Verify(bc, state, &pendingSlashes[i]); err == nil {
valid = append(valid, pendingSlashes[i])
}
}
if l, c := len(valid), len(current); l > maxPendingSlashes {
return errors.Wrapf(
errExceedMaxPendingSlashes, "current %d with-additional %d", c, l,
)
}
bc.pendingSlashes = pendingSlashes
bc.pendingSlashes = valid
return bc.writeSlashes(bc.pendingSlashes)
}

@ -1,9 +1,10 @@
package apr
import (
"math/big"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/shard"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/block"

@ -119,6 +119,7 @@ var (
errAlreadyBannedValidator = errors.New("cannot slash on already banned validator")
errSignerKeyNotRightSize = errors.New("bls keys from slash candidate not right side")
errSlashFromFutureEpoch = errors.New("cannot have slash from future epoch")
errSlashBlockNoConflict = errors.New("cannot slash for signing on non-conflicting blocks")
)
// MarshalJSON ..
@ -179,6 +180,10 @@ func Verify(
)
}
if first.ViewID != second.ViewID || first.Height != second.Height || first.BlockHeaderHash == second.BlockHeaderHash {
return errors.Wrapf(errSlashBlockNoConflict, "first %v+ second %v+", first, second)
}
if shard.CompareBlsPublicKey(first.SignerPubKey, second.SignerPubKey) != 0 {
k1, k2 := first.SignerPubKey.Hex(), second.SignerPubKey.Hex()
return errors.Wrapf(
@ -226,7 +231,7 @@ func Verify(
if err := signature.Deserialize(ballot.Signature); err != nil {
return err
}
if err := first.SignerPubKey.ToLibBLSPublicKey(publicKey); err != nil {
if err := ballot.SignerPubKey.ToLibBLSPublicKey(publicKey); err != nil {
return err
}

Loading…
Cancel
Save