diff --git a/test/EVMHost.cpp b/test/EVMHost.cpp index fd5394fb5..3c9e6449e 100644 --- a/test/EVMHost.cpp +++ b/test/EVMHost.cpp @@ -172,6 +172,28 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept message.destination = convertToEVMC(createAddress); code = evmc::bytes(message.input_data, message.input_data + message.input_size); } + else if (message.kind == EVMC_CREATE2) + { + Address createAddress(keccak256( + bytes(1, 0xff) + + bytes(begin(message.sender.bytes), end(message.sender.bytes)) + + bytes(begin(message.create2_salt.bytes), end(message.create2_salt.bytes)) + + keccak256(bytes(message.input_data, message.input_data + message.input_size)).asBytes() + )); + message.destination = convertToEVMC(createAddress); + if (accounts.count(message.destination) && ( + accounts[message.destination].nonce > 0 || + !accounts[message.destination].code.empty() + )) + { + evmc::result result({}); + result.status_code = EVMC_OUT_OF_GAS; + accounts = stateBackup; + return result; + } + + code = evmc::bytes(message.input_data, message.input_data + message.input_size); + } else if (message.kind == EVMC_DELEGATECALL) { code = accounts[message.destination].code; @@ -184,7 +206,6 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept } else code = accounts[message.destination].code; - //TODO CREATE2 auto& destination = accounts[message.destination]; @@ -199,7 +220,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept evmc::result result = m_vm.execute(*this, m_evmRevision, message, code.data(), code.size()); m_currentAddress = currentAddress; - if (message.kind == EVMC_CREATE) + if (message.kind == EVMC_CREATE || message.kind == EVMC_CREATE2) { result.gas_left -= evmasm::GasCosts::createDataGas * result.output_size; if (result.gas_left < 0)