Support keccak func for concrete data

storage/bugfix
Nikhil Parasaram 6 years ago
parent e08ce7e785
commit 7374f1677e
  1. 41
      mythril/laser/ethereum/instructions.py

@ -951,6 +951,8 @@ class Instruction:
result = symbol_factory.BitVecFuncVal( result = symbol_factory.BitVecFuncVal(
util.concrete_int_from_bytes(keccak, 0), "keccak256", 256, input_=data util.concrete_int_from_bytes(keccak, 0), "keccak256", 256, input_=data
) )
keccak_function_manager.add_keccak(result, state.memory[index])
log.debug("Computed SHA3 Hash: " + str(binascii.hexlify(keccak))) log.debug("Computed SHA3 Hash: " + str(binascii.hexlify(keccak)))
state.stack.append(result) state.stack.append(result)
@ -1367,11 +1369,8 @@ class Instruction:
index = state.stack.pop() index = state.stack.pop()
log.debug("Storage access at index " + str(index)) log.debug("Storage access at index " + str(index))
try: index = simplify(index)
index = util.get_concrete_int(index)
return self._sload_helper(global_state, index)
except TypeError:
if not keccak_function_manager.is_keccak(index): if not keccak_function_manager.is_keccak(index):
return self._sload_helper(global_state, str(index)) return self._sload_helper(global_state, str(index))
@ -1384,20 +1383,24 @@ class Instruction:
for keccak_key in keccak_keys: for keccak_key in keccak_keys:
key_argument = keccak_function_manager.get_argument(keccak_key) key_argument = keccak_function_manager.get_argument(keccak_key)
index_argument = keccak_function_manager.get_argument(index) index_argument = keccak_function_manager.get_argument(index)
constraints.append((keccak_key, key_argument == index_argument)) condition = index_argument == key_argument
condition = (
condition
if isinstance(condition, Bool)
else symbol_factory.Bool(condition)
)
constraints.append((keccak_key, condition))
for (keccak_key, constraint) in constraints: for (keccak_key, constraint) in constraints:
if constraint in state.constraints: if constraint in state.constraints:
results += self._sload_helper( results += self._sload_helper(global_state, keccak_key, [constraint])
global_state, keccak_key, [constraint]
)
if len(results) > 0: if len(results) > 0:
return results return results
for (keccak_key, constraint) in constraints: for (keccak_key, constraint) in constraints:
results += self._sload_helper( results += self._sload_helper(copy(global_state), keccak_key, [constraint])
copy(global_state), keccak_key, [constraint]
)
if len(results) > 0: if len(results) > 0:
return results return results
@ -1452,12 +1455,10 @@ class Instruction:
state = global_state.mstate state = global_state.mstate
index, value = state.stack.pop(), state.stack.pop() index, value = state.stack.pop(), state.stack.pop()
log.debug("Write to storage[" + str(index) + "]") log.debug("Write to storage[" + str(index) + "]")
index = simplify(index)
try:
index = util.get_concrete_int(index)
return self._sstore_helper(global_state, index, value)
except TypeError:
is_keccak = keccak_function_manager.is_keccak(index) is_keccak = keccak_function_manager.is_keccak(index)
if not is_keccak: if not is_keccak:
return self._sstore_helper(global_state, str(index), value) return self._sstore_helper(global_state, str(index), value)
@ -1489,18 +1490,13 @@ class Instruction:
) )
results += self._sstore_helper( results += self._sstore_helper(
copy(global_state), copy(global_state), keccak_key, value, key_argument == index_argument
keccak_key,
value,
key_argument == index_argument,
) )
new = Or(new, cast(Bool, key_argument != index_argument)) new = Or(new, cast(Bool, key_argument != index_argument))
if len(results) > 0: if len(results) > 0:
results += self._sstore_helper( results += self._sstore_helper(copy(global_state), str(index), value, new)
copy(global_state), str(index), value, new
)
return results return results
return self._sstore_helper(global_state, str(index), value) return self._sstore_helper(global_state, str(index), value)
@ -1522,7 +1518,6 @@ class Instruction:
global_state.accounts[ global_state.accounts[
global_state.environment.active_account.address global_state.environment.active_account.address
] = global_state.environment.active_account ] = global_state.environment.active_account
global_state.environment.active_account.storage[index] = ( global_state.environment.active_account.storage[index] = (
value if not isinstance(value, Expression) else simplify(value) value if not isinstance(value, Expression) else simplify(value)
) )

Loading…
Cancel
Save