@@ -61,19 +61,7 @@ func (e *environment) refundGas(add uint64) error {
61
61
}
62
62
63
63
func (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
77
65
}
78
66
79
67
func (e * environment ) Addresses () * libevm.AddressContext {
@@ -108,19 +96,6 @@ func (e *environment) Call(addr common.Address, input []byte, gas uint64, value
108
96
}
109
97
110
98
func (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
-
124
99
var caller ContractRef = e .self
125
100
if options .As [callConfig ](opts ... ).unsafeCallerAddressProxying {
126
101
// 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
133
108
}
134
109
}
135
110
136
- if in . readOnly && value != nil && ! value .IsZero () {
111
+ if e . ReadOnly () && value != nil && ! value .IsZero () {
137
112
return nil , ErrWriteProtection
138
113
}
139
114
if ! e .UseGas (gas ) {
0 commit comments