@@ -61,19 +61,7 @@ func (e *environment) refundGas(add uint64) error {
6161}
6262
6363func (e * environment ) ReadOnly () bool {
64- // A switch statement provides clearer code coverage for difficult-to-test
65- // cases.
66- switch {
67- case e .callType == StaticCall :
68- // evm.interpreter.readOnly is only set to true via a call to
69- // EVMInterpreter.Run() so, if a precompile is called directly with
70- // StaticCall(), then readOnly might not be set yet.
71- return true
72- case e .evm .interpreter .readOnly :
73- return true
74- default :
75- return false
76- }
64+ return e .evm .interpreter .readOnly
7765}
7866
7967func (e * environment ) Addresses () * libevm.AddressContext {
@@ -108,19 +96,6 @@ func (e *environment) Call(addr common.Address, input []byte, gas uint64, value
10896}
10997
11098func (e * environment ) callContract (typ CallType , addr common.Address , input []byte , gas uint64 , value * uint256.Int , opts ... CallOption ) (retData []byte , retErr error ) {
111- // Depth and read-only setting are handled by [EVMInterpreter.Run], which
112- // isn't used for precompiles, so we need to do it ourselves to maintain the
113- // expected invariants.
114- in := e .evm .interpreter
115-
116- in .evm .depth ++
117- defer func () { in .evm .depth -- }()
118-
119- if e .ReadOnly () && ! in .readOnly { // i.e. the precompile was StaticCall()ed
120- in .readOnly = true
121- defer func () { in .readOnly = false }()
122- }
123-
12499 var caller ContractRef = e .self
125100 if options .As [callConfig ](opts ... ).unsafeCallerAddressProxying {
126101 // Note that, in addition to being unsafe, this breaks an EVM
@@ -133,7 +108,7 @@ func (e *environment) callContract(typ CallType, addr common.Address, input []by
133108 }
134109 }
135110
136- if in . readOnly && value != nil && ! value .IsZero () {
111+ if e . ReadOnly () && value != nil && ! value .IsZero () {
137112 return nil , ErrWriteProtection
138113 }
139114 if ! e .UseGas (gas ) {
0 commit comments