diff --git a/libaleth-interpreter/VM.h b/libaleth-interpreter/VM.h index 4dd3eb085a6..277d5b31966 100644 --- a/libaleth-interpreter/VM.h +++ b/libaleth-interpreter/VM.h @@ -42,6 +42,7 @@ struct VMSchedule static constexpr int64_t valueTransferGas = 9000; static constexpr int64_t callStipend = 2300; static constexpr int64_t callNewAccount = 25000; + static constexpr int64_t callSelfGas = 40; }; class VM diff --git a/libaleth-interpreter/VMCalls.cpp b/libaleth-interpreter/VMCalls.cpp index 52ac5107adf..e9a8386e0be 100644 --- a/libaleth-interpreter/VMCalls.cpp +++ b/libaleth-interpreter/VMCalls.cpp @@ -190,7 +190,13 @@ void VM::caseCall() bool VM::caseCallSetup(evmc_message& o_msg, bytesRef& o_output) { - m_runGas = m_rev >= EVMC_TANGERINE_WHISTLE ? 700 : 40; + evmc_address const destination = toEvmC(asAddress(m_SP[1])); + + // Check for call-to-self (eip1380) and adjust gas accordingly + if (fromEvmC(m_message->destination) == fromEvmC(destination) && m_rev >= EVMC_BERLIN) + m_runGas = VMSchedule::callSelfGas; + else + m_runGas = evmc_get_instruction_metrics_table(m_rev)[static_cast(m_OP)].gas_cost; switch (m_OP) { @@ -212,8 +218,6 @@ bool VM::caseCallSetup(evmc_message& o_msg, bytesRef& o_output) bool const haveValueArg = m_OP == Instruction::CALL || m_OP == Instruction::CALLCODE; - evmc_address destination = toEvmC(asAddress(m_SP[1])); - if (m_OP == Instruction::CALL && (m_SP[2] > 0 || m_rev < EVMC_SPURIOUS_DRAGON) && !m_context->host->account_exists(m_context, &destination)) {