From cab1cff11cbcd4ff60f1a149deb71ec87413b487 Mon Sep 17 00:00:00 2001 From: gary rong Date: Tue, 24 Jul 2018 22:22:03 +0800 Subject: 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 --- core/vm/instructions.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'core/vm/instructions.go') diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 1ec13ba35..b25c0111a 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -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()) -- cgit v1.2.3