David/verify headers (#13)

* Updated verifyheader logic for Aura

* Fixed errors returned and comments
This commit is contained in:
David Ansermino 2018-09-08 08:07:48 -06:00 committed by Dustin Brickwood
parent d30a22bfa5
commit 69f2029dbe

View file

@ -92,6 +92,10 @@ var (
// their extra-data fields. // their extra-data fields.
errExtraSigners = errors.New("non-checkpoint block contains extra signer list") errExtraSigners = errors.New("non-checkpoint block contains extra signer list")
// errInvalidValidatorSeal is returned if the extra data field length is not
// equal to the length of a seal
errInvalidExtraData = errors.New("extra data field in block header is invalid")
// errInvalidCheckpointSigners is returned if a checkpoint block contains an // errInvalidCheckpointSigners is returned if a checkpoint block contains an
// invalid list of signers (i.e. non divisible by 20 bytes, or not the correct // invalid list of signers (i.e. non divisible by 20 bytes, or not the correct
// ones). // ones).
@ -267,32 +271,21 @@ func (a *Aura) verifyHeader(chain consensus.ChainReader, header *types.Header, p
if header.Time.Cmp(big.NewInt(time.Now().Unix())) > 0 { if header.Time.Cmp(big.NewInt(time.Now().Unix())) > 0 {
return consensus.ErrFutureBlock return consensus.ErrFutureBlock
} }
// TODO: Are any of these necessary checks?
// Checkpoint blocks need to enforce zero beneficiary // Checkpoint blocks need to enforce zero beneficiary
checkpoint := (number % a.config.Epoch) == 0 //checkpoint := (number % a.config.Epoch) == 0
if checkpoint && header.Coinbase != (common.Address{}) { //if checkpoint && header.Coinbase != (common.Address{}) {
return errInvalidCheckpointBeneficiary // return errInvalidCheckpointBeneficiary
} //}
// Nonces must be 0x00..0 or 0xff..f, zeroes enforced on checkpoints // Nonces must be 0x00..0 or 0xff..f, zeroes enforced on checkpoints
if !bytes.Equal(header.Nonce[:], nonceAuthVote) && !bytes.Equal(header.Nonce[:], nonceDropVote) { //if !bytes.Equal(header.Nonce[:], nonceAuthVote) && !bytes.Equal(header.Nonce[:], nonceDropVote) {
return errInvalidVote // return errInvalidVote
} //}
if checkpoint && !bytes.Equal(header.Nonce[:], nonceDropVote) {
return errInvalidCheckpointVote // Ensure that the extra-data contains a single signature
} signersBytes := len(header.Extra) - extraSeal
// Check that the extra-data contains both the vanity and signature if signersBytes != 0 {
if len(header.Extra) < extraVanity { return errInvalidExtraData
return errMissingVanity
}
if len(header.Extra) < extraVanity+extraSeal {
return errMissingSignature
}
// Ensure that the extra-data contains a signer list on checkpoint, but none otherwise
signersBytes := len(header.Extra) - extraVanity - extraSeal
if !checkpoint && signersBytes != 0 {
return errExtraSigners
}
if checkpoint && signersBytes%common.AddressLength != 0 {
return errInvalidCheckpointSigners
} }
// Ensure that the mix digest is zero as we don't have fork protection currently // Ensure that the mix digest is zero as we don't have fork protection currently
if header.MixDigest != (common.Hash{}) { if header.MixDigest != (common.Hash{}) {
@ -302,9 +295,9 @@ func (a *Aura) verifyHeader(chain consensus.ChainReader, header *types.Header, p
if header.UncleHash != uncleHash { if header.UncleHash != uncleHash {
return errInvalidUncleHash return errInvalidUncleHash
} }
// Ensure that the block's difficulty is meaningful (may not be correct at this point) // Ensure that the block's difficulty is correct (it should be constant)
if number > 0 { if number > 0 {
if header.Difficulty == nil || (header.Difficulty.Cmp(diffInTurn) != 0 && header.Difficulty.Cmp(diffNoTurn) != 0) { if header.Difficulty != chain.Config().Difficulty {
return errInvalidDifficulty return errInvalidDifficulty
} }
} }