[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7AB52TTP5E7NSM4FWWK1C74":3,"skill-same:01M7AB52TTP5E7NSM4FWWK1C74":47},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":31,"updatedAt":32,"install":33,"resources":46},"01M7AB52TTP5E7NSM4FWWK1C74","correctness-assurance",null,"重要な不変条件・事前条件・事後条件を抽出し、型・静的解析・runtime assertion・テスト・property\u002Fdifferential testing・formal verification・reviewの中から最小十分な保証手段を設計する時に使用する。","rebuildup\u002Fproject-init","rebuildup","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F176191237?v=4","01M7AB3QGQ73Q2YNFNFGPAVVRX","samuido","01M7AB3QHEEN3RPZSTXYW3062Y",2,"MIT","https:\u002F\u002Fgithub.com\u002Frebuildup\u002Fproject-init\u002Fblob\u002Fmain\u002Fskills\u002Fcorrectness-assurance\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: correctness-assurance\ndescription: 重要な不変条件・事前条件・事後条件を抽出し、型・静的解析・runtime assertion・テスト・property\u002Fdifferential testing・formal verification・reviewの中から最小十分な保証手段を設計する時に使用する。\n---\n\n# Correctness Assurance\n\ncorrectness assuranceは、単一の手法で「正しさ」を保証することではない。\n\n**何を正しいと呼ぶのかを性質ごとに分解し、その性質に対して最小十分なassurance mechanismを割り当て、保証できた範囲・保証していない範囲・前提を明示する。**\n\n形式検証を自動的に優先しない。型・静的解析・テスト・runtime check・reviewで十分な性質にproofを持ち込まない。一方で、有限個のテストでは本質的に届かない全称的な性質を「テストが多いから十分」と扱わない。\n\n## 1. いつ使うか\n\n次のいずれかがある場合に使用する。\n\n- 配列添字、範囲、長さ、offset、cursor、partition等の境界条件がある\n- sentinel \u002F optional state \u002F partial stateを最終的に解消する必要がある\n- state machineで到達不能状態や遷移制約がある\n- sort \u002F merge \u002F search \u002F scheduler \u002F parser \u002F allocator等に構造的不変条件がある\n- 「事前条件を満たすすべての入力」で成り立ってほしい性質がある\n- property-based testや差分テストでも入力空間を有限標本としてしか扱えない\n- 破れるとpanic \u002F trap \u002F out-of-bounds \u002F corruption \u002F wrong-stateになる\n- 型で責任箇所を狭められるが、そのconstruction function自体の正しさが残る\n- runtime semanticsとverification\u002Fmodel semanticsの差がriskになる\n- AI生成・変更されるコードに、機械可読なcontractを置く価値がある\n\n次だけを理由に起動しない。\n\n- UIの見た目だけを確認したい\n- external API \u002F DB \u002F network wiringだけを確認したい\n- product semantics自体がまだ決まっていない\n- 重要な性質を具体的なpredicateとして書けない\n- formal verification toolを使ってみたいだけ\n\n## 2. 最初に「正しさ」を分解する\n\n実装を見る前に、必要な性質を曖昧な「正しい」から分離する。\n\n最低限、該当するものを列挙する。\n\n### Structure \u002F construction\n\n例:\n\n- この値は特定constructorを通してのみ生成される\n- invalid variantを呼び出し側へ渡せない\n- schema \u002F shape \u002F enum stateが正しい\n\n主に型・visibility・module boundaryで担保する。\n\n### Range \u002F bounds\n\n例:\n\n- `0 \u003C= index \u003C length`\n- offsetがbuffer範囲内\n- selected rangeが空間外へ出ない\n- integer resultがruntime表現範囲内\n\n型だけで表現できない場合、contract \u002F static analysis \u002F runtime assertion \u002F proofを検討する。\n\n### Totality \u002F completion\n\n例:\n\n- completion後にsentinelが残らない\n- `Option` \u002F nullable stateがfinal phaseではすべて解消される\n- partial mappingがcompleteになる\n\n「特定関数を通った」と「その関数が本当にcompleteにした」を分ける。\n\n### State transition\n\n例:\n\n- forbidden transitionが存在しない\n- terminal stateから通常stateへ戻らない\n- event sequenceに対してinvariantが保存される\n\n型、state-machine test、model checking、formal verification等を候補にする。\n\n### Ordering \u002F uniqueness \u002F preservation\n\n例:\n\n- sort後に順序が保たれる\n- stable orderingが必要\n- keyが重複しない\n- length \u002F membership \u002F correspondenceが処理前後で保存される\n\n### Arithmetic \u002F numeric model\n\n例:\n\n- overflowしない\n- saturation semanticsを守る\n- floating-point orderingの差で結果順序を壊さない\n- fixed-width integerと数学整数を混同しない\n\nここはverification modelとruntime modelの一致確認を必須にする。\n\n### Semantic correctness\n\n例:\n\n- 最適解である\n- 推薦結果が正しい\n- business rule上正解である\n- user intentを満たす\n\n構造的安全性と分離する。「クラッシュしない」を「答えが正しい」に拡張しない。\n\n## 3. Assurance mechanismをproperty単位で選ぶ\n\n各propertyについて、最小十分な手段を選択する。\n\n| Mechanism | 強い領域 | 単独では弱い領域 |\n| --- | --- | --- |\n| Type system | shape、construction boundary、invalid stateの排除 | collection全体の内容、不変条件、constructor内部の仕事 |\n| Static analysis | language\u002Ftoolがmodelできるdefect class | runtime integration、tool model外 |\n| Runtime assertion | 実行したcaseのpre\u002Fpost condition違反 | 未実行入力への全称保証 |\n| Unit test | 局所behavior、境界値、machine semantics | 入力空間全体 |\n| Property-based test | 広い入力探索、反例発見 | 全入力保証ではない |\n| Differential test | 既存実装との互換性、移植 | oracle自体の誤り、未実行入力 |\n| Integration\u002FE2E | real boundaryとsystem behavior | 局所invariantの網羅 |\n| Formal verification \u002F model checking | model内の全入力・全状態に対するproperty | specification error、model外のruntime semantics |\n| Review | specificationの十分性、意図、assumption妥当性 | 機械的網羅性 |\n\n原則:\n\n> **同じpropertyを複数手法で無意味に重複させるのではなく、異なるfailure classを補完する。**\n\nただし高risk propertyでは独立な二重化が有効な場合がある。たとえばproofしたpredicateと同義のruntime checkerを別実装で持ち、model\u002Fruntimeの食い違いを検出する。\n\n## 4. Assurance mapを作る\n\n実装前または変更前に、対象propertyごとに次を記録する。\n\n```text\nProperty:\n  completion後に未決定sentinelが残らない\n\nScope:\n  事前条件を満たすすべてのmapping input\n\nMechanism:\n  formal verification\n\nSupporting mechanisms:\n  runtime checker\n  boundary unit tests\n\nAssumptions:\n  input length > 0\n  first\u002Flast entries are assigned\n  verification modelのinteger semanticsが対象propertyに十分\n\nNot covered:\n  assigned valueが有効な参照添字であること\n  floating-point側の候補選択の正しさ\n  global optimum\n```\n\n**「Aを証明した」からB・Cまで保証したように書かない。**\n\n## 5. Contractを具体的にする\n\nformal verificationを使うかどうかに関係なく、重要なpropertyは可能なら次へ分解する。\n\n- precondition \u002F requires\n- postcondition \u002F ensures\n- invariant\n- frame \u002F preservation property\n- termination condition\n- model assumption\n\n悪い例:\n\n```text\nmapping is valid\n```\n\n良い分解:\n\n```text\nforall i in [0, map.length):\n  map[i] != SENTINEL\n\nforall i in [0, map.length):\n  0 \u003C= map[i] \u003C reference.length\n\nresult.length == input.length\n```\n\nsentinelが消えたことと、有効なindexだけが入っていることは別propertyとして扱う。\n\n## 6. Preconditionをcall chainで閉じる\n\ncontractのpreconditionはruntime checkとは限らない。\n\n```text\ncaller\n  ↓ must establish P\nfunction f requires P\n  ↓ proves Q\ncaller uses Q\n```\n\n次を確認する。\n\n- preconditionはどこで成立するのか\n- 呼び出し側でもproof\u002Fstatic checkされるのか\n- runtime validationが必要なのか\n- external inputから来る場合、trusted boundaryはどこか\n- call chain途中で保証が切れていないか\n\n「functionがproof済み」でも、precondition違反のcallが可能ならその実行は保証外である。\n\n## 7. 検証困難なら先にboundaryを疑う\n\n重要なinvariantが検証しにくい場合、すぐにcontractを弱めない。\n\n次が混在していないか確認する。\n\n- I\u002FO\n- mutable shared state\n- floating-point decision\n- external service\n- nondeterminism\n- time\n- random\n- UI\u002Fevent wiring\n- index\u002Frange arithmetic\n- pure transformation\n\n可能なら、\n\n```text\nunverified \u002F environment-dependent layer\n        ↓ explicit boundary\nsmall verifiable core\n        ↓\nunverified \u002F environment-dependent layer\n```\n\nへ分離する。\n\n典型例:\n\n- floating-pointで「どれを選ぶか」を決める\n- integer coreで「選ばれた位置を安全に扱う」\n- external layerで結果をI\u002FOへ接続する\n\nただし、**proofの都合だけで不必要なallocation、copy、latency、複雑化を入れる場合は、その設計コストを明示する。**\n\n## 8. Formal verificationを選ぶ基準\n\n次が揃うほど適用価値が高い。\n\n- propertyが明確なpredicateとして書ける\n- 全入力・全状態に対する保証が本当に必要\n- test enumerationでは本質的に保証できない\n- pureまたは副作用が限定されたcoreへ分離できる\n- index\u002Frange\u002Fstate\u002Fordering等の構造的property\n- failure impactが高い\n- solver\u002Fmodelが必要なlanguage featureを正しく扱える\n- proof maintenance costに見合う\n\n適用価値が低い、または先に別手段を選ぶ例:\n\n- specificationが曖昧\n- UI appearance\n- external integration correctness\n- modelが対象featureを表現できない\n- rapidly changing exploratory codeでproperty自体が未確定\n- unit\u002Fproperty testで十分な局所logic\n- proofを通すこと自体が目的化している\n\n## 9. Verification modelとruntime semanticsを照合する\n\nproofの前後で必ずmodel boundaryを確認する。\n\n最低限:\n\n- integerはmathematical integerかfixed-width machine integerか\n- overflow \u002F underflowはmodelされるか\n- floating-pointはIEEE 754としてmodelされるか、未対応か\n- division \u002F modulo \u002F shift semanticsはruntimeと同じか\n- pointer \u002F alias \u002F mutation \u002F memory modelは同じか\n- concurrency \u002F atomicity \u002F orderingはmodelされるか\n- exceptions \u002F panic \u002F trapはmodelされるか\n- compiler target差、Wasm\u002FJS\u002Fnative差があるか\n- library \u002F host functionはaxiom扱いか、verified implementationか\n\n例:\n\n```text\nproof model: unbounded mathematical Int\nruntime: signed 32-bit Int\n```\n\nなら、結果範囲のcontractだけでは途中式のoverflow安全性を保証できない場合がある。\n\n**proof greenとmachine-safeを同義にしない。**\n\n## 10. Specification自体をadversarialにreviewする\n\nsolverは「書いた仕様」を検証する。必要だった仕様を自動で発見してはくれない。\n\nreviewでは少なくとも次を行う。\n\n### Counterexample challenge\n\ncontractを満たすが、実際には受け入れたくない値を探す。\n\n例:\n\n```text\nproperty: value != -1\ncounterexample: -2\n```\n\nこの反例が危険なら、必要propertyは `0 \u003C= value \u003C n` のように強化する。\n\n### Vacuity challenge\n\npreconditionが強すぎて、実質的に何も保証していない可能性を確認する。\n\n### Missing-dimension challenge\n\n- safetyだけでlivenessを忘れていないか\n- totalityだけでrange validityを忘れていないか\n- local correctnessだけでpreservationを忘れていないか\n- resultだけでintermediate overflowを忘れていないか\n\n### Oracle challenge\n\ndifferential testではreference implementation自体を無条件に正しいと扱わない。\n\n## 11. Loop \u002F recursive invariantは必要な性質から逆算する\n\n強いinvariantを大量に入れれば良いわけではない。\n\nまずpostconditionに必要なpropertyを特定し、そのpropertyを各stepで保存できる最小限のinvariantを置く。\n\n例:\n\n```text\npost:\n  all entries are assigned\n\nloop invariant:\n  all entries before cursor are assigned\n```\n\n必要以上に値そのものを追うことでsolver costやmaintenance costが増える場合がある。\n\n一方で、弱すぎるinvariantでproofを通すために本来必要なpropertyを削ってはいけない。\n\n## 12. Tool resultの意味を正確に読む\n\nformal toolのstatusを過大解釈しない。\n\n- proved \u002F valid: 指定model・assumption・contractのもとで成立\n- invalid \u002F counterexample: propertyが偽であるevidenceになり得る\n- timeout \u002F unknown: この設定では結論が出なかっただけ\n- unsupported: model外。propertyが正しいとも間違いとも言っていない\n\ntimeoutを「バグがある証拠」と扱わない。\nproof obligation数を「保証の強さ」のmetricとして使わない。\n\n## 13. Runtime verificationを残す判断\n\nproof済みでもruntime checkやtestを残す価値がある。\n\n残す候補:\n\n- machine integer境界\n- floating-point behavior\n- compiler\u002Fbackend差\n- Wasm\u002FJS\u002Fnative差\n- serialization\n- FFI\n- generated code\n- host API\n- unsafe code\n- proof modelで抽象化したboundary\n- contractと同義のindependent runtime checker\n\ncontractがcompile artifactへ残らないtoolでは、必要ならruntime safety checkを別途設計する。\n\n## 14. Evidence\n\nassuranceの結果は最低限次で報告する。\n\n**既知のmodel gapが存在する場合、`Known model gaps`項目に必ず記載する。** gapがないと確認できる場合のみ「なし」と明記する。\n\n```text\nCorrectness properties\n- P1: ...\n- P2: ...\n\nVerified \u002F assured\n- P1: formal proof, tool\u002Fversion, result\n- P2: type-level construction boundary\n\nRuntime-tested\n- integer boundary cases\n- differential compatibility\n- target backend behavior\n\nAssumptions\n- ...\n- ...\n\nNot verified\n- ...\n- ...\n\nKnown model gaps\n- ...\n- ...\n\nEvidence\n- command\n- artifact\n- commit\u002FSHA\n- toolchain\u002Fversion\n```\n\n「tests green」「proof green」だけで終了しない。\n\n## 15. Reproducibility\n\nproof\u002FtoolingをCIやteamで使う場合は、通常のtest toolchainと同じく再現可能にする。\n\n- compiler\u002Ftool version\n- verifier \u002F SMT solver \u002F model checker version\n- solver strategy\u002Fconfiguration\n- timeout\u002Fresource limit\n- architecture差\n- package\u002Flock\u002FNix\u002Fcontainer等のenvironment definition\n\nsolver versionやstrategy差で結果が変わり得る場合は、current working environmentを固定する。\n\n## 16. AI agent向けルール\n\nAIにcontract・invariant・proof annotationを書かせることはできるが、生成されたcontractを意図の代わりにしない。\n\nAI agentは:\n\n1. 先にpropertyを自然言語とpredicateの両方で述べる\n2. implementationから都合の良いpostconditionを逆算しない\n3. counterexampleを最低1回探す\n4. model\u002Fruntime差を確認する\n5. proofを通すためだけにpreconditionを強めない\n6. unsupported領域を隠さない\n7. verified \u002F Not verified \u002F assumptionsを分離する\n8. contract変更をbehavior変更と同じくreview対象にする\n\ncontractはAIにとってもmachine-readable specificationとして扱う。\n\n## 17. Anti-patterns\n\n禁止:\n\n- 「formal verification済み」だけでprogram全体の正しさを主張する\n- test件数の多さから全入力保証を推論する\n- proof greenをruntime overflow安全性へ自動拡張する\n- sentinel absenceをindex validityと同一視する\n- timeoutをfailure\u002Fcounterexampleとみなす\n- type-safeだからcollection invariantも成立するとみなす\n- abstract type constructorを通ったからconstructor内部も正しいとみなす\n- proofを通すために必要なpropertyを弱める\n- preconditionを呼び出し側で成立させずに利用する\n- modelで扱えない部分を「証明済み範囲」に含める\n- generated proof obligation数をquality KPIにする\n- testをproofで置換する\n- proofを理由にreviewを省略する\n\n## 18. Completion gate\n\nこのSkillを適用したtaskは、少なくとも次を満たして終了する。\n\n- correctness-critical propertyが列挙されている\n- 各propertyのassurance mechanismが決まっている\n- mechanism選択理由がpropertyの性質とriskに対応している\n- 必要なpre\u002Fpost\u002Finvariantが具体化されている\n- preconditionの成立元が追跡できる\n- verification modelとruntime modelの差を確認した\n- formal verificationを使う場合、unsupported領域を明示した\n- specificationへcounterexample challengeを行った\n- verified \u002F runtime-tested \u002F assumptions \u002F Not verifiedを分離した\n- Known model gapsを明示している\n- evidenceがcurrent code revisionへ紐づいている\n\n## 19. Source case\n\nこのSkillの初期設計では、MoonBitで実プロダクトの整数部分をSMT solverで検証した次の記事を重要なcase studyとして使用した。\n\n- Mates Engineering: [アルゴリズムの実装に MoonBit の Formal Verification を活用する](https:\u002F\u002Feng.mates.education\u002Fblog\u002Fb-moonbit-formal-verification\u002F)\n\ncase studyから一般化した主な点:\n\n- 型・テスト・proof・reviewは競合ではなく責務が異なる\n- finite test suiteと全称propertyを区別する\n- verifiableな整数の骨格を、浮動小数点等のmodel外領域から分離できる\n- mathematical integer modelとmachine integerの差はproofのsoundness interpretationに直結する\n- specificationの不足はsolverでは救えない\n- proofはtestの置き換えではなく、testでは見落とし得るfailure classを検出する手段である。finite test suite が見落とすfailure classをproofは補完的に検出し、両者は相互補完の関係にある\n\nMoonBit固有の制約を他toolへ一般化してはならない。実際のprojectでは採用するlanguage\u002Fverifier\u002Fmodelのcurrent behaviorを個別に確認する。\n","# Correctness Assurance\n\ncorrectness assuranceは、単一の手法で「正しさ」を保証することではない。\n\n**何を正しいと呼ぶのかを性質ごとに分解し、その性質に対して最小十分なassurance mechanismを割り当て、保証できた範囲・保証していない範囲・前提を明示する。**\n\n形式検証を自動的に優先しない。型・静的解析・テスト・runtime check・reviewで十分な性質にproofを持ち込まない。一方で、有限個のテストでは本質的に届かない全称的な性質を「テストが多いから十分」と扱わない。\n\n## 1. いつ使うか\n\n次のいずれかがある場合に使用する。\n\n- 配列添字、範囲、長さ、offset、cursor、partition等の境界条件がある\n- sentinel \u002F optional state \u002F partial stateを最終的に解消する必要がある\n- state machineで到達不能状態や遷移制約がある\n- sort \u002F merge \u002F search \u002F scheduler \u002F parser \u002F allocator等に構造的不変条件がある\n- 「事前条件を満たすすべての入力」で成り立ってほしい性質がある\n- property-based testや差分テストでも入力空間を有限標本としてしか扱えない\n- 破れるとpanic \u002F trap \u002F out-of-bounds \u002F corruption \u002F wrong-stateになる\n- 型で責任箇所を狭められるが、そのconstruction function自体の正しさが残る\n- runtime semanticsとverification\u002Fmodel semanticsの差がriskになる\n- AI生成・変更されるコードに、機械可読なcontractを置く価値がある\n\n次だけを理由に起動しない。\n\n- UIの見た目だけを確認したい\n- external API \u002F DB \u002F network wiringだけを確認したい\n- product semantics自体がまだ決まっていない\n- 重要な性質を具体的なpredicateとして書けない\n- formal verification toolを使ってみたいだけ\n\n## 2. 最初に「正しさ」を分解する\n\n実装を見る前に、必要な性質を曖昧な「正しい」から分離する。\n\n最低限、該当するものを列挙する。\n\n### Structure \u002F construction\n\n例:\n\n- この値は特定constructorを通してのみ生成される\n- invalid variantを呼び出し側へ渡せない\n- schema \u002F shape \u002F enum stateが正しい\n\n主に型・visibility・module boundaryで担保する。\n\n### Range \u002F bounds\n\n例:\n\n- `0 \u003C= index \u003C length`\n- offsetがbuffer範囲内\n- selected rangeが空間外へ出ない\n- integer resultがruntime表現範囲内\n\n型だけで表現できない場合、contract \u002F static analysis \u002F runtime assertion \u002F proofを検討する。\n\n### Totality \u002F completion\n\n例:\n\n- completion後にsentinelが残らない\n- `Option` \u002F nullable stateがfinal phaseではすべて解消される\n- partial mappingがcompleteになる\n\n「特定関数を通った」と「その関数が本当にcompleteにした」を分ける。\n\n### State transition\n\n例:\n\n- forbidden transitionが存在しない\n- terminal stateから通常stateへ戻らない\n- event sequenceに対してinvariantが保存される\n\n型、state-machine test、model checking、formal verification等を候補にする。\n\n### Ordering \u002F uniqueness \u002F preservation\n\n例:\n\n- sort後に順序が保たれる\n- stable orderingが必要\n- keyが重複しない\n- length \u002F membership \u002F correspondenceが処理前後で保存される\n\n### Arithmetic \u002F numeric model\n\n例:\n\n- overflowしない\n- saturation semanticsを守る\n- floating-point orderingの差で結果順序を壊さない\n- fixed-width integerと数学整数を混同しない\n\nここはverification modelとruntime modelの一致確認を必須にする。\n\n### Semantic correctness\n\n例:\n\n- 最適解である\n- 推薦結果が正しい\n- business rule上正解である\n- user intentを満たす\n\n構造的安全性と分離する。「クラッシュしない」を「答えが正しい」に拡張しない。\n\n## 3. Assurance mechanismをproperty単位で選ぶ\n\n各propertyについて、最小十分な手段を選択する。\n\n| Mechanism | 強い領域 | 単独では弱い領域 |\n| --- | --- | --- |\n| Type system | shape、construction boundary、invalid stateの排除 | collection全体の内容、不変条件、constructor内部の仕事 |\n| Static analysis | language\u002Ftoolがmodelできるdefect class | runtime integration、tool model外 |\n| Runtime assertion | 実行したcaseのpre\u002Fpost condition違反 | 未実行入力への全称保証 |\n| Unit test | 局所behavior、境界値、machine semantics | 入力空間全体 |\n| Property-based test | 広い入力探索、反例発見 | 全入力保証ではない |\n| Differential test | 既存実装との互換性、移植 | oracle自体の誤り、未実行入力 |\n| Integration\u002FE2E | real boundaryとsystem behavior | 局所invariantの網羅 |\n| Formal verification \u002F model checking | model内の全入力・全状態に対するproperty | specification error、model外のruntime semantics |\n| Review | specificationの十分性、意図、assumption妥当性 | 機械的網羅性 |\n\n原則:\n\n> **同じpropertyを複数手法で無意味に重複させるのではなく、異なるfailure classを補完する。**\n\nただし高risk propertyでは独立な二重化が有効な場合がある。たとえばproofしたpredicateと同義のruntime checkerを別実装で持ち、model\u002Fruntimeの食い違いを検出する。\n\n## 4. Assurance mapを作る\n\n実装前または変更前に、対象propertyごとに次を記録する。\n\n```text\nProperty:\n  completion後に未決定sentinelが残らない\n\nScope:\n  事前条件を満たすすべてのmapping input\n\nMechanism:\n  formal verification\n\nSupporting mechanisms:\n  runtime checker\n  boundary unit tests\n\nAssumptions:\n  input length > 0\n  first\u002Flast entries are assigned\n  verification modelのinteger semanticsが対象propertyに十分\n\nNot covered:\n  assigned valueが有効な参照添字であること\n  floating-point側の候補選択の正しさ\n  global optimum\n```\n\n**「Aを証明した」からB・Cまで保証したように書かない。**\n\n## 5. Contractを具体的にする\n\nformal verificationを使うかどうかに関係なく、重要なpropertyは可能なら次へ分解する。\n\n- precondition \u002F requires\n- postcondition \u002F ensures\n- invariant\n- frame \u002F preservation property\n- termination condition\n- model assumption\n\n悪い例:\n\n```text\nmapping is valid\n```\n\n良い分解:\n\n```text\nforall i in [0, map.length):\n  map[i] != SENTINEL\n\nforall i in [0, map.length):\n  0 \u003C= map[i] \u003C reference.length\n\nresult.length == input.length\n```\n\nsentinelが消えたことと、有効なindexだけが入っていることは別propertyとして扱う。\n\n## 6. Preconditionをcall chainで閉じる\n\ncontractのpreconditionはruntime checkとは限らない。\n\n```text\ncaller\n  ↓ must establish P\nfunction f requires P\n  ↓ proves Q\ncaller uses Q\n```\n\n次を確認する。\n\n- preconditionはどこで成立するのか\n- 呼び出し側でもproof\u002Fstatic checkされるのか\n- runtime validationが必要なのか\n- external inputから来る場合、trusted boundaryはどこか\n- call chain途中で保証が切れていないか\n\n「functionがproof済み」でも、precondition違反のcallが可能ならその実行は保証外である。\n\n## 7. 検証困難なら先にboundaryを疑う\n\n重要なinvariantが検証しにくい場合、すぐにcontractを弱めない。\n\n次が混在していないか確認する。\n\n- I\u002FO\n- mutable shared state\n- floating-point decision\n- external service\n- nondeterminism\n- time\n- random\n- UI\u002Fevent wiring\n- index\u002Frange arithmetic\n- pure transformation\n\n可能なら、\n\n```text\nunverified \u002F environment-dependent layer\n        ↓ explicit boundary\nsmall verifiable core\n        ↓\nunverified \u002F environment-dependent layer\n```\n\nへ分離する。\n\n典型例:\n\n- floating-pointで「どれを選ぶか」を決める\n- integer coreで「選ばれた位置を安全に扱う」\n- external layerで結果をI\u002FOへ接続する\n\nただし、**proofの都合だけで不必要なallocation、copy、latency、複雑化を入れる場合は、その設計コストを明示する。**\n\n## 8. Formal verificationを選ぶ基準\n\n次が揃うほど適用価値が高い。\n\n- propertyが明確なpredicateとして書ける\n- 全入力・全状態に対する保証が本当に必要\n- test enumerationでは本質的に保証できない\n- pureまたは副作用が限定されたcoreへ分離できる\n- index\u002Frange\u002Fstate\u002Fordering等の構造的property\n- failure impactが高い\n- solver\u002Fmodelが必要なlanguage featureを正しく扱える\n- proof maintenance costに見合う\n\n適用価値が低い、または先に別手段を選ぶ例:\n\n- specificationが曖昧\n- UI appearance\n- external integration correctness\n- modelが対象featureを表現できない\n- rapidly changing exploratory codeでproperty自体が未確定\n- unit\u002Fproperty testで十分な局所logic\n- proofを通すこと自体が目的化している\n\n## 9. Verification modelとruntime semanticsを照合する\n\nproofの前後で必ずmodel boundaryを確認する。\n\n最低限:\n\n- integerはmathematical integerかfixed-width machine integerか\n- overflow \u002F underflowはmodelされるか\n- floating-pointはIEEE 754としてmodelされるか、未対応か\n- division \u002F modulo \u002F shift semanticsはruntimeと同じか\n- pointer \u002F alias \u002F mutation \u002F memory modelは同じか\n- concurrency \u002F atomicity \u002F orderingはmodelされるか\n- exceptions \u002F panic \u002F trapはmodelされるか\n- compiler target差、Wasm\u002FJS\u002Fnative差があるか\n- library \u002F host functionはaxiom扱いか、verified implementationか\n\n例:\n\n```text\nproof model: unbounded mathematical Int\nruntime: signed 32-bit Int\n```\n\nなら、結果範囲のcontractだけでは途中式のoverflow安全性を保証できない場合がある。\n\n**proof greenとmachine-safeを同義にしない。**\n\n## 10. Specification自体をadversarialにreviewする\n\nsolverは「書いた仕様」を検証する。必要だった仕様を自動で発見してはくれない。\n\nreviewでは少なくとも次を行う。\n\n### Counterexample challenge\n\ncontractを満たすが、実際には受け入れたくない値を探す。\n\n例:\n\n```text\nproperty: value != -1\ncounterexample: -2\n```\n\nこの反例が危険なら、必要propertyは `0 \u003C= value \u003C n` のように強化する。\n\n### Vacuity challenge\n\npreconditionが強すぎて、実質的に何も保証していない可能性を確認する。\n\n### Missing-dimension challenge\n\n- safetyだけでlivenessを忘れていないか\n- totalityだけでrange validityを忘れていないか\n- local correctnessだけでpreservationを忘れていないか\n- resultだけでintermediate overflowを忘れていないか\n\n### Oracle challenge\n\ndifferential testではreference implementation自体を無条件に正しいと扱わない。\n\n## 11. Loop \u002F recursive invariantは必要な性質から逆算する\n\n強いinvariantを大量に入れれば良いわけではない。\n\nまずpostconditionに必要なpropertyを特定し、そのpropertyを各stepで保存できる最小限のinvariantを置く。\n\n例:\n\n```text\npost:\n  all entries are assigned\n\nloop invariant:\n  all entries before cursor are assigned\n```\n\n必要以上に値そのものを追うことでsolver costやmaintenance costが増える場合がある。\n\n一方で、弱すぎるinvariantでproofを通すために本来必要なpropertyを削ってはいけない。\n\n## 12. Tool resultの意味を正確に読む\n\nformal toolのstatusを過大解釈しない。\n\n- proved \u002F valid: 指定model・assumption・contractのもとで成立\n- invalid \u002F counterexample: propertyが偽であるevidenceになり得る\n- timeout \u002F unknown: この設定では結論が出なかっただけ\n- unsupported: model外。propertyが正しいとも間違いとも言っていない\n\ntimeoutを「バグがある証拠」と扱わない。\nproof obligation数を「保証の強さ」のmetricとして使わない。\n\n## 13. Runtime verificationを残す判断\n\nproof済みでもruntime checkやtestを残す価値がある。\n\n残す候補:\n\n- machine integer境界\n- floating-point behavior\n- compiler\u002Fbackend差\n- Wasm\u002FJS\u002Fnative差\n- serialization\n- FFI\n- generated code\n- host API\n- unsafe code\n- proof modelで抽象化したboundary\n- contractと同義のindependent runtime checker\n\ncontractがcompile artifactへ残らないtoolでは、必要ならruntime safety checkを別途設計する。\n\n## 14. Evidence\n\nassuranceの結果は最低限次で報告する。\n\n**既知のmodel gapが存在する場合、`Known model gaps`項目に必ず記載する。** gapがないと確認できる場合のみ「なし」と明記する。\n\n```text\nCorrectness properties\n- P1: ...\n- P2: ...\n\nVerified \u002F assured\n- P1: formal proof, tool\u002Fversion, result\n- P2: type-level construction boundary\n\nRuntime-tested\n- integer boundary cases\n- differential compatibility\n- target backend behavior\n\nAssumptions\n- ...\n- ...\n\nNot verified\n- ...\n- ...\n\nKnown model gaps\n- ...\n- ...\n\nEvidence\n- command\n- artifact\n- commit\u002FSHA\n- toolchain\u002Fversion\n```\n\n「tests green」「proof green」だけで終了しない。\n\n## 15. Reproducibility\n\nproof\u002FtoolingをCIやteamで使う場合は、通常のtest toolchainと同じく再現可能にする。\n\n- compiler\u002Ftool version\n- verifier \u002F SMT solver \u002F model checker version\n- solver strategy\u002Fconfiguration\n- timeout\u002Fresource limit\n- architecture差\n- package\u002Flock\u002FNix\u002Fcontainer等のenvironment definition\n\nsolver versionやstrategy差で結果が変わり得る場合は、current working environmentを固定する。\n\n## 16. AI agent向けルール\n\nAIにcontract・invariant・proof annotationを書かせることはできるが、生成されたcontractを意図の代わりにしない。\n\nAI agentは:\n\n1. 先にpropertyを自然言語とpredicateの両方で述べる\n2. implementationから都合の良いpostconditionを逆算しない\n3. counterexampleを最低1回探す\n4. model\u002Fruntime差を確認する\n5. proofを通すためだけにpreconditionを強めない\n6. unsupported領域を隠さない\n7. verified \u002F Not verified \u002F assumptionsを分離する\n8. contract変更をbehavior変更と同じくreview対象にする\n\ncontractはAIにとってもmachine-readable specificationとして扱う。\n\n## 17. Anti-patterns\n\n禁止:\n\n- 「formal verification済み」だけでprogram全体の正しさを主張する\n- test件数の多さから全入力保証を推論する\n- proof greenをruntime overflow安全性へ自動拡張する\n- sentinel absenceをindex validityと同一視する\n- timeoutをfailure\u002Fcounterexampleとみなす\n- type-safeだからcollection invariantも成立するとみなす\n- abstract type constructorを通ったからconstructor内部も正しいとみなす\n- proofを通すために必要なpropertyを弱める\n- preconditionを呼び出し側で成立させずに利用する\n- modelで扱えない部分を「証明済み範囲」に含める\n- generated proof obligation数をquality KPIにする\n- testをproofで置換する\n- proofを理由にreviewを省略する\n\n## 18. Completion gate\n\nこのSkillを適用したtaskは、少なくとも次を満たして終了する。\n\n- correctness-critical propertyが列挙されている\n- 各propertyのassurance mechanismが決まっている\n- mechanism選択理由がpropertyの性質とriskに対応している\n- 必要なpre\u002Fpost\u002Finvariantが具体化されている\n- preconditionの成立元が追跡できる\n- verification modelとruntime modelの差を確認した\n- formal verificationを使う場合、unsupported領域を明示した\n- specificationへcounterexample challengeを行った\n- verified \u002F runtime-tested \u002F assumptions \u002F Not verifiedを分離した\n- Known model gapsを明示している\n- evidenceがcurrent code revisionへ紐づいている\n\n## 19. Source case\n\nこのSkillの初期設計では、MoonBitで実プロダクトの整数部分をSMT solverで検証した次の記事を重要なcase studyとして使用した。\n\n- Mates Engineering: [アルゴリズムの実装に MoonBit の Formal Verification を活用する](https:\u002F\u002Feng.mates.education\u002Fblog\u002Fb-moonbit-formal-verification\u002F)\n\ncase studyから一般化した主な点:\n\n- 型・テスト・proof・reviewは競合ではなく責務が異なる\n- finite test suiteと全称propertyを区別する\n- verifiableな整数の骨格を、浮動小数点等のmodel外領域から分離できる\n- mathematical integer modelとmachine integerの差はproofのsoundness interpretationに直結する\n- specificationの不足はsolverでは救えない\n- proofはtestの置き換えではなく、testでは見落とし得るfailure classを検出する手段である。finite test suite が見落とすfailure classをproofは補完的に検出し、両者は相互補完の関係にある\n\nMoonBit固有の制約を他toolへ一般化してはならない。実際のprojectでは採用するlanguage\u002Fverifier\u002Fmodelのcurrent behaviorを個別に確認する。\n",{"name":5,"description":7},"main","fae2dd6b4eb2a8c4744ff719f591e6e697efe4a4","skills\u002Fcorrectness-assurance",0,"https:\u002F\u002Fgithub.com\u002Frebuildup\u002Fproject-init","https:\u002F\u002Fgithub.com\u002Frebuildup","https:\u002F\u002Frebuildup.dev","jp 2007\r\nweb制作か映像制作、それにまつわるツールの制作をしている高専生","2026-11-13 16:51:04",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add rebuildup\u002Fproject-init --skill correctness-assurance",{"tool":39,"command":40},"bunx","bunx skills add rebuildup\u002Fproject-init --skill correctness-assurance",{"tool":42,"command":43},"pnpm","pnpm dlx skills add rebuildup\u002Fproject-init --skill correctness-assurance","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Frebuildup\u002Fproject-init\u002Fblob\u002Fmain\u002Fskills\u002Fcorrectness-assurance\u002FSKILL.md",true,[],[48,55,62,69,76,83],{"skillNo":49,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":54,"publishedAt":19},"01M7AB77SBZEANKTQWPK1A9YW5","worktree-workflow","current release-driven profileでWorktrunkをWSL\u002FLinux workspace lifecycle Practiceとして使い、Rust\u002FCargo worktreeのbuild-output isolation・cache reuse・cleanupを含め、同等以上のguaranteeを持つalternativeへのrefinementも判断する時に使用する。","https:\u002F\u002Fgithub.com\u002Frebuildup\u002Fproject-init\u002Fblob\u002Fmain\u002Fskills\u002Fworktree-workflow\u002FSKILL.md",[],[],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":19},"01M7AB74AK8FAJ98HBC7KK1648","skill-selection","projectの初期化や再整備で、どのAgent Skillを導入するかを決める時に使用する。必要な能力を判定し、project-initの能力一覧と候補記録、さらに外部の探索から候補を評価して、能力ごとに担当を決め、project-localに導入してlockと採否を記録する。","https:\u002F\u002Fgithub.com\u002Frebuildup\u002Fproject-init\u002Fblob\u002Fmain\u002Fskills\u002Fskill-selection\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M7AB71CFH8ZKF0QPV5H9QPS0","security-maintenance","framework\u002Fruntime\u002Fdependencyの脆弱性情報を収集し、projectへの実影響と優先度を判定してticket\u002Freleaseへ反映する時に使用する。","https:\u002F\u002Fgithub.com\u002Frebuildup\u002Fproject-init\u002Fblob\u002Fmain\u002Fskills\u002Fsecurity-maintenance\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M7AB6YFYS2QF2D1YH4K1117G","security-audit","source codeから未知のsecurity invariant failureを能動的に探索し、coverageを明示しながら独立検証されたfindingへ変換する時に使用する。","https:\u002F\u002Fgithub.com\u002Frebuildup\u002Fproject-init\u002Fblob\u002Fmain\u002Fskills\u002Fsecurity-audit\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M7AB6QW54HQ8JTRADE6NQ52X","secrets-management","application \u002F serviceのenvironment secretをInfisical中心で設計・初期化・移行・検証する時に使用する。CLI-first、repository-controlled schema、Machine Identity、GitHub OIDC、agent least-privilege、secret-safe evidenceを扱う。","https:\u002F\u002Fgithub.com\u002Frebuildup\u002Fproject-init\u002Fblob\u002Fmain\u002Fskills\u002Fsecrets-management\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M7AB6N6WC13K9E0BPAFXWNPH","sandbox-runtime","implementation worker用の独立sandboxを作成・検証し、macOS \u002F WSL\u002FLinux \u002F remote provider差を吸収する時に使用する。","https:\u002F\u002Fgithub.com\u002Frebuildup\u002Fproject-init\u002Fblob\u002Fmain\u002Fskills\u002Fsandbox-runtime\u002FSKILL.md",[],[]]