Fix issue with integer arthimetic (#1541)

pull/1544/head
Nikhil Parasaram 3 years ago committed by GitHub
parent f30dd19181
commit e7d50f3c60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      mythril/analysis/module/modules/integer.py

@ -161,25 +161,22 @@ class IntegerArithmetics(DetectionModule):
def _handle_exp(self, state): def _handle_exp(self, state):
op0, op1 = self._get_args(state) op0, op1 = self._get_args(state)
if op1.value == 0 or op0.value < 2:
return
if op0.symbolic and op1.symbolic: if op0.symbolic and op1.symbolic:
constraint = And( constraint = And(
op1 > symbol_factory.BitVecVal(256, 256), op1 > symbol_factory.BitVecVal(256, 256),
op0 > symbol_factory.BitVecVal(1, 256), op0 > symbol_factory.BitVecVal(1, 256),
) )
elif op1.symbolic:
if op0.value < 2:
return
constraint = op1 >= symbol_factory.BitVecVal(
ceil(256 / log2(op0.value)), 256
)
elif op0.symbolic: elif op0.symbolic:
if op1.value == 0:
return
constraint = op0 >= symbol_factory.BitVecVal( constraint = op0 >= symbol_factory.BitVecVal(
2 ** ceil(256 / op1.value), 256 2 ** ceil(256 / op1.value), 256
) )
else: else:
constraint = op0.value ** op1.value >= 2 ** 256 constraint = op1 >= symbol_factory.BitVecVal(
ceil(256 / log2(op0.value)), 256
)
annotation = OverUnderflowAnnotation(state, "exponentiation", constraint) annotation = OverUnderflowAnnotation(state, "exponentiation", constraint)
op0.annotate(annotation) op0.annotate(annotation)

Loading…
Cancel
Save