Skip to content

Commit

Permalink
Merge pull request #39 from UnSciPreneur/instruction_pr
Browse files Browse the repository at this point in the history
Updated Instruction set to the current state of ethereum-cpp
  • Loading branch information
msuiche authored Jan 16, 2018
2 parents cdca169 + e648824 commit 4050e53
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 35 deletions.
9 changes: 4 additions & 5 deletions porosity/porosity/Contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ auto
Contract::addBasicBlock(
uint32_t _offset,
uint32_t _size
) {
) -> map<unsigned int, _BasicBlockInfo>::iterator {
BasicBlockInfo newEntry = { 0 };
newEntry.offset = _offset;
newEntry.size = _size;
Expand Down Expand Up @@ -992,7 +992,7 @@ Contract::decompileBlock(
break;
case Instruction::SSTORE:
{

if (i->stack.size()) {

string valueName = "";
Expand All @@ -1014,18 +1014,17 @@ Contract::decompileBlock(
} else {
exp = "store[?];";
}

if (_block->Flags & BlockFlags::NoMoreSSTORE) errCode |= DCode_Err_ReentrantVulnerablity;
break;

}
case Instruction::RETURN:
if (i->stack.size()) {
exp = "return " + i->stack[0].name + ";";
} else {
exp = "return;";
}

result = false;
break;
case Instruction::STOP:
Expand Down
4 changes: 2 additions & 2 deletions porosity/porosity/Contract.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Contract {
m_byteCodeRuntime = bytecode;
}
else {
// In the caes IsRuntimeCode() didn't return the offset we move on.
// In the case IsRuntimeCode() didn't return the offset we move on.
if (!m_runtimeOffset) return;

bytes runtimeCode(bytecode.begin() + m_runtimeOffset, bytecode.end());
Expand Down Expand Up @@ -121,7 +121,7 @@ class Contract {
addBasicBlock(
uint32_t _offset,
uint32_t _size
);
) -> map<unsigned int, _BasicBlockInfo>::iterator;

uint32_t
getInstructionIndexAtOffset(
Expand Down
34 changes: 34 additions & 0 deletions porosity/porosity/Instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,41 @@ static const std::map<Instruction, InstructionInfo> c_instructionInfo =
{ Instruction::PUTLOCAL, { "PUTLOCAL", 2, 1, 0, true, Tier::VeryLow } },
{ Instruction::GETLOCAL, { "GETLOCAL", 2, 0, 1, true, Tier::VeryLow } },

{ Instruction::XADD, { "XADD", 1, 0, 0, false, Tier::Special } },
{ Instruction::XMUL, { "XMUL", 1, 2, 1, false, Tier::Special } },
{ Instruction::XSUB, { "XSUB", 1, 2, 1, false, Tier::Special } },
{ Instruction::XDIV, { "XDIV", 1, 2, 1, false, Tier::Special } },
{ Instruction::XSDIV, { "XSDIV", 1, 2, 1, false, Tier::Special } },
{ Instruction::XMOD, { "XMOD", 1, 2, 1, false, Tier::Special } },
{ Instruction::XSMOD, { "XSMOD", 1, 2, 1, false, Tier::Special } },
{ Instruction::XLT, { "XLT", 1, 2, 1, false, Tier::Special } },
{ Instruction::XGT, { "XGT", 1, 2, 1, false, Tier::Special } },
{ Instruction::XSLT, { "XSLT", 1, 2, 1, false, Tier::Special } },
{ Instruction::XSGT, { "XSGT", 1, 2, 1, false, Tier::Special } },
{ Instruction::XEQ, { "XEQ", 1, 2, 1, false, Tier::Special } },
{ Instruction::XISZERO, { "XISZERO", 1, 2, 1, false, Tier::Special } },
{ Instruction::XAND, { "XAND", 1, 1, 1, false, Tier::Special } },
{ Instruction::XOR, { "XOR", 1, 2, 1, false, Tier::Special } },
{ Instruction::XXOR, { "XXOR", 1, 2, 1, false, Tier::Special } },
{ Instruction::XNOT, { "XNOT", 1, 2, 1, false, Tier::Special } },
{ Instruction::XSHL, { "XSHL", 1, 2, 1, false, Tier::Special } },
{ Instruction::XSHR, { "XSHR", 1, 2, 1, false, Tier::Special } },
{ Instruction::XSAR, { "XSAR", 1, 2, 1, false, Tier::Special } },
{ Instruction::XROL, { "XROL", 1, 2, 1, false, Tier::Special } },
{ Instruction::XROR, { "XROR", 1, 2, 1, false, Tier::Special } },
{ Instruction::XPUSH, { "XPUSH", 1, 1, 1, false, Tier::VeryLow } },
{ Instruction::XMLOAD, { "XMLOAD", 1, 1, 1, false, Tier::VeryLow } },
{ Instruction::XMSTORE, { "XMSTORE", 1, 2, 0, true, Tier::VeryLow } },
{ Instruction::XSLOAD, { "XSLOAD", 1, 1, 1, false, Tier::Special } },
{ Instruction::XSSTORE, { "XSSTORE", 1, 2, 0, true, Tier::Special } },
{ Instruction::XVTOWIDE, { "XVTOWIDE", 1, 1, 1, false, Tier::VeryLow } },
{ Instruction::XWIDETOV, { "XWIDETOV", 1, 1, 1, false, Tier::VeryLow } },
{ Instruction::XPUT, { "XPUT", 1, 3, 1, false, Tier::Special } },
{ Instruction::XGET, { "XGET", 1, 2, 1, false, Tier::Special } },
{ Instruction::XSWIZZLE, { "XSWIZZLE", 1, 2, 1, false, Tier::Special } },
{ Instruction::XSHUFFLE, { "XSHUFFLE", 1, 3, 1, false, Tier::Special } },
{ Instruction::CREATE, { "CREATE", 0, 3, 1, true, Tier::Special } },
{ Instruction::CREATE2, { "CREATE2", 0, 4, 1, true, Tier::Special } },
{ Instruction::CALL, { "CALL", 0, 7, 1, true, Tier::Special } },
{ Instruction::CALLCODE, { "CALLCODE", 0, 7, 1, true, Tier::Special } },
{ Instruction::RETURN, { "RETURN", 0, 2, 0, true, Tier::Zero } },
Expand Down
89 changes: 62 additions & 27 deletions porosity/porosity/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace dev
{
STOP = 0x00, ///< halts execution
ADD, ///< addition operation
MUL, ///< mulitplication operation
MUL, ///< multiplication operation
SUB, ///< subtraction operation
DIV, ///< integer division operation
SDIV, ///< signed integer division operation
Expand All @@ -51,7 +51,7 @@ namespace dev
AND, ///< bitwise AND operation
OR, ///< bitwise OR operation
XOR, ///< bitwise XOR operation
NOT, ///< bitwise NOT opertation
NOT, ///< bitwise NOT operation
BYTE, ///< retrieve single byte from word

SHA3 = 0x20, ///< compute SHA3-256 hash
Expand Down Expand Up @@ -165,31 +165,66 @@ namespace dev
LOG3, ///< Makes a log entry; 3 topics.
LOG4, ///< Makes a log entry; 4 topics.

// these are generated by the interpreter - should never be in user code
PUSHC = 0xac, ///< push value from constant pool
JUMPC, ///< alter the program counter - pre-verified
JUMPCI, ///< conditionally alter the program counter - pre-verified

JUMPTO = 0xb0, ///< alter the program counter to a jumpdest
JUMPIF, ///< conditionally alter the program counter
JUMPSUB, ///< alter the program counter to a beginsub
JUMPV, ///< alter the program counter to a jumpdest
JUMPSUBV, ///< alter the program counter to a beginsub
BEGINSUB, ///< set a potential jumpsub destination
BEGINDATA, ///< begine the data section
RETURNSUB, ///< return to subroutine jumped from
PUTLOCAL, ///< pop top of stack to local variable
GETLOCAL, ///< push local variable to top of stack

CREATE = 0xf0, ///< create a new account with associated code
CALL, ///< message-call into an account
CALLCODE, ///< message-call with another account's code only
RETURN, ///< halt execution returning output data
DELEGATECALL, ///< like CALLCODE but keeps caller's value and sender
STATICCALL = 0xfa, ///< like CALL except state changing operation are not permitted (will throw)
REVERT = 0xfd, ///< stop execution and revert state changes, without consuming all provided gas
INVALID = 0xfe, ///< dedicated invalid instruction
SUICIDE = 0xff ///< halt execution and register account for later deletion
// these are generated by the interpreter - should never be in user code
PUSHC = 0xac, ///< push value from constant pool
JUMPC, ///< alter the program counter - pre-verified
JUMPCI, ///< conditionally alter the program counter - pre-verified

JUMPTO = 0xb0, ///< alter the program counter to a jumpdest
JUMPIF, ///< conditionally alter the program counter
JUMPSUB, ///< alter the program counter to a beginsub
JUMPV, ///< alter the program counter to a jumpdest
JUMPSUBV, ///< alter the program counter to a beginsub
BEGINSUB, ///< set a potential jumpsub destination
BEGINDATA, ///< begin the data section
RETURNSUB, ///< return to subroutine jumped from
PUTLOCAL, ///< pop top of stack to local variable
GETLOCAL, ///< push local variable to top of stack

XADD = 0xc1, ///< addition operation
XMUL, ///< multiplication operation
XSUB, ///< subtraction operation
XDIV, ///< integer division operation
XSDIV, ///< signed integer division operation
XMOD, ///< modulo remainder operation
XSMOD, ///< signed modulo remainder operation
XLT = 0xd0, ///< less-than comparision
XGT, ///< greater-than comparision
XSLT, ///< signed less-than comparision
XSGT, ///< signed greater-than comparision
XEQ, ///< equality comparision
XISZERO, ///< simple not operator
XAND, ///< bitwise AND operation
XOOR, ///< bitwise OR operation
XXOR, ///< bitwise XOR operation
XNOT, ///< bitwise NOT operation
XSHL = 0xdb, ///< shift left operation
XSHR, ///< shift right operation
XSAR, ///< shift arithmetic right operation
XROL, ///< rotate left operation
XROR, ///< rotate right operation
XPUSH = 0xe0, ///< push vector to stack
XMLOAD, ///< load vector from memory
XMSTORE, ///< save vector to memory
XSLOAD = 0xe4, ///< load vector from storage
XSSTORE, ///< save vector to storage
XVTOWIDE, ///< convert vector to wide integer
XWIDETOV, ///< convert wide integer to vector
XGET, ///< get data from vector
XPUT, ///< put data in vector
XSWIZZLE, ///< permute data in vector
XSHUFFLE, ///< permute data in two vectors

CREATE = 0xf0, ///< create a new account with associated code
CALL, ///< message-call into an account
CALLCODE, ///< message-call with another account's code only
RETURN, ///< halt execution returning output data
DELEGATECALL, ///< like CALLCODE but keeps caller's value and sender
STATICCALL = 0xfa, ///< like CALL except state changing operation are not permitted (will throw)
CREATE2 = 0xfb, ///< create a new account with associated code. sha3((sender + salt + sha3(code))
REVERT = 0xfd, ///< stop execution and revert state changes, without consuming all provided gas
INVALID = 0xfe, ///< dedicated invalid instruction
SUICIDE = 0xff ///< halt execution and register account for later deletion
};

/// @returns the number of PUSH Instruction _inst
Expand Down
4 changes: 3 additions & 1 deletion porosity/porosity/Porosity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Revision History:

uint32_t g_VerboseLevel = VERBOSE_LEVEL;
bool g_SingleStepping = false;
bytes defaultArguments = {
bytes defaultArguments = {
0xee, 0xe9, 0x72, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // arg1
0xee, 0xe9, 0x72, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // arg2
0xee, 0xe9, 0x72, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // arg3
Expand Down Expand Up @@ -121,9 +121,11 @@ parse(
out->method |= MethodListFunctions;
}
else if (((kw == "--runtime-code") || (kw == "--code")) && arg.size()) {
// ToDo: why do we have out->codeByte AND out->codeByteRuntime? the former does not seem to get used.
out->codeByteRuntime = fromHex(arg);
}
else if ((kw == "--code") && arg.size()) {
// ToDo: this case never matches. see the one above
out->codeByte = fromHex(arg);
}
else if ((kw == "--code-file") && arg.size()) {
Expand Down

0 comments on commit 4050e53

Please sign in to comment.