Calculational Design of a Static Dependency Analysis
Total Page:16
File Type:pdf, Size:1020Kb
2019 Mooly Fest April 6th, 2019 — ETAPS, Prague, Czech Republic Calculational design of a static dependency analysis Patrick Cousot New York University, Courant Institute of Mathematics, Computer Science [email protected] cs.nyu.edu/~pcousot “Calculational design of, a static dependency analysis” – 1/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 . Motivation . “Calculational design of, a static dependency analysis” – 2/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Dependency Dependency is prevalent in computer science: • Non-interference (confidentiality, integrity) • Security, privacy • Slicing • Temporal dependencies in synchronous languages (Lustre, Signal, etc.) • etc. The existing definitions • are postulated a priori (par exemple Cheney, Ahmed, and Acar, 2011; D. E. Denning and P. J. Denning, 1977), • without semantics justifications (except Assaf, Naumann, Signoles, Totel, and Tronel, 2017 (“hyper-collecting semantics”), Urban and Müller, 2018 on program exit uniquely) We are interested in principles, in soundness proofs, not so much in a new more powerful dependency analysis. “Calculational design of, a static dependency analysis” – 3/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Structural fixpoint trace semantics . “Calculational design of, a static dependency analysis” – 4/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Program syntax • C statements limited to integers, assignments, statement lits, conditionals, iterations • Programs are labelled to designate program points • atJSK: entry program point of S starts; • afterJSK: normal exit program point of S; • inJSK: reachable program points of S (excluding afterJSK); • break-toJSK: breaking point when S contains a break ; to exit a loop (then escapeJSK = tt); . “Calculational design of, a static dependency analysis” – 5/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Execution traces • Program: ℓ1 x = 0 ; while ℓ2 (tt) { ℓ3 x = x+1 ;} ℓ4 x = 0 = 0 tt x = x + 1 = 1 tt • Infinite execution trace: ℓ1 −−−−−−−−−−−−−−−→ ℓ2 −−−−→ ℓ3 −−−−−−−−−−−−−−−−−−−−−→ ℓ2 −−−−→ ℓ3 x = x + 1 = 2 tt x = x + 1 = 푛 tt x = x + 1 = 푛 + 1 −−−−−−−−−−−−−−−−−−−−−→ ℓ2 …ℓ2 −−−−→ ℓ3 −−−−−−−−−−−−−−−−−−−−−→ ℓ2 −−−−→ ℓ3 −−−−−−−−−−−−−−−−−−−−−−−−−−→ ℓ2 … • Trace: finite or infinite sequence of program points separated by action (x = A = value, B, ¬B, et break ;) . “Calculational design of, a static dependency analysis” – 6/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Value of a variable (and an expression) • The value of a variable x along a trace 휋 is the last assigned value (or 0 at initialization). x = E = 푣 흔(휋ℓ −−−−−−−−−−−−−−−→ ℓ′)x ≜ 푣 … 흔(휋ℓ −−−−−−→ ℓ′)x ≜ 흔(휋ℓ) otherwise 흔(ℓ)x ≜ 0 • Value of an arithmetic expression 퓐J1K휌 ≜ 1 퓐JxK휌 ≜ 휌(x) J K J K J K 퓐 A1 - A2 휌 ≜ 퓐 A1 휌 − 퓐 A2 휌 • Same for boolean expressions. “Calculational design of, a static dependency analysis” – 7/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Structural fixpoint prefix/maximal trace semantics 퓢̂ ∗JSK • The prefix trace semantics 퓢̂ ∗JSK is a relation between J K J K • an initialization trace 휋0at S arriving at S , and • the prefix execution traces atJSK휋 continuing this initialization by zero or more execution steps • The maximal trace semantics 퓢̂ +∞JSK collects the maximal finite traces and the infinite traces obtained as limits of their prefixes. “Calculational design of, a static dependency analysis” – 8/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Structural fixpoint definition of the prefix trace semantics (I) • Assignment S ∶∶= ℓ x = A ; (where atJSK = ℓ) 퓢∗JSK ≜ {⟨휋ℓ, ℓ⟩ ∣ 휋ℓ ∈ 핋+} ∪ x = A = 휈 {⟨휋ℓ, ℓ −−−−−−−−−−−−−−−−→ afterJSK⟩ ∣ 휋ℓ ∈ 핋+ ∧ 휈 = 퓐JAK흔(휋ℓ)} . “Calculational design of, a static dependency analysis” – 9/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Structural fixpoint definition of the prefix trace semantics (II) ℓ J K ℓ • Iteration S ∶∶= while (B) S푏 (where at S = ): 퓢∗JSK = lfp⊆ 퓕∗JSK ∗J ℓ K ℓ′ ℓ′ ℓ′ + ℓ′ ℓ 퓕 while (B) S푏 (푋) ≜ {⟨휋1 , ⟩ | 휋1 ∈ 핋 ∧ = } (a) ¬(B) ℓ′ ℓ′ ℓ′ J K ℓ′ ℓ′ ℓ′ ∪ {⟨휋1 , 휋2 −−−−−−−−−→ after S ⟩ | ⟨휋1 , 휋2 ⟩ ∈ 푋 ∧ J K ℓ′ ℓ′ ℓ′ ℓ 퓑 B 흔(휋1 휋2 ) = ff ∧ = } (b) B ℓ′ ℓ′ ℓ′ J K ⌢ ℓ′ ℓ′ ℓ′ ∪ {⟨휋1 , 휋2 −−−−→ at S푏 ⋅ 휋3⟩ | ⟨휋1 , 휋2 ⟩ ∈ 푋 ∧ B J K ℓ′ ℓ′ ℓ′ ℓ′ J K ∗J K ℓ′ ℓ 퓑 B 흔(휋1 휋2 ) = tt ∧ ⟨휋1 휋2 −−−−→at S푏 , 휋3⟩ ∈ 퓢 S푏 ∧ = } (c) A definition of the form 푑(푥)⃗ ≜ {푓(푥′)⃗ ∣ 푃(푥′,⃗ 푥)}⃗ has the variables 푥′⃗ in 푃(푥′,⃗ 푥)⃗ bound to those of 푓(푥′)⃗ whereas 푥⃗ is free in 푃(푥′,⃗ 푥)⃗ since it appears neither in 푓(푥′)⃗ nor (by assumption) under quantifiers in 푃(푥′,⃗ 푥)⃗ . The 푥⃗ of 푃(푥′,⃗ 푥)⃗ is therefore bound to the 푥⃗ of 푑(푥)⃗ . “Calculational design of, a static dependency analysis” – 10/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Properties . “Calculational design of, a static dependency analysis” – 11/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Property • A property is represented by a set of elements (those elements which have the property) • Even intergers: 2Z ≜ {2푘 ∣ 푘 ∈ Z} • 푥 has property 푃 is 푥 ∈ 푃 • Implication is 푃1 ⊆ 푃2 . “Calculational design of, a static dependency analysis” – 12/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Semantic property • The prefix trace semantics belongs to ℘(핋+ × 핋+∞) • A semantics property belongs to ℘(℘(핋+ × 핋+∞)) • The abstraction 휆 푄 . ℘(푄) + +∞ + +∞ ⟨℘(℘(핋 × 핋 )), ⊆⟩ −−−−−−−−−−−−→⟶←−−−−−−−−−−−−−− ⟨℘(핋 × 핋 ), ⊆⟩ 휆 푃 . ∪푃 provides trace properties (e.g.safety, liveness, etc.) . “Calculational design of, a static dependency analysis” – 13/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Dependency, informally . “Calculational design of, a static dependency analysis” – 14/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Dependency, informally ℓ • At program point , the variable y depends upon the initial value 푥0 of variable x iff changing only 푥0 will change the non-empty sequences of values 푦0, 푦1,… of y observed at ℓ whenever control reaches ℓ • Example: ℓ0 if (x=0) { y=x; ℓ1} ℓ2 • y does not depend on x neither at ℓ0 nor at ℓ1 • y depends on x at ℓ2 • No need to distinguish between explicit and implicit dependencies • Absence of observation is not an observation • No timing channels . “Calculational design of, a static dependency analysis” – 15/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Dependency, formally . “Calculational design of, a static dependency analysis” – 16/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Observation of the sequence of values of a variable at a program point + • non-empty initialization trace 휋0 ∈ 핋 • non-empty continuation trace 휋 ∈ 핋+∞ J Kℓ ℓ • seqval y (휋0, 휋) is the sequence of values of the variable y at program point along the trace 휋 continuing 휋0 J Kℓ ℓ seqval y (휋0, ) ≜ 흔(휋0)y J Kℓ ℓ′ seqval y (휋0, ) ≜ ϶ 푎 푎 J Kℓ ℓ ℓ″ J Kℓ ⌢ ℓ ℓ″ ℓ″ seqval y (휋0, −−−−→ 휋) ≜ 흔(휋0)y ⋅ seqval y (휋0 ⋅ −−−−→ , 휋) 푎 푎 J Kℓ ℓ′ ℓ″ J Kℓ ⌢ ℓ′ ℓ″ ℓ″ seqval y (휋0, −−−−→ 휋) ≜ seqval y (휋0 ⋅ −−−−→ , 휋) J Kℓ ℓ • seqval y (휋0, 휋) is the empty sequence ϶ if never appears in 휋 (co-inductive definition for infinite traces). “Calculational design of, a static dependency analysis” – 17/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Difference between sequences of values 휔 and 휔′ • Sequences that differ may have a common prefix but must eventually havea different value at some position in the sequences. diff(휔, 휔′) ≜ ∃휔0, 휔1, 휔′1, 휈, 휈′ . 휔 = 휔0 ⋅ 휈 ⋅ 휔1 ∧ 휔′ = 휔0 ⋅ 휈′ ⋅ 휔′1 ∧ 휈 ≠ 휈′ . “Calculational design of, a static dependency analysis” – 18/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Dependency, formally • Dependency property: ℓ + +∞ 풟diff ⟨x, y⟩ ≜ {Π ∈ ℘(핋 × 핋 ) ∣ ∃⟨휋0, 휋1⟩, ⟨휋′0, 휋′1⟩ ∈ Π . (∀z ∈ V ⧵ {x}. 흔(휋0)z = 흔(휋′0)z) ∧ J Kℓ J Kℓ diff(seqval y (휋0, 휋1), seqval y (휋′0, 휋′1))} • y depends on the initial value of x at program point ℓ in program P is: ̂ +∞J K 퓢 P ∈ 풟diff ℓ⟨x, y⟩ • Lemma ̂ +∞J K ̂ ∗J K 퓢 P ∈ 풟diff ℓ⟨x, y⟩ ⇔ 퓢 P ∈ 풟diff ℓ⟨x, y⟩ . “Calculational design of, a static dependency analysis” – 19/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Value dependency abstraction . “Calculational design of, a static dependency analysis” – 20/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Abstraction en dépendance de données • The abstraction of a semantic property S ∈ ℘(℘(핋+ × 핋+∞)) into a value dependency property 훼ᶁ(S) ∈ L → ℘(V × V ) is: ᶁ 훼 (S)ℓ ≜ {⟨x, y⟩ ∣ S ∈ 풟diff ℓ⟨x, y⟩} • This is a Galois connection: 훾ᶁ + +∞ ᶁ Lemma 1 ⟨℘(℘(핋 × 핋 )), ⊆⟩ −−−−−→←−−−−− ⟨L → ℘(V × V ), ⊇ ⟩ where the concretization 훼ᶁ of a dependency property 퐃 ∈ L → ℘(V × V ) is: ᶁ 훾 (퐃) ≜ ⋂ ⋂ 풟diff ℓ⟨x, y⟩ ℓ∈L ⟨x, y⟩∈퐃(ℓ) (the more semantics, the less common dependencies) . “Calculational design of, a static dependency analysis” – 21/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Static dependency analysis . “Calculational design of, a static dependency analysis” – 22/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Potential dependency • 훼ᶁ({퓢∗JSK}) is not computable (Rice theorem) • We design an over-approximation: ̂ diff Abstract potential dependency semantics 퓢 ∃ : ᶁ +∞J K ̂ diffJ K 훼 ({퓢 S }) ⊆̇ 퓢 ∃ S • The abstraction in D. E. Denning and P. J. Denning, 1977 is purely syntactic; • We do a little better by taking the semantics is a simple way. “Calculational design of, a static dependency analysis” – 23/39 – © P. Cousot, NYU, CIMS, CS, April 6th, 2019 Calculation design ̂ diffJ K • 퓢 ∃ S is designed by calculus (in principle can be checked in Coq as Jourdan, Laporte, Blazy, Leroy, and Pichardie, 2015); • By structural induction on the program syntax; • By fixpoint approximation for iteration: Theorem (fixpoint over-approximation) If ⟨C, ⊑, ⊥, ⊤, ⊔, ⊓⟩ and ⟨A, ≼, 0, 1, ⋎, 훾 ⋏⟩ are complete lattices, ⟨C, ⊑⟩ ←−−−− ⟨A, ≼⟩ is a Galois connection, 푓 ∈ C ⟶↗ C and −−−−→훼 푓 ∈ A ⟶↗ A are monotonally increasing and 훼 ∘ 푓 ≼̇ 푓 ∘ 훼 (semi-commutation) then lfp⊑ 푓 ⊑ 훾(lfp≼ 푓).