Browse Source

Manage invalid instructions without bombing.

cl-refactor
Gav Wood 11 years ago
parent
commit
0571b637ab
  1. 9
      alethzero/MainWin.cpp
  2. 4
      libethereum/Transaction.cpp
  3. 12
      libevmface/Instruction.cpp
  4. 4
      libevmface/Instruction.h

9
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)

4
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;

12
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({"<INVALID_INSTRUCTION: " + toString((unsigned)_inst) + ">", 0, 0, 0});
}
}

4
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<Instruction, InstructionInfo> c_instructionInfo;

Loading…
Cancel
Save