66 "github.com/onflow/atree"
77 "github.com/onflow/flow-go/fvm/evm"
88 "github.com/onflow/flow-go/fvm/evm/emulator"
9+ "github.com/onflow/flow-go/fvm/evm/offchain/blocks"
910 "github.com/onflow/flow-go/fvm/evm/precompiles"
1011 "github.com/onflow/flow-go/fvm/evm/types"
1112 flowGo "github.com/onflow/flow-go/model/flow"
@@ -98,6 +99,13 @@ func (s *BlockExecutor) Run(
9899 s .gasUsed += res .GasConsumed
99100 s .txIndex ++
100101
102+ if res .GasConsumed != receipt .GasUsed {
103+ return fmt .Errorf (
104+ "used gas mismatch, expected: %d, got: %d" ,
105+ receipt .GasUsed ,
106+ res .GasConsumed ,
107+ )
108+ }
101109 l .Debug ().Msg ("transaction executed successfully" )
102110
103111 return nil
@@ -110,25 +118,11 @@ func (s *BlockExecutor) blockContext(
110118 receipt * models.Receipt ,
111119 tracer * tracers.Tracer ,
112120) (types.BlockContext , error ) {
113- ctx := types.BlockContext {
114- ChainID : types .EVMChainIDFromFlowChainID (s .chainID ),
115- BlockNumber : s .block .Height ,
116- BlockTimestamp : s .block .Timestamp ,
117- DirectCallBaseGasUsage : types .DefaultDirectCallBaseGasUsage ,
118- DirectCallGasPrice : types .DefaultDirectCallGasPrice ,
119- GasFeeCollector : types .CoinbaseAddress ,
120- GetHashFunc : func (n uint64 ) common.Hash {
121- // For block heights greater than or equal to the current,
122- // return an empty block hash.
123- if n >= s .block .Height {
124- return common.Hash {}
125- }
126- // If the given block height, is more than 256 blocks
127- // in the past, return an empty block hash.
128- if s .block .Height - n > 256 {
129- return common.Hash {}
130- }
131-
121+ ctx , err := blocks .NewBlockContext (
122+ s .chainID ,
123+ s .block .Height ,
124+ s .block .Timestamp ,
125+ func (n uint64 ) common.Hash {
132126 block , err := s .blocks .GetByHeight (n )
133127 if err != nil {
134128 return common.Hash {}
@@ -140,12 +134,17 @@ func (s *BlockExecutor) blockContext(
140134
141135 return blockHash
142136 },
143- Random : s .block .PrevRandao ,
144- TxCountSoFar : s .txIndex ,
145- TotalGasUsedSoFar : s .gasUsed ,
146- Tracer : tracer ,
137+ s .block .PrevRandao ,
138+ tracer ,
139+ )
140+
141+ if err != nil {
142+ return types.BlockContext {}, err
147143 }
148144
145+ ctx .TxCountSoFar = s .txIndex
146+ ctx .TotalGasUsedSoFar = s .gasUsed
147+
149148 // only add precompile cadence arch contract if we have a receipt
150149 if receipt != nil {
151150 calls , err := types .AggregatedPrecompileCallsFromEncoded (receipt .PrecompiledCalls )
0 commit comments