This commit is contained in:
Martin Holst Swende 2017-05-04 11:04:39 +02:00
parent e1dc7ece62
commit a8aaac7e68
2 changed files with 7 additions and 0 deletions

View file

@ -27,6 +27,8 @@ var (
tt256 = BigPow(2, 256) tt256 = BigPow(2, 256)
tt256m1 = new(big.Int).Sub(tt256, big.NewInt(1)) tt256m1 = new(big.Int).Sub(tt256, big.NewInt(1))
MaxBig256 = new(big.Int).Set(tt256m1) MaxBig256 = new(big.Int).Set(tt256m1)
tt63 = BigPow(2,63)
TT63m1 = new(big.Int).Sub(tt63,big.NewInt(1))
) )
const ( const (

View file

@ -243,6 +243,11 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
if expected.Cmp(header.Difficulty) != 0 { if expected.Cmp(header.Difficulty) != 0 {
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected) return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
} }
// Verify that the gas limit is < 2^63
if header.GasLimit.Cmp(math.TT63m1) > 0{
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, math.TT63m1)
}
// Verify that the gas limit remains within allowed bounds // Verify that the gas limit remains within allowed bounds
diff := new(big.Int).Set(parent.GasLimit) diff := new(big.Int).Set(parent.GasLimit)
diff = diff.Sub(diff, header.GasLimit) diff = diff.Sub(diff, header.GasLimit)