aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/math/big.go2
-rw-r--r--consensus/ethash/consensus.go9
2 files changed, 11 insertions, 0 deletions
diff --git a/common/math/big.go b/common/math/big.go
index 5255a88e9..fd0174b36 100644
--- a/common/math/big.go
+++ b/common/math/big.go
@@ -27,6 +27,8 @@ var (
tt256 = BigPow(2, 256)
tt256m1 = new(big.Int).Sub(tt256, big.NewInt(1))
MaxBig256 = new(big.Int).Set(tt256m1)
+ tt63 = BigPow(2, 63)
+ MaxBig63 = new(big.Int).Sub(tt63, big.NewInt(1))
)
const (
diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go
index 4f1ab8702..2930032e5 100644
--- a/consensus/ethash/consensus.go
+++ b/consensus/ethash/consensus.go
@@ -243,6 +243,15 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
if expected.Cmp(header.Difficulty) != 0 {
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
}
+ // Verify that the gas limit is <= 2^63-1
+ if header.GasLimit.Cmp(math.MaxBig63) > 0 {
+ return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, math.MaxBig63)
+ }
+ // Verify that the gasUsed is <= gasLimit
+ if header.GasUsed.Cmp(header.GasLimit) > 0 {
+ return fmt.Errorf("invalid gasUsed: have %v, gasLimit %v", header.GasUsed, header.GasLimit)
+ }
+
// Verify that the gas limit remains within allowed bounds
diff := new(big.Int).Set(parent.GasLimit)
diff = diff.Sub(diff, header.GasLimit)