|
|
@ -14,7 +14,7 @@ from mythril.laser.ethereum.state import GlobalState, CalldataType |
|
|
|
import mythril.laser.ethereum.natives as natives |
|
|
|
import mythril.laser.ethereum.natives as natives |
|
|
|
from mythril.laser.ethereum.transaction import MessageCallTransaction, TransactionStartSignal, \ |
|
|
|
from mythril.laser.ethereum.transaction import MessageCallTransaction, TransactionStartSignal, \ |
|
|
|
ContractCreationTransaction |
|
|
|
ContractCreationTransaction |
|
|
|
from mythril.laser.ethereum.exceptions import VmException, StackUnderflowException |
|
|
|
from mythril.laser.ethereum.exceptions import VmException |
|
|
|
|
|
|
|
|
|
|
|
TT256 = 2 ** 256 |
|
|
|
TT256 = 2 ** 256 |
|
|
|
TT256M1 = 2 ** 256 - 1 |
|
|
|
TT256M1 = 2 ** 256 - 1 |
|
|
@ -92,51 +92,41 @@ class Instruction: |
|
|
|
@instruction |
|
|
|
@instruction |
|
|
|
def swap_(self, global_state): |
|
|
|
def swap_(self, global_state): |
|
|
|
depth = int(self.op_code[4:]) |
|
|
|
depth = int(self.op_code[4:]) |
|
|
|
try: |
|
|
|
stack = global_state.mstate.stack |
|
|
|
stack = global_state.mstate.stack |
|
|
|
stack[-depth - 1], stack[-1] = stack[-1], stack[-depth - 1] |
|
|
|
stack[-depth - 1], stack[-1] = stack[-1], stack[-depth - 1] |
|
|
|
|
|
|
|
except IndexError: |
|
|
|
|
|
|
|
raise StackUnderflowException |
|
|
|
|
|
|
|
return [global_state] |
|
|
|
return [global_state] |
|
|
|
|
|
|
|
|
|
|
|
@instruction |
|
|
|
@instruction |
|
|
|
def pop_(self, global_state): |
|
|
|
def pop_(self, global_state): |
|
|
|
try: |
|
|
|
global_state.mstate.stack.pop() |
|
|
|
global_state.mstate.stack.pop() |
|
|
|
|
|
|
|
except IndexError: |
|
|
|
|
|
|
|
raise StackUnderflowException |
|
|
|
|
|
|
|
return [global_state] |
|
|
|
return [global_state] |
|
|
|
|
|
|
|
|
|
|
|
@instruction |
|
|
|
@instruction |
|
|
|
def and_(self, global_state): |
|
|
|
def and_(self, global_state): |
|
|
|
try: |
|
|
|
stack = global_state.mstate.stack |
|
|
|
stack = global_state.mstate.stack |
|
|
|
op1, op2 = stack.pop(), stack.pop() |
|
|
|
op1, op2 = stack.pop(), stack.pop() |
|
|
|
if type(op1) == BoolRef: |
|
|
|
if type(op1) == BoolRef: |
|
|
|
op1 = If(op1, BitVecVal(1, 256), BitVecVal(0, 256)) |
|
|
|
op1 = If(op1, BitVecVal(1, 256), BitVecVal(0, 256)) |
|
|
|
if type(op2) == BoolRef: |
|
|
|
if type(op2) == BoolRef: |
|
|
|
op2 = If(op2, BitVecVal(1, 256), BitVecVal(0, 256)) |
|
|
|
op2 = If(op2, BitVecVal(1, 256), BitVecVal(0, 256)) |
|
|
|
|
|
|
|
|
|
|
|
stack.append(op1 & op2) |
|
|
|
stack.append(op1 & op2) |
|
|
|
|
|
|
|
except IndexError: |
|
|
|
|
|
|
|
raise StackUnderflowException |
|
|
|
|
|
|
|
return [global_state] |
|
|
|
return [global_state] |
|
|
|
|
|
|
|
|
|
|
|
@instruction |
|
|
|
@instruction |
|
|
|
def or_(self, global_state): |
|
|
|
def or_(self, global_state): |
|
|
|
stack = global_state.mstate.stack |
|
|
|
stack = global_state.mstate.stack |
|
|
|
try: |
|
|
|
op1, op2 = stack.pop(), stack.pop() |
|
|
|
op1, op2 = stack.pop(), stack.pop() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if type(op1) == BoolRef: |
|
|
|
if type(op1) == BoolRef: |
|
|
|
op1 = If(op1, BitVecVal(1, 256), BitVecVal(0, 256)) |
|
|
|
op1 = If(op1, BitVecVal(1, 256), BitVecVal(0, 256)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if type(op2) == BoolRef: |
|
|
|
|
|
|
|
op2 = If(op2, BitVecVal(1, 256), BitVecVal(0, 256)) |
|
|
|
|
|
|
|
|
|
|
|
if type(op2) == BoolRef: |
|
|
|
stack.append(op1 | op2) |
|
|
|
op2 = If(op2, BitVecVal(1, 256), BitVecVal(0, 256)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stack.append(op1 | op2) |
|
|
|
|
|
|
|
except IndexError: # Stack underflow |
|
|
|
|
|
|
|
raise StackUnderflowException |
|
|
|
|
|
|
|
return [global_state] |
|
|
|
return [global_state] |
|
|
|
|
|
|
|
|
|
|
|
@instruction |
|
|
|
@instruction |
|
|
|