Proving Python code correct with Nagini
summary
Nagini verifies Python by running mypy, encoding typed code into the Viper intermediate language, and discharging assertions with an SMT solver (Z3). Examples include catching a division by zero missed by types, encoding caller preconditions via requires/ensures calls, and proving a summation by adding a loop invariant; a quicksort example checks element multiset preservation and ordering. Limitations: unsupported dynamic features, heavy annotation and verification cost, counterexamples returned, and runtime spec calls are evaluated but are no-ops (removable for production).
AI-written summary · about
chapters (23)
- 0:00Introduction and speaker introduction
- 2:32Why formal verification beyond types
- 5:41Preventing runtime errors with preconditions
- 7:49Writing expressive specifications
- 8:31Proving correctness with postconditions
- 10:21Loop invariants and termination proofs
- 12:32Nagini architecture and Viper encoding
- 15:52Case study: Verifying quicksort
- 18:19Counterexamples and debugging
- 19:48Supported and unsupported Python features
- 21:12Limitations and performance issues
- 22:59Complexity of specifications
- 24:01Future plans and open source
- 25:05Q&A: Handling unknown inputs
- 26:08Q&A: Viper language clarification
- 27:12Q&A: Production use and performance
- 28:18Q&A: What is an SMT solver?
- 29:40Q&A: Integration with testing tools
- 31:07Q&A: Python vs Rust/Go verification
- 32:09Q&A: Runtime behavior of contracts
- 33:12Q&A: Integration with mypy
- 34:39Q&A: Non-invasive Nagini version
- 36:24Closing remarks
