Abstract Satisfiability-Based Program Reasoning And
Total Page:16
File Type:pdf, Size:1020Kb
ABSTRACT Title of dissertation: SATISFIABILITY-BASED PROGRAM REASONING AND PROGRAM SYNTHESIS Saurabh Srivastava, Doctor of Philosophy, 2010 Dissertation directed by: Professor Jeffrey S. Foster Department of Computer Science Program reasoning consists of the tasks of automatically and statically ver- ifying correctness and inferring properties of programs. Program synthesis is the task of automatically generating programs. Both program reasoning and synthesis are theoretically undecidable, but the results in this dissertation show that they are practically tractable. We show that there is enough structure in programs written by human developers to make program reasoning feasible, and additionally we can leverage program reasoning technology for automatic program synthesis. This dissertation describes expressive and efficient techniques for program rea- soning and program synthesis. Our techniques work by encoding the underlying inference tasks as solutions to satisfiability instances. A core ingredient in the re- duction of these problems to finite satisfiability instances is the assumption of tem- plates. Templates are user-provided hints about the structural form of the desired artifact, e.g., invariant, pre- and postcondition templates for reasoning; or program templates for synthesis. We propose novel algorithms, parameterized by suitable templates, that reduce the inference of these artifacts to satisfiability. We show that fixed-point computation—the key technical challenge in program reasoning—is encodable as SAT instances. We also show that program synthesis can be viewed as generalized verification, facilitating the use of program reasoning tools as synthesizers. Lastly, we show that program reasoning tools augmented with symbolic testing can be used to build powerful synthesizers with approximate guarantees. We implemented the techniques developed in this dissertation in the form of the VS3—Verification and Synthesis using SMT Solvers—suite of tools. Using the VS3 tools, we were able to verify and infer expressive properties of programs, and synthesize difficult benchmarks from specifications. These prototype tools demon- strate that we can exploit the engineering advances in current SAT/SMT solvers to do automatic program reasoning and synthesis. We propose building future auto- matic program reasoning and synthesis tools based on the ideas presented in this dissertation. SATISFIABILITY-BASED PROGRAM REASONING AND PROGRAM SYNTHESIS by Saurabh Srivastava Dissertation submitted to the Faculty of the Graduate School of the University of Maryland, College Park in partial fulfillment of the requirements for the degree of Doctor of Philosophy 2010 Advisory Committee: Professor Jeffrey S. Foster, Chair/Advisor Professor Michael W. Hicks Dr. Sumit Gulwani Professor Jonathan Katz Professor Mike Boyle c Copyright by Saurabh Srivastava 2010 To my parents, Preeti and Prakash, and my grandparents. Acknowledgments I am greatly indebted to my advisor, Jeff Foster, whose willingness to accept, encourage, and fund, every experimental and contentious research thought I decided to pursue, amazes me in hindsight. It would be fair to say that he introduced me to research in programming languages. My interest in the foundations of programming languages started with a course he taught. To say that the knowledge I got from him was just technical would be a gross understatement. Research is half about knowing what problems to solve. Jeff has given me the perspective to pursue the right research ideas, and also the right attitude to overcome the hurdles a research project invariably presents. Not only that, his constant advising on matter not just technical, has helped hone my skills in writing, presentation, articulation, and maybe even helped me become a more capable social being. Talking of the research and mentoring “process,” there is probably no better person to refer to than Mike Hicks, my second advisor. Mike has the uncanny ability to recognize a student’s aptitude, interests, and potential, and then to encourage them in exactly the right way. I started working in programming languages as his student and he introduced me to the rigor in the foundations of programming languages—which he knew would attract me to the field. His own research diversity and time management skills have been a constant source of inspiration and I hope I can one day be as efficient a researcher as he is. His advising and presence ensured that my graduate career was a breeze and enjoyable every step of the way. “This appears to be an impossible problem. Let us see if we can solve it.” If this was ever a research philosophy, Sumit Gulwani’s would be this. From Sumit, my third advisor, I have learned that a research agenda is not useful if it is not adventurous, ambitious, and borderline crazy. In my internship under his guidance, Sumit introduced me to program verification, and we decided to ignore traditional approaches in favor of an experimental satisfiability-based approach to program reasoning. Our experimental program reasoning approach served as a segue into automatic program synthesis, a problem typically considered intractable. Also, un- der his mentorship, I have learnt that research is a social, collaborative, activity. Only through constant conversation do guesses and intuition develop into concrete solutions. Lastly, from his work ethic I have learned that a task worth pursuing is a task worth doing well; even if that means spending 16 to 18 hours a day on it. I have gained immensely from my interactions with all three of my advisors. I persevere to constantly change myself to imbibe the qualities they each possess, and I admire. I am grateful to them for having invested as much time as they did, and for showing me the way forward. My graduate research career has been meandering, and I would not have been in my current position, if it had not been for the efforts of my advisors “on the way”. A special thanks goes out to Bobby Bhattacharjee, whose prodding is partly the reason why I stuck around in graduate school. He has mentored me in all things non-technical, and indoctrinated in me the perspective that the only livable place is academia! His motivation and encouragement has helped me immensely. iii Also, a thanks to my undergraduate research advisors, Dheeraj Sanghi and Ajit K. Chaturvedi, at IIT Kanpur, who got me started on research early. I would also like to thank other professors in the department and on my committee. I am grateful to Samir Khuller, Aravind Srinivasan, Jonathan Katz, and Mike Boyle for having taken the time out to give me very useful feedback on my research. A shout-out is in order to the graduate students, present and past, that make up the Programming Languages group at the University of Maryland (PLUM). Nik, Polyvios, Iulian, Chris, Yit, Elnatan, Mark, David An, Mike Furr, Martin, Evan, Avik, Stephen, Ted, and David Greenfieldboyce were all a constant source of enlightening conversations (research or otherwise). Also, to all my other friends in the department, Srinivas Kashyap, Shiv, Bhargav, Aswin, Gaurav, Narayanan, Akhil, and Abheek; who made my graduate school days worth every moment. Only half jokingly, a nod to all the local coffee shops, without their presence there would be no caffeine induced writing rampages and this dissertation would have taken twice as long. A special thanks to my family, immediate and extended. I am humbled by the constant support and encouragement that my parents have provided throughout this period. My father, a professor and researcher in Inorganic Chemistry, has been a constant role model for my professional life; while my mother, with her open- mindedness and enthusiasm for absorbing ideas has been a constant role model for my personal life. I am also thankful to them for providing the most intellectually nurturing environment that a child could ask for, and for setting the right expecta- tions for me as an adult. Also, a big thanks to my younger brothers, Abhishek and Prashast. They have been a source of constant pride and perspective. They are my connection to the non-academic world. Lastly, to the person whose constant presence made the last four years incredibly enjoyable, and who I cannot thank enough, Lauren. iv Table of Contents List of Tables ix List of Figures x List of Abbreviations xii 1 Introduction 1 1.1 Satisfiability- and Template-based Program Reasoning and Synthesis 3 1.1.1 Satisfiability for Reasoning . 4 1.1.2 Satisfiability for Synthesis . 10 1.1.3 Templates . 11 1.1.4 Maximally Best Solutions using Satisfiability . 14 1.2 Program reasoning with linear arithmetic . 16 1.3 Program reasoning with predicate abstraction . 18 1.4 Verification-inspired synthesis . 20 1.5 Testing-inspired synthesis . 23 1.6 Engineering Verifiers and Synthesizers . 27 1.7 Key Contributions and Organization . 28 2 Program Reasoning over Linear Arithmetic 30 2.1 Using SAT Solvers for Invariant Inference . 31 2.2 Program Verification . 34 2.2.1 Verification Conditions . 35 2.2.2 Template specification T ..................... 39 2.2.3 Constraint solving . 40 2.2.4 Choice of cut-set . 47 2.2.5 Examples . 50 2.3 Interprocedural Analysis . 52 2.4 Maximally weak Precondition . 59 2.4.1 Locally pointwise-weakest strategy . 62 2.5 Maximally strong Postcondition . 68 2.6 Specification Inference . 70 2.7 Applications . 77 2.7.1 Termination and Bounds Analysis . 77 2.7.2 Counterexamples for Safety Properties . 80 2.7.3 Counterexamples for Termination Properties . 83 2.8 Experiments . 84 2.9 Summary . 89 2.10 Further Reading . 89 v 3 Program Reasoning over Predicate Abstraction 92 3.1 Using SMT Solvers for Program Reasoning . 93 3.2 Motivating Examples . 96 3.3 Notation . 103 3.3.1 Templates for Predicate Abstraction . 103 3.3.2 Program Model . 105 3.3.3 Invariant Solution . 107 3.4 Optimal Solutions . 109 3.5 Iterative Propagation Based Algorithms . 117 3.5.1 Least Fixed-point .