from opcodes import GT, SUB
from rule import Rule
from util import BVUnsignedMax, BVUnsignedUpCast
from z3 import BitVec, BVAddNoOverflow, Not
n_bits = 256
type_bits = 8
while type_bits <= n_bits:
rule = Rule()
X_short = BitVec('X', type_bits)
Y_short = BitVec('Y', type_bits)
actual_overflow = Not(BVAddNoOverflow(X_short, Y_short, False))
X = BVUnsignedUpCast(X_short, n_bits)
Y = BVUnsignedUpCast(Y_short, n_bits)
maxValue = BVUnsignedMax(type_bits, n_bits)
overflow_check = GT(X, SUB(maxValue, Y))
rule.check(overflow_check != 0, actual_overflow)
type_bits *= 2