core/vm: implement metropolis static call opcode

This commit is contained in:
Jeffrey Wilcke
2017-08-15 11:23:23 +03:00
committed by Péter Szilágyi
parent 9facf6423d
commit 3d123bcde6
7 changed files with 153 additions and 3 deletions

View File

@ -17,6 +17,7 @@
package vm
import (
"errors"
"fmt"
"math/big"
@ -28,7 +29,8 @@ import (
)
var (
bigZero = new(big.Int)
bigZero = new(big.Int)
errWriteProtection = errors.New("evm: write protection")
)
func opAdd(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
@ -656,6 +658,35 @@ func opDelegateCall(pc *uint64, evm *EVM, contract *Contract, memory *Memory, st
return ret, nil
}
func opStaticCall(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
// pop gas
gas := stack.pop().Uint64()
// pop address
addr := stack.pop()
// pop input size and offset
inOffset, inSize := stack.pop(), stack.pop()
// pop return size and offset
retOffset, retSize := stack.pop(), stack.pop()
address := common.BigToAddress(addr)
// Get the arguments from the memory
args := memory.Get(inOffset.Int64(), inSize.Int64())
ret, returnGas, err := evm.StaticCall(contract, address, args, gas)
if err != nil {
stack.push(new(big.Int))
} else {
stack.push(big.NewInt(1))
memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
}
contract.Gas += returnGas
evm.interpreter.intPool.put(addr, inOffset, inSize, retOffset, retSize)
return ret, nil
}
func opReturn(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
offset, size := stack.pop(), stack.pop()
ret := memory.GetPtr(offset.Int64(), size.Int64())