330 likes | 416 Vues
Explore verifying type systems using model checking, defining type checking, type errors, and soundness as well as implementing Glass Box Model Checking. Find bugs at compile time, prove type soundness, and apply Glass Box Checking to enhance verification processes.
E N D
Verifying Type Systems with Glass Box Model Checking Melanie Agnew Michael Roberson
Overview • Project Goal: Use model checking to verify a type system • Project Background / Motivation • What does it mean to verify a type system? • Why do we care? • Project Summary • Project Results
Type Checking • What is type checking? • process of verifying that the statements in the program use types correctly • “correct” type usage is defined by the language • ex: int a = “abc”; • What is a type error? • bug in the program that results in undefined behavior
Type Checking All Programs Is every program that passes type checking inside here? Programs with Type Errors
Type Soundness • What is type soundness? • type soundness is a property of the language that guarantees that any program that passes type checking has no type errors • we can verify this by checking that from any well typed state we transition to another well typed state if b then a = 0 else a = 3 if b then a = 0 else a = 3 State Transition
Example Language literals: 0, true, false operators: +1, -1 if statement: ife1thene2elsee3 Types: Boolean, Integer Example program: (if true then 0 else 0+1)+1
Example Language TypeOf((if true then 0 else 0+1)+1) = ? Use Typing Rules to find the type of this expression. If it has a valid type then it passes type checking. It is then called “well-typed”.
Example Language TypeOf((if true then 0 else 0+1)+1) = ? Integer Integer Integer Boolean TypeOf(true) = Boolean TypeOf(0) = Integer
= e1 Example Language TypeOf((if true then 0 else 0+1)+1) = ? Integer Integer Integer Boolean Integer TypeOf(e1+1) = Integer if: TypeOf(e1) = Integer
Example Language TypeOf((if true then 0 else 0+1)+1) = ? Integer Integer Integer Boolean Integer Integer = e1 TypeOf(ife1thene2elsee3) = TypeOf(e2) if: TypeOf(e1) = Boolean TypeOf(e2) = TypeOf(e3) = e2 = e3
= e1 Example Language TypeOf((if true then 0 else 0+1)+1) = ? Integer Integer Integer Boolean Integer Integer Integer TypeOf(e1+1) = Integer if: TypeOf(e1) = Integer
Example Language TypeOf((if true then 0 else 0+1)+1) = Integer Integer Integer Integer Boolean Integer Integer Integer The expression is well-typed.
Example 2 What happens if our language uses a different rule for if-then-else? TypeOf(ife1thene2elsee3) = TypeOf(e2) if: TypeOf(e1) = Boolean TypeOf(e2) = TypeOf(e3) TypeOf(ife1thene2elsee3) = TypeOf(e2) if: TypeOf(e1) = Boolean Then this passes the type checker: (if false then 0 else true)+1 …but it contains a type error! (true+1 is undefined)
In Summary • What does it mean to verify a type system? • Prove Type Soundness of the type system • Why do we care? • Detect an entire class of bugs at compile time!
Proving Type Soundness • Traditional method is to write out a symbolic proof • need to prove soundness for each type of statement • We use software model checking • Verify that each well-typed program state transitions to another well-typed state
Proving Type Soundness • Traditional method is to write out a symbolic proof • need to prove soundness for each type of statement • We use software model checking • Verify that each well-typed program state transitions to another well-typed state Example 1 State Transition (if true then 0 else 0+1)+1 0+1 Type: Integer Type: Integer
Proving Type Soundness • Traditional method is to write out a symbolic proof • need to prove soundness for each type of statement • We use software model checking • Verify that each well-typed program state transitions to another well-typed state Example 2 State Transition (if false then 0 else true)+1 true+1 Type: Integer Type: Invalid
Glass Box Model Checking • Traditional model checking explores state transitions S' S State Logic 1 s1 s'1 0 s2 s'2 0 0 s3 s'3 1 0 s4 s'4 1 0 s5 s'5 1 1
Glass Box Model Checking • Glass Box checking determines which part of the state is used S' S Which bits are used? State Logic 1 s1 s'1 0 s2 s'2 0 0 s3 s'3 1 0 s4 s'4 1 0 s5 s'5 1 1
Glass Box Model Checking • Prune away similar states S' S Which bits are used? State Logic 1 s1 s'1 0 s2 s'2 0 0 s3 s'3 1 0 s4 s'4 1 0 s5 s'5 1 1
Glass Box Model Checking • Overall strategy: • Keep a set of states that need to be checked • Can use a BDD or a SAT formula • Iterate until the set is empty • Choose a state from the set, check it • Remove all similar states from the set
Glass Box Checking +Type Soundness • We applied Glass Box checking to Type Soundness • Language Implementation • Build an interpreter for the language • Define the type system, build a type checker • Instrumentation • Check which parts of the state are accessed • Automatically generated from interpreter • Initial Search Space • BDD/SAT representation of all well-typed states • Size-limited
Languages • We verified the type soundness of three languages: • Expression Language • While Language • Featherweight Java
Languages • Simple Language of Integer and Boolean Expressions • if-then-else • booleans and integers succ( if true then 0 else succ(0))
Expression Height • Expression height measures the number of statements in a specific program body height 1: true height 2: succ(0) height 3: isZero(if true then 0 else 0) height 4: succ(if isZero(0) then succ(0) else 0)
Results Expression Language
Languages • While language • Imperative language • while loops • variables int a a := 5; while (a < 7) a := a+1
Results While Language (vars = height and nums = height)
Languages • Featherweight Java • Simplified java • Classes • Methods • Inheritance
Results Featherweight Java (class height=3, method height = 2)
Conclusions • Model checking type systems is feasible • SAT seems to outperform BDDs on complex languages • Glass box pruning dramatically reduces the type soundness state space
future work • Investigating methods for type checking-specific pruning • Automatic generation of initial state constraints • Investigating alternative logics for set representation