4141)
4242
4343// run runs the given contract and takes care of running precompiles with a fallback to the byte code interpreter.
44- func run (evm * EVM , contract * Contract , input []byte ) ([]byte , error ) {
44+ func run (evm * EVM , contract * Contract , input []byte , readOnly bool ) ([]byte , error ) {
4545 if contract .CodeAddr != nil {
4646 precompiles := PrecompiledContractsHomestead
4747 if evm .ChainConfig ().IsByzantium (evm .BlockNumber ) {
@@ -61,7 +61,7 @@ func run(evm *EVM, contract *Contract, input []byte) ([]byte, error) {
6161 }(evm .interpreter )
6262 evm .interpreter = interpreter
6363 }
64- return interpreter .Run (contract , input )
64+ return interpreter .Run (contract , input , readOnly )
6565 }
6666 }
6767 return nil , ErrNoCompatibleInterpreter
@@ -210,7 +210,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
210210 evm .vmConfig .Tracer .CaptureEnd (ret , gas - contract .Gas , time .Since (start ), err )
211211 }()
212212 }
213- ret , err = run (evm , contract , input )
213+ ret , err = run (evm , contract , input , false )
214214
215215 // When an error was returned by the EVM or when setting the creation code
216216 // above we revert to the snapshot and consume any gas remaining. Additionally
@@ -255,7 +255,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
255255 contract := NewContract (caller , to , value , gas )
256256 contract .SetCallCode (& addr , evm .StateDB .GetCodeHash (addr ), evm .StateDB .GetCode (addr ))
257257
258- ret , err = run (evm , contract , input )
258+ ret , err = run (evm , contract , input , false )
259259 if err != nil {
260260 evm .StateDB .RevertToSnapshot (snapshot )
261261 if err != errExecutionReverted {
@@ -288,7 +288,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
288288 contract := NewContract (caller , to , nil , gas ).AsDelegate ()
289289 contract .SetCallCode (& addr , evm .StateDB .GetCodeHash (addr ), evm .StateDB .GetCode (addr ))
290290
291- ret , err = run (evm , contract , input )
291+ ret , err = run (evm , contract , input , false )
292292 if err != nil {
293293 evm .StateDB .RevertToSnapshot (snapshot )
294294 if err != errExecutionReverted {
@@ -310,13 +310,6 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
310310 if evm .depth > int (params .CallCreateDepth ) {
311311 return nil , gas , ErrDepth
312312 }
313- // Make sure the readonly is only set if we aren't in readonly yet
314- // this makes also sure that the readonly flag isn't removed for
315- // child calls.
316- if ! evm .interpreter .IsReadOnly () {
317- evm .interpreter .SetReadOnly (true )
318- defer func () { evm .interpreter .SetReadOnly (false ) }()
319- }
320313
321314 var (
322315 to = AccountRef (addr )
@@ -331,7 +324,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
331324 // When an error was returned by the EVM or when setting the creation code
332325 // above we revert to the snapshot and consume any gas remaining. Additionally
333326 // when we're in Homestead this also counts for code storage gas errors.
334- ret , err = run (evm , contract , input )
327+ ret , err = run (evm , contract , input , true )
335328 if err != nil {
336329 evm .StateDB .RevertToSnapshot (snapshot )
337330 if err != errExecutionReverted {
@@ -382,7 +375,7 @@ func (evm *EVM) create(caller ContractRef, code []byte, gas uint64, value *big.I
382375 }
383376 start := time .Now ()
384377
385- ret , err := run (evm , contract , nil )
378+ ret , err := run (evm , contract , nil , false )
386379
387380 // check whether the max code size has been exceeded
388381 maxCodeSizeExceeded := evm .ChainConfig ().IsEIP158 (evm .BlockNumber ) && len (ret ) > params .MaxCodeSize
0 commit comments