Skip to content

Commit

Permalink
fix ecRecover core in balance transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyShi22 committed Jan 18, 2024
1 parent 3de96ac commit 96534ea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
23 changes: 1 addition & 22 deletions bcos-executor/src/precompiled/extension/AccountPrecompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,7 @@ void AccountPrecompiled::addAccountBalance(const std::string& accountTableName,
getErrorCodeOut(_callParameters->mutableExecResult(), CODE_NO_AUTHORIZED, codec);
return;
}
if (isPrecompiledAddressRange(accountTableName.substr(USER_APPS_PREFIX.length())))
{
PRECOMPILED_LOG(INFO) << BLOCK_NUMBER(blockContext.number())
<< LOG_BADGE("AccountPrecompiled, addAccountBalance")
<< LOG_DESC("account is precompiled address")
<< LOG_KV(
"account", accountTableName.substr(USER_APPS_PREFIX.length()));
BOOST_THROW_EXCEPTION(
PrecompiledError("addBalance failed, toAddress is precompiledAddress!"));
return;
}

// check account exist
auto table = _executive->storage().openTable(accountTableName);
if (!table.has_value()) [[unlikely]]
Expand Down Expand Up @@ -365,17 +355,6 @@ void AccountPrecompiled::subAccountBalance(const std::string& accountTableName,
getErrorCodeOut(_callParameters->mutableExecResult(), CODE_NO_AUTHORIZED, codec);
return;
}
// check account is precompiled address, if true, return
if (isPrecompiledAddressRange(accountTableName.substr(USER_APPS_PREFIX.length())))
{
PRECOMPILED_LOG(INFO) << BLOCK_NUMBER(blockContext.number())
<< LOG_BADGE("AccountPrecompiled, addAccountBalance")
<< LOG_DESC("account is precompiled address")
<< LOG_KV("account", accountTableName.substr(6));
BOOST_THROW_EXCEPTION(
PrecompiledError("addBalance failed, toAddress is precompiledAddress!"));
return;
}

// check account exist
auto table = _executive->storage().openTable(accountTableName);
Expand Down
13 changes: 13 additions & 0 deletions bcos-executor/src/vm/Precompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,19 @@ const int RSV_LENGTH = 65;
const int PUBLIC_KEY_LENGTH = 64;
pair<bool, bytes> ecRecover(bytesConstRef _in)
{ // _in is hash(32),v(32),r(32),s(32), return address

if (_in == bytesConstRef())
{
BCOS_LOG(TRACE) << LOG_BADGE("Precompiled") << LOG_DESC("ecRecover: nullptr input");
return {false, {}};
}

if (_in.size() != 64 + RSV_LENGTH)
{
BCOS_LOG(TRACE) << LOG_BADGE("Precompiled") << LOG_DESC("ecRecover: invalid input size");
return {true, {}};
}

BCOS_LOG(TRACE) << LOG_BADGE("Precompiled") << LOG_DESC("ecRecover: ") << _in.size();
byte rawRSV[RSV_LENGTH];
memcpy(rawRSV, _in.data() + 64, RSV_LENGTH - 1);
Expand Down
37 changes: 21 additions & 16 deletions bcos-framework/test/unittests/interfaces/FeaturesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,27 @@ BOOST_AUTO_TEST_CASE(feature)
BOOST_CHECK_EQUAL(features7.get("feature_balance_policy1"), true);

auto keys = Features::featureKeys();

BOOST_CHECK_EQUAL(keys.size(), 14);
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], "bugfix_event_log_order");
BOOST_CHECK_EQUAL(keys[4], "bugfix_call_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_CHECK_EQUAL(keys[13], "feature_paillier_add_raw");
// clang-format off
std::vector<std::string> compareKeys = {
"bugfix_revert",
"bugfix_statestorage_hash",
"bugfix_evm_create2_delegatecall_staticcall_codecopy",
"bugfix_event_log_order",
"bugfix_call_noaddr_return",
"bugfix_precompiled_codehash",
"feature_dmc2serial",
"feature_sharding",
"feature_rpbft",
"feature_balance",
"feature_balance_precompiled",
"feature_balance_policy1",
"feature_paillier_add_raw"
};
// clang-format on
for (size_t i = 0; i < keys.size(); ++i)
{
BOOST_CHECK_EQUAL(keys[i], compareKeys[i]);
}
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 96534ea

Please sign in to comment.