Skip to content

Commit

Permalink
bugfix_staticcall_noaddr_return & bugfix_support_transfer_receive_fa…
Browse files Browse the repository at this point in the history
…llback
  • Loading branch information
JimmyShi22 committed May 9, 2024
1 parent 5b71bcd commit 97d3de6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
19 changes: 17 additions & 2 deletions bcos-executor/src/executive/TransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@ CallParameters::UniquePtr TransactionExecutive::execute(CallParameters::UniquePt
callParameters->value > 0)
{
bool onlyTransfer = callParameters->data.empty();
if (m_blockContext.features().get(
ledger::Features::Flag::bugfix_support_transfer_receive_fallback))
{
// Note: To support receive fallback.
// Transfer from EOA or contract tx's data is empty. But we still need to executive as
// an normal transaction.
// If "to" is contract, go to contract's receive() fallback.
// If "to" is EOA, go to AccountPrecompiled receive() logic.
onlyTransfer = false;
}


bool transferFromEVM = callParameters->seq != 0;
int64_t requiredGas = transferFromEVM ? 0 : BALANCE_TRANSFER_GAS;
auto currentContextAddress = callParameters->receiveAddress;
Expand Down Expand Up @@ -1142,11 +1154,14 @@ CallParameters::UniquePtr TransactionExecutive::go(
)
{
// Note: to be the same as eth
// Just fix DMC:
// if bugfix_call_noaddr_return is not set, callResult->evmStatus is still
// default to EVMC_SUCCESS and serial mode is execute same as eth, but DMC is
// using callResult->status, so we need to compat with DMC here

if (m_blockContext.features().get(
ledger::Features::Flag::bugfix_staticcall_noaddr_return))
{
callResult->data = bytes();
}
callResult->type = CallParameters::FINISHED;
callResult->evmStatus = EVMC_SUCCESS;
callResult->status = (int32_t)TransactionStatus::None;
Expand Down
23 changes: 22 additions & 1 deletion bcos-executor/src/precompiled/extension/AccountPrecompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const char* const AM_METHOD_GET_ACCOUNT_STATUS = "getAccountStatus()";
const char* const AM_METHOD_GET_ACCOUNT_BALANCE = "getAccountBalance()";
const char* const AM_METHOD_ADD_ACCOUNT_BALANCE = "addAccountBalance(uint256)";
const char* const AM_METHOD_SUB_ACCOUNT_BALANCE = "subAccountBalance(uint256)";
const uint32_t AM_METHOD_RECEIVE_FALLBACK_SELECTOR = 1;


AccountPrecompiled::AccountPrecompiled(crypto::Hash::Ptr hashImpl) : Precompiled(hashImpl)
Expand Down Expand Up @@ -62,7 +63,18 @@ std::shared_ptr<PrecompiledExecResult> AccountPrecompiled::call(
auto accountTableName = dynamicParams.at(0);
// get user call actual params
auto originParam = ref(param);
uint32_t func = getParamFunc(originParam);
uint32_t func;
if (originParam.size() == 0 &&
blockContext.features().get(
ledger::Features::Flag::bugfix_support_transfer_receive_fallback))
{
// Transfer to EOA operation, call receive() function
func = AM_METHOD_RECEIVE_FALLBACK_SELECTOR;
}
else
{
func = getParamFunc(originParam);
}
bytesConstRef data = getParamData(originParam);
auto table = _executive->storage().openTable(accountTableName);

Expand All @@ -86,6 +98,15 @@ std::shared_ptr<PrecompiledExecResult> AccountPrecompiled::call(
{
subAccountBalance(accountTableName, _executive, data, _callParameters);
}
else if (func == AM_METHOD_RECEIVE_FALLBACK_SELECTOR)
{
// Transfer to EOA operation
// receive() fallback logic
// Just return _callParameters, do noting
PRECOMPILED_LOG(TRACE) << LOG_BADGE("AccountPrecompiled")
<< LOG_DESC("call receive() function. do nothing")
<< LOG_KV("func", func);
}
else
{
PRECOMPILED_LOG(INFO) << LOG_BADGE("AccountPrecompiled")
Expand Down
6 changes: 5 additions & 1 deletion bcos-framework/bcos-framework/ledger/Features.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Features
bugfix_eip55_addr,
bugfix_eoa_as_contract,
bugfix_dmc_deploy_gas_used,
bugfix_staticcall_noaddr_return,
bugfix_support_transfer_receive_fallback,
feature_dmc2serial,
feature_sharding,
feature_rpbft,
Expand Down Expand Up @@ -156,7 +158,9 @@ class Features
Flag::bugfix_sharding_call_in_child_executive,
Flag::bugfix_internal_create_permission_denied}},
{protocol::BlockVersion::V3_7_3_VERSION,
{Flag::bugfix_eoa_as_contract, Flag::bugfix_dmc_deploy_gas_used}}});
{Flag::bugfix_eoa_as_contract, Flag::bugfix_dmc_deploy_gas_used,
Flag::bugfix_staticcall_noaddr_return,
Flag::bugfix_support_transfer_receive_fallback}}});
for (const auto& upgradeFeatures : upgradeRoadmap)
{
if (((to < protocol::BlockVersion::V3_2_7_VERSION) && (to >= upgradeFeatures.to)) ||
Expand Down
2 changes: 2 additions & 0 deletions bcos-framework/test/unittests/interfaces/FeaturesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ BOOST_AUTO_TEST_CASE(feature)
"bugfix_eip55_addr",
"bugfix_eoa_as_contract",
"bugfix_dmc_deploy_gas_used",
"bugfix_staticcall_noaddr_return",
"bugfix_support_transfer_receive_fallback",
"feature_dmc2serial",
"feature_sharding",
"feature_rpbft",
Expand Down

0 comments on commit 97d3de6

Please sign in to comment.