Skip to content

Commit

Permalink
add precompiledAddress filter for balance interface
Browse files Browse the repository at this point in the history
  • Loading branch information
wenlinlee committed Jan 4, 2024
1 parent 201f892 commit 06279af
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
22 changes: 21 additions & 1 deletion bcos-executor/src/precompiled/extension/AccountPrecompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,16 @@ void AccountPrecompiled::addAccountBalance(const std::string& accountTableName,
getErrorCodeOut(_callParameters->mutableExecResult(), CODE_NO_AUTHORIZED, codec);
return;
}

if (isPrecompiledAddressRange(accountTableName.substr(6)))
{
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);
if (!table.has_value()) [[unlikely]]
Expand Down Expand Up @@ -353,6 +362,17 @@ 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(6)))
{
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
9 changes: 9 additions & 0 deletions bcos-framework/bcos-framework/executor/PrecompiledTypeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#pragma once
#include "bcos-framework/protocol/ProtocolTypeDef.h"
#include <bcos-utilities/Common.h>
#include <charconv>
#include <sstream>

namespace bcos
{
Expand All @@ -31,6 +33,13 @@ constexpr inline bool isSysContractDeploy(protocol::BlockNumber _number)
return _number == SYS_CONTRACT_DEPLOY_NUMBER;
}

constexpr inline bool isPrecompiledAddressRange(std::string_view _address)
{
unsigned int address;
auto result = std::from_chars(_address.data(), _address.data() + _address.size(), address, 16);
return result.ec == std::errc() && (address >= 0x0 && address < 0x20000);
}

namespace precompiled
{
/// precompiled contract path for wasm
Expand Down
3 changes: 0 additions & 3 deletions bcos-sdk/bcos-cpp-sdk/utilities/logger/LogInitializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class LogInitializer
}
catch (const std::exception& e)
{
std::cerr << "Not found available log config(./clog.ini or ./conf/clog.ini), use "
"the default configuration items, disable log by default."
<< std::endl;
// log disable by default
pt.put("log.enable", false);
}
Expand Down

0 comments on commit 06279af

Please sign in to comment.