Skip to content

Commit

Permalink
handle height 0 explicitly (ethereum#45)
Browse files Browse the repository at this point in the history
Co-authored-by: blockchaindevsh <[email protected]>
  • Loading branch information
blockchaindevsh and blockchaindevsh authored Mar 14, 2022
1 parent 2ce03ad commit c621b5c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions consensus/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ func (c *Tendermint) verifyHeader(chain consensus.ChainHeaderReader, header *typ
return errUnknownBlock
}
number := header.Number.Uint64()
if number == 0 {
genesisHeader := chain.GetHeaderByNumber(0)
if header.Hash() != genesisHeader.Hash() {
return fmt.Errorf("invalid genesis header")
}
return nil
}

// Don't waste time checking blocks from the future
if header.Time > uint64(time.Now().Unix()) {
Expand Down Expand Up @@ -351,11 +358,10 @@ func (c *Tendermint) verifyHeader(chain consensus.ChainHeaderReader, header *typ
return errInvalidUncleHash
}
// Ensure that the block's difficulty is meaningful (may not be correct at this point)
if number > 0 {
if header.Difficulty == nil || (header.Difficulty.Cmp(big.NewInt(1)) != 0) {
return errInvalidDifficulty
}
if header.Difficulty == nil || (header.Difficulty.Cmp(big.NewInt(1)) != 0) {
return errInvalidDifficulty
}

// Verify that the gas limit is <= 2^63-1
if header.GasLimit > params.MaxGasLimit {
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, params.MaxGasLimit)
Expand Down

0 comments on commit c621b5c

Please sign in to comment.