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

Commit

Permalink
Merge pull request #4320 from cdetrio/standard-vmtrace
Browse files Browse the repository at this point in the history
standardized vmtrace logs
  • Loading branch information
pirapira authored Aug 16, 2017
2 parents f84d61c + 5be721f commit a8bac5d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
1 change: 1 addition & 0 deletions libethereum/Executive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void StandardTrace::operator()(uint64_t _steps, uint64_t PC, Instruction inst, b
r["pc"] = toString(PC);
r["gas"] = toString(gas);
r["gasCost"] = toString(gasCost);
r["depth"] = toString(ext.depth);
if (!!newMemSize)
r["memexpand"] = toString(newMemSize);

Expand Down
30 changes: 15 additions & 15 deletions libevm/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ owning_bytes_ref VM::exec(u256& _io_gas, ExtVMFace& _ext, OnOpFunc const& _onOp)
m_ext = &_ext;
m_schedule = &m_ext->evmSchedule();
m_onOp = _onOp;
m_onFail = &VM::onOperation;
m_onFail = &VM::onOperation; // this results in operations that fail being logged twice in the trace

try
{
Expand Down Expand Up @@ -263,9 +263,9 @@ void VM::interpretCases()

CASE(RETURN)
{
ON_OP();
m_copyMemSize = 0;
updateMem(memNeed(m_SP[0], m_SP[1]));
ON_OP();
updateIOGas();

uint64_t b = (uint64_t)m_SP[0];
Expand Down Expand Up @@ -330,8 +330,8 @@ void VM::interpretCases()

CASE(MLOAD)
{
updateMem(toInt63(m_SP[0]) + 32);
ON_OP();
updateMem(toInt63(m_SP[0]) + 32);
updateIOGas();

m_SPP[0] = (u256)*(h256 const*)(m_mem.data() + (unsigned)m_SP[0]);
Expand All @@ -340,8 +340,8 @@ void VM::interpretCases()

CASE(MSTORE)
{
updateMem(toInt63(m_SP[0]) + 32);
ON_OP();
updateMem(toInt63(m_SP[0]) + 32);
updateIOGas();

*(h256*)&m_mem[(unsigned)m_SP[0]] = (h256)m_SP[1];
Expand All @@ -350,8 +350,8 @@ void VM::interpretCases()

CASE(MSTORE8)
{
updateMem(toInt63(m_SP[0]) + 1);
ON_OP();
updateMem(toInt63(m_SP[0]) + 1);
updateIOGas();

m_mem[(unsigned)m_SP[0]] = (byte)(m_SP[1] & 0xff);
Expand All @@ -360,9 +360,9 @@ void VM::interpretCases()

CASE(SHA3)
{
ON_OP();
m_runGas = toInt63(m_schedule->sha3Gas + (u512(m_SP[1]) + 31) / 32 * m_schedule->sha3WordGas);
updateMem(memNeed(m_SP[0], m_SP[1]));
ON_OP();
updateIOGas();

uint64_t inOff = (uint64_t)m_SP[0];
Expand All @@ -373,11 +373,11 @@ void VM::interpretCases()

CASE(LOG0)
{
ON_OP();
if (m_ext->staticCall)
throwDisallowedStateChange();

logGasMem();
ON_OP();
updateIOGas();

m_ext->log({}, bytesConstRef(m_mem.data() + (uint64_t)m_SP[0], (uint64_t)m_SP[1]));
Expand All @@ -386,11 +386,11 @@ void VM::interpretCases()

CASE(LOG1)
{
ON_OP();
if (m_ext->staticCall)
throwDisallowedStateChange();

logGasMem();
ON_OP();
updateIOGas();

m_ext->log({m_SP[2]}, bytesConstRef(m_mem.data() + (uint64_t)m_SP[0], (uint64_t)m_SP[1]));
Expand All @@ -399,11 +399,11 @@ void VM::interpretCases()

CASE(LOG2)
{
ON_OP();
if (m_ext->staticCall)
throwDisallowedStateChange();

logGasMem();
ON_OP();
updateIOGas();

m_ext->log({m_SP[2], m_SP[3]}, bytesConstRef(m_mem.data() + (uint64_t)m_SP[0], (uint64_t)m_SP[1]));
Expand All @@ -412,11 +412,11 @@ void VM::interpretCases()

CASE(LOG3)
{
ON_OP();
if (m_ext->staticCall)
throwDisallowedStateChange();

logGasMem();
ON_OP();
updateIOGas();

m_ext->log({m_SP[2], m_SP[3], m_SP[4]}, bytesConstRef(m_mem.data() + (uint64_t)m_SP[0], (uint64_t)m_SP[1]));
Expand All @@ -425,11 +425,11 @@ void VM::interpretCases()

CASE(LOG4)
{
ON_OP();
if (m_ext->staticCall)
throwDisallowedStateChange();

logGasMem();
ON_OP();
updateIOGas();

m_ext->log({m_SP[2], m_SP[3], m_SP[4], m_SP[5]}, bytesConstRef(m_mem.data() + (uint64_t)m_SP[0], (uint64_t)m_SP[1]));
Expand Down Expand Up @@ -1220,9 +1220,9 @@ void VM::interpretCases()

CASE(CALLDATACOPY)
{
ON_OP();
m_copyMemSize = toInt63(m_SP[2]);
updateMem(memNeed(m_SP[0], m_SP[2]));
ON_OP();
updateIOGas();

copyDataToMemory(m_ext->data, m_SP);
Expand All @@ -1248,9 +1248,9 @@ void VM::interpretCases()

CASE(CODECOPY)
{
ON_OP();
m_copyMemSize = toInt63(m_SP[2]);
updateMem(memNeed(m_SP[0], m_SP[2]));
ON_OP();
updateIOGas();

copyDataToMemory(&m_ext->code, m_SP);
Expand All @@ -1259,10 +1259,10 @@ void VM::interpretCases()

CASE(EXTCODECOPY)
{
ON_OP();
m_runGas = toInt63(m_schedule->extcodecopyGas);
m_copyMemSize = toInt63(m_SP[3]);
updateMem(memNeed(m_SP[1], m_SP[3]));
ON_OP();
updateIOGas();

Address a = asAddress(m_SP[0]);
Expand All @@ -1282,8 +1282,8 @@ void VM::interpretCases()

CASE(BLOCKHASH)
{
m_runGas = toInt63(m_schedule->blockhashGas);
ON_OP();
m_runGas = toInt63(m_schedule->blockhashGas);
updateIOGas();

m_SPP[0] = (u256)m_ext->blockHash(m_SP[0]);
Expand Down
28 changes: 18 additions & 10 deletions libevm/VMCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,39 @@ void VM::copyDataToMemory(bytesConstRef _data, u256*_sp)

void VM::throwOutOfGas()
{
if (m_onFail)
(this->*m_onFail)();
// disabled to prevent duplicate steps in vmtrace log
//if (m_onFail)
// (this->*m_onFail)();
BOOST_THROW_EXCEPTION(OutOfGas());
}

void VM::throwBadInstruction()
{
if (m_onFail)
(this->*m_onFail)();
// disabled to prevent duplicate steps in vmtrace log
//if (m_onFail)
// (this->*m_onFail)();
BOOST_THROW_EXCEPTION(BadInstruction());
}

void VM::throwBadJumpDestination()
{
if (m_onFail)
(this->*m_onFail)();
// disabled to prevent duplicate steps in vmtrace log
//if (m_onFail)
// (this->*m_onFail)();
BOOST_THROW_EXCEPTION(BadJumpDestination());
}

void VM::throwDisallowedStateChange()
{
if (m_onFail)
(this->*m_onFail)();
// disabled to prevent duplicate steps in vmtrace log
//if (m_onFail)
// (this->*m_onFail)();
BOOST_THROW_EXCEPTION(DisallowedStateChange());
}

// throwBadStack is called from fetchInstruction() -> adjustStack()
// its the only exception that can happen before ON_OP() log is done for an opcode case in VM.cpp
// so the call to m_onFail is needed here
void VM::throwBadStack(unsigned _removed, unsigned _added)
{
bigint size = m_stackEnd - m_SPP;
Expand All @@ -96,6 +103,7 @@ void VM::throwRevertInstruction(owning_bytes_ref&& _output)

void VM::throwBufferOverrun(bigint const& _endOfAccess)
{
// todo: disable this m_onFail, may result in duplicate log step in the trace
if (m_onFail)
(this->*m_onFail)();
BOOST_THROW_EXCEPTION(BufferOverrun() << RequirementError(_endOfAccess, bigint(m_returnData.size())));
Expand Down Expand Up @@ -124,10 +132,10 @@ int64_t VM::verifyJumpDest(u256 const& _dest, bool _throw)

void VM::caseCreate()
{
ON_OP();
m_bounce = &VM::interpretCases;
m_runGas = toInt63(m_schedule->createGas);
updateMem(memNeed(m_SP[1], m_SP[2]));
ON_OP();
updateIOGas();

auto const& endowment = m_SP[0];
Expand Down Expand Up @@ -211,6 +219,7 @@ bool VM::caseCallSetup(CallParameters *callParams, bytesRef& o_output)
assert(callParams->valueTransfer == 0);
assert(callParams->apparentValue == 0);

ON_OP();
m_runGas = toInt63(m_schedule->callGas);

callParams->staticCall = (m_OP == Instruction::STATICCALL || m_ext->staticCall);
Expand Down Expand Up @@ -251,7 +260,6 @@ bool VM::caseCallSetup(CallParameters *callParams, bytesRef& o_output)
}

m_runGas = toInt63(callParams->gas);
ON_OP();
updateIOGas();

if (haveValueArg && m_SP[2] > 0)
Expand Down
4 changes: 1 addition & 3 deletions test/tools/libtesteth/ImportTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,11 @@ std::tuple<eth::State, ImportTest::ExecOutput, eth::ChangeLog> ImportTest::execu
unique_ptr<SealEngineFace> se(ChainParams(genesisInfo(_sealEngineNetwork)).createSealEngine());
if (Options::get().jsontrace)
{
Json::Value trace;
StandardTrace st;
st.setShowMnemonics();
st.setOptions(Options::get().jsontraceOptions);
out = initialState.execute(_env, *se.get(), _tr, Permanence::Uncommitted, st.onOp());
Json::Reader().parse(st.json(), trace);
cout << trace;
cout << st.json();
}
else
out = initialState.execute(_env, *se.get(), _tr, Permanence::Uncommitted);
Expand Down

0 comments on commit a8bac5d

Please sign in to comment.