73
論理と検証技術 モデル検査と定理証明 2011年7月29日 藤田 憲悦

Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

論理と検証技術

モデル検査と定理証明

2011年7月29日

藤田 憲悦

Page 2: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

状態遷移図 Mm×Mc

m: W1 → B0 → B1 → W0cat:W1↓

B0↓

B1↓

W0↓↑

W2

IW

W

catcat

Page 3: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

猫とねずみ• 次のようなフィールド上で猫とねずみが追いかけっこをする

• ねずみは[北西]から、ネコは[南]からスタートする

• 隣り合うポイントにのみ動ける

• 先攻がねずみ、後攻がネコで交互に動く

• ネコがねずみを捕まえたらネコの勝ち

Page 4: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

斜め線と勝利条件

• 斜め線が無い場合、初期位置での互いの距離の偶奇性で勝敗が決まる

・・・今回の初期位置では、ななめ線が無い場合、勝利条件を満たせない

• 斜め線の通過により偶奇性が変わるのが鍵

Page 5: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

状態遷移図 Mm×Mc

m: W1 → B0 → B1 → W0cat:W1↓

B0↓

B1↓

W0↓↑

W2

IW

W

catcat

Page 6: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

状態遷移図 Mm×Mc

m: W2←W1 → B0 → B1 → W0 → W1’ → B0’→B1’→W0’

cat:W1↓

B0↓

B1↓

W0↓↑

W2

I W

W

W

W

catcat

m

Page 7: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

模倣と抽象化

• Mc = < Sc, Rc, Ic, Atom, Lc >• Ma = < Sa, Ra, Ia, Atom, La >• f : Sc→Sa がMcからMaへの模倣写像1.Lc(s) = La (f(s))2.Rc(s, t) ⇒ Ra(f(s), f(t))3.f(Ic) = Ia

• 保存定理:McからMaへの模倣写像が存在するなら,任意のLTL式Aに対して,

Ma |= A ⇒ Mc |= A

Page 8: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

模倣射像 f:Mc→Ma

p p

Mc Ma

Page 9: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

模倣射像 f:Mc→Ma

p p

Mc |= X X ¬ p Ma |= X X ¬ p

偽反例

f

f

Page 10: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

プロセスPwhile True{

//non‐critical sectionx:=y+1;while y != 0 and x > y{}

//critical sectionx:=0;}

プロセスQwhile True{

//non‐critical sectiony:=x+1;while x != 0 and x < y{}

//critical sectiony:=0;}

排他制御(ベーカリーアルゴリズム)

NC

Wait

Critical

x:=y+1

x:=0

y!=0andx>y

o.w.

NC

Wait

Critical

y:=x+1

y:=0

x!=0andy>x

o.w.

Page 11: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

プロセスPwhile True{

//non‐critical sectionx:=y+1;while y != 0 and x > y{}

//critical sectionx:=0;}

プロセスQwhile True{

//non‐critical sectiony:=x+1;while x != 0 and x < y{}

//critical sectiony:=0;}

排他制御(ベーカリーアルゴリズム)

NC

Wait

Critical

x:=y+1

x:=0

y!=0andx>y

o.w.

NC

Wait

Critical

y:=x+1

y:=0

x!=0andy>x

o.w.

|≠G(x<10)

Page 12: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

プロセスPwhile True{

//non‐critical sectionx:=y+1;while y != 0 and x > y{}

//critical sectionx:=0;}

プロセスQwhile True{

//non‐critical sectiony:=x+1;while x != 0 and x < y{}

//critical sectiony:=0;}

模倣射像 g : N×N → { ZZ, pZ, Zp, lp, pl, pEq }

ZZ (x=y=0)pZ (x>0かつy=0)

g(x, y) = Zp (x=0かつy>0) 述語による N×N の分割lp (0<x<y)pl (0<y<x)pEq (0<x=y)

述語抽象化

Page 13: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

N

N

4

3

2

1

0 1 2 3 4

lp g(x,y)

ZZ pZ

Zp

pl

pEq

Page 14: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

N

N

4

3

2

1

0 1 2 3 4

lp

pEq

g(x,y)

ZZ pZ

Zp

pl

Page 15: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Abstract model: process P

Zp

lp

pEq

pl

pZZZ

x:=0

x:=y+1

x:=y+1

x:=y+1

x:=0

x:=0

x:=0

x:=y+1

x:=y+1x:=y+1

Page 16: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Abstract model: process P

Zp

lp

pEq

pl

pZZZ

x:=0

x:=y+1

x:=y+1

x:=y+1

x:=0

x:=0

x:=0

x:=y+1

x:=y+1

y:=0

x:=y+1

y:=0

y:=x+1

y:=x+1

y:=0y:=x+1

y:=0

y:=x+1y:=x+1

y:=x+1

Page 17: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Abstract model: process P

Zp

lp

pEq

pl

pZZZ

x:=0

x:=y+1

x:=y+1

x:=y+1

x:=0

x:=0

x:=0

x:=y+1

x:=y+1

y:=0

x:=y+1

y:=0

y:=x+1

y:=x+1

y:=0y:=x+1

y:=0

y:=x+1y:=x+1

y:=x+1

(x,y) : (0,0) →(1,0)→(1,2)→(0,2)→(3,2)→(3, 0)→ …..

Page 18: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Combined approach of Verification and model

checking :D.A.Peled

System Model PropertiesVerify

Simulation

Model

Checking

* The adequacy of the simplification (abstraction).

* The essential properties are preserved.

Page 19: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Forward simulation:concrete Mc refines abstract Ma

• Forward simulation R ⊆ Sc×Sa:1. ∀ ic∈Ic ∃ia∈ Ia. R(ic, ia)2. R(s, r) ⇒ Lc(s) = La(r)3. s → s’ & R(s,r) ⇒ ∃r’.r → r’ & R(s’,r’)

r r’

s s’

∀ Concrete operation in Mc

∃ Abstract operation in Ma

State Relation R State Relation R

Page 20: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Forward simulation:concrete Mc refines abstract Ma

• Forward simulation R ⊆ Sc×Sa:1. ∀ ic∈Ic ∃ia∈ Ia. R(ic, ia)2. R(s, r) ⇒ Lc(s) = La(r)3. s → s’ & R(s,r) ⇒ ∃r’.r → r’ & R(s’,r’)

r r’

s s’

∀ Concrete operation in Mc

∃ Abstract operation in Ma

State Relation R State Relation R

Ma |= A ⇒ Mc |= A

£[A]

∪£[Ma]

∪£[Mc]

Page 21: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Backward simulation:• Backward simulation Q ⊆ Sa×Sc:

1. ∀ ia∈Ia ∃ic∈ Ic. Q(ia, ic)2. Q(r, s) ⇒ La(r) = Lc(s) 3. r → r’ & Q(r, s) ⇒ ∃s’. s → s’ & Q(r’,s’)

r r’

s s’

∃ Concrete operation in Mc

∀ Abstract operation in Ma

State Relation Q State Relation Q

Ma |≠ A ⇒ Mc | ≠ A

Page 22: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Combined approach of Verification and model

checking :D.A.Peled

System Model PropertiesVerify

Simulation

Model

Checking

System Model_c Model_a PropertiesVerify

Simulation

Model

Checking

Page 23: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Refinement layers in seL4 Verifi.(G.Klein, et. al. )

• All properties of abstract model also hold for the refined model:

• Abstract specification: MA

↑ high-level (abstract)• Executable specification: ME

↓ low-level (concrete, refined)• High-performance C implementation: MC

Page 24: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Refinement layers in seL4 Verifi.(G.Klein, et. al. )

• All properties of abstract model also hold for the refined model:

• Abstract specification: MA

↑ high-level (abstract)• Executable specification: ME

↓ low-level (concrete, refined)• High-performance C implementation: MC

• Th. MC refines ME, and ME refines MA.

Page 25: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Formally verified compiler(X. Leroy, et. al. )

• Safety properties on source code also hold for compiled code:

• Clight (subset of C program. lang.): MA

↓ compilation• 8 Intermediate languages ‥‥‥

↓ compilation• PowerPC assembly code: MC

• Semantic preservation: MC behaves following semantics of MA.

Page 26: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Comparison: verification and model checking

System Model_c Model_a PropertiesVerify

Simulation

Model

Checking

Implement.Spec. Spec_a Spec_cRefine

Simulation

Page 27: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Hoare 論理へ

• ⇒ 定理証明システムを活用した検証

Page 28: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

JMLツールの例

• JMLツールの調査

Page 29: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 30: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 31: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 32: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 33: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

定理証明器の活用

• Coqの例

Page 34: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 35: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 36: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Java プログラムの検証

• ⇒ Krakatoaへ

Page 37: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 38: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 39: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Mulメソッドの検証

• Breunesse, Catano, Huisman, Jacobs:Formal methods for smart cards: an experience report,Science of Computer Programming 55 (2005) 53—80

• Short 型16bit で小数の積の計算をする mul メソッドを実装して,定理証明システムLOOPで検証

Page 40: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Gemplus電子財布アプレット

• Genplusが開発したJava Card用電子財布

• Purseアプレット:入金,出金,外貨両替

• Card issuerアプレット:本人認証

• Loyaltyアプレット:ロイリャリティ・ポイント

Page 41: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 42: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

(2^15 -1)

Page 43: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Mulメソッド

Page 44: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

The “rest-part”

• a.b * e.f = a*e + a*0.f + 0.b * e + 0.b*0.f • b, f < 1000 and (b*f)/10^6 < 1

• decimal = a*e*PRECISION + a*f + e*b + (b*f)/10^3

• floor「(b*f)/10^3」• Overflow: “b*f” は short 型• Rounding:

(b*f)/10^3 ≠ (b/10^3 * f/10^3)*10^3

Page 45: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Original Specification (a.b*e.f)/*@ requires 0 <= f && f < PRECISION &&@ 0 <= e && e <= MAX_DECIMAL_NUMBER &&@ (e+1) * (intPart+1) < MAX_DECIMAL_NUMBER@ modifies decimal;@ ensures decimal = e * ¥old(intPart) * PRECISION@ + ¥old(intPart) * f@ + e * ¥old(decPart)@ + @ ( ( f > 100 && ¥old(decPart) > 100) ?@ ( ((¥old(decPart)/10) * (f/10)) / 10 ) :@ ( ( f > 100 && ¥old(decPart) <= 100) ?@ ( (¥old(decPart) * (f/10)) / 100 ) :@ ……….@ ( ( f <= 100 && ¥old(decPart) <= 100) ?@ ( (¥old(decPart) * f) / 1000 )))); ……….@*/private void mul(short e, short f) { ……….}

Page 46: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Original Specification (a.b*e.f)/*@ requires 0 <= f && f < PRECISION &&@ 0 <= e && e <= MAX_DECIMAL_NUMBER &&@ (e+1) * (intPart+1) < MAX_DECIMAL_NUMBER@ modifies decimal;@ ensures decimal = e * ¥old(intPart) * PRECISION@ + ¥old(intPart) * f@ + e * ¥old(decPart)@ + @ ( ( f > 100 && ¥old(decPart) > 100) ?@ ( ((¥old(decPart)/10) * (f/10)) / 10 ) :@ …………………………………………………

No overflow: (1000/10 * 1000/10) = 100*100 < 32767But rounding:( 999/10 * 999/10)/10 = (99 * 99)/10 = 9801/10 = 9800.999 * 0.999 = 0.998001 998!

Page 47: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 48: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

0.b: b=a1a2a3

0.b * 0.f

Page 49: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 50: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 51: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 52: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 53: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 54: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 55: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

Mul メソッドの検証

• PostCondition:

intPart*PRECISION + decPart= a*e*PRECIEION

+ a*f + e*b + (b*f)/10^3

Page 56: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 57: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

a.b*e.f :

Page 58: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

(a. b * e) < (a+1) * e

Page 59: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

(0.f * a) < a

Page 60: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 61: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

(0.f * 0.b) < 1

Page 62: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

(a+1)*(e+1) = (e+1)*(intPart +1) < Max : PreCondition

Page 63: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 64: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 65: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 66: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 67: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 68: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 69: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 70: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 71: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 72: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •
Page 73: Verification and Model checking - Gunma University · 2013. 11. 19. · 猫とねずみ • 次のようなフィールド上で猫とねずみが追いかけっこをする 北 •

参考資料へ

• Formal methods for smart cards• seL4: Formal Verification of an Operating

System Kernel• Formal verification of a realistic compiler• Software Reliability Methods

• The Seventeen Provers of the World• Survey: Verification Tools (Jave+JML)