From bb1814a62c5e12591c4b97e00a2140d0daf69c7a Mon Sep 17 00:00:00 2001 From: Michael Maurer Date: Wed, 21 Aug 2024 12:56:08 -0400 Subject: [PATCH] Convert assert in create into a warning Turn the assert statement in create into a warning, this restores the ability to import tokens through Metamask. Details: When importing tokens, Metamask sends a create call without sender information, triggering an assert failure. Signed-off-by: Michael Maurer --- src/parsec/agent/runners/evm/host.cpp | 33 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/parsec/agent/runners/evm/host.cpp b/src/parsec/agent/runners/evm/host.cpp index b1191c2ba..3184464b8 100644 --- a/src/parsec/agent/runners/evm/host.cpp +++ b/src/parsec/agent/runners/evm/host.cpp @@ -214,9 +214,9 @@ namespace cbdc::parsec::agent::runner { return n; } - auto evm_host::selfdestruct(const evmc::address& addr, - const evmc::address& beneficiary) noexcept - -> bool { + auto + evm_host::selfdestruct(const evmc::address& addr, + const evmc::address& beneficiary) noexcept -> bool { m_log->trace("EVM selfdestruct:", to_hex(addr), to_hex(beneficiary)); // TODO: delete storage keys and code transfer(addr, beneficiary, evmc::uint256be{}); @@ -225,7 +225,15 @@ namespace cbdc::parsec::agent::runner { auto evm_host::create(const evmc_message& msg) noexcept -> evmc::Result { auto maybe_sender_acc = get_account(msg.sender, false); - assert(maybe_sender_acc.has_value()); + if(!maybe_sender_acc.has_value()) { + m_log->warn("EVM CREATE: sender account not found"); + return evmc::Result( + evmc::make_result(evmc_status_code::EVMC_REVERT, + 0, + 0, + nullptr, + 0)); + } auto& sender_acc = maybe_sender_acc.value(); auto new_addr = evmc::address(); @@ -298,6 +306,11 @@ namespace cbdc::parsec::agent::runner { } auto evm_host::call(const evmc_message& msg) noexcept -> evmc::Result { + if(msg.kind == EVMC_CREATE2) { + m_log->info("EVM CREATE2 called"); + } else if(msg.kind == EVMC_CREATE) { + m_log->info("EVM CREATE called"); + } if(msg.kind == EVMC_CREATE2 || msg.kind == EVMC_CREATE) { return create(msg); } @@ -432,10 +445,9 @@ namespace cbdc::parsec::agent::runner { return make_buffer(tn_hash); } - auto evm_host::log_index_key( - evmc::address addr, - std::optional tn) const - -> cbdc::buffer { + auto evm_host::log_index_key(evmc::address addr, + std::optional + tn) const -> cbdc::buffer { if(!tn) { tn = m_ticket_number; } @@ -640,9 +652,8 @@ namespace cbdc::parsec::agent::runner { return data; } - auto evm_host::get_account_code(const evmc::address& addr, - bool write) const - -> std::optional { + auto evm_host::get_account_code(const evmc::address& addr, bool write) + const -> std::optional { m_log->trace("EVM request account code:", to_hex(addr)); if(is_precompile(addr)) {