From 0571b637ab525487ad9d1cc5df5f077e5761df6d Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 26 Aug 2014 22:23:37 +0200 Subject: [PATCH] Manage invalid instructions without bombing. --- alethzero/MainWin.cpp | 9 ++++----- libethereum/Transaction.cpp | 4 ++-- libevmface/Instruction.cpp | 12 ++++++++++++ libevmface/Instruction.h | 4 +++- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index f499f38b9..4c18364ba 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -82,7 +82,6 @@ using eth::operator<<; // vars using eth::g_logPost; using eth::g_logVerbosity; -using eth::c_instructionInfo; static void initUnits(QComboBox* _b) { @@ -1702,7 +1701,7 @@ void Main::on_dumpTracePretty_triggered() f << " STORAGE" << endl; for (auto const& i: ws.storage) f << showbase << hex << i.first << ": " << i.second << endl; - f << dec << ws.levels.size() << " | " << ws.cur << " | #" << ws.steps << " | " << hex << setw(4) << setfill('0') << ws.curPC << " : " << c_instructionInfo.at(ws.inst).name << " | " << dec << ws.gas << " | -" << dec << ws.gasCost << " | " << ws.newMemSize << "x32"; + f << dec << ws.levels.size() << " | " << ws.cur << " | #" << ws.steps << " | " << hex << setw(4) << setfill('0') << ws.curPC << " : " << eth::instructionInfo(ws.inst).name << " | " << dec << ws.gas << " | -" << dec << ws.gasCost << " | " << ws.newMemSize << "x32"; } } @@ -1851,7 +1850,7 @@ void Main::updateDebugger() ostringstream out; out << s.cur.abridged(); if (i) - out << " " << c_instructionInfo.at(s.inst).name << " @0x" << hex << s.curPC; + out << " " << instructionInfo(s.inst).name << " @0x" << hex << s.curPC; ui->callStack->addItem(QString::fromStdString(out.str())); } } @@ -1867,7 +1866,7 @@ void Main::updateDebugger() byte b = i < code.size() ? code[i] : 0; try { - QString s = c_instructionInfo.at((Instruction)b).name; + QString s = QString::fromStdString(instructionInfo((Instruction)b).name); ostringstream out; out << hex << setw(4) << setfill('0') << i; m_pcWarp[i] = dc->count(); @@ -1917,7 +1916,7 @@ void Main::updateDebugger() cwarn << "PC (" << (unsigned)ws.curPC << ") is after code range (" << m_codes[ws.code].size() << ")"; ostringstream ss; - ss << dec << "STEP: " << ws.steps << " | PC: 0x" << hex << ws.curPC << " : " << c_instructionInfo.at(ws.inst).name << " | ADDMEM: " << dec << ws.newMemSize << " words | COST: " << dec << ws.gasCost << " | GAS: " << dec << ws.gas; + ss << dec << "STEP: " << ws.steps << " | PC: 0x" << hex << ws.curPC << " : " << eth::instructionInfo(ws.inst).name << " | ADDMEM: " << dec << ws.newMemSize << " words | COST: " << dec << ws.gasCost << " | GAS: " << dec << ws.gas; ui->debugStateInfo->setText(QString::fromStdString(ss.str())); stringstream s; for (auto const& i: ws.storage) diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 5a0fa8eeb..9968683fe 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -27,7 +27,7 @@ using namespace std; using namespace eth; -#define ETH_ADDRESS_DEBUG 0 +#define ETH_ADDRESS_DEBUG 1 Transaction::Transaction(bytesConstRef _rlpData, bool _checkSender) { @@ -85,7 +85,7 @@ Address Transaction::sender() const cout << "MSG: " << msg << endl; cout << "R S V: " << sig[0] << " " << sig[1] << " " << (int)(vrs.v - 27) << "+27" << endl; cout << "PUB: " << toHex(bytesConstRef(&(pubkey[1]), 64)) << endl; - cout << "ADR: " << ret << endl; + cout << "ADR: " << m_sender << endl; #endif } return m_sender; diff --git a/libevmface/Instruction.cpp b/libevmface/Instruction.cpp index c31194475..0f68cdaf4 100644 --- a/libevmface/Instruction.cpp +++ b/libevmface/Instruction.cpp @@ -296,3 +296,15 @@ string eth::disassemble(bytes const& _mem) } return ret.str(); } + +InstructionInfo eth::instructionInfo(Instruction _inst) +{ + try + { + return c_instructionInfo.at(_inst); + } + catch (...) + { + return InstructionInfo({"", 0, 0, 0}); + } +} diff --git a/libevmface/Instruction.h b/libevmface/Instruction.h index 1afe930aa..54f243e11 100644 --- a/libevmface/Instruction.h +++ b/libevmface/Instruction.h @@ -169,12 +169,14 @@ enum class Instruction: uint8_t /// Information structure for a particular instruction. struct InstructionInfo { - char const* name; ///< The name of the instruction. + std::string name; ///< The name of the instruction. int additional; ///< Additional items required in memory for this instructions (only for PUSH). int args; ///< Number of items required on the stack for this instruction (and, for the purposes of ret, the number taken from the stack). int ret; ///< Number of items placed (back) on the stack by this instruction, assuming args items were removed. }; +InstructionInfo instructionInfo(Instruction _inst); + /// Information on all the instructions. extern const std::map c_instructionInfo;