Skip to content

Commit 4050e53

Browse files
authored
Merge pull request #39 from UnSciPreneur/instruction_pr
Updated Instruction set to the current state of ethereum-cpp
2 parents cdca169 + e648824 commit 4050e53

5 files changed

Lines changed: 105 additions & 35 deletions

File tree

porosity/porosity/Contract.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ auto
5151
Contract::addBasicBlock(
5252
uint32_t _offset,
5353
uint32_t _size
54-
) {
54+
) -> map<unsigned int, _BasicBlockInfo>::iterator {
5555
BasicBlockInfo newEntry = { 0 };
5656
newEntry.offset = _offset;
5757
newEntry.size = _size;
@@ -992,7 +992,7 @@ Contract::decompileBlock(
992992
break;
993993
case Instruction::SSTORE:
994994
{
995-
995+
996996
if (i->stack.size()) {
997997

998998
string valueName = "";
@@ -1014,18 +1014,17 @@ Contract::decompileBlock(
10141014
} else {
10151015
exp = "store[?];";
10161016
}
1017-
1017+
10181018
if (_block->Flags & BlockFlags::NoMoreSSTORE) errCode |= DCode_Err_ReentrantVulnerablity;
10191019
break;
1020-
10211020
}
10221021
case Instruction::RETURN:
10231022
if (i->stack.size()) {
10241023
exp = "return " + i->stack[0].name + ";";
10251024
} else {
10261025
exp = "return;";
10271026
}
1028-
1027+
10291028
result = false;
10301029
break;
10311030
case Instruction::STOP:

porosity/porosity/Contract.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Contract {
2929
m_byteCodeRuntime = bytecode;
3030
}
3131
else {
32-
// In the caes IsRuntimeCode() didn't return the offset we move on.
32+
// In the case IsRuntimeCode() didn't return the offset we move on.
3333
if (!m_runtimeOffset) return;
3434

3535
bytes runtimeCode(bytecode.begin() + m_runtimeOffset, bytecode.end());
@@ -121,7 +121,7 @@ class Contract {
121121
addBasicBlock(
122122
uint32_t _offset,
123123
uint32_t _size
124-
);
124+
) -> map<unsigned int, _BasicBlockInfo>::iterator;
125125

126126
uint32_t
127127
getInstructionIndexAtOffset(

porosity/porosity/Instruction.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,41 @@ static const std::map<Instruction, InstructionInfo> c_instructionInfo =
162162
{ Instruction::PUTLOCAL, { "PUTLOCAL", 2, 1, 0, true, Tier::VeryLow } },
163163
{ Instruction::GETLOCAL, { "GETLOCAL", 2, 0, 1, true, Tier::VeryLow } },
164164

165+
{ Instruction::XADD, { "XADD", 1, 0, 0, false, Tier::Special } },
166+
{ Instruction::XMUL, { "XMUL", 1, 2, 1, false, Tier::Special } },
167+
{ Instruction::XSUB, { "XSUB", 1, 2, 1, false, Tier::Special } },
168+
{ Instruction::XDIV, { "XDIV", 1, 2, 1, false, Tier::Special } },
169+
{ Instruction::XSDIV, { "XSDIV", 1, 2, 1, false, Tier::Special } },
170+
{ Instruction::XMOD, { "XMOD", 1, 2, 1, false, Tier::Special } },
171+
{ Instruction::XSMOD, { "XSMOD", 1, 2, 1, false, Tier::Special } },
172+
{ Instruction::XLT, { "XLT", 1, 2, 1, false, Tier::Special } },
173+
{ Instruction::XGT, { "XGT", 1, 2, 1, false, Tier::Special } },
174+
{ Instruction::XSLT, { "XSLT", 1, 2, 1, false, Tier::Special } },
175+
{ Instruction::XSGT, { "XSGT", 1, 2, 1, false, Tier::Special } },
176+
{ Instruction::XEQ, { "XEQ", 1, 2, 1, false, Tier::Special } },
177+
{ Instruction::XISZERO, { "XISZERO", 1, 2, 1, false, Tier::Special } },
178+
{ Instruction::XAND, { "XAND", 1, 1, 1, false, Tier::Special } },
179+
{ Instruction::XOR, { "XOR", 1, 2, 1, false, Tier::Special } },
180+
{ Instruction::XXOR, { "XXOR", 1, 2, 1, false, Tier::Special } },
181+
{ Instruction::XNOT, { "XNOT", 1, 2, 1, false, Tier::Special } },
182+
{ Instruction::XSHL, { "XSHL", 1, 2, 1, false, Tier::Special } },
183+
{ Instruction::XSHR, { "XSHR", 1, 2, 1, false, Tier::Special } },
184+
{ Instruction::XSAR, { "XSAR", 1, 2, 1, false, Tier::Special } },
185+
{ Instruction::XROL, { "XROL", 1, 2, 1, false, Tier::Special } },
186+
{ Instruction::XROR, { "XROR", 1, 2, 1, false, Tier::Special } },
187+
{ Instruction::XPUSH, { "XPUSH", 1, 1, 1, false, Tier::VeryLow } },
188+
{ Instruction::XMLOAD, { "XMLOAD", 1, 1, 1, false, Tier::VeryLow } },
189+
{ Instruction::XMSTORE, { "XMSTORE", 1, 2, 0, true, Tier::VeryLow } },
190+
{ Instruction::XSLOAD, { "XSLOAD", 1, 1, 1, false, Tier::Special } },
191+
{ Instruction::XSSTORE, { "XSSTORE", 1, 2, 0, true, Tier::Special } },
192+
{ Instruction::XVTOWIDE, { "XVTOWIDE", 1, 1, 1, false, Tier::VeryLow } },
193+
{ Instruction::XWIDETOV, { "XWIDETOV", 1, 1, 1, false, Tier::VeryLow } },
194+
{ Instruction::XPUT, { "XPUT", 1, 3, 1, false, Tier::Special } },
195+
{ Instruction::XGET, { "XGET", 1, 2, 1, false, Tier::Special } },
196+
{ Instruction::XSWIZZLE, { "XSWIZZLE", 1, 2, 1, false, Tier::Special } },
197+
{ Instruction::XSHUFFLE, { "XSHUFFLE", 1, 3, 1, false, Tier::Special } },
165198
{ Instruction::CREATE, { "CREATE", 0, 3, 1, true, Tier::Special } },
199+
{ Instruction::CREATE2, { "CREATE2", 0, 4, 1, true, Tier::Special } },
166200
{ Instruction::CALL, { "CALL", 0, 7, 1, true, Tier::Special } },
167201
{ Instruction::CALLCODE, { "CALLCODE", 0, 7, 1, true, Tier::Special } },
168202
{ Instruction::RETURN, { "RETURN", 0, 2, 0, true, Tier::Zero } },

porosity/porosity/Instruction.h

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace dev
3131
{
3232
STOP = 0x00, ///< halts execution
3333
ADD, ///< addition operation
34-
MUL, ///< mulitplication operation
34+
MUL, ///< multiplication operation
3535
SUB, ///< subtraction operation
3636
DIV, ///< integer division operation
3737
SDIV, ///< signed integer division operation
@@ -51,7 +51,7 @@ namespace dev
5151
AND, ///< bitwise AND operation
5252
OR, ///< bitwise OR operation
5353
XOR, ///< bitwise XOR operation
54-
NOT, ///< bitwise NOT opertation
54+
NOT, ///< bitwise NOT operation
5555
BYTE, ///< retrieve single byte from word
5656

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

168-
// these are generated by the interpreter - should never be in user code
169-
PUSHC = 0xac, ///< push value from constant pool
170-
JUMPC, ///< alter the program counter - pre-verified
171-
JUMPCI, ///< conditionally alter the program counter - pre-verified
172-
173-
JUMPTO = 0xb0, ///< alter the program counter to a jumpdest
174-
JUMPIF, ///< conditionally alter the program counter
175-
JUMPSUB, ///< alter the program counter to a beginsub
176-
JUMPV, ///< alter the program counter to a jumpdest
177-
JUMPSUBV, ///< alter the program counter to a beginsub
178-
BEGINSUB, ///< set a potential jumpsub destination
179-
BEGINDATA, ///< begine the data section
180-
RETURNSUB, ///< return to subroutine jumped from
181-
PUTLOCAL, ///< pop top of stack to local variable
182-
GETLOCAL, ///< push local variable to top of stack
183-
184-
CREATE = 0xf0, ///< create a new account with associated code
185-
CALL, ///< message-call into an account
186-
CALLCODE, ///< message-call with another account's code only
187-
RETURN, ///< halt execution returning output data
188-
DELEGATECALL, ///< like CALLCODE but keeps caller's value and sender
189-
STATICCALL = 0xfa, ///< like CALL except state changing operation are not permitted (will throw)
190-
REVERT = 0xfd, ///< stop execution and revert state changes, without consuming all provided gas
191-
INVALID = 0xfe, ///< dedicated invalid instruction
192-
SUICIDE = 0xff ///< halt execution and register account for later deletion
168+
// these are generated by the interpreter - should never be in user code
169+
PUSHC = 0xac, ///< push value from constant pool
170+
JUMPC, ///< alter the program counter - pre-verified
171+
JUMPCI, ///< conditionally alter the program counter - pre-verified
172+
173+
JUMPTO = 0xb0, ///< alter the program counter to a jumpdest
174+
JUMPIF, ///< conditionally alter the program counter
175+
JUMPSUB, ///< alter the program counter to a beginsub
176+
JUMPV, ///< alter the program counter to a jumpdest
177+
JUMPSUBV, ///< alter the program counter to a beginsub
178+
BEGINSUB, ///< set a potential jumpsub destination
179+
BEGINDATA, ///< begin the data section
180+
RETURNSUB, ///< return to subroutine jumped from
181+
PUTLOCAL, ///< pop top of stack to local variable
182+
GETLOCAL, ///< push local variable to top of stack
183+
184+
XADD = 0xc1, ///< addition operation
185+
XMUL, ///< multiplication operation
186+
XSUB, ///< subtraction operation
187+
XDIV, ///< integer division operation
188+
XSDIV, ///< signed integer division operation
189+
XMOD, ///< modulo remainder operation
190+
XSMOD, ///< signed modulo remainder operation
191+
XLT = 0xd0, ///< less-than comparision
192+
XGT, ///< greater-than comparision
193+
XSLT, ///< signed less-than comparision
194+
XSGT, ///< signed greater-than comparision
195+
XEQ, ///< equality comparision
196+
XISZERO, ///< simple not operator
197+
XAND, ///< bitwise AND operation
198+
XOOR, ///< bitwise OR operation
199+
XXOR, ///< bitwise XOR operation
200+
XNOT, ///< bitwise NOT operation
201+
XSHL = 0xdb, ///< shift left operation
202+
XSHR, ///< shift right operation
203+
XSAR, ///< shift arithmetic right operation
204+
XROL, ///< rotate left operation
205+
XROR, ///< rotate right operation
206+
XPUSH = 0xe0, ///< push vector to stack
207+
XMLOAD, ///< load vector from memory
208+
XMSTORE, ///< save vector to memory
209+
XSLOAD = 0xe4, ///< load vector from storage
210+
XSSTORE, ///< save vector to storage
211+
XVTOWIDE, ///< convert vector to wide integer
212+
XWIDETOV, ///< convert wide integer to vector
213+
XGET, ///< get data from vector
214+
XPUT, ///< put data in vector
215+
XSWIZZLE, ///< permute data in vector
216+
XSHUFFLE, ///< permute data in two vectors
217+
218+
CREATE = 0xf0, ///< create a new account with associated code
219+
CALL, ///< message-call into an account
220+
CALLCODE, ///< message-call with another account's code only
221+
RETURN, ///< halt execution returning output data
222+
DELEGATECALL, ///< like CALLCODE but keeps caller's value and sender
223+
STATICCALL = 0xfa, ///< like CALL except state changing operation are not permitted (will throw)
224+
CREATE2 = 0xfb, ///< create a new account with associated code. sha3((sender + salt + sha3(code))
225+
REVERT = 0xfd, ///< stop execution and revert state changes, without consuming all provided gas
226+
INVALID = 0xfe, ///< dedicated invalid instruction
227+
SUICIDE = 0xff ///< halt execution and register account for later deletion
193228
};
194229

195230
/// @returns the number of PUSH Instruction _inst

porosity/porosity/Porosity.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Revision History:
2121

2222
uint32_t g_VerboseLevel = VERBOSE_LEVEL;
2323
bool g_SingleStepping = false;
24-
bytes defaultArguments = {
24+
bytes defaultArguments = {
2525
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
2626
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
2727
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
@@ -121,9 +121,11 @@ parse(
121121
out->method |= MethodListFunctions;
122122
}
123123
else if (((kw == "--runtime-code") || (kw == "--code")) && arg.size()) {
124+
// ToDo: why do we have out->codeByte AND out->codeByteRuntime? the former does not seem to get used.
124125
out->codeByteRuntime = fromHex(arg);
125126
}
126127
else if ((kw == "--code") && arg.size()) {
128+
// ToDo: this case never matches. see the one above
127129
out->codeByte = fromHex(arg);
128130
}
129131
else if ((kw == "--code-file") && arg.size()) {

0 commit comments

Comments
 (0)