Verification and Certification of Java
An experience report Gilles Barthe
IMDEA Software, Madrid
Septembre 2009
Gilles Barthe Verification and Certification of Java
Verification and Certification of Java An experience report Gilles - - PowerPoint PPT Presentation
Verification and Certification of Java An experience report Gilles Barthe IMDEA Software, Madrid Septembre 2009 Gilles Barthe Verification and Certification of Java Context: formal methods for small devices smartcard platform and
IMDEA Software, Madrid
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
1
2
3
4
5
Gilles Barthe Verification and Certification of Java
Source program Source Specification (types + logics) Runtime environment Bytecode program Bytecode Specification
Certificate
Requirements
Certificate checker Certificate generation Certificate Certificate
Bytecode program Bytecode Specification
Interactive proofs Java compiler Spec compiler Proof compiler
Code producer Code consumer
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
1
2
3
Gilles Barthe Verification and Certification of Java
1
2
3
Gilles Barthe Verification and Certification of Java
1
2
3
Gilles Barthe Verification and Certification of Java
1
2
3
Gilles Barthe Verification and Certification of Java
1
2
3
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
< assrt > ::= @ requires ( < prop >∗ ) | @ ensures ( < prop >∗ ) | @ costs ( < resource usage >∗ ) < resource usage > ::= res usage(< approx >, res name, < arith expr >) < approx def > ::= approx def(< approx >, arith function) < prop > ::= size(var, < approx >, < sz metric >, < arith expr >) | size metric(var, < sz metric >) < approx > ::= ub | lb | o < sz metric > ::= value | length | size < arith expr > ::= < sz val > | ⊖(< sz val >∗) < sz val > ::= num | < sz metric > (var)
Gilles Barthe Verification and Certification of Java
Intermediate Representation Resource Usage Analysis Java bytecode Data Dependency Analysis Size Analysis Size
Solver Recurrence Upper−bound Upper−bound Size Rel. Gilles Barthe Verification and Certification of Java
Intermediate Representation Resource Usage Analysis Data Dependency Analysis Size Analysis Size
Upper−bound Size Rel. Solver Recurrence Upper−bound Java bytecode Energy Consumption Model Gilles Barthe Verification and Certification of Java
Intermediate Representation Resource Usage Analysis Energy Consumption Model Data Dependency Analysis Size Analysis Size
Upper−bound Size Rel. Solver Recurrence Upper−bound Java bytecode Upper−bound Energy cons. Energy Cons. Equations Gilles Barthe Verification and Certification of Java
Program Resource(s) t Resource Usage Func. BST Heap usage 367 O(2n) n ≡ tree depth CellPhone SMS monetary cost 386 O(n2) n ≡ packets length Client Bytes received and 527 O(n) n ≡ stream length bandwidth required O(1) — Dhrystone Energy consumption 759 O(n) n ≡ int value Divbytwo Stack usage 219 O(log2(n)) n ≡ int value Files Files left open and 649 O(n) n ≡ number of files Data stored O(n × m) m ≡ stream length Join DB accesses 460 O(n × m) n, m ≡ table records Screen Screen width 536 O(n) n ≡ stream length
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Virtual machine Operating system Source program Bytecode program Interactive proofs API JML specification specification Bytecode Certificate Certificate Certificate checker
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
VCGen Verification Conditions Prover Certificate Certificate
Producer Consumer
Proof Checker OK Source Program Execution VCGen Verification Conditions Compiled Program Preservation of Proof Obligations Compiler Non−optimizing Gilles Barthe Verification and Certification of Java
VCGen Verification Conditions Prover Certificate Certificate
Producer Consumer
Proof Checker OK Source Program Execution VCGen Verification Conditions Compiled Program Preservation of Proof Obligations Compiler Non−optimizing Gilles Barthe Verification and Certification of Java
VCGen Verification Conditions Prover Certificate Certificate VCGen Compiled Program Optimizer
Producer Consumer
Proof Checker OK Source Program Execution Verification Conditions Preservation of Proof Obligations Compiler Non−optimizing Optimized Program Gilles Barthe Verification and Certification of Java
VCGen Verification Conditions Prover Certificate Certificate VCGen Compiled Program Optimizer
Producer Consumer
Proof Checker OK Source Program Execution Verification Conditions Preservation of Proof Obligations Compiler Non−optimizing Optimized Program
Gilles Barthe Verification and Certification of Java
VCGen Verification Conditions Prover Certificate Certificate Certificate Translator
Producer Consumer
Proof Checker OK Source Program Compiler Execution VCGen Verification Conditions Compiled Program
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
¨ αP(Postif B then St else Sf fi) =
¨ αP ¨ αP ∘ Postif B then St else Sf fi ∘ ¨ γ P =
¨ αP ∘ post[τ ⋆if B then St else Sf fi] ∘ ¨ γ P = big step operational semantics (93) ¨ αP ∘ post [(1P ∪ τ B) ∘ τ ⋆St ∘ (1P ∪ τ t) ∪ (1P ∪ τ ¯
B) ∘ τ ⋆Sf ∘ (1P ∪
τ f )] ∘ ¨ γ P = Galois connection (98) so that post preserves joins ¨ αP ∘ (post [(1P ∪ τ B) ∘ τ ⋆St ∘ (1P ∪ τ t)] ˙ ∪ post[(1P ∪ τ ¯
B) ∘ τ ⋆Sf ∘ (1P ∪ τ f )]) ∘ ¨
γ P = Galois connection (106) so that ¨ αP preserves joins (¨ αP ∘ post[(1P ∪ τ B) ∘ τ ⋆St ∘ (1P ∪ τ t)] ∘ ¨ γ P) ˙ ¨ ⊔ (¨ αP ∘ post[(1P ∪ τ ¯
B) ∘ τ ⋆Sf ∘ (1P ∪ τ f )] ∘ ¨
γ P) ˙ ¨ ⊑ lemma (5.3) and similar one for the else branch λJ • let J t′ = λl ∈ inPP•( (l = atPSt ? JatPSt ˙ ⊔ AbexpB(Jℓ) ¿ Jl) ) in let J t′′ = APostSt(J t′) in λl ∈ inPP•( (l = ℓ′ ? J t′′
ℓ′ ˙
⊔ J t′′ afterPSt ¿ J t′′
l )
) ¨ ⊔ let J f ′ = λl ∈ inPP•( (l = atPSf ? JatPSf ˙ ⊔ AbexpT (¬B)(Jℓ) ¿ Jl) ) in let J f ′′ = APostSf (J f ′) in λl ∈ inPP•( (l = ℓ′ ? J f ′′
ℓ′
˙ ⊔ J f ′′ afterPSf ¿ J f ′′
l
) ) (120) = by grouping similar terms λJ • let J t′ = λl ∈ inPP•( (l = atPSt ? JatPSt ˙ ⊔ AbexpB(Jℓ) ¿ Jl) ) and J f ′ = λl ∈ inPP•( (l = atPSf ? JatPSf ˙ ⊔ AbexpT (¬B)(Jℓ) ¿ Jl) ) in let J t′′ = APostSt(J t′) and J f ′′ = APostSf (J f ′) in λl ∈ inPP•( (l = ℓ′ ? J t′′
ℓ′ ˙
⊔ J t′′ afterPSt ˙ ⊔ J f ′′
ℓ′
˙ ⊔ J f ′′ afterPSf ¿ J t′′
l
˙ ⊔ J f ′′
l
) ) = by locality (113) and labelling scheme (59) so that in particular J t′′
ℓ′ = J t′ ℓ′ = J t ℓ′ = J f ℓ′
= J f ′
ℓ′ = J f ′′ ℓ′ and APostSt and APostSf do not interfere
Gilles Barthe Verification and Certification of Java
¨ αP(Postif B then St else Sf fi) =
¨ αP ¨ αP ∘ Postif B then St else Sf fi ∘ ¨ γ P =
¨ αP ∘ post[τ ⋆if B then St else Sf fi] ∘ ¨ γ P = big step operational semantics (93) ¨ αP ∘ post [(1P ∪ τ B) ∘ τ ⋆St ∘ (1P ∪ τ t) ∪ (1P ∪ τ ¯
B) ∘ τ ⋆Sf ∘ (1P ∪
τ f )] ∘ ¨ γ P = Galois connection (98) so that post preserves joins ¨ αP ∘ (post [(1P ∪ τ B) ∘ τ ⋆St ∘ (1P ∪ τ t)] ˙ ∪ post[(1P ∪ τ ¯
B) ∘ τ ⋆Sf ∘ (1P ∪ τ f )]) ∘ ¨
γ P = Galois connection (106) so that ¨ αP preserves joins (¨ αP ∘ post[(1P ∪ τ B) ∘ τ ⋆St ∘ (1P ∪ τ t)] ∘ ¨ γ P) ˙ ¨ ⊔ (¨ αP ∘ post[(1P ∪ τ ¯
B) ∘ τ ⋆Sf ∘ (1P ∪ τ f )] ∘ ¨
γ P) ˙ ¨ ⊑ lemma (5.3) and similar one for the else branch λJ • let J t′ = λl ∈ inPP•( (l = atPSt ? JatPSt ˙ ⊔ AbexpB(Jℓ) ¿ Jl) ) in let J t′′ = APostSt(J t′) in λl ∈ inPP•( (l = ℓ′ ? J t′′
ℓ′ ˙
⊔ J t′′ afterPSt ¿ J t′′
l )
) ¨ ⊔ let J f ′ = λl ∈ inPP•( (l = atPSf ? JatPSf ˙ ⊔ AbexpT (¬B)(Jℓ) ¿ Jl) ) in let J f ′′ = APostSf (J f ′) in λl ∈ inPP•( (l = ℓ′ ? J f ′′
ℓ′
˙ ⊔ J f ′′ afterPSf ¿ J f ′′
l
) ) (120) = by grouping similar terms λJ • let J t′ = λl ∈ inPP•( (l = atPSt ? JatPSt ˙ ⊔ AbexpB(Jℓ) ¿ Jl) ) and J f ′ = λl ∈ inPP•( (l = atPSf ? JatPSf ˙ ⊔ AbexpT (¬B)(Jℓ) ¿ Jl) ) in let J t′′ = APostSt(J t′) and J f ′′ = APostSf (J f ′) in λl ∈ inPP•( (l = ℓ′ ? J t′′
ℓ′ ˙
⊔ J t′′ afterPSt ˙ ⊔ J f ′′
ℓ′
˙ ⊔ J f ′′ afterPSf ¿ J t′′
l
˙ ⊔ J f ′′
l
) ) = by locality (113) and labelling scheme (59) so that in particular J t′′
ℓ′ = J t′ ℓ′ = J t ℓ′ = J f ℓ′
= J f ′
ℓ′ = J f ′′ ℓ′ and APostSt and APostSf do not interfere
matrix_t* _matrix_alloc_int(const int mr, const int nc) { matrix_t* mat = (matrix_t*)malloc(sizeof(matrix_t)); mat->nbrows = mat->_maxrows = mr; mat->nbcolumns = nc; mat->_sorted = s; if (mr*nc>0){ int i; pkint_t* q; mat->_pinit = _vector_alloc_int(mr*nc); mat->p = (pkint_t**)malloc(mr * sizeof(pkint_t*)); q = mat->_pinit; for (i=0;i<mr;i++){ mat->p[i]=q; q=q+nc; }} return mat; } void backsubstitute(matrix_t* con, int rank) { int i,j,k; for (k=rank-1; k>=0; k--) { j = pk_cherni_intp[k]; for (i=0; i<k; i++) { if (pkint_sgn(con->p[i][j])) matrix_combine_rows(con,i,k,i,j); } for (i=k+1; i<con->nbrows; i++) { if (pkint_sgn(con->p[i][j])) matrix_combine_rows(con,i,k,i,j); }} }
Gilles Barthe Verification and Certification of Java
¨ αP(Postif B then St else Sf fi) =
¨ αP ¨ αP ∘ Postif B then St else Sf fi ∘ ¨ γ P =
¨ αP ∘ post[τ ⋆if B then St else Sf fi] ∘ ¨ γ P = big step operational semantics (93) ¨ αP ∘ post [(1P ∪ τ B) ∘ τ ⋆St ∘ (1P ∪ τ t) ∪ (1P ∪ τ ¯
B) ∘ τ ⋆Sf ∘ (1P ∪
τ f )] ∘ ¨ γ P = Galois connection (98) so that post preserves joins ¨ αP ∘ (post [(1P ∪ τ B) ∘ τ ⋆St ∘ (1P ∪ τ t)] ˙ ∪ post[(1P ∪ τ ¯
B) ∘ τ ⋆Sf ∘ (1P ∪ τ f )]) ∘ ¨
γ P = Galois connection (106) so that ¨ αP preserves joins (¨ αP ∘ post[(1P ∪ τ B) ∘ τ ⋆St ∘ (1P ∪ τ t)] ∘ ¨ γ P) ˙ ¨ ⊔ (¨ αP ∘ post[(1P ∪ τ ¯
B) ∘ τ ⋆Sf ∘ (1P ∪ τ f )] ∘ ¨
γ P) ˙ ¨ ⊑ lemma (5.3) and similar one for the else branch λJ • let J t′ = λl ∈ inPP•( (l = atPSt ? JatPSt ˙ ⊔ AbexpB(Jℓ) ¿ Jl) ) in let J t′′ = APostSt(J t′) in λl ∈ inPP•( (l = ℓ′ ? J t′′
ℓ′ ˙
⊔ J t′′ afterPSt ¿ J t′′
l )
) ¨ ⊔ let J f ′ = λl ∈ inPP•( (l = atPSf ? JatPSf ˙ ⊔ AbexpT (¬B)(Jℓ) ¿ Jl) ) in let J f ′′ = APostSf (J f ′) in λl ∈ inPP•( (l = ℓ′ ? J f ′′
ℓ′
˙ ⊔ J f ′′ afterPSf ¿ J f ′′
l
) ) (120) = by grouping similar terms λJ • let J t′ = λl ∈ inPP•( (l = atPSt ? JatPSt ˙ ⊔ AbexpB(Jℓ) ¿ Jl) ) and J f ′ = λl ∈ inPP•( (l = atPSf ? JatPSf ˙ ⊔ AbexpT (¬B)(Jℓ) ¿ Jl) ) in let J t′′ = APostSt(J t′) and J f ′′ = APostSf (J f ′) in λl ∈ inPP•( (l = ℓ′ ? J t′′
ℓ′ ˙
⊔ J t′′ afterPSt ˙ ⊔ J f ′′
ℓ′
˙ ⊔ J f ′′ afterPSf ¿ J t′′
l
˙ ⊔ J f ′′
l
) ) = by locality (113) and labelling scheme (59) so that in particular J t′′
ℓ′ = J t′ ℓ′ = J t ℓ′ = J f ℓ′
= J f ′
ℓ′ = J f ′′ ℓ′ and APostSt and APostSf do not interfere
matrix_t* _matrix_alloc_int(const int mr, const int nc) { matrix_t* mat = (matrix_t*)malloc(sizeof(matrix_t)); mat->nbrows = mat->_maxrows = mr; mat->nbcolumns = nc; mat->_sorted = s; if (mr*nc>0){ int i; pkint_t* q; mat->_pinit = _vector_alloc_int(mr*nc); mat->p = (pkint_t**)malloc(mr * sizeof(pkint_t*)); q = mat->_pinit; for (i=0;i<mr;i++){ mat->p[i]=q; q=q+nc; }} return mat; } void backsubstitute(matrix_t* con, int rank) { int i,j,k; for (k=rank-1; k>=0; k--) { j = pk_cherni_intp[k]; for (i=0; i<k; i++) { if (pkint_sgn(con->p[i][j])) matrix_combine_rows(con,i,k,i,j); } for (i=k+1; i<con->nbrows; i++) { if (pkint_sgn(con->p[i][j])) matrix_combine_rows(con,i,k,i,j); }} }
Gilles Barthe Verification and Certification of Java
1
2
3
4
Gilles Barthe Verification and Certification of Java
1
2
3
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java
PCC verifier
Gilles Barthe Verification and Certification of Java
PCC verifier
Gilles Barthe Verification and Certification of Java
PCC verifier
Gilles Barthe Verification and Certification of Java
PCC verifier PCC verifier
Gilles Barthe Verification and Certification of Java
PCC verifier PCC verifier
Gilles Barthe Verification and Certification of Java
PCC verifier PCC verifier
Gilles Barthe Verification and Certification of Java
PCC verifier PCC verifier
Gilles Barthe Verification and Certification of Java
PCC verifier PCC verifier
proof
Gilles Barthe Verification and Certification of Java
PCC verifier PCC verifier
proof
Gilles Barthe Verification and Certification of Java
PCC verifier PCC verifier
proof
Gilles Barthe Verification and Certification of Java
PCC verifier PCC verifier
proof
Gilles Barthe Verification and Certification of Java
PCC verifier PCC verifier
proof
Gilles Barthe Verification and Certification of Java
PCC verifier PCC verifier
proof proof proof
Gilles Barthe Verification and Certification of Java
Gilles Barthe Verification and Certification of Java