core, crypto, params: implement CREATE2 evm instrction (#17196)

* core, crypto, params: implement CREATE2 evm instrction

* core/vm: add opcode to string mapping

* core: remove past fork checking

* core, crypto: use option2 to generate new address
This commit is contained in:
gary rong
2018-07-24 22:22:03 +08:00
committed by Péter Szilágyi
parent 2909f6d7a2
commit cab1cff11c
8 changed files with 94 additions and 17 deletions

View File

@ -665,6 +665,34 @@ func opCreate(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *S
return nil, nil
}
func opCreate2(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
var (
endowment = stack.pop()
offset, size = stack.pop(), stack.pop()
salt = stack.pop()
input = memory.Get(offset.Int64(), size.Int64())
gas = contract.Gas
)
// Apply EIP150
gas -= gas / 64
contract.UseGas(gas)
res, addr, returnGas, suberr := evm.Create2(contract, input, gas, endowment, salt)
// Push item on the stack based on the returned error.
if suberr != nil {
stack.push(evm.interpreter.intPool.getZero())
} else {
stack.push(addr.Big())
}
contract.Gas += returnGas
evm.interpreter.intPool.put(endowment, offset, size, salt)
if suberr == errExecutionReverted {
return res, nil
}
return nil, nil
}
func opCall(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
// Pop gas. The actual gas in in evm.callGasTemp.
evm.interpreter.intPool.put(stack.pop())