Skip to content

Commit

Permalink
Convert assert in create into a warning
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
maurermi committed Aug 21, 2024
1 parent 30797cb commit bb1814a
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/parsec/agent/runners/evm/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{});
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<interface::ticket_number_type> tn) const
-> cbdc::buffer {
auto evm_host::log_index_key(evmc::address addr,
std::optional<interface::ticket_number_type>
tn) const -> cbdc::buffer {
if(!tn) {
tn = m_ticket_number;
}
Expand Down Expand Up @@ -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<evm_account_code> {
auto evm_host::get_account_code(const evmc::address& addr, bool write)
const -> std::optional<evm_account_code> {
m_log->trace("EVM request account code:", to_hex(addr));

if(is_precompile(addr)) {
Expand Down

0 comments on commit bb1814a

Please sign in to comment.