@@ -33,6 +33,7 @@ import (
3333 "encoding/json"
3434 "errors"
3535 "fmt"
36+ "math/big"
3637 "os"
3738 "runtime"
3839 "sync"
@@ -959,17 +960,32 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
959960 }
960961 defer release ()
961962
962- vmctx := core .NewEVMBlockContext (block .Header (), api .chainContext (ctx ), nil )
963+ h := block .Header ()
964+ blockContext := core .NewEVMBlockContext (h , api .chainContext (ctx ), nil )
963965
964966 // Apply the customization rules if required.
965967 if config != nil {
968+ if config .BlockOverrides != nil && config .BlockOverrides .Number .ToInt ().Uint64 () == h .Number .Uint64 ()+ 1 {
969+ // Overriding the block number to n+1 is a common way for wallets to
970+ // simulate transactions, however without the following fix, a contract
971+ // can assert it is being simulated by checking if blockhash(n) == 0x0 and
972+ // can behave differently during the simulation. (#32175 for more info)
973+ // --
974+ // Modify the parent hash and number so that downstream, blockContext's
975+ // GetHash function can correctly return n.
976+ h .ParentHash = h .Hash ()
977+ h .Number .Add (h .Number , big .NewInt (1 ))
978+ }
966979 originalTime := block .Time ()
967- config .BlockOverrides .Apply (& vmctx )
980+ config .BlockOverrides .Apply (& blockContext )
968981 // Apply all relevant upgrades from [originalTime] to the block time set in the override.
969982 // Should be applied before the state overrides.
970- blockContext := core .NewBlockContext (vmctx .BlockNumber , vmctx .Time )
971- err = core .ApplyUpgrades (api .backend .ChainConfig (), & originalTime , blockContext , statedb )
972- if err != nil {
983+ if err := core .ApplyUpgrades (
984+ api .backend .ChainConfig (),
985+ & originalTime ,
986+ core .NewBlockContext (block .Number (), block .Time ()),
987+ statedb ,
988+ ); err != nil {
973989 return nil , err
974990 }
975991
@@ -978,7 +994,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
978994 }
979995 }
980996 // Execute the trace
981- msg , err := args .ToMessage (api .backend .RPCGasCap (), vmctx .BaseFee )
997+ msg , err := args .ToMessage (api .backend .RPCGasCap (), blockContext .BaseFee )
982998 if err != nil {
983999 return nil , err
9841000 }
@@ -987,7 +1003,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
9871003 if config != nil {
9881004 traceConfig = & config .TraceConfig
9891005 }
990- return api .traceTx (ctx , msg , new (Context ), vmctx , statedb , traceConfig )
1006+ return api .traceTx (ctx , msg , new (Context ), blockContext , statedb , traceConfig )
9911007}
9921008
9931009// traceTx configures a new tracer according to the provided configuration, and
0 commit comments