Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Implement EIP1380 (call self) in aleth-interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
halfalicious committed Oct 3, 2019
1 parent 33cc6cc commit 1c05d84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions libaleth-interpreter/VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions libaleth-interpreter/VMCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(m_OP)].gas_cost;

switch (m_OP)
{
Expand All @@ -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))
{
Expand Down

0 comments on commit 1c05d84

Please sign in to comment.