[staking][validation][protocol] (#2396)
* [staking][validation][protocol] Limit max bls keys * [staking-era] Fold banned and active into single field * [slash][effective] Remove LRU cache for slash, change .Active to enumeration * [slash] Remove leftover wrong usage of Logger * [slash][offchain] Only Decode if len > 0 * [offchain] cosmetic * [slash] Remove some logs in proposal * [webhook] Move webhook with call for when cannot commit block * [shard] Finally make finding subcommittee by shardID an explicit error * [node] Whitespace, prefer literal * [webhook] Report bad block to webhook * [slash] Expand verify, remove bad log usage, explicit error handle * [slash] Check on key size * [slash] Explicit upper bound of pending slashes * [slash] Use right epoch snapshot, fail to verify if epoch wrong on beaconchain * [multibls] Make max count allowed be 1/3 of external slots * [quorum] Remove bad API of ShardIDProvider, factor out committee key as method of committee * [verify] Begin factor out of common verification approach * [project] Further remove RawJSON log, use proper epoch for snapshot * [slash] Implement verification * [slash] Implement BLS key verification of ballots * [rpc] Keep validator information as meaningful as possible * [staking] Never can stop being banned * [slash] Comments and default Unknown case of eligibility * [slash] Be explicit on what input values allowed when want to change EPOSStatus * [consensus] Remove unneeded TODO * [verify] Add proper error message * [rpc] Give back to caller their wrong chain id * [chain] Add extra map dump of delegation sizing for downstream analysis * [engine] Less code, more methods * [offchain] More leniency in handling slash bytes and delete from pending * [validator] Remove errors on bad input for editpull/2454/head
parent
304cf10007
commit
2baab4864c
@ -1,10 +1,22 @@ |
|||||||
package effective |
package effective |
||||||
|
|
||||||
import ( |
// Eligibility represents ability to participate in EPoS auction
|
||||||
staking "github.com/harmony-one/harmony/staking/types" |
// that occurs just once an epoch on beaconchain
|
||||||
) |
type Eligibility byte |
||||||
|
|
||||||
// IsEligibleForEPOSAuction ..
|
const ( |
||||||
func IsEligibleForEPOSAuction(v *staking.ValidatorWrapper) bool { |
// Nil is a default state that represents a no-op
|
||||||
return v.Active && !v.Banned |
Nil Eligibility = iota |
||||||
} |
// Active means allowed in epos auction
|
||||||
|
Active |
||||||
|
// Inactive means validator did not sign enough over 66%
|
||||||
|
// of the time in an epoch and so they are removed from
|
||||||
|
// the possibility of being in the epos auction, which happens
|
||||||
|
// only once an epoch and only
|
||||||
|
// by beaconchain, aka shard.BeaconChainShardID
|
||||||
|
Inactive |
||||||
|
// Banned records whether this validator is banned
|
||||||
|
// from the network because they double-signed
|
||||||
|
// it can never be undone
|
||||||
|
Banned |
||||||
|
) |
||||||
|
@ -0,0 +1,59 @@ |
|||||||
|
package verify |
||||||
|
|
||||||
|
import ( |
||||||
|
"encoding/binary" |
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common" |
||||||
|
"github.com/harmony-one/bls/ffi/go/bls" |
||||||
|
"github.com/harmony-one/harmony/consensus/quorum" |
||||||
|
bls_cosi "github.com/harmony-one/harmony/crypto/bls" |
||||||
|
"github.com/harmony-one/harmony/multibls" |
||||||
|
"github.com/harmony-one/harmony/shard" |
||||||
|
"github.com/pkg/errors" |
||||||
|
) |
||||||
|
|
||||||
|
var ( |
||||||
|
errQuorumVerifyAggSign = errors.New("insufficient voting power to verify aggreate sig") |
||||||
|
errAggregateSigFail = errors.New("could not verify hash of aggregate signature") |
||||||
|
) |
||||||
|
|
||||||
|
// AggregateSigForCommittee ..
|
||||||
|
func AggregateSigForCommittee( |
||||||
|
committee *shard.Committee, |
||||||
|
aggSignature *bls.Sign, |
||||||
|
hash common.Hash, |
||||||
|
blockNum uint64, |
||||||
|
bitmap []byte, |
||||||
|
) error { |
||||||
|
committerKeys, err := committee.BLSPublicKeys() |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
mask, err := bls_cosi.NewMask(committerKeys, nil) |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
if err := mask.SetMask(bitmap); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
decider := quorum.NewDecider(quorum.SuperMajorityStake) |
||||||
|
decider.SetMyPublicKeyProvider(func() (*multibls.PublicKey, error) { |
||||||
|
return nil, nil |
||||||
|
}) |
||||||
|
if _, err := decider.SetVoters(committee.Slots); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
if !decider.IsQuorumAchievedByMask(mask) { |
||||||
|
return errQuorumVerifyAggSign |
||||||
|
} |
||||||
|
|
||||||
|
blockNumBytes := make([]byte, 8) |
||||||
|
binary.LittleEndian.PutUint64(blockNumBytes, blockNum) |
||||||
|
commitPayload := append(blockNumBytes, hash[:]...) |
||||||
|
if !aggSignature.VerifyHash(mask.AggregatePublic, commitPayload) { |
||||||
|
return errAggregateSigFail |
||||||
|
} |
||||||
|
|
||||||
|
return nil |
||||||
|
} |
Loading…
Reference in new issue