Formal Methods in Designing Critical Cyber-Physical Systems