Skip to content

Commit

Permalink
Fix event log order & delegatecall noaddr return true & precompiled c…
Browse files Browse the repository at this point in the history
…odeHash
  • Loading branch information
JimmyShi22 committed Nov 17, 2023
1 parent 43858f8 commit 501097f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 18 deletions.
24 changes: 18 additions & 6 deletions bcos-executor/src/executive/CoroutineTransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,27 @@ 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.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);
}

if (versionCompareTo(
m_blockContext.blockVersion(), protocol::BlockVersion::V3_3_VERSION) >= 0)
if (versionCompareTo(m_blockContext.blockVersion(), protocol::BlockVersion::V3_3_VERSION) >= 0)
{
if (output->type == CallParameters::REVERT)
{
Expand Down
19 changes: 16 additions & 3 deletions bcos-executor/src/executive/TransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,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.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);
}

Expand Down Expand Up @@ -186,7 +198,8 @@ CallParameters::UniquePtr TransactionExecutive::externalCall(CallParameters::Uni
}


auto executive = buildChildExecutive(input->codeAddress, m_contextID, newSeq, ExecutiveType::common);
auto executive =
buildChildExecutive(input->codeAddress, m_contextID, newSeq, ExecutiveType::common);

m_childExecutives.push_back(executive); // add child executive for revert() if needed

Expand Down
14 changes: 14 additions & 0 deletions bcos-executor/src/vm/HostContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,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));

Expand Down Expand Up @@ -474,6 +479,15 @@ h256 HostContext::codeHashAt(const std::string_view& address)
return {0};
}
auto code = externalCodeRequest(address);

if (code.empty())
{
if (features().get(ledger::Features::Flag::bugfix_precompiled_codehash))
{
return {0};
}
}

auto hash = hashImpl()->hash(code).asBytes();
return h256(hash);
}
Expand Down
12 changes: 11 additions & 1 deletion bcos-framework/bcos-framework/ledger/Features.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ 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,
bugfix_precompiled_codehash,
feature_dmc2serial,
feature_sharding,
feature_rpbft,
Expand Down Expand Up @@ -63,7 +66,7 @@ class Features
{
BOOST_THROW_EXCEPTION(NoSuchFeatureError{});
}

validate(*value);
}

Expand Down Expand Up @@ -122,6 +125,13 @@ class Features
set(Flag::bugfix_statestorage_hash);
set(Flag::bugfix_evm_create2_delegatecall_staticcall_codecopy);
}
if (version >= protocol::BlockVersion::V3_6_VERSION)
{
set(Flag::bugfix_event_log_order);
set(Flag::bugfix_delegatecall_noaddr_return);
set(Flag::bugfix_precompiled_codehash);
}

setToShardingDefault(version);
}

Expand Down
19 changes: 11 additions & 8 deletions bcos-framework/test/unittests/interfaces/FeaturesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,20 @@ BOOST_AUTO_TEST_CASE(feature)

auto keys = Features::featureKeys();

BOOST_CHECK_EQUAL(keys.size(), 10);
BOOST_CHECK_EQUAL(keys.size(), 13);
BOOST_CHECK_EQUAL(keys[0], "bugfix_revert");
BOOST_CHECK_EQUAL(keys[1], "bugfix_statestorage_hash");
BOOST_CHECK_EQUAL(keys[2], "bugfix_evm_create2_delegatecall_staticcall_codecopy");
BOOST_CHECK_EQUAL(keys[3], "feature_dmc2serial");
BOOST_CHECK_EQUAL(keys[4], "feature_sharding");
BOOST_CHECK_EQUAL(keys[5], "feature_rpbft");
BOOST_CHECK_EQUAL(keys[6], "feature_paillier");
BOOST_CHECK_EQUAL(keys[7], "feature_balance");
BOOST_CHECK_EQUAL(keys[8], "feature_balance_precompiled");
BOOST_CHECK_EQUAL(keys[9], "feature_balance_policy1");
BOOST_CHECK_EQUAL(keys[3], "bugfix_event_log_order");
BOOST_CHECK_EQUAL(keys[4], "bugfix_delegatecall_noaddr_return");
BOOST_CHECK_EQUAL(keys[5], "bugfix_precompiled_codehash");
BOOST_CHECK_EQUAL(keys[6], "feature_dmc2serial");
BOOST_CHECK_EQUAL(keys[7], "feature_sharding");
BOOST_CHECK_EQUAL(keys[8], "feature_rpbft");
BOOST_CHECK_EQUAL(keys[9], "feature_paillier");
BOOST_CHECK_EQUAL(keys[10], "feature_balance");
BOOST_CHECK_EQUAL(keys[11], "feature_balance_precompiled");
BOOST_CHECK_EQUAL(keys[12], "feature_balance_policy1");
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 501097f

Please sign in to comment.