Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
プログラム検証入門
Search
r1ru
September 14, 2024
Technology
3.9k
6
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
プログラム検証入門
r1ru
September 14, 2024
More Decks by r1ru
See All by r1ru
ImaginaryCTF 2025 stillerer-printf (魔女のお茶会 #8)
riru
0
610
Infer入門
riru
5
2.1k
Formal Development of Operating Systems in Rust
riru
1
860
モデル検査入門
riru
3
230
Symbolic model checker from scratch in Rust
riru
1
1.1k
WasmOS: Wasmを実行する自作Microkernel
riru
0
980
Other Decks in Technology
See All in Technology
試験勉強はGrokBotでやれ
maigo999
0
110
[General] 개발자로 해외 기업에서 일하기
skydoves
1
300
サボる子はいねぇがー!AgentCoreハーネスの脆弱性に学ぶ、エージェントの入力バリデーション
iwamot
PRO
4
280
AIがGISを代替する日:〜すべてをAIが創る時代に、私たちがFOSS4Gに関わる意味〜
lehupa
1
210
Copilot Coworkで「みのるん式」やってみた
minorun365
PRO
2
1.6k
re:Invent の去年のスケジュールを公開します!
miu_crescent
PRO
0
300
レガシーコードに対する loop engineering的なAI開発プロセス導入について
kubell_hr
0
270
増え続けるプロダクトの品質をどう担保するか。ProductSpecとTypeScriptによる取り組み
joere
3
420
Don't write the architecture only in the prompt.
neohsu
0
310
超⼩型・多⾔語検索モデル Bekko Embedding
hotchpotch
1
110
Autonomous AI Lakehouse - Live AI Hubから始めるセキュアなAIデータ活用 -
oracle4engineer
PRO
3
190
デザインレビューは自動化できるのか?─ Flutter × Figma で UI 品質保証を考える
techiro
2
800
Featured
See All Featured
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
520
Making Projects Easy
brettharned
120
6.8k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.2k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
400
Technical Leadership for Architectural Decision Making
baasie
3
640
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
RailsConf 2023
tenderlove
30
1.6k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
Transcript
プログラム検証入門 Riru Oda @ri5255 情報科学若手の会2024 1
Riru Oda @ri5255 過去の発表 • Symbolic model checker from scratch
in Rust • WasmOS: Wasmを実行する自作Microkernel 低レイヤ開発とセキュリティとプログラム検証 最近の興味 • Rustの形式検証 2
本発表のゴール • 型システム、モデル検査、定理証明について雰囲気を理解する • プログラムの「正しさ」について考えてみる • あわよくばプログラム検証に入門してみようという気になる 3
動機 • ソフトウェアにバグはつきもの • バグを修正してもそれで十分とは言い切れない • テストでバグが見つからなかったから正しいとも言い切れない 4 ある種のバグが無いことを理論的に保証できないか?
型システム 5
型システムについて • 一番身近にある形式手法 • 文法上は問題ないが、評価できない項を除くことが目的 • ここでは簡単なプログラミング言語の型安全性を証明してみる 6
構文 t := true | false | if t then
t else t | 0 | succ t 例 • if true then (succ 0) else 0 • succ (if true then (succ 0) else 0) • If 0 then true else false • succ true 7
意味 E_IFTRUE if true then t2 else t3 -> t2
E_IFFALSE if false t2 else t3 -> t3 E_IF t1 -> t1’ ならば if t1 then t2 else t3 -> if t1’ then t2 else t3 E_SUCC t1 -> t1’ ならば succ t1 -> succ t1’ 8 例 • if true then (succ 0) else 0 -> succ 0 • succ (if true then (succ 0) else 0) -> succ (succ 0) • If 0 then true else false • succ true • 値でなくかつ評価できない項が存在する • このような「正しくない」項を除きたい
型システム T := Nat | Bool T_TRUE true: Bool T_FALSE
false: Bool T_IF t1: Bool かつ t2:T かつ t3:T ならば if t1 then t2 else t3: T T_SUCC t1: Nat ならば succ t1: Nat 9 例 • if true then (succ 0) else 0: Nat • succ (if true then (succ 0) else 0): Nat • If 0 then true else false • succ true • 「正しくない」項には型が付かない
性質 定理 (進行) 任意のt, Tについてt:Tならばtは行き詰まり状態でない 10 • 値でなくかつ評価できない項は行き詰まり状態であるという 定理 (保存)
任意のt, t’, Tについて t :Tかつt->t’ならばt’:T
発展的な話 • Double freeやDeadlock等、プログラムにとって「正しくない」状態は沢山ある • これらが行き詰まり状態になるように意味論を定義する • そのうえで型システムを作る (Linear Types,
Session Types…) • すると型が付くプログラムにはこれらのバグが無いことが保証される 例 • free(x); free(x); • !c(v); done || !c(v); done 11
参考資料 • Benjamin C. Pierce. Types and Programming Languages (1st.
ed.). The MIT Press, 2002. • Benjamin C. Pierce. Advanced Topics in Types and Programming Languages. The MIT Press, 2004. • 高野 祐輝. ゼロから学ぶRust. 講談社, 2022. 12
モデル検査 13
モデル検査について 14 • プログラムが取りうる状態を網羅的に検査する • 性質を論理式で表現してモデル検査器で検証する • 自動で検証可能な性質を扱う • ここでは以下の問題について考え、「正しさ」をモデル検査器(TLC)で検証する
問題設定 2つのスレッドで1つのリソースを共有させる「正しい」アルゴリズムをかけ
検証 問題設定 2つのスレッドで1つのリソースを共有させる「正しい」アルゴリズムをかけ 「正しさ」の定義 • Deadlockがない • 2つのスレッドが同時にクリティカルセクションに入らない 15 •
この定義で十分かどうかには議論の余地がある(後述)
検証 アルゴリズム 16 検証結果 • 交互にP1を実行しDeadlockに陥る実行パス
検証 アルゴリズム 17 検証結果 • 検査に成功する(91状態)
検証 アルゴリズム 18 検証結果 • どちらもP2で無限ループする実行パス (Livelock) • 検証の結果は「正しさ」の定義に依存する
検証 アルゴリズム 19 検証結果 • 検証にパスする(256状態)
発展的な話 • モデル検査の一番の課題は状態空間爆発 • 対策としてAbstractionやPartial Order Reductionなどのテクニックがある • Symbolic Model
Checkingなどの発展的なモデル検査アルゴリズムがある 20 https://www.youtube.com/live/96u4dBAOzao?t=9802s
参考資料 • Edmund M. Clarke, Orna Grumberg, and Doron A.
Peled. Model checking. MIT Press, 2000. • Hillel Wayne. 実践TLA+. 翔泳社, 2021. • チェシャ猫. モデル検査器をつくる, 2024. 21
定理証明 22
定理証明について • 型システム、モデル検査では検証できない様々な性質を検証可能 • 表現力が高い分、自動での検証は困難(半自動) • ここでは簡単なコンパイラの「正しさ」を 定理証明支援系(Coq)で検証する 23
Source Language 24 構文 意味
Target Language 25 構文 意味
Compiler 26 定義
検証 27 • コンパイル後の機械語を評価した値が元の式を評価した値と一致する
Extraction 28 OCamlのコードを自動生成 実行結果
参考資料 • Adam Chlipala. Formal Reasoning About Programs. • 池渕未来.
“プログラミングCoq”. IIJ. 2011. https://www.iijlab.net/activities/programming-coq/. 29
まとめ 30
入門前後の認識の変化 入門前 • 「プログラム検証で正しさを証明済み = 絶対にバグがない最強のプログラム」だと思っていた 入門後 • 「正しさ」を定義するのは人間なので残念ながらそんなことはない •
それでもプログラム検証は役に立つ • 「プログラムの正しさとは何か」について厳密に考えるための道具 31
展望 • 実用に基づいた理論を研究したい • Rustの形式検証とOS開発に興味がある • Atmosphere: Towards Practical Verified
Kernels in Rust • Beyond isolation: OS verification as a foundation for correct applications • 実際に形式手法を活用している企業の方にお話を聞きたい 32