Skip to content

Commit

Permalink
David/verify headers (#13)
Browse files Browse the repository at this point in the history
* Updated verifyheader logic for Aura

* Fixed errors returned and comments
  • Loading branch information
ansermino authored and dutterbutter committed Sep 8, 2018
1 parent d30a22b commit 69f2029
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions consensus/aura/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ var (
// their extra-data fields.
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
// invalid list of signers (i.e. non divisible by 20 bytes, or not the correct
// ones).
Expand Down Expand Up @@ -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 {
return consensus.ErrFutureBlock
}
// TODO: Are any of these necessary checks?
// Checkpoint blocks need to enforce zero beneficiary
checkpoint := (number % a.config.Epoch) == 0
if checkpoint && header.Coinbase != (common.Address{}) {
return errInvalidCheckpointBeneficiary
}
//checkpoint := (number % a.config.Epoch) == 0
//if checkpoint && header.Coinbase != (common.Address{}) {
// return errInvalidCheckpointBeneficiary
//}
// Nonces must be 0x00..0 or 0xff..f, zeroes enforced on checkpoints
if !bytes.Equal(header.Nonce[:], nonceAuthVote) && !bytes.Equal(header.Nonce[:], nonceDropVote) {
return errInvalidVote
}
if checkpoint && !bytes.Equal(header.Nonce[:], nonceDropVote) {
return errInvalidCheckpointVote
}
// Check that the extra-data contains both the vanity and signature
if len(header.Extra) < extraVanity {
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
//if !bytes.Equal(header.Nonce[:], nonceAuthVote) && !bytes.Equal(header.Nonce[:], nonceDropVote) {
// return errInvalidVote
//}

// Ensure that the extra-data contains a single signature
signersBytes := len(header.Extra) - extraSeal
if signersBytes != 0 {
return errInvalidExtraData
}
// Ensure that the mix digest is zero as we don't have fork protection currently
if header.MixDigest != (common.Hash{}) {
Expand All @@ -302,9 +295,9 @@ func (a *Aura) verifyHeader(chain consensus.ChainReader, header *types.Header, p
if header.UncleHash != uncleHash {
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 header.Difficulty == nil || (header.Difficulty.Cmp(diffInTurn) != 0 && header.Difficulty.Cmp(diffNoTurn) != 0) {
if header.Difficulty != chain.Config().Difficulty {
return errInvalidDifficulty
}
}
Expand Down

0 comments on commit 69f2029

Please sign in to comment.