SlideShare a Scribd company logo
Using Dynamic Analysis to Discover Polynomial
and Array Invariants
Paper by Thanh Vu Nguyen, Deepak Kapur, Westley Weimer
and Stephanie Forest in ICSE 2012
Gagandeep Singh
ETH Zurich
15 April 2013
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 1 / 19
Dynamic Invariant Analysis
◮ Dynamic Discovery of Program Invariants
◮ Execute Program on a set of inputs
◮ Infer Invariants using obtained traces
◮ Useful in
◮ Program Documentation
◮ Refactoring
◮ Debugging
◮ Verification
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 2 / 19
Dynamic Invariant Analysis
◮ Daikon is widely used for such analysis
◮ Supports only a limited subset of Linear Relations
◮ No support for Nonlinear Relations
◮ Limited support for Array Invariants
◮ Contribution from the Paper
◮ Polynomial (Nonlinear) Invariants
◮ Linear Array Invariants
◮ Simple
◮ Nested
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 3 / 19
Polynomial Invariants
◮ Polynomial Equalities
◮ Solve using Linear Algebra
◮ Polynomial Inequalities
◮ Use Polyhedra
◮ Deduction from Loop Conditions
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 4 / 19
Terminology
◮ V = Set of Instrumented Variables at a Location
◮ D = Maximum Degree of Polynomial
◮ T = Set of Terms over V with Maximum degree D
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 5 / 19
Polynomial Equalities
1 x := a
i := 1
3 wh ile ( i <= n ){
// Inv : x = i ∗ a
5 x := x + a
i := i + 1
7 }
◮ V = {x, i, a}
◮ D = 2
◮ T = {1, x, i, a, xi, xa, ia, x2, i2, a2}
◮ Linear Equation Template:
c1 + c2x + c3i + c4a + . . . + c10a2 = 0
instantiated per Trace
◮ Complexity of solving this Linear System
is O |T|3
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 6 / 19
Polynomial Inequalities
1 x := a
i := 1
3 wh ile ( i <= n ){
// Inv : x <= n ∗ a
5 x := x + a
i := i + 1
7 }
◮ V = {x, n, a}
◮ D = 2
◮ T = {1, x, n, a, xn, xa, na, x2, n2, a2}
◮ Construct |T| dimensional points from
traces and build Bounded Convex
Polyhedron that covers all trace points
◮ Boundary of Polyhedron satisfies
c1 + c2x + c3n + c4a + . . . + c10a2 ≥ 0
◮ The Complexity of building Polyhedron
with k points in n dimensions has upper
bound O k⌊n/2⌋
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 7 / 19
Deduction From Loop Conditions
1 x := a
i := 1
3 wh ile ( i <= n ){
// Inv : x <= n ∗ a
5 x := x + a
i := i + 1
7 }
◮ Combine inequalities at loop head with
found equalites
◮ x ≤ n ∗ a can be deduced from i ≤
n and x = i ∗ a
◮ O |T|3 Complexity but can only
deduce Inequalities derivable from Loop
Conditions and Found Equalities
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 8 / 19
Linear Array Invariants
◮ Simple Array Relations
◮ D = 1
◮ Relations Among Array Elements
◮ Relations Among Array Indices
◮ Nested Array Relations
◮ Reachability Analysis
◮ Satisfiability Problem Formulation
◮ Functions
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 9 / 19
Simple Array Relations
◮ Expand set V of array variables to V’ representing elements of
arrays in V
◮ Find Set of Linear Equalities R between variables in V’ from
traces of the form
A0 + b0Bj0 + c0 = 0
A1 + b1Bj1 + c1 = 0
A2 + b2Bj2 + c2 = 0
...
Am + bmBjm + cm = 0
A is pivot as ci, bi and ji are expressed in terms of indices of A
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 10 / 19
Simple Array Relations
◮ bi, ci and ji are linear relations ranging over indices of A
A[i] = (p0i + q0)B[p1i + q1] + (p2i + q2)
◮ The Coefficients are determined using information from R
◮ The Complexity of the procedure is O |V ′|3
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 11 / 19
Nested Array Relations
◮ Reachability Analysis
◮ Satisfiability Problem Formulation
◮ Functions
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 12 / 19
Reachability Analysis
◮ Elements of A reach elements of C through elements of B
A[i] = B[C[pi + q]]
◮ Elements of A are subset of elements of B
◮ Indices of B are subset of elements of C
◮ The Time Complexity of Reachability Analysis is Exponential
in Nesting Depth
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 13 / 19
Satisfiability Problem Formulation
◮ Encode finding Nested Array Relations into a CNF formula f
◮ We can pose
A[i] = B[C[pi + q]]
as a CNF formula f:
(1 = q) ∧ (2 = p + q ∨ 3 = p + q) ∧ (5 = 2p + q)
◮ Use SMT Solver to find Solution of f
◮ Same Worst Case Complexity
◮ Improves Performance of Reachability Analysis compared to
Original method
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 14 / 19
Functions
◮ Consider user defined functions
A[i] = f(C[i], g(D[i]))
◮ Consider a function f with n arguments as an n dimensional
array F
F[i1] . . . [in] = f(i1 . . . in)
◮ Enforce finite depth in Nested Array Relations by disallowing a
function to appear in scope of one of its arguments
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 15 / 19
Evaluation
◮ Prototype tool invgen in python uses Sage mathematical
environment and Z3 as SMT solver
◮ Available at
https://code.google.com/p/invgen/
◮ Evaluation on Nonlinear Arithmetic (NLA) test suite
containing simple algorithms and an implementation of AES
◮ Can find all the documented invariants for NLA test suite and
57% of the documented invariants for AES
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 16 / 19
NLA
◮ Cohencu
◮ Cohendiv
◮ Dijkstra
◮ Euclidex
◮ Fermat
◮ Freire
◮ LCM
◮ MannaDiv
◮ Sqrt
◮ Wensley
◮ More Info about functions can be found here
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 17 / 19
AES
◮ AddRoundKey
◮ RotWord
◮ ShiftRows
◮ Block2State
◮ KeySetupEnc
◮ SubBytes
◮ Mul
◮ Xor
◮ SubBytes
◮ SubWord
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 18 / 19
Conclusion
◮ Pros
◮ Extends current Dynamic Analysis Techniques
◮ Loop Invariant Inference
◮ Can be applied in Verification of Complex Numeric Algorithms
◮ Cons
◮ May not scale well for large programs
◮ Effectiveness depends on quality of traces
◮ Does not consider certain forms of Array Invariants like
A[i] = 2B[100C[. . .]]
Gagandeep Singh ETH Zurich
Using Dynamic Analysis to Discover Polynomial and Array Invariants 19 / 19

More Related Content

What's hot

S6 l04 analytical and numerical methods of structural analysis
S6 l04 analytical and numerical methods of structural analysisS6 l04 analytical and numerical methods of structural analysis
S6 l04 analytical and numerical methods of structural analysis
Shaikh Mohsin
 
Numerical Analysis and Computer Applications
Numerical Analysis and Computer ApplicationsNumerical Analysis and Computer Applications
Numerical Analysis and Computer Applications
Mujeeb UR Rahman
 
Secante
SecanteSecante
Secante
oskrjulia
 
What is a function?
What is a function?What is a function?
What is a function?
aliciataite
 
Matrices, Arrays and Vectors in MATLAB
Matrices, Arrays and Vectors in MATLABMatrices, Arrays and Vectors in MATLAB
Matrices, Arrays and Vectors in MATLAB
Abu Raihan Ibna Ali
 
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questioCS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
Karthik Venkatachalam
 
NACA Regula Falsi Method
 NACA Regula Falsi Method NACA Regula Falsi Method
NACA Regula Falsi Method
Mujeeb UR Rahman
 
APLICACIONES DE ESPACIOS Y SUBESPACIOS VECTORIALES EN LA CARRERA DE ELECTRÓNI...
APLICACIONES DE ESPACIOS Y SUBESPACIOS VECTORIALES EN LA CARRERA DE ELECTRÓNI...APLICACIONES DE ESPACIOS Y SUBESPACIOS VECTORIALES EN LA CARRERA DE ELECTRÓNI...
APLICACIONES DE ESPACIOS Y SUBESPACIOS VECTORIALES EN LA CARRERA DE ELECTRÓNI...
GersonMendoza15
 
Network centrality measures and their effectiveness
Network centrality measures and their effectivenessNetwork centrality measures and their effectiveness
Network centrality measures and their effectiveness
emapesce
 
Fuzzy(2)
Fuzzy(2)Fuzzy(2)
Diagonalization of Matrices
Diagonalization of MatricesDiagonalization of Matrices
Diagonalization of Matrices
AmenahGondal1
 
Djikstra's Algorithm
Djikstra's Algorithm Djikstra's Algorithm
Djikstra's Algorithm
Samar Kenkre
 
Warshalls and floyds algorithms
Warshalls and floyds algorithmsWarshalls and floyds algorithms
Warshalls and floyds algorithms
RasikhaCSEngineering
 
5HBC: How to Graph Implicit Relations Intro Packet!
5HBC: How to Graph Implicit Relations Intro Packet!5HBC: How to Graph Implicit Relations Intro Packet!
5HBC: How to Graph Implicit Relations Intro Packet!
A Jorge Garcia
 
Geometry
GeometryGeometry
NUMERICAL METHODS
NUMERICAL   METHODSNUMERICAL   METHODS
NUMERICAL METHODS
AMOGHA A K
 
A2 1 linear fxns
A2 1 linear fxns A2 1 linear fxns
A2 1 linear fxns
vhiggins1
 
Matlab lecture 9 – simpson 1,3 and trapezoidal method@taj
Matlab lecture 9 – simpson 1,3 and trapezoidal method@tajMatlab lecture 9 – simpson 1,3 and trapezoidal method@taj
Matlab lecture 9 – simpson 1,3 and trapezoidal method@taj
Tajim Md. Niamat Ullah Akhund
 
11.6 graphing linear inequalities in two variables
11.6 graphing linear inequalities in two variables11.6 graphing linear inequalities in two variables
11.6 graphing linear inequalities in two variables
GlenSchlee
 
Linear inequalities in two variables
Linear inequalities in two variablesLinear inequalities in two variables
Linear inequalities in two variables
christianjustine
 

What's hot (20)

S6 l04 analytical and numerical methods of structural analysis
S6 l04 analytical and numerical methods of structural analysisS6 l04 analytical and numerical methods of structural analysis
S6 l04 analytical and numerical methods of structural analysis
 
Numerical Analysis and Computer Applications
Numerical Analysis and Computer ApplicationsNumerical Analysis and Computer Applications
Numerical Analysis and Computer Applications
 
Secante
SecanteSecante
Secante
 
What is a function?
What is a function?What is a function?
What is a function?
 
Matrices, Arrays and Vectors in MATLAB
Matrices, Arrays and Vectors in MATLABMatrices, Arrays and Vectors in MATLAB
Matrices, Arrays and Vectors in MATLAB
 
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questioCS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
CS 6402 – DESIGN AND ANALYSIS OF ALGORITHMS questio
 
NACA Regula Falsi Method
 NACA Regula Falsi Method NACA Regula Falsi Method
NACA Regula Falsi Method
 
APLICACIONES DE ESPACIOS Y SUBESPACIOS VECTORIALES EN LA CARRERA DE ELECTRÓNI...
APLICACIONES DE ESPACIOS Y SUBESPACIOS VECTORIALES EN LA CARRERA DE ELECTRÓNI...APLICACIONES DE ESPACIOS Y SUBESPACIOS VECTORIALES EN LA CARRERA DE ELECTRÓNI...
APLICACIONES DE ESPACIOS Y SUBESPACIOS VECTORIALES EN LA CARRERA DE ELECTRÓNI...
 
Network centrality measures and their effectiveness
Network centrality measures and their effectivenessNetwork centrality measures and their effectiveness
Network centrality measures and their effectiveness
 
Fuzzy(2)
Fuzzy(2)Fuzzy(2)
Fuzzy(2)
 
Diagonalization of Matrices
Diagonalization of MatricesDiagonalization of Matrices
Diagonalization of Matrices
 
Djikstra's Algorithm
Djikstra's Algorithm Djikstra's Algorithm
Djikstra's Algorithm
 
Warshalls and floyds algorithms
Warshalls and floyds algorithmsWarshalls and floyds algorithms
Warshalls and floyds algorithms
 
5HBC: How to Graph Implicit Relations Intro Packet!
5HBC: How to Graph Implicit Relations Intro Packet!5HBC: How to Graph Implicit Relations Intro Packet!
5HBC: How to Graph Implicit Relations Intro Packet!
 
Geometry
GeometryGeometry
Geometry
 
NUMERICAL METHODS
NUMERICAL   METHODSNUMERICAL   METHODS
NUMERICAL METHODS
 
A2 1 linear fxns
A2 1 linear fxns A2 1 linear fxns
A2 1 linear fxns
 
Matlab lecture 9 – simpson 1,3 and trapezoidal method@taj
Matlab lecture 9 – simpson 1,3 and trapezoidal method@tajMatlab lecture 9 – simpson 1,3 and trapezoidal method@taj
Matlab lecture 9 – simpson 1,3 and trapezoidal method@taj
 
11.6 graphing linear inequalities in two variables
11.6 graphing linear inequalities in two variables11.6 graphing linear inequalities in two variables
11.6 graphing linear inequalities in two variables
 
Linear inequalities in two variables
Linear inequalities in two variablesLinear inequalities in two variables
Linear inequalities in two variables
 

Similar to Singh presentation

D026017036
D026017036D026017036
D026017036
inventionjournals
 
Spline interpolation numerical methods presentation
Spline interpolation numerical methods presentationSpline interpolation numerical methods presentation
Spline interpolation numerical methods presentation
Shohanur Nishad
 
06-07 Chapter interpolation in MATLAB
06-07 Chapter interpolation in MATLAB06-07 Chapter interpolation in MATLAB
06-07 Chapter interpolation in MATLAB
Dr. Mohammed Danish
 
A quantum-inspired optimization heuristic for the multiple sequence alignment...
A quantum-inspired optimization heuristic for the multiple sequence alignment...A quantum-inspired optimization heuristic for the multiple sequence alignment...
A quantum-inspired optimization heuristic for the multiple sequence alignment...
Konstantinos Giannakis
 
A short and naive introduction to using network in prediction models
A short and naive introduction to using network in prediction modelsA short and naive introduction to using network in prediction models
A short and naive introduction to using network in prediction models
tuxette
 
Ap4103260265
Ap4103260265Ap4103260265
Ap4103260265
IJERA Editor
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
appasami
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
Amrinder Arora
 
5. Linear Algebra for Machine Learning: Singular Value Decomposition and Prin...
5. Linear Algebra for Machine Learning: Singular Value Decomposition and Prin...5. Linear Algebra for Machine Learning: Singular Value Decomposition and Prin...
5. Linear Algebra for Machine Learning: Singular Value Decomposition and Prin...
Ceni Babaoglu, PhD
 
Unger
UngerUnger
Unger
Uri Unger
 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical Methods
ESUG
 
Solution of second kind volterra integro equations using linear
Solution of second kind volterra integro equations using linearSolution of second kind volterra integro equations using linear
Solution of second kind volterra integro equations using linear
Alexander Decker
 
Seminar Report (Final)
Seminar Report (Final)Seminar Report (Final)
Seminar Report (Final)
Aruneel Das
 
Investigation on the Pattern Synthesis of Subarray Weights for Low EMI Applic...
Investigation on the Pattern Synthesis of Subarray Weights for Low EMI Applic...Investigation on the Pattern Synthesis of Subarray Weights for Low EMI Applic...
Investigation on the Pattern Synthesis of Subarray Weights for Low EMI Applic...
IOSRJECE
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
Amrinder Arora
 
vj kb kh o15085 17210-1-pb
vj kb kh o15085 17210-1-pbvj kb kh o15085 17210-1-pb
vj kb kh o15085 17210-1-pb
Engr M Javaid
 
Digit Factorial Chains .(Euler Problem -74) (Matlab Programming Solution)
Digit Factorial Chains .(Euler Problem -74) (Matlab Programming Solution)Digit Factorial Chains .(Euler Problem -74) (Matlab Programming Solution)
Digit Factorial Chains .(Euler Problem -74) (Matlab Programming Solution)
Omkar Rane
 
Cryptography Baby Step Giant Step
Cryptography Baby Step Giant StepCryptography Baby Step Giant Step
Cryptography Baby Step Giant Step
SAUVIK BISWAS
 
Classification of handwritten characters by their symmetry features
Classification of handwritten characters by their symmetry featuresClassification of handwritten characters by their symmetry features
Classification of handwritten characters by their symmetry features
AYUSH RAJ
 
Incremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher QueriesIncremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher Queries
Gábor Szárnyas
 

Similar to Singh presentation (20)

D026017036
D026017036D026017036
D026017036
 
Spline interpolation numerical methods presentation
Spline interpolation numerical methods presentationSpline interpolation numerical methods presentation
Spline interpolation numerical methods presentation
 
06-07 Chapter interpolation in MATLAB
06-07 Chapter interpolation in MATLAB06-07 Chapter interpolation in MATLAB
06-07 Chapter interpolation in MATLAB
 
A quantum-inspired optimization heuristic for the multiple sequence alignment...
A quantum-inspired optimization heuristic for the multiple sequence alignment...A quantum-inspired optimization heuristic for the multiple sequence alignment...
A quantum-inspired optimization heuristic for the multiple sequence alignment...
 
A short and naive introduction to using network in prediction models
A short and naive introduction to using network in prediction modelsA short and naive introduction to using network in prediction models
A short and naive introduction to using network in prediction models
 
Ap4103260265
Ap4103260265Ap4103260265
Ap4103260265
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
5. Linear Algebra for Machine Learning: Singular Value Decomposition and Prin...
5. Linear Algebra for Machine Learning: Singular Value Decomposition and Prin...5. Linear Algebra for Machine Learning: Singular Value Decomposition and Prin...
5. Linear Algebra for Machine Learning: Singular Value Decomposition and Prin...
 
Unger
UngerUnger
Unger
 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical Methods
 
Solution of second kind volterra integro equations using linear
Solution of second kind volterra integro equations using linearSolution of second kind volterra integro equations using linear
Solution of second kind volterra integro equations using linear
 
Seminar Report (Final)
Seminar Report (Final)Seminar Report (Final)
Seminar Report (Final)
 
Investigation on the Pattern Synthesis of Subarray Weights for Low EMI Applic...
Investigation on the Pattern Synthesis of Subarray Weights for Low EMI Applic...Investigation on the Pattern Synthesis of Subarray Weights for Low EMI Applic...
Investigation on the Pattern Synthesis of Subarray Weights for Low EMI Applic...
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
vj kb kh o15085 17210-1-pb
vj kb kh o15085 17210-1-pbvj kb kh o15085 17210-1-pb
vj kb kh o15085 17210-1-pb
 
Digit Factorial Chains .(Euler Problem -74) (Matlab Programming Solution)
Digit Factorial Chains .(Euler Problem -74) (Matlab Programming Solution)Digit Factorial Chains .(Euler Problem -74) (Matlab Programming Solution)
Digit Factorial Chains .(Euler Problem -74) (Matlab Programming Solution)
 
Cryptography Baby Step Giant Step
Cryptography Baby Step Giant StepCryptography Baby Step Giant Step
Cryptography Baby Step Giant Step
 
Classification of handwritten characters by their symmetry features
Classification of handwritten characters by their symmetry featuresClassification of handwritten characters by their symmetry features
Classification of handwritten characters by their symmetry features
 
Incremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher QueriesIncremental View Maintenance for openCypher Queries
Incremental View Maintenance for openCypher Queries
 

Singh presentation

  • 1. Using Dynamic Analysis to Discover Polynomial and Array Invariants Paper by Thanh Vu Nguyen, Deepak Kapur, Westley Weimer and Stephanie Forest in ICSE 2012 Gagandeep Singh ETH Zurich 15 April 2013 Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 1 / 19
  • 2. Dynamic Invariant Analysis ◮ Dynamic Discovery of Program Invariants ◮ Execute Program on a set of inputs ◮ Infer Invariants using obtained traces ◮ Useful in ◮ Program Documentation ◮ Refactoring ◮ Debugging ◮ Verification Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 2 / 19
  • 3. Dynamic Invariant Analysis ◮ Daikon is widely used for such analysis ◮ Supports only a limited subset of Linear Relations ◮ No support for Nonlinear Relations ◮ Limited support for Array Invariants ◮ Contribution from the Paper ◮ Polynomial (Nonlinear) Invariants ◮ Linear Array Invariants ◮ Simple ◮ Nested Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 3 / 19
  • 4. Polynomial Invariants ◮ Polynomial Equalities ◮ Solve using Linear Algebra ◮ Polynomial Inequalities ◮ Use Polyhedra ◮ Deduction from Loop Conditions Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 4 / 19
  • 5. Terminology ◮ V = Set of Instrumented Variables at a Location ◮ D = Maximum Degree of Polynomial ◮ T = Set of Terms over V with Maximum degree D Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 5 / 19
  • 6. Polynomial Equalities 1 x := a i := 1 3 wh ile ( i <= n ){ // Inv : x = i ∗ a 5 x := x + a i := i + 1 7 } ◮ V = {x, i, a} ◮ D = 2 ◮ T = {1, x, i, a, xi, xa, ia, x2, i2, a2} ◮ Linear Equation Template: c1 + c2x + c3i + c4a + . . . + c10a2 = 0 instantiated per Trace ◮ Complexity of solving this Linear System is O |T|3 Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 6 / 19
  • 7. Polynomial Inequalities 1 x := a i := 1 3 wh ile ( i <= n ){ // Inv : x <= n ∗ a 5 x := x + a i := i + 1 7 } ◮ V = {x, n, a} ◮ D = 2 ◮ T = {1, x, n, a, xn, xa, na, x2, n2, a2} ◮ Construct |T| dimensional points from traces and build Bounded Convex Polyhedron that covers all trace points ◮ Boundary of Polyhedron satisfies c1 + c2x + c3n + c4a + . . . + c10a2 ≥ 0 ◮ The Complexity of building Polyhedron with k points in n dimensions has upper bound O k⌊n/2⌋ Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 7 / 19
  • 8. Deduction From Loop Conditions 1 x := a i := 1 3 wh ile ( i <= n ){ // Inv : x <= n ∗ a 5 x := x + a i := i + 1 7 } ◮ Combine inequalities at loop head with found equalites ◮ x ≤ n ∗ a can be deduced from i ≤ n and x = i ∗ a ◮ O |T|3 Complexity but can only deduce Inequalities derivable from Loop Conditions and Found Equalities Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 8 / 19
  • 9. Linear Array Invariants ◮ Simple Array Relations ◮ D = 1 ◮ Relations Among Array Elements ◮ Relations Among Array Indices ◮ Nested Array Relations ◮ Reachability Analysis ◮ Satisfiability Problem Formulation ◮ Functions Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 9 / 19
  • 10. Simple Array Relations ◮ Expand set V of array variables to V’ representing elements of arrays in V ◮ Find Set of Linear Equalities R between variables in V’ from traces of the form A0 + b0Bj0 + c0 = 0 A1 + b1Bj1 + c1 = 0 A2 + b2Bj2 + c2 = 0 ... Am + bmBjm + cm = 0 A is pivot as ci, bi and ji are expressed in terms of indices of A Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 10 / 19
  • 11. Simple Array Relations ◮ bi, ci and ji are linear relations ranging over indices of A A[i] = (p0i + q0)B[p1i + q1] + (p2i + q2) ◮ The Coefficients are determined using information from R ◮ The Complexity of the procedure is O |V ′|3 Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 11 / 19
  • 12. Nested Array Relations ◮ Reachability Analysis ◮ Satisfiability Problem Formulation ◮ Functions Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 12 / 19
  • 13. Reachability Analysis ◮ Elements of A reach elements of C through elements of B A[i] = B[C[pi + q]] ◮ Elements of A are subset of elements of B ◮ Indices of B are subset of elements of C ◮ The Time Complexity of Reachability Analysis is Exponential in Nesting Depth Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 13 / 19
  • 14. Satisfiability Problem Formulation ◮ Encode finding Nested Array Relations into a CNF formula f ◮ We can pose A[i] = B[C[pi + q]] as a CNF formula f: (1 = q) ∧ (2 = p + q ∨ 3 = p + q) ∧ (5 = 2p + q) ◮ Use SMT Solver to find Solution of f ◮ Same Worst Case Complexity ◮ Improves Performance of Reachability Analysis compared to Original method Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 14 / 19
  • 15. Functions ◮ Consider user defined functions A[i] = f(C[i], g(D[i])) ◮ Consider a function f with n arguments as an n dimensional array F F[i1] . . . [in] = f(i1 . . . in) ◮ Enforce finite depth in Nested Array Relations by disallowing a function to appear in scope of one of its arguments Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 15 / 19
  • 16. Evaluation ◮ Prototype tool invgen in python uses Sage mathematical environment and Z3 as SMT solver ◮ Available at https://code.google.com/p/invgen/ ◮ Evaluation on Nonlinear Arithmetic (NLA) test suite containing simple algorithms and an implementation of AES ◮ Can find all the documented invariants for NLA test suite and 57% of the documented invariants for AES Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 16 / 19
  • 17. NLA ◮ Cohencu ◮ Cohendiv ◮ Dijkstra ◮ Euclidex ◮ Fermat ◮ Freire ◮ LCM ◮ MannaDiv ◮ Sqrt ◮ Wensley ◮ More Info about functions can be found here Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 17 / 19
  • 18. AES ◮ AddRoundKey ◮ RotWord ◮ ShiftRows ◮ Block2State ◮ KeySetupEnc ◮ SubBytes ◮ Mul ◮ Xor ◮ SubBytes ◮ SubWord Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 18 / 19
  • 19. Conclusion ◮ Pros ◮ Extends current Dynamic Analysis Techniques ◮ Loop Invariant Inference ◮ Can be applied in Verification of Complex Numeric Algorithms ◮ Cons ◮ May not scale well for large programs ◮ Effectiveness depends on quality of traces ◮ Does not consider certain forms of Array Invariants like A[i] = 2B[100C[. . .]] Gagandeep Singh ETH Zurich Using Dynamic Analysis to Discover Polynomial and Array Invariants 19 / 19