15
Towards Verified Implementation of Event-B Models in Dafny MohammadSadegh Dalvandi, Michael Butler 5th Rodin User and Developer Workshop, June 2014, Toulouse

Towards Verified Implementation of Event-B Models in Dafny

Embed Size (px)

Citation preview

Page 1: Towards Verified Implementation of Event-B Models in Dafny

Towards Verified Implementation of Event-B Models in Dafny MohammadSadegh  Dalvandi,  Michael  Butler  5th  Rodin  User  and  Developer  Workshop,  June  2014,  Toulouse  

Page 2: Towards Verified Implementation of Event-B Models in Dafny

Software Correctness: Constructive & Analytical Approaches

•   Construc*ve  Approach:  VerificaEon  of  formal  models  of  required  system  behaviour  at  different  levels  of  abstracEon  -­‐  Aims  at  early  stages  of  development  •   Analy*cal  Approach:  VerificaEon  of  properEes  of  program  code  against  formal  specificaEon  of  the  system  -­‐  Aims  at  coding  stage  

Page 3: Towards Verified Implementation of Event-B Models in Dafny

Linking Constructive & Analytical Approaches  •   ConstrucEve  and  analyEcal  approaches  are  mutually  beneficial  •   ConstrucEve  approach  for  verifying  high-­‐level  func9onal  proper9es  •   AnalyEcal  approach  for  verifying  implementa9on-­‐oriented  proper9es  

•   To  invesEgate  this,  we  are  trying  to  build  a  link  between  these  two  approaches.  

Page 4: Towards Verified Implementation of Event-B Models in Dafny

Linking Event-B and Dafny  Event-­‐B  

• A  formal  method  for  system-­‐level  modelling  and  analysis  • Based  on  set  theory  and  predicate  logic  • SupporEng  refinement    • Construc9ve  approach    

 Dafny  • A  language  and  program  verifier  for  funcEonal  correctness  • Has  built-­‐in  specificaEon  constructs:  pre-­‐  &  post-­‐condiEons,  asserEon,…  • Analy9cal  approach    

Page 5: Towards Verified Implementation of Event-B Models in Dafny

Dafny: A Language and Program Verifier

Page 6: Towards Verified Implementation of Event-B Models in Dafny

Case Study: A Map Abstract Data Type (1) Dafny:  

•   SpecificaEon:  using  two  sequences  keys  and  values  •   ImplementaEon:  using  a  linked-­‐list  where  each  node  has  three  fields:  key,  val,  and  next  

Event-­‐B:  •   Map  modelled  as  par9al  func9on  in  the  most  abstract  level  •   Sequences  and  linked-­‐list  added  through  refinement  levels  •   Event-­‐B  extended  by  Theory  Plug-­‐in  to  accommodate  sequences  

Page 7: Towards Verified Implementation of Event-B Models in Dafny

Case Study: A Map Abstract Data Type (2) • Adding  a  new  key  to  the  map  (Dafny  implementaEon):  

Method  SpecificaEon  

Method  Body  

Page 8: Towards Verified Implementation of Event-B Models in Dafny

Case Study: A Map Abstract Data Type (2) • Adding  a  new  key  to  the  map  (Dafny  implementaEon):  

If  key  is  already  exists  in  the  map,  returns  the  node  that  key  is  stored  in  it,  the  posiEon  of  the  node  in  linked-­‐list,  and  the  

previous  node  in  the  list.  Otherwise  returns  null  

Adding  a  new  key  to  the  

map  

UpdaEng  the  value  of  an  exisEng  key  

Page 9: Towards Verified Implementation of Event-B Models in Dafny

Case Study: A Map Abstract Data Type (3) • Event-­‐B  model  for  adding  new  keys  to  the  map(first  refinement):    

Page 10: Towards Verified Implementation of Event-B Models in Dafny

Case Study: A Map Abstract Data Type (4) • Event-­‐B  model  for  updaEng  value  of  exisEng  keys  (first  refinement):    

Page 11: Towards Verified Implementation of Event-B Models in Dafny

Case Study: A Map Abstract Data Type (5) • Event-­‐B  model  for  adding  new  keys  (second  refinement):    

Page 12: Towards Verified Implementation of Event-B Models in Dafny

Case Study: A Map Abstract Data Type (6) • Event-­‐B  model  for  updaEng  value  of  exisEng  keys  (second  refinement):    

Page 13: Towards Verified Implementation of Event-B Models in Dafny

Case Study: A Map Abstract Data Type (7)

FindIndex(key)  is  implicitly  modelled  as  guards  of  events  Add1  

&  Add2  

Page 14: Towards Verified Implementation of Event-B Models in Dafny

Case Study: A Map Abstract Data Type (8) •   Invariants:  

• Dafny  does  not  have  any  special  construct  for  invariants  •  Invariants  are  placed  in  a  boolean  funcEon  called  Valid()  • Valid()  is  a  pre-­‐  and  post-­‐condiEon  for  all  methods  

Page 15: Towards Verified Implementation of Event-B Models in Dafny

  Thank  you  for  your  aZenEon.     QuesEons?  Comments?