solidity/test/formal/signextend_shl.py
2021-08-16 18:54:33 +02:00

26 lines
503 B
Python

from rule import Rule
from opcodes import *
"""
Rule:
SHL(A, SIGNEXTEND(B, X)) -> SIGNEXTEND((A >> 3) + B, SHL(A, X))
given return A & 7 == 0 AND A <= WordSize AND B <= WordSize / 8
"""
n_bits = 256
# Input vars
X = BitVec('X', n_bits)
Y = BitVec('Y', n_bits)
A = BitVec('A', n_bits)
B = BitVec('B', n_bits)
rule = Rule()
rule.require(A & 7 == 0)
rule.require(ULE(A, n_bits))
rule.require(ULE(B, n_bits / 8))
rule.check(
SHL(A, SIGNEXTEND(B, X)),
SIGNEXTEND(LShR(A, 3) + B, SHL(A, X))
)