From bd134db8d7f7e606c129af4097dbfe9bc6d6d676 Mon Sep 17 00:00:00 2001 From: JimmyShi22 <417711026@qq.com> Date: Fri, 17 Nov 2023 17:22:09 +0800 Subject: [PATCH] fix event log order & delegatecall noaddr return true --- CMakeLists.txt | 2 +- .../CoroutineTransactionExecutive.cpp | 21 +++++++++++++++---- .../src/executive/TransactionExecutive.cpp | 16 ++++++++++++-- bcos-executor/src/vm/HostContext.cpp | 8 ++++++- .../bcos-framework/ledger/Features.h | 7 +++++++ .../bcos-framework/protocol/Protocol.h | 3 ++- 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b3552e80c..10273e4939 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ endif() list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) -set(VERSION "3.2.4") +set(VERSION "3.2.5") set(VERSION_SUFFIX "") include(Options) configure_project() diff --git a/bcos-executor/src/executive/CoroutineTransactionExecutive.cpp b/bcos-executor/src/executive/CoroutineTransactionExecutive.cpp index 2300cec5f3..a0c1a8ebef 100644 --- a/bcos-executor/src/executive/CoroutineTransactionExecutive.cpp +++ b/bcos-executor/src/executive/CoroutineTransactionExecutive.cpp @@ -88,11 +88,24 @@ CallParameters::UniquePtr CoroutineTransactionExecutive::externalCall( if (output->delegateCall && output->type != CallParameters::FINISHED) { - EXECUTIVE_LOG(DEBUG) << "Could not getCode during DMC externalCall" - << LOG_KV("codeAddress", output->codeAddress); output->data = bytes(); - output->status = (int32_t)bcos::protocol::TransactionStatus::RevertInstruction; - output->evmStatus = EVMC_REVERT; + if (m_blockContext.lock()->features().get( + ledger::Features::Flag::bugfix_delegatecall_noaddr_return)) + { + // This is eth's bug, but we still need to compat with it :) + // https://docs.soliditylang.org/en/v0.8.17/control-structures.html#error-handling-assert-require-revert-and-exceptions + output->status = (int32_t)bcos::protocol::TransactionStatus::None; + output->evmStatus = EVMC_SUCCESS; + } + else + { + output->status = (int32_t)bcos::protocol::TransactionStatus::RevertInstruction; + output->evmStatus = EVMC_REVERT; + } + EXECUTIVE_LOG(DEBUG) << "Could not getCode during DMC externalCall" + << LOG_KV("codeAddress", output->codeAddress) + << LOG_KV("status", output->status) + << LOG_KV("evmStatus", output->evmStatus); } // After coroutine switch, set the recoder diff --git a/bcos-executor/src/executive/TransactionExecutive.cpp b/bcos-executor/src/executive/TransactionExecutive.cpp index e36b43fc20..2740859e27 100644 --- a/bcos-executor/src/executive/TransactionExecutive.cpp +++ b/bcos-executor/src/executive/TransactionExecutive.cpp @@ -134,9 +134,21 @@ CallParameters::UniquePtr TransactionExecutive::externalCall(CallParameters::Uni auto& output = input; EXECUTIVE_LOG(DEBUG) << "Could not getCodeHash during externalCall" << LOG_KV("codeAddress", input->codeAddress); + output->data = bytes(); - output->status = (int32_t)TransactionStatus::RevertInstruction; - output->evmStatus = EVMC_REVERT; + if (m_blockContext.lock()->features().get( + ledger::Features::Flag::bugfix_delegatecall_noaddr_return)) + { + // This is eth's bug, but we still need to compat with it :) + // https://docs.soliditylang.org/en/v0.8.17/control-structures.html#error-handling-assert-require-revert-and-exceptions + output->status = (int32_t)TransactionStatus::None; + output->evmStatus = EVMC_SUCCESS; + } + else + { + output->status = (int32_t)TransactionStatus::RevertInstruction; + output->evmStatus = EVMC_REVERT; + } return std::move(output); } diff --git a/bcos-executor/src/vm/HostContext.cpp b/bcos-executor/src/vm/HostContext.cpp index 329cf7b110..cb5deb0e1e 100644 --- a/bcos-executor/src/vm/HostContext.cpp +++ b/bcos-executor/src/vm/HostContext.cpp @@ -136,7 +136,8 @@ evmc_result HostContext::externalRequest(const evmc_message* _msg) { case EVMC_CREATE2: request->createSalt = fromEvmC(_msg->create2_salt); - if (features().get(ledger::Features::Flag::bugfix_evm_create2_delegatecall_staticcall_codecopy)) + if (features().get( + ledger::Features::Flag::bugfix_evm_create2_delegatecall_staticcall_codecopy)) { request->data.assign(_msg->input_data, _msg->input_data + _msg->input_size); request->create = true; @@ -239,6 +240,11 @@ evmc_result HostContext::externalRequest(const evmc_message* _msg) .create_address = toEvmC(boost::algorithm::unhex(response->newEVMContractAddress)), .padding = {}}; + if (features().get(ledger::Features::Flag::bugfix_event_log_order)) + { + // put event log by stack(dfs) order + m_callParameters->logEntries = std::move(response->logEntries); + } // Put response to store in order to avoid data lost m_responseStore.emplace_back(std::move(response)); diff --git a/bcos-framework/bcos-framework/ledger/Features.h b/bcos-framework/bcos-framework/ledger/Features.h index 909d4f6c8f..e16e6aeadb 100644 --- a/bcos-framework/bcos-framework/ledger/Features.h +++ b/bcos-framework/bcos-framework/ledger/Features.h @@ -29,6 +29,8 @@ class Features bugfix_revert, // https://github.com/FISCO-BCOS/FISCO-BCOS/issues/3629 bugfix_statestorage_hash, bugfix_evm_create2_delegatecall_staticcall_codecopy, + bugfix_event_log_order, + bugfix_delegatecall_noaddr_return, feature_dmc2serial, }; @@ -85,6 +87,11 @@ class Features set(Flag::bugfix_statestorage_hash); set(Flag::bugfix_evm_create2_delegatecall_staticcall_codecopy); } + if (version >= protocol::BlockVersion::V3_2_5_VERSION) + { + set(Flag::bugfix_event_log_order); + set(Flag::bugfix_delegatecall_noaddr_return); + } } auto flags() const diff --git a/bcos-framework/bcos-framework/protocol/Protocol.h b/bcos-framework/bcos-framework/protocol/Protocol.h index b5905e1434..80bc46d614 100644 --- a/bcos-framework/bcos-framework/protocol/Protocol.h +++ b/bcos-framework/bcos-framework/protocol/Protocol.h @@ -113,6 +113,7 @@ enum ProtocolVersion : uint32_t enum class BlockVersion : uint32_t { + V3_2_5_VERSION = 0x03020500, V3_2_4_VERSION = 0x03020400, V3_2_3_VERSION = 0x03020300, V3_2_VERSION = 0x03020000, @@ -120,7 +121,7 @@ enum class BlockVersion : uint32_t V3_0_VERSION = 0x03000000, RC4_VERSION = 4, MIN_VERSION = RC4_VERSION, - MAX_VERSION = V3_2_4_VERSION, + MAX_VERSION = V3_2_5_VERSION, }; const std::string RC4_VERSION_STR = "3.0.0-rc4"; const std::string V3_0_VERSION_STR = "3.0.0";