Skip to content

Commit 14cc40a

Browse files
holimankaralabe
authored andcommitted
Hive-test fixes (#14419)
* core: Fix for consensus test gasLimit > 2^63-1 https://github.com/ethereum/tests/blob/develop/BlockchainTests/bcInvalidHeaderTest.json#L238 * core: fix testcase for uncle gasUsage > gasLimit : https://github.com/ethereum/tests/blob/develop/BlockchainTests/EIP150/bcUncleHeaderValiditiy.json#L986 * math/big: rename TTM63m1 -> MaxBig63, + go fmt * core: documentation
1 parent 881df0e commit 14cc40a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

common/math/big.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ var (
2727
tt256 = BigPow(2, 256)
2828
tt256m1 = new(big.Int).Sub(tt256, big.NewInt(1))
2929
MaxBig256 = new(big.Int).Set(tt256m1)
30+
tt63 = BigPow(2, 63)
31+
MaxBig63 = new(big.Int).Sub(tt63, big.NewInt(1))
3032
)
3133

3234
const (

consensus/ethash/consensus.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
243243
if expected.Cmp(header.Difficulty) != 0 {
244244
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
245245
}
246+
// Verify that the gas limit is <= 2^63-1
247+
if header.GasLimit.Cmp(math.MaxBig63) > 0 {
248+
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, math.MaxBig63)
249+
}
250+
// Verify that the gasUsed is <= gasLimit
251+
if header.GasUsed.Cmp(header.GasLimit) > 0 {
252+
return fmt.Errorf("invalid gasUsed: have %v, gasLimit %v", header.GasUsed, header.GasLimit)
253+
}
254+
246255
// Verify that the gas limit remains within allowed bounds
247256
diff := new(big.Int).Set(parent.GasLimit)
248257
diff = diff.Sub(diff, header.GasLimit)

0 commit comments

Comments
 (0)