Skip to content

Commit

Permalink
evm_runtime: Allow exec action to work with frozen accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
elmato committed Sep 5, 2023
1 parent 15881e4 commit e49990b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion contract/include/evm_runtime/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ struct state : State {
name _self;
name _ram_payer;
bool _read_only;
bool _allow_frozen;
mutable std::map<evmc::address, uint64_t> addr2id;
mutable std::map<bytes32, bytes> addr2code;
mutable db_stats stats;
std::optional<config2> _config2;

explicit state(name self, name ram_payer, bool read_only=false) : _self(self), _ram_payer(ram_payer), _read_only{read_only}{}
explicit state(name self, name ram_payer, bool read_only=false, bool allow_frozen=true) : _self(self), _ram_payer(ram_payer), _read_only{read_only}, _allow_frozen{allow_frozen}{}
virtual ~state() override;

uint64_t get_next_account_id();
Expand Down
4 changes: 2 additions & 2 deletions contract/src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void evm_contract::exec(const exec_input& input, const std::optional<exec_callba
evm_common::prepare_block_header(block.header, bm, get_self().value,
bm.timestamp_to_evm_block_num(eosio::current_time_point().time_since_epoch().count()));

evm_runtime::state state{get_self(), get_self(), true};
evm_runtime::state state{get_self(), get_self(), true, true};
IntraBlockState ibstate{state};

EVM evm{block, ibstate, *found_chain_config.value().second};
Expand Down Expand Up @@ -390,7 +390,7 @@ void evm_contract::pushtx( eosio::name miner, const bytes& rlptx ) {

silkworm::consensus::TrustEngine engine{*found_chain_config->second};

evm_runtime::state state{get_self(), get_self()};
evm_runtime::state state{get_self(), get_self(), false, false};
silkworm::ExecutionProcessor ep{block, engine, state, *found_chain_config->second};

Transaction tx;
Expand Down
2 changes: 1 addition & 1 deletion contract/src/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::optional<Account> state::read_account(const evmc::address& address) const n
if (itr == inx.end()) {
return {};
}
eosio::check(!itr->has_flag(account::flag::frozen), "account is frozen");
eosio::check(_allow_frozen || !itr->has_flag(account::flag::frozen), "account is frozen");

addr2id[address] = itr->id;

Expand Down
4 changes: 2 additions & 2 deletions contract/tests/admin_actions_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ BOOST_FIXTURE_TEST_CASE(freezeaccnt_tests, admin_action_tester) try {
auto [contract_addr, contract_account_id] = deploy_simple_contract(evm1);
freezeaccnt(contract_account_id, true);

BOOST_REQUIRE_EXCEPTION(getval(contract_addr),
eosio_assert_message_exception, eosio_assert_message_is("account is frozen"));
// We allow evm::exec action to work with frozen accounts
BOOST_REQUIRE(getval(contract_addr) == 0);

BOOST_REQUIRE_EXCEPTION(transfer_token("alice"_n, evm_account_name, make_asset(to_bridge), fc::variant(contract_addr).as_string()),
eosio_assert_message_exception, eosio_assert_message_is("account is frozen"));
Expand Down

0 comments on commit e49990b

Please sign in to comment.