From 372412d3a2112b59955152de5a494d919056ad15 Mon Sep 17 00:00:00 2001 From: Petr Hanzl Date: Tue, 9 Apr 2024 13:00:52 +0200 Subject: [PATCH] Fix baseFee nilptr dereference. --- rlp/rlp_env.go | 7 ++++++- types/hash.go | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rlp/rlp_env.go b/rlp/rlp_env.go index c2338f7..ec5cb17 100644 --- a/rlp/rlp_env.go +++ b/rlp/rlp_env.go @@ -51,6 +51,11 @@ type Env struct { // ToSubstate transforms e from Env to substate.Env. func (e Env) ToSubstate() *substate.Env { + var baseFee *big.Int + if e.BaseFee != nil { + baseFee = e.BaseFee.Big() + } + se := &substate.Env{ Coinbase: e.Coinbase, Difficulty: e.Difficulty, @@ -58,7 +63,7 @@ func (e Env) ToSubstate() *substate.Env { Number: e.Number, Timestamp: e.Timestamp, BlockHashes: make(map[uint64]types.Hash), - BaseFee: new(big.Int).SetBytes(e.BaseFee[:]), + BaseFee: baseFee, } // iterate through BlockHashes diff --git a/types/hash.go b/types/hash.go index 2574493..08310fe 100644 --- a/types/hash.go +++ b/types/hash.go @@ -35,6 +35,9 @@ func (h Hash) IsEmpty() bool { // Uint64 converts a hash to a uint64. func (h Hash) Uint64() uint64 { return new(big.Int).SetBytes(h[:]).Uint64() } +// Big converts a hash to a big integer. +func (h Hash) Big() *big.Int { return new(big.Int).SetBytes(h[:]) } + // Compare two big int representations of h and h2. func (h Hash) Compare(h2 Hash) int { b1 := new(big.Int).SetBytes(h[:])