From a8aaac7e680cb9fe96aef55c2407bf98ff0647da Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 4 May 2017 11:04:39 +0200 Subject: [PATCH] core: Fix for consensus test gasLimit > 2^63-1 https://github.com/ethereum/tests/blob/develop/BlockchainTests/bcInvalidHeaderTest.json#L238 --- common/math/big.go | 2 ++ consensus/ethash/consensus.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/common/math/big.go b/common/math/big.go index 5255a88e9f..5f62b010fa 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) + TT63m1 = new(big.Int).Sub(tt63,big.NewInt(1)) ) const ( diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 4f1ab87024..b7e8244cdc 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -243,6 +243,11 @@ 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 + 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 diff := new(big.Int).Set(parent.GasLimit) diff = diff.Sub(diff, header.GasLimit)