@@ -245,6 +245,51 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
245245 return ret , contract .Gas , err
246246}
247247
248+ func (evm * EVM ) StaticCall (caller ContractRef , addr common.Address , input []byte , gas uint64 ) (ret []byte , leftOverGas uint64 , err error ) {
249+ if evm .vmConfig .NoRecursion && evm .depth > 0 {
250+ return nil , gas , nil
251+ }
252+
253+ // Depth check execution. Fail if we're trying to execute above the
254+ // limit.
255+ if evm .depth > int (params .CallCreateDepth ) {
256+ return nil , gas , ErrDepth
257+ }
258+
259+ // make sure the readonly is only set if we aren't in readonly yet
260+ // this makes also sure that the readonly flag isn't removed for
261+ // child calls.
262+ if ! evm .interpreter .readonly {
263+ evm .interpreter .readonly = true
264+ defer func () { evm .interpreter .readonly = false }()
265+ }
266+
267+ var (
268+ to = AccountRef (addr )
269+ snapshot = evm .StateDB .Snapshot ()
270+ )
271+ if ! evm .StateDB .Exist (addr ) {
272+ return nil , gas , nil
273+ }
274+
275+ // initialise a new contract and set the code that is to be used by the
276+ // EVM. The contract is a scoped evmironment for this execution context
277+ // only.
278+ contract := NewContract (caller , to , new (big.Int ), gas )
279+ contract .SetCallCode (& addr , evm .StateDB .GetCodeHash (addr ), evm .StateDB .GetCode (addr ))
280+
281+ ret , err = evm .interpreter .Run (snapshot , contract , input )
282+ // When an error was returned by the EVM or when setting the creation code
283+ // above we revert to the snapshot and consume any gas remaining. Additionally
284+ // when we're in homestead this also counts for code storage gas errors.
285+ if err != nil {
286+ contract .UseGas (contract .Gas )
287+
288+ evm .StateDB .RevertToSnapshot (snapshot )
289+ }
290+ return ret , contract .Gas , err
291+ }
292+
248293// Create creates a new contract using code as deployment code.
249294func (evm * EVM ) Create (caller ContractRef , code []byte , gas uint64 , value * big.Int ) (ret []byte , contractAddr common.Address , leftOverGas uint64 , err error ) {
250295 if evm .vmConfig .NoRecursion && evm .depth > 0 {
0 commit comments