@@ -282,22 +282,23 @@ func (evm *EVM) Call(caller common.Address, addr common.Address, input []byte, g
282282 }
283283 evm .Context .Transfer (evm .StateDB , caller , addr , value )
284284
285+ // The contract is a scoped environment for this execution context only.
286+ contract := NewContract (caller , addr , value , gas , evm .jumpDests )
287+ contract .IsSystemCall = isSystemCall (caller )
285288 if isPrecompile {
286- ret , gas , err = RunPrecompiledContract ( p , input , gas , evm . Config . Tracer )
289+ contract . SetPrecompile ( p )
287290 } else {
288291 // Initialise a new contract and set the code that is to be used by the EVM.
289292 code := evm .resolveCode (addr )
290293 if len (code ) == 0 {
291- ret , err = nil , nil // gas is unchanged
292- } else {
293- // The contract is a scoped environment for this execution context only.
294- contract := NewContract (caller , addr , value , gas , evm .jumpDests )
295- contract .IsSystemCall = isSystemCall (caller )
296- contract .SetCallCode (evm .resolveCodeHash (addr ), code )
297- ret , err = evm .Run (contract , input , false )
298- gas = contract .Gas
294+ return nil , gas , nil // gas is unchanged
299295 }
296+
297+ contract .SetCallCode (evm .resolveCodeHash (addr ), code )
300298 }
299+
300+ ret , err = evm .Run (contract , input , false )
301+ gas = contract .Gas
301302 // When an error was returned by the EVM or when setting the creation code
302303 // above we revert to the snapshot and consume any gas remaining. Additionally,
303304 // when we're in homestead this also counts for code storage gas errors.
@@ -345,17 +346,18 @@ func (evm *EVM) CallCode(caller common.Address, addr common.Address, input []byt
345346 }
346347 var snapshot = evm .StateDB .Snapshot ()
347348
348- // It is allowed to call precompiles, even via delegatecall
349+ // Initialise a new contract and set the code that is to be used by the EVM.
350+ // The contract is a scoped environment for this execution context only.
351+ contract := NewContract (caller , caller , value , gas , evm .jumpDests )
349352 if p , isPrecompile := evm .precompile (addr ); isPrecompile {
350- ret , gas , err = RunPrecompiledContract (p , input , gas , evm .Config .Tracer )
353+ // It is allowed to call precompiles, even via delegatecall
354+ contract .SetPrecompile (p )
351355 } else {
352- // Initialise a new contract and set the code that is to be used by the EVM.
353- // The contract is a scoped environment for this execution context only.
354- contract := NewContract (caller , caller , value , gas , evm .jumpDests )
355356 contract .SetCallCode (evm .resolveCodeHash (addr ), evm .resolveCode (addr ))
356- ret , err = evm .Run (contract , input , false )
357- gas = contract .Gas
358357 }
358+
359+ ret , err = evm .Run (contract , input , false )
360+ gas = contract .Gas
359361 if err != nil {
360362 evm .StateDB .RevertToSnapshot (snapshot )
361363 if err != ErrExecutionReverted {
@@ -388,18 +390,19 @@ func (evm *EVM) DelegateCall(originCaller common.Address, caller common.Address,
388390 }
389391 var snapshot = evm .StateDB .Snapshot ()
390392
391- // It is allowed to call precompiles, even via delegatecall
393+ // Initialise a new contract and make initialise the delegate values
394+ //
395+ // Note: The value refers to the original value from the parent call.
396+ contract := NewContract (originCaller , caller , value , gas , evm .jumpDests )
392397 if p , isPrecompile := evm .precompile (addr ); isPrecompile {
393- ret , gas , err = RunPrecompiledContract (p , input , gas , evm .Config .Tracer )
398+ // It is allowed to call precompiles, even via delegatecall
399+ contract .SetPrecompile (p )
394400 } else {
395- // Initialise a new contract and make initialise the delegate values
396- //
397- // Note: The value refers to the original value from the parent call.
398- contract := NewContract (originCaller , caller , value , gas , evm .jumpDests )
399401 contract .SetCallCode (evm .resolveCodeHash (addr ), evm .resolveCode (addr ))
400- ret , err = evm .Run (contract , input , false )
401- gas = contract .Gas
402402 }
403+
404+ ret , err = evm .Run (contract , input , false )
405+ gas = contract .Gas
403406 if err != nil {
404407 evm .StateDB .RevertToSnapshot (snapshot )
405408 if err != ErrExecutionReverted {
@@ -441,20 +444,20 @@ func (evm *EVM) StaticCall(caller common.Address, addr common.Address, input []b
441444 // future scenarios
442445 evm .StateDB .AddBalance (addr , new (uint256.Int ), tracing .BalanceChangeTouchAccount )
443446
447+ // Initialise a new contract and set the code that is to be used by the EVM.
448+ // The contract is a scoped environment for this execution context only.
449+ contract := NewContract (caller , addr , new (uint256.Int ), gas , evm .jumpDests )
444450 if p , isPrecompile := evm .precompile (addr ); isPrecompile {
445- ret , gas , err = RunPrecompiledContract ( p , input , gas , evm . Config . Tracer )
451+ contract . SetPrecompile ( p )
446452 } else {
447- // Initialise a new contract and set the code that is to be used by the EVM.
448- // The contract is a scoped environment for this execution context only.
449- contract := NewContract (caller , addr , new (uint256.Int ), gas , evm .jumpDests )
450453 contract .SetCallCode (evm .resolveCodeHash (addr ), evm .resolveCode (addr ))
451-
452- // When an error was returned by the EVM or when setting the creation code
453- // above we revert to the snapshot and consume any gas remaining. Additionally
454- // when we're in Homestead this also counts for code storage gas errors.
455- ret , err = evm .Run (contract , input , true )
456- gas = contract .Gas
457454 }
455+
456+ // When an error was returned by the EVM or when setting the creation code
457+ // above we revert to the snapshot and consume any gas remaining. Additionally
458+ // when we're in Homestead this also counts for code storage gas errors.
459+ ret , err = evm .Run (contract , input , true )
460+ gas = contract .Gas
458461 if err != nil {
459462 evm .StateDB .RevertToSnapshot (snapshot )
460463 if err != ErrExecutionReverted {
0 commit comments