Formally Verified C Code Generation from Hybrid Communicating Sequential Processes (2402.15674v2)
Abstract: Hybrid Communicating Sequential Processes (HCSP) is a formal model for hybrid systems, including primitives for evolution along an ordinary differential equation (ODE), communication, and parallel composition. Code generation is needed to convert HCSP models into code that can be executed in practice, and the correctness of this conversion is essential to ensure that the generated code accurately reflects the formal model. In this paper, we propose a code generation algorithm from HCSP to C with POSIX library for concurrency. The main difficulties include how to bridge the gap between the synchronized communication model in HCSP and the use of mutexes for synchronization in C, and how to discretize evolution along ODEs and support interrupt of ODE evolution by communication. To prove the correctness of code generation, we define a formal semantics for POSIX C, and build transition system models for both HCSP and C programs. We then define an approximate bisimulation relation between traces of transition systems, and show that under certain robustness conditions for HCSP, the generated C program is approximately bisimilar to the original model. Finally, we evaluate the code generation algorithm on a detailed model for automatic cruise control, showing its utility on real-world examples.
- Generating reliable code from hybrid-systems models. IEEE Trans. Computers, 59(9):1281–1294, 2010.
- Non-standard semantics of hybrid systems modelers. Journal of Computer and System Sciences, 78:877–910, May 2012.
- A formally verified compiler for Lustre. In PLDI 2017, 2017.
- Process algebra for hybrid systems. Theor. Comput. Sci., 335(2-3):215–280, 2005.
- T. Bourke and M. Pouzet. Zélus: a synchronous language with ODEs. In HSCC 2013, pages 113–118. ACM, 2013.
- VeriPhy: verified controller executables from verified cyber-physical system models. In PLDI 2018, pages 617–630. ACM, 2018.
- Hybrid process algebra. J. Log. Algebraic Methods Program., 62(2):191–245, 2005.
- Event-B hybridation: A proof and refinement-based framework for modelling hybrid systems. ACM Trans. Embed. Comput. Syst., 20(4):35:1–35:37, 2021.
- F. X. Dormoy. SCADE 6: a model based solution for safety critical software development. In ERTS 2008, 2008.
- Monitoring CTMCs by multi-clock timed automata. In CAV 2018, Part I, volume 10981 of LNCS, pages 507–526. Springer, 2018.
- KeYmaera X: an axiomatic tactical theorem prover for hybrid systems. In CADE 2015, volume 9195 of LNCS, pages 527–538. Springer, 2015.
- A. Girard and G. J. Pappas. Approximation metrics for discrete and continuous systems. IEEE Trans. Autom. Contr., 52(5):782–798, 2007.
- The synchronous data flow programming language LUSTRE. Proc. IEEE, 79(9):1305–1320, 1991.
- J. He. From CSP to hybrid systems. In A Classical Mind: Essays in Honour of C. A. R. Hoare, pages 171–189. Prentice Hall International (UK) Ltd., 1994.
- T. A. Henzinger. The theory of hybrid automata. In LICS 1996, pages 278–292. IEEE Computer Society, 1996.
- C. A. R. Hoare. Communicating sequential processes. Communications of the ACM, 21(8):666–677, 1978.
- Approximate equivalence and synchronization of metric transition systems. Syst. Control. Lett., 58(2):94–101, 2009.
- MathWorks Inc. Simulink User’s Guide, 2013. http://www.math- works.com/help/pdf_doc/simulink/sl_using.pdf.
- MathWorks Inc. Stateflow User’s Guide, 2013. http://www.math- works.com/help/pdf_doc/stateflow/sf_ug.pdf.
- OSATE. 2017. https://osate.org.
- A. Platzer. Logical Foundations of Cyber-Physical Systems. Springer, 2018.
- J. Stoer and R. Bulirsch. Introduction to Numerical Analysis. 2013.
- HHLPy: Practical verification of hybrid systems using Hoare logic. In FM 2023, volume 14000 of LNCS, pages 160–178. Springer, 2023.
- The opacity of real-time automata. IEEE Trans. Comput. Aided Des. Integr. Circuits Syst., 37(11):2845–2856, 2018.
- Unified graphical co-modeling, analysis and verification of cyber-physical systems by combining AADL and Simulink/Stateflow. Theor. Comput. Sci., 903:1–25, 2022.
- Automatically generating SystemC code from HCSP formal models. ACM Trans. Softw. Eng. Methodol., 29(1):4:1–4:39, 2020.
- Unified graphical co-modelling of cyber-physical systems using AADL and Simulink/Stateflow. In UTP 2019, volume 11885 of LNCS, pages 109–129. Springer, 2019.
- Formal Verification of Simulink/Stateflow Diagrams (A Deductive Approach). Springer, 2017.
- Zero-crossing location and detection algorithms for hybrid system simulation. IFAC Proceedings Volumes, 41(2):7967–7972, 2008.
- Verifying Simulink diagrams via a hybrid Hoare logic prover. In EMSOFT 2013, pages 9:1–9:10. IEEE, 2013.
- A generalized hybrid Hoare logic. In arxiv.org/abs/2303.15020, 2023.