[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75F9AA6WXMP008YFDJ8K1VD":3,"skill-same:01M75F9AA6WXMP008YFDJ8K1VD":60},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":28,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":6,"updatedAt":31,"install":32,"resources":45},"01M75F9AA6WXMP008YFDJ8K1VD","mermaid-to-proverif",null,"Translates Mermaid sequenceDiagrams describing cryptographic protocols into ProVerif formal verification models (.pv files). Use when generating a ProVerif model, formally verifying a protocol, converting a Mermaid diagram to ProVerif, verifying protocol security properties (secrecy, authentication, forward secrecy), checking for replay attacks, or producing a .pv file from a sequence diagram.","agisota\u002Fold-one","agisota","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F121413592?v=4","01M75B4BRNT67EC1NDRT8QZEP2","01M75B4BS7QR9VP580MSCPTS3X",3,"MIT","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fmermaid-to-proverif\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: mermaid-to-proverif\ndescription: \"Translates Mermaid sequenceDiagrams describing cryptographic protocols into ProVerif formal verification models (.pv files). Use when generating a ProVerif model, formally verifying a protocol, converting a Mermaid diagram to ProVerif, verifying protocol security properties (secrecy, authentication, forward secrecy), checking for replay attacks, or producing a .pv file from a sequence diagram.\"\n---\n\n# Mermaid to ProVerif\n\nReads a Mermaid `sequenceDiagram` describing a cryptographic protocol and\nproduces a ProVerif model (`.pv` file) that can be passed directly to the\nProVerif verifier.\n\n**Tools used:** Read, Write, Grep, Glob.\n\nThe typical input is the output of the `crypto-protocol-diagram` skill — a\nMermaid `sequenceDiagram` annotated with cryptographic operations (`Sign`,\n`Verify`, `DH`, `HKDF`, `Enc`, `Dec`, etc.) and message arrows.\n\n## When to Use\n\n- User asks to formally verify a cryptographic protocol described as a Mermaid sequenceDiagram\n- User wants to generate a ProVerif model (.pv file) from a protocol diagram\n- User wants to prove secrecy, authentication, or forward secrecy properties\n- Input is the output of the `crypto-protocol-diagram` skill\n\n## When NOT to Use\n\n- No Mermaid sequenceDiagram exists yet — use `crypto-protocol-diagram` first to generate one\n- User wants to verify properties of non-cryptographic systems (state machines, access control)\n- User wants to run ProVerif on an existing .pv file — just run `proverif model.pv` directly\n\n## Rationalizations to Reject\n\n| Rationalization | Why It's Wrong | Required Action |\n|-----------------|----------------|-----------------|\n| \"Reachability queries are just busywork\" | If events aren't reachable, all other query results are meaningless | Always add reachability queries first as a sanity check |\n| \"Public channels are fine for all messages\" | Private channels for internal state prevent false attacks | Use private channels for intra-process state threading |\n| \"I'll skip the forward secrecy test\" | Ephemeral keys demand forward secrecy verification | Add the ForwardSecrecyTest process whenever the diagram shows ephemeral keys |\n| \"Unused declarations are harmless\" | ProVerif may report spurious results from orphan declarations | Clean up all unused types, functions, and events |\n| \"The model compiles, so it's correct\" | A compiling model can have dead receives, type mismatches, or impossible guards that make queries vacuously true | Validate reachability before trusting any security query |\n| \"I don't need to check the example first\" | The example defines the expected output quality bar | Study `examples\u002Fsimple-handshake\u002F` before working on unfamiliar protocols |\n\n---\n\n## Workflow\n\n```\nProVerif Model Progress:\n- [ ] Step 1: Parse participants and channels\n- [ ] Step 2: Inventory cryptographic operations\n- [ ] Step 3: Declare types, functions, and equations\n- [ ] Step 4: Identify and declare events\n- [ ] Step 5: Formulate security queries\n- [ ] Step 6: Write participant processes\n- [ ] Step 7: Write main process and finalize\n- [ ] Step 8: Verify and deliver\n```\n\n### Step 1: Parse Participants and Channels\n\nFrom the Mermaid diagram:\n\n1. Extract every `participant` or `actor` declaration. Each becomes a\n   ProVerif process.\n2. Count message arrows (`->>`, `-->>`, `-x`, `--x`). Each distinct\n   `A ->> B: label` creates a communication step on a channel.\n3. Decide channel model:\n   - **Public channel** for any message sent over the network before a\n     secure channel is established (e.g., ClientHello, ephemeral keys,\n     ciphertext to be decrypted by the peer).\n   - **Private channel** only for internal state threading within a single\n     party process (not for cross-party messages).\n   - Default: declare one shared public channel `c` for all cross-party\n     messages. Add per-flow channels only when two distinct parallel sessions\n     must be independent.\n\n```proverif\nfree c: channel.\n```\n\n### Step 2: Inventory Cryptographic Operations\n\nWalk through every `Note over` annotation and message label. Build a list of\nall distinct operations used. Map each to a ProVerif declaration category:\n\n| Mermaid annotation | ProVerif category |\n|--------------------|-------------------|\n| `keygen() → sk, pk` | New name (`new sk`), public key derived via function |\n| `DH(sk_A, pk_B)` | DH function or `exp` with group |\n| `Sign(sk, msg) → σ` | Signature function |\n| `Verify(pk, msg, σ)` | Equation or destructor |\n| `Enc(key, msg) → ct` | Symmetric or asymmetric encryption function |\n| `Dec(key, ct) → msg` | Destructor (equation) |\n| `HKDF(ikm, info) → k` | PRF\u002FKDF function |\n| `HMAC(key, msg) → tag` | MAC function |\n| `H(msg) → digest` | Hash function |\n| `Commit(v, r) → C` | Commitment function |\n| `Open(C, v, r)` | Commitment equation |\n\nConsult [references\u002Fcrypto-to-proverif-mapping.md](references\u002Fcrypto-to-proverif-mapping.md)\nfor exact ProVerif syntax for each.\n\n### Step 3: Declare Types, Functions, and Equations\n\nBuild the cryptographic preamble in this order:\n\n1. **Types** — declare custom types used to distinguish key material:\n\n```proverif\ntype key.\ntype pkey.   (* public key *)\ntype skey.   (* secret key *)\ntype nonce.\n```\n\n2. **Constants** — for fixed strings used as domain separators or labels:\n\n```proverif\nconst msg1_label: bitstring.\nconst msg2_label: bitstring.\nconst info_session_key: bitstring.\n```\n\n3. **Functions** — constructors and destructors. Destructors use inline `reduc`\n   so that the process aborts on verification or decryption failure:\n\n```proverif\n(* Asymmetric encryption *)\nfun aenc(bitstring, pkey): bitstring.\nfun adec(bitstring, skey): bitstring\n    reduc forall m: bitstring, k: skey;\n        adec(aenc(m, pk(k)), k) = m.\nfun pk(skey): pkey.\n\n(* Symmetric encryption \u002F AEAD *)\nfun aead_enc(bitstring, key): bitstring.\nfun aead_dec(bitstring, key): bitstring\n    reduc forall m: bitstring, k: key;\n        aead_dec(aead_enc(m, k), k) = m.\n\n(* Digital signatures — verify returns the message on success, aborts on failure *)\nfun sign(bitstring, skey): bitstring.\nfun verify(bitstring, bitstring, pkey): bitstring\n    reduc forall m: bitstring, k: skey;\n        verify(sign(m, k), m, pk(k)) = m.\n\n(* KDF — first arg is key (from DH), second is bitstring (info\u002Fcontext) *)\nfun hkdf(key, bitstring): key.\n\n(* MAC *)\nfun mac(bitstring, key): bitstring.\n\n(* Hash *)\nfun hash(bitstring): bitstring.\n\n(* DH *)\nfun dh(skey, pkey): key.\nfun dhpk(skey): pkey.\n\n(* Serialization — ProVerif is strongly typed: pkey cannot appear\n * where bitstring is expected. Use these to build signed payloads. *)\nfun pkey2bs(pkey): bitstring.\nfun concat(bitstring, bitstring): bitstring.\n```\n\n4. **Equations** — algebraic identities on constructors only (not on destructors,\n   which already have their rewrite rules inline):\n\n```proverif\nequation forall sk_a: skey, sk_b: skey;\n    dh(sk_a, dhpk(sk_b)) = dh(sk_b, dhpk(sk_a)).\n```\n\nOnly declare what the diagram actually uses. Do not add functions for\noperations not present.\n\n### Step 4: Identify and Declare Events\n\nEvents mark security-relevant moments in the protocol execution. Extract them\nby identifying:\n\n- **Begin events** (`event beginRole(params)`): triggered immediately before a\n  party sends a message that depends on a long-term identity commitment (e.g.,\n  right before sending a signed message or a MAC'd message).\n- **End events** (`event endRole(params)`): triggered immediately after a party\n  successfully verifies the peer's identity (e.g., after `Verify(...)` or MAC\n  check passes, session key confirmed).\n- **Secrecy markers**: any key or nonce that should remain unknown to the\n  attacker after the handshake.\n\n```proverif\nevent beginI(pkey, pkey).     (* pk_I, pk_R — fired before sending the signed message *)\nevent endI(pkey, pkey, key).  (* pk_I, pk_R, session_key — fired after accepting *)\nevent beginR(pkey, pkey).\nevent endR(pkey, pkey, key).\n```\n\nParameters should uniquely identify the session: the parties' public keys,\nplus the session key or a transcript hash.\n\n### Step 5: Formulate Security Queries\n\nWrite one query per security property. Choose from:\n\n**Reachability (always add first — structural sanity check):**\n\nVerify that the success events are actually reachable. If ProVerif reports any\nof these as `false`, the model has a structural bug (dead receive, type mismatch,\nimpossible guard) and no other query result should be trusted. Once the model\nis validated, comment them out if they slow down the main property checks:\n\n```proverif\n(* Sanity: both endpoints must be reachable — comment out once validated. *)\n(*\nquery pk_i: pkey, pk_r: pkey, k: key; event(endI(pk_i, pk_r, k)).\nquery pk_i: pkey, pk_r: pkey, k: key; event(endR(pk_i, pk_r, k)).\n*)\n```\n\n**Secrecy** (key not derivable by attacker):\n\nDeclare a private free name and encrypt it under the session key. The attacker\nknowing `private_I` is equivalent to breaking the session key:\n\n```proverif\nfree private_I: bitstring [private].\n\n(* In process, after deriving sk_session: *)\nout(c, aead_enc(private_I, sk_session));\n\n(* Query: *)\nquery attacker(private_I).\n```\n\n**Weak authentication** (if B accepted, A ran at some point with matching\nparams — does not prevent replay):\n\n```proverif\nquery pk_i: pkey, pk_r: pkey, k: key;\n    event(endR(pk_i, pk_r, k)) ==> event(beginI(pk_i, pk_r)).\n```\n\n**Injective authentication** (prevents replay — each B-accept corresponds to\na distinct A-run):\n\n```proverif\nquery pk_i: pkey, pk_r: pkey, k: key;\n    inj-event(endR(pk_i, pk_r, k)) ==>\n    inj-event(beginI(pk_i, pk_r)).\n```\n\n**Forward secrecy**: add a `ForwardSecrecyTest` process to the main process\nthat leaks both long-term secret keys to the attacker, then check that a past\nsession key remains secret. Pair it with a `free fs_witness: key [private]`\ndeclaration and `query attacker(fs_witness)`. See\n[references\u002Fsecurity-properties.md](references\u002Fsecurity-properties.md) →\nForward Secrecy, and the worked example in\n`examples\u002Fsimple-handshake\u002Fsample-output.pv`.\n\nChoose the strongest applicable query for each property. See\n[references\u002Fsecurity-properties.md](references\u002Fsecurity-properties.md) for\nthe full decision tree.\n\n### Step 6: Write Participant Processes\n\nWrite one `let` process per participant. Structure each process to mirror the\nMermaid diagram step-by-step, in order.\n\n**Template for a two-party protocol:**\n\n```proverif\nlet Initiator(sk_I: skey, pk_R: pkey) =\n    (* Step: generate ephemeral key *)\n    new ek_I: skey;\n    let epk_I = dhpk(ek_I) in\n    (* Step: sign and send msg1 — pkey2bs casts pkey to bitstring *)\n    let sig_I = sign(concat(msg1_label, pkey2bs(epk_I)), sk_I) in\n    event beginI(pk(sk_I), pk_R);\n    out(c, (epk_I, sig_I));\n    (* Step: receive msg2 *)\n    in(c, (epk_R: pkey, sig_R: bitstring));\n    (* Step: verify responder signature — destructor aborts on failure *)\n    let transcript = concat(pkey2bs(epk_I), pkey2bs(epk_R)) in\n    let _ = verify(sig_R, concat(msg2_label, transcript), pk_R) in\n    (* Step: derive session key *)\n    let dh_val = dh(ek_I, epk_R) in\n    let sk_session = hkdf(dh_val, concat(info_session_key, transcript)) in\n    event endI(pk(sk_I), pk_R, sk_session);\n    (* Secrecy witness: encrypt private_I under the session key.\n     * Declared as: free private_I: bitstring [private].\n     * The query attacker(private_I) checks the attacker cannot derive it. *)\n    out(c, aead_enc(private_I, sk_session)).\n```\n\n**Rules for writing processes:**\n\n- Each `A ->> B: msg_contents` in the diagram becomes:\n  - `out(c, msg_contents)` in A's process\n  - `in(c, x)` (with matching destructuring) in B's process\n- Each `Note over A: op → result` becomes a `let result = op in` binding\n- Each `Note over A: Verify(...)` becomes a `let _ = verify(...) in`\n  binding (the destructor aborts on failure — no explicit else needed,\n  modeling abort)\n- Use `alt` blocks in the diagram as `if\u002Fthen\u002Felse` in the process\n- Long-term keys are process parameters; ephemeral values use `new`\n\n**N-party or MPC protocols:** write one process per distinct role. For\nthreshold protocols, write a single role process and replicate it `!N` times\nin the main process.\n\n### Step 7: Write Main Process and Finalize\n\nThe main process:\n\n1. Generates long-term keys with `new`\n2. Publishes public keys to the attacker via `out(c, pk(sk))`\n3. Runs participant processes in parallel under replication (`!`) to allow\n   multiple sessions\n4. Optionally leaks long-term keys for forward-secrecy analysis\n\n```proverif\nprocess\n    new sk_I: skey; let pk_I = pk(sk_I) in out(c, pk_I);\n    new sk_R: skey; let pk_R = pk(sk_R) in out(c, pk_R);\n    (\n        !Initiator(sk_I, pk_R)\n      | !Responder(sk_R, pk_I)\n    )\n```\n\nPlace the full file in this order:\n\n```\n(* 1. Channel declarations (free c: channel. \u002F free ch: channel [private].) *)\n(* 2. noselect directives (if needed for termination) *)\n(* 3. Type declarations *)\n(* 4. Constants *)\n(* 5. Function declarations *)\n(* 6. Equations (algebraic identities on constructors only) *)\n(* 7. Table declarations *)\n(* 8. Events *)\n(* 9. Queries *)\n(* 10. Let processes *)\n(* 11. Main process *)\n```\n\n### Step 8: Verify and Deliver\n\nBefore writing the file:\n\n- [ ] Every participant in the diagram has a matching `let` process\n- [ ] Every `out(c, ...)` has a matching `in(c, ...)` on the other side with\n      compatible types\n- [ ] Every function used in a process is declared in the preamble\n- [ ] Every destructor uses inline `reduc` (not a separate `equation` block)\n- [ ] Every event in a query is declared and triggered in a process\n- [ ] Long-term public keys are output to channel `c` in the main process\n      (attacker can see them — that is the Dolev-Yao model)\n- [ ] No unused declarations (clean up anything added speculatively)\n- [ ] If `table` declarations are present: every `insert T(...)` has a\n      corresponding `get T(...)` with compatible column types and matching\n      pattern constraints (`=key` vs bare name)\n- [ ] If `noselect` is used: its tuple structure matches the actual message\n      shapes sent on `c` (e.g., pairs → `mess(c, (x, y))`)\n- [ ] If the Key Exposure Oracle pattern is used: `event key_exposed(sk_type)`\n      is declared, the oracle `in(c, guess: sk_type); if pk(guess) = pk_new then\n      event key_exposed(guess)` appears at the end of the process that holds the\n      secret, and the query is `query x: sk_type; event(key_exposed(x))`\n\n**Write the model to a `.pv` file.** Choose a filename from the protocol name,\ne.g. `noise-xx-handshake.pv` or `x3dh-key-agreement.pv`.\n\nAfter writing, print a brief summary:\n\n```\nProtocol:   \u003CName>\nOutput:     \u003Cfilename>\nQueries:    \u003Clist each query and what property it tests>\nAssumptions: \u003Clist modeling decisions and simplifications>\n```\n\n---\n\n## Decision Tree\n\n```\n├─ No Mermaid diagram provided?\n│  └─ Ask the user: \"Please provide the Mermaid sequenceDiagram,\n│     or run the crypto-protocol-diagram skill first.\"\n│\n├─ Diagram uses DH (not just symmetric crypto)?\n│  └─ Use dh\u002Fdhpk with commutativity equation\n│     See references\u002Fcrypto-to-proverif-mapping.md → DH section\n│\n├─ Diagram uses asymmetric signatures (Sign\u002FVerify)?\n│  └─ Use sign\u002Fverify with inline reduc (not equation)\n│     verify returns the message on success; let _ = verify(...) in to abort on failure\n│     Distinguish signing key (skey) from verification key (pkey)\n│\n├─ Diagram has an \"alt\" block (abort path)?\n│  └─ Model as if\u002Fthen only — the else branch aborts (process terminates)\n│     Do NOT add out(c, error_message) unless the diagram shows it\n│\n├─ Protocol has N > 2 parties?\n│  └─ Write one process per role, use ! for replication\n│     Pass participant index as a parameter if roles differ by index only\n│\n├─ Forward secrecy requested?\n│  └─ Add a ForwardSecrecy variant in the main process that leaks\n│     long-term sk after session; add secrecy query for past session_key\n│     See references\u002Fsecurity-properties.md → Forward Secrecy\n│\n├─ Type-checker rejects the model?\n│  └─ ProVerif is typed: check every function arg type matches declaration.\n│     bitstring is the catch-all; key\u002Fpkey\u002Fskey\u002Fnonce are stricter.\n│     Cast with explicit constructors when needed.\n│\n├─ Protocol has cross-process state coordination (e.g., one process must wait\n│  for another to record acceptance before proceeding)?\n│  └─ Use ProVerif tables (table\u002Finsert\u002Fget)\n│     See references\u002Fproverif-syntax.md → Tables\n│\n├─ Verification does not terminate after several minutes?\n│  └─ Add noselect directive matching the message tuple structure on c\n│     See references\u002Fproverif-syntax.md → noselect\n│\n├─ Protocol generates a private-type key (type sk [private]) that is never\n│  output directly but whose secrecy should be verified?\n│  └─ Use the Key Exposure Oracle pattern instead of query attacker(sk)\n│     See references\u002Fsecurity-properties.md → Key Exposure Oracle\n│\n└─ Unsure which security properties to verify?\n   └─ Default set: secrecy of session key + injective authentication\n      (both directions). Add forward secrecy if diagram shows ephemeral keys.\n```\n\n---\n\n## Example\n\n`examples\u002Fsimple-handshake\u002F` contains a worked example:\n\n- **`diagram.md`** — Mermaid sequenceDiagram for a two-party authenticated key\n  exchange (X25519 DH + Ed25519 signing + HKDF)\n- **`sample-output.pv`** — exact ProVerif model the skill should produce,\n  with secrecy and injective authentication queries\n\nStudy this before working on an unfamiliar protocol.\n\n---\n\n## Supporting Documentation\n\n- **[references\u002Fcrypto-to-proverif-mapping.md](references\u002Fcrypto-to-proverif-mapping.md)** —\n  Mapping table from Mermaid cryptographic annotations to ProVerif function\n  declarations, equations, and process patterns\n- **[references\u002Fproverif-syntax.md](references\u002Fproverif-syntax.md)** —\n  ProVerif language reference: types, functions, equations, processes, events,\n  queries, and common pitfalls\n- **[references\u002Fsecurity-properties.md](references\u002Fsecurity-properties.md)** —\n  Decision guide for choosing the right queries: secrecy, authentication\n  (weak vs injective), forward secrecy, unlinkability, and how to model them\n","# Mermaid to ProVerif\n\nReads a Mermaid `sequenceDiagram` describing a cryptographic protocol and\nproduces a ProVerif model (`.pv` file) that can be passed directly to the\nProVerif verifier.\n\n**Tools used:** Read, Write, Grep, Glob.\n\nThe typical input is the output of the `crypto-protocol-diagram` skill — a\nMermaid `sequenceDiagram` annotated with cryptographic operations (`Sign`,\n`Verify`, `DH`, `HKDF`, `Enc`, `Dec`, etc.) and message arrows.\n\n## When to Use\n\n- User asks to formally verify a cryptographic protocol described as a Mermaid sequenceDiagram\n- User wants to generate a ProVerif model (.pv file) from a protocol diagram\n- User wants to prove secrecy, authentication, or forward secrecy properties\n- Input is the output of the `crypto-protocol-diagram` skill\n\n## When NOT to Use\n\n- No Mermaid sequenceDiagram exists yet — use `crypto-protocol-diagram` first to generate one\n- User wants to verify properties of non-cryptographic systems (state machines, access control)\n- User wants to run ProVerif on an existing .pv file — just run `proverif model.pv` directly\n\n## Rationalizations to Reject\n\n| Rationalization | Why It's Wrong | Required Action |\n|-----------------|----------------|-----------------|\n| \"Reachability queries are just busywork\" | If events aren't reachable, all other query results are meaningless | Always add reachability queries first as a sanity check |\n| \"Public channels are fine for all messages\" | Private channels for internal state prevent false attacks | Use private channels for intra-process state threading |\n| \"I'll skip the forward secrecy test\" | Ephemeral keys demand forward secrecy verification | Add the ForwardSecrecyTest process whenever the diagram shows ephemeral keys |\n| \"Unused declarations are harmless\" | ProVerif may report spurious results from orphan declarations | Clean up all unused types, functions, and events |\n| \"The model compiles, so it's correct\" | A compiling model can have dead receives, type mismatches, or impossible guards that make queries vacuously true | Validate reachability before trusting any security query |\n| \"I don't need to check the example first\" | The example defines the expected output quality bar | Study `examples\u002Fsimple-handshake\u002F` before working on unfamiliar protocols |\n\n---\n\n## Workflow\n\n```\nProVerif Model Progress:\n- [ ] Step 1: Parse participants and channels\n- [ ] Step 2: Inventory cryptographic operations\n- [ ] Step 3: Declare types, functions, and equations\n- [ ] Step 4: Identify and declare events\n- [ ] Step 5: Formulate security queries\n- [ ] Step 6: Write participant processes\n- [ ] Step 7: Write main process and finalize\n- [ ] Step 8: Verify and deliver\n```\n\n### Step 1: Parse Participants and Channels\n\nFrom the Mermaid diagram:\n\n1. Extract every `participant` or `actor` declaration. Each becomes a\n   ProVerif process.\n2. Count message arrows (`->>`, `-->>`, `-x`, `--x`). Each distinct\n   `A ->> B: label` creates a communication step on a channel.\n3. Decide channel model:\n   - **Public channel** for any message sent over the network before a\n     secure channel is established (e.g., ClientHello, ephemeral keys,\n     ciphertext to be decrypted by the peer).\n   - **Private channel** only for internal state threading within a single\n     party process (not for cross-party messages).\n   - Default: declare one shared public channel `c` for all cross-party\n     messages. Add per-flow channels only when two distinct parallel sessions\n     must be independent.\n\n```proverif\nfree c: channel.\n```\n\n### Step 2: Inventory Cryptographic Operations\n\nWalk through every `Note over` annotation and message label. Build a list of\nall distinct operations used. Map each to a ProVerif declaration category:\n\n| Mermaid annotation | ProVerif category |\n|--------------------|-------------------|\n| `keygen() → sk, pk` | New name (`new sk`), public key derived via function |\n| `DH(sk_A, pk_B)` | DH function or `exp` with group |\n| `Sign(sk, msg) → σ` | Signature function |\n| `Verify(pk, msg, σ)` | Equation or destructor |\n| `Enc(key, msg) → ct` | Symmetric or asymmetric encryption function |\n| `Dec(key, ct) → msg` | Destructor (equation) |\n| `HKDF(ikm, info) → k` | PRF\u002FKDF function |\n| `HMAC(key, msg) → tag` | MAC function |\n| `H(msg) → digest` | Hash function |\n| `Commit(v, r) → C` | Commitment function |\n| `Open(C, v, r)` | Commitment equation |\n\nConsult [references\u002Fcrypto-to-proverif-mapping.md](references\u002Fcrypto-to-proverif-mapping.md)\nfor exact ProVerif syntax for each.\n\n### Step 3: Declare Types, Functions, and Equations\n\nBuild the cryptographic preamble in this order:\n\n1. **Types** — declare custom types used to distinguish key material:\n\n```proverif\ntype key.\ntype pkey.   (* public key *)\ntype skey.   (* secret key *)\ntype nonce.\n```\n\n2. **Constants** — for fixed strings used as domain separators or labels:\n\n```proverif\nconst msg1_label: bitstring.\nconst msg2_label: bitstring.\nconst info_session_key: bitstring.\n```\n\n3. **Functions** — constructors and destructors. Destructors use inline `reduc`\n   so that the process aborts on verification or decryption failure:\n\n```proverif\n(* Asymmetric encryption *)\nfun aenc(bitstring, pkey): bitstring.\nfun adec(bitstring, skey): bitstring\n    reduc forall m: bitstring, k: skey;\n        adec(aenc(m, pk(k)), k) = m.\nfun pk(skey): pkey.\n\n(* Symmetric encryption \u002F AEAD *)\nfun aead_enc(bitstring, key): bitstring.\nfun aead_dec(bitstring, key): bitstring\n    reduc forall m: bitstring, k: key;\n        aead_dec(aead_enc(m, k), k) = m.\n\n(* Digital signatures — verify returns the message on success, aborts on failure *)\nfun sign(bitstring, skey): bitstring.\nfun verify(bitstring, bitstring, pkey): bitstring\n    reduc forall m: bitstring, k: skey;\n        verify(sign(m, k), m, pk(k)) = m.\n\n(* KDF — first arg is key (from DH), second is bitstring (info\u002Fcontext) *)\nfun hkdf(key, bitstring): key.\n\n(* MAC *)\nfun mac(bitstring, key): bitstring.\n\n(* Hash *)\nfun hash(bitstring): bitstring.\n\n(* DH *)\nfun dh(skey, pkey): key.\nfun dhpk(skey): pkey.\n\n(* Serialization — ProVerif is strongly typed: pkey cannot appear\n * where bitstring is expected. Use these to build signed payloads. *)\nfun pkey2bs(pkey): bitstring.\nfun concat(bitstring, bitstring): bitstring.\n```\n\n4. **Equations** — algebraic identities on constructors only (not on destructors,\n   which already have their rewrite rules inline):\n\n```proverif\nequation forall sk_a: skey, sk_b: skey;\n    dh(sk_a, dhpk(sk_b)) = dh(sk_b, dhpk(sk_a)).\n```\n\nOnly declare what the diagram actually uses. Do not add functions for\noperations not present.\n\n### Step 4: Identify and Declare Events\n\nEvents mark security-relevant moments in the protocol execution. Extract them\nby identifying:\n\n- **Begin events** (`event beginRole(params)`): triggered immediately before a\n  party sends a message that depends on a long-term identity commitment (e.g.,\n  right before sending a signed message or a MAC'd message).\n- **End events** (`event endRole(params)`): triggered immediately after a party\n  successfully verifies the peer's identity (e.g., after `Verify(...)` or MAC\n  check passes, session key confirmed).\n- **Secrecy markers**: any key or nonce that should remain unknown to the\n  attacker after the handshake.\n\n```proverif\nevent beginI(pkey, pkey).     (* pk_I, pk_R — fired before sending the signed message *)\nevent endI(pkey, pkey, key).  (* pk_I, pk_R, session_key — fired after accepting *)\nevent beginR(pkey, pkey).\nevent endR(pkey, pkey, key).\n```\n\nParameters should uniquely identify the session: the parties' public keys,\nplus the session key or a transcript hash.\n\n### Step 5: Formulate Security Queries\n\nWrite one query per security property. Choose from:\n\n**Reachability (always add first — structural sanity check):**\n\nVerify that the success events are actually reachable. If ProVerif reports any\nof these as `false`, the model has a structural bug (dead receive, type mismatch,\nimpossible guard) and no other query result should be trusted. Once the model\nis validated, comment them out if they slow down the main property checks:\n\n```proverif\n(* Sanity: both endpoints must be reachable — comment out once validated. *)\n(*\nquery pk_i: pkey, pk_r: pkey, k: key; event(endI(pk_i, pk_r, k)).\nquery pk_i: pkey, pk_r: pkey, k: key; event(endR(pk_i, pk_r, k)).\n*)\n```\n\n**Secrecy** (key not derivable by attacker):\n\nDeclare a private free name and encrypt it under the session key. The attacker\nknowing `private_I` is equivalent to breaking the session key:\n\n```proverif\nfree private_I: bitstring [private].\n\n(* In process, after deriving sk_session: *)\nout(c, aead_enc(private_I, sk_session));\n\n(* Query: *)\nquery attacker(private_I).\n```\n\n**Weak authentication** (if B accepted, A ran at some point with matching\nparams — does not prevent replay):\n\n```proverif\nquery pk_i: pkey, pk_r: pkey, k: key;\n    event(endR(pk_i, pk_r, k)) ==> event(beginI(pk_i, pk_r)).\n```\n\n**Injective authentication** (prevents replay — each B-accept corresponds to\na distinct A-run):\n\n```proverif\nquery pk_i: pkey, pk_r: pkey, k: key;\n    inj-event(endR(pk_i, pk_r, k)) ==>\n    inj-event(beginI(pk_i, pk_r)).\n```\n\n**Forward secrecy**: add a `ForwardSecrecyTest` process to the main process\nthat leaks both long-term secret keys to the attacker, then check that a past\nsession key remains secret. Pair it with a `free fs_witness: key [private]`\ndeclaration and `query attacker(fs_witness)`. See\n[references\u002Fsecurity-properties.md](references\u002Fsecurity-properties.md) →\nForward Secrecy, and the worked example in\n`examples\u002Fsimple-handshake\u002Fsample-output.pv`.\n\nChoose the strongest applicable query for each property. See\n[references\u002Fsecurity-properties.md](references\u002Fsecurity-properties.md) for\nthe full decision tree.\n\n### Step 6: Write Participant Processes\n\nWrite one `let` process per participant. Structure each process to mirror the\nMermaid diagram step-by-step, in order.\n\n**Template for a two-party protocol:**\n\n```proverif\nlet Initiator(sk_I: skey, pk_R: pkey) =\n    (* Step: generate ephemeral key *)\n    new ek_I: skey;\n    let epk_I = dhpk(ek_I) in\n    (* Step: sign and send msg1 — pkey2bs casts pkey to bitstring *)\n    let sig_I = sign(concat(msg1_label, pkey2bs(epk_I)), sk_I) in\n    event beginI(pk(sk_I), pk_R);\n    out(c, (epk_I, sig_I));\n    (* Step: receive msg2 *)\n    in(c, (epk_R: pkey, sig_R: bitstring));\n    (* Step: verify responder signature — destructor aborts on failure *)\n    let transcript = concat(pkey2bs(epk_I), pkey2bs(epk_R)) in\n    let _ = verify(sig_R, concat(msg2_label, transcript), pk_R) in\n    (* Step: derive session key *)\n    let dh_val = dh(ek_I, epk_R) in\n    let sk_session = hkdf(dh_val, concat(info_session_key, transcript)) in\n    event endI(pk(sk_I), pk_R, sk_session);\n    (* Secrecy witness: encrypt private_I under the session key.\n     * Declared as: free private_I: bitstring [private].\n     * The query attacker(private_I) checks the attacker cannot derive it. *)\n    out(c, aead_enc(private_I, sk_session)).\n```\n\n**Rules for writing processes:**\n\n- Each `A ->> B: msg_contents` in the diagram becomes:\n  - `out(c, msg_contents)` in A's process\n  - `in(c, x)` (with matching destructuring) in B's process\n- Each `Note over A: op → result` becomes a `let result = op in` binding\n- Each `Note over A: Verify(...)` becomes a `let _ = verify(...) in`\n  binding (the destructor aborts on failure — no explicit else needed,\n  modeling abort)\n- Use `alt` blocks in the diagram as `if\u002Fthen\u002Felse` in the process\n- Long-term keys are process parameters; ephemeral values use `new`\n\n**N-party or MPC protocols:** write one process per distinct role. For\nthreshold protocols, write a single role process and replicate it `!N` times\nin the main process.\n\n### Step 7: Write Main Process and Finalize\n\nThe main process:\n\n1. Generates long-term keys with `new`\n2. Publishes public keys to the attacker via `out(c, pk(sk))`\n3. Runs participant processes in parallel under replication (`!`) to allow\n   multiple sessions\n4. Optionally leaks long-term keys for forward-secrecy analysis\n\n```proverif\nprocess\n    new sk_I: skey; let pk_I = pk(sk_I) in out(c, pk_I);\n    new sk_R: skey; let pk_R = pk(sk_R) in out(c, pk_R);\n    (\n        !Initiator(sk_I, pk_R)\n      | !Responder(sk_R, pk_I)\n    )\n```\n\nPlace the full file in this order:\n\n```\n(* 1. Channel declarations (free c: channel. \u002F free ch: channel [private].) *)\n(* 2. noselect directives (if needed for termination) *)\n(* 3. Type declarations *)\n(* 4. Constants *)\n(* 5. Function declarations *)\n(* 6. Equations (algebraic identities on constructors only) *)\n(* 7. Table declarations *)\n(* 8. Events *)\n(* 9. Queries *)\n(* 10. Let processes *)\n(* 11. Main process *)\n```\n\n### Step 8: Verify and Deliver\n\nBefore writing the file:\n\n- [ ] Every participant in the diagram has a matching `let` process\n- [ ] Every `out(c, ...)` has a matching `in(c, ...)` on the other side with\n      compatible types\n- [ ] Every function used in a process is declared in the preamble\n- [ ] Every destructor uses inline `reduc` (not a separate `equation` block)\n- [ ] Every event in a query is declared and triggered in a process\n- [ ] Long-term public keys are output to channel `c` in the main process\n      (attacker can see them — that is the Dolev-Yao model)\n- [ ] No unused declarations (clean up anything added speculatively)\n- [ ] If `table` declarations are present: every `insert T(...)` has a\n      corresponding `get T(...)` with compatible column types and matching\n      pattern constraints (`=key` vs bare name)\n- [ ] If `noselect` is used: its tuple structure matches the actual message\n      shapes sent on `c` (e.g., pairs → `mess(c, (x, y))`)\n- [ ] If the Key Exposure Oracle pattern is used: `event key_exposed(sk_type)`\n      is declared, the oracle `in(c, guess: sk_type); if pk(guess) = pk_new then\n      event key_exposed(guess)` appears at the end of the process that holds the\n      secret, and the query is `query x: sk_type; event(key_exposed(x))`\n\n**Write the model to a `.pv` file.** Choose a filename from the protocol name,\ne.g. `noise-xx-handshake.pv` or `x3dh-key-agreement.pv`.\n\nAfter writing, print a brief summary:\n\n```\nProtocol:   \u003CName>\nOutput:     \u003Cfilename>\nQueries:    \u003Clist each query and what property it tests>\nAssumptions: \u003Clist modeling decisions and simplifications>\n```\n\n---\n\n## Decision Tree\n\n```\n├─ No Mermaid diagram provided?\n│  └─ Ask the user: \"Please provide the Mermaid sequenceDiagram,\n│     or run the crypto-protocol-diagram skill first.\"\n│\n├─ Diagram uses DH (not just symmetric crypto)?\n│  └─ Use dh\u002Fdhpk with commutativity equation\n│     See references\u002Fcrypto-to-proverif-mapping.md → DH section\n│\n├─ Diagram uses asymmetric signatures (Sign\u002FVerify)?\n│  └─ Use sign\u002Fverify with inline reduc (not equation)\n│     verify returns the message on success; let _ = verify(...) in to abort on failure\n│     Distinguish signing key (skey) from verification key (pkey)\n│\n├─ Diagram has an \"alt\" block (abort path)?\n│  └─ Model as if\u002Fthen only — the else branch aborts (process terminates)\n│     Do NOT add out(c, error_message) unless the diagram shows it\n│\n├─ Protocol has N > 2 parties?\n│  └─ Write one process per role, use ! for replication\n│     Pass participant index as a parameter if roles differ by index only\n│\n├─ Forward secrecy requested?\n│  └─ Add a ForwardSecrecy variant in the main process that leaks\n│     long-term sk after session; add secrecy query for past session_key\n│     See references\u002Fsecurity-properties.md → Forward Secrecy\n│\n├─ Type-checker rejects the model?\n│  └─ ProVerif is typed: check every function arg type matches declaration.\n│     bitstring is the catch-all; key\u002Fpkey\u002Fskey\u002Fnonce are stricter.\n│     Cast with explicit constructors when needed.\n│\n├─ Protocol has cross-process state coordination (e.g., one process must wait\n│  for another to record acceptance before proceeding)?\n│  └─ Use ProVerif tables (table\u002Finsert\u002Fget)\n│     See references\u002Fproverif-syntax.md → Tables\n│\n├─ Verification does not terminate after several minutes?\n│  └─ Add noselect directive matching the message tuple structure on c\n│     See references\u002Fproverif-syntax.md → noselect\n│\n├─ Protocol generates a private-type key (type sk [private]) that is never\n│  output directly but whose secrecy should be verified?\n│  └─ Use the Key Exposure Oracle pattern instead of query attacker(sk)\n│     See references\u002Fsecurity-properties.md → Key Exposure Oracle\n│\n└─ Unsure which security properties to verify?\n   └─ Default set: secrecy of session key + injective authentication\n      (both directions). Add forward secrecy if diagram shows ephemeral keys.\n```\n\n---\n\n## Example\n\n`examples\u002Fsimple-handshake\u002F` contains a worked example:\n\n- **`diagram.md`** — Mermaid sequenceDiagram for a two-party authenticated key\n  exchange (X25519 DH + Ed25519 signing + HKDF)\n- **`sample-output.pv`** — exact ProVerif model the skill should produce,\n  with secrecy and injective authentication queries\n\nStudy this before working on an unfamiliar protocol.\n\n---\n\n## Supporting Documentation\n\n- **[references\u002Fcrypto-to-proverif-mapping.md](references\u002Fcrypto-to-proverif-mapping.md)** —\n  Mapping table from Mermaid cryptographic annotations to ProVerif function\n  declarations, equations, and process patterns\n- **[references\u002Fproverif-syntax.md](references\u002Fproverif-syntax.md)** —\n  ProVerif language reference: types, functions, equations, processes, events,\n  queries, and common pitfalls\n- **[references\u002Fsecurity-properties.md](references\u002Fsecurity-properties.md)** —\n  Decision guide for choosing the right queries: secrecy, authentication\n  (weak vs injective), forward secrecy, unlinkability, and how to model them\n",{"name":5,"description":7},"main","f37de8f681f0c0ca0e0ebab6e5fddf764ca7553d","skills\u002Fmermaid-to-proverif",1,"https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one","https:\u002F\u002Fagisota.github.io\u002Fold-one\u002F","https:\u002F\u002Fgithub.com\u002Fagisota","pzd.world","2026-07-04 22:32:06",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add agisota\u002Fold-one --skill mermaid-to-proverif",{"tool":38,"command":39},"bunx","bunx skills add agisota\u002Fold-one --skill mermaid-to-proverif",{"tool":41,"command":42},"pnpm","pnpm dlx skills add agisota\u002Fold-one --skill mermaid-to-proverif","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fmermaid-to-proverif\u002FSKILL.md",true,[46,52,56],{"path":47,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":50,"sourceHtmlUrl":51},"references\u002Fcrypto-to-proverif-mapping.md","REFERENCE","参考文档",10317,"https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fmermaid-to-proverif\u002Freferences\u002Fcrypto-to-proverif-mapping.md",{"path":53,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":54,"sourceHtmlUrl":55},"references\u002Fproverif-syntax.md",14109,"https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fmermaid-to-proverif\u002Freferences\u002Fproverif-syntax.md",{"path":57,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":58,"sourceHtmlUrl":59},"references\u002Fsecurity-properties.md",11836,"https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fmermaid-to-proverif\u002Freferences\u002Fsecurity-properties.md",[61,68,75,84,91,98],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":18},"01M75KRGZWQWE9JDBS6RX42NWV","zoom-out","Tell the agent to zoom out and give broader context or a higher-level perspective. Use when you're unfamiliar with a section of code or need to understand how it fits into the bigger picture.","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fzoom-out\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":18},"01M75KRCZHKE0ZYAQFFYHS0YNP","zeroize-audit","Detects missing zeroization of sensitive data in source code and identifies zeroization removed by compiler optimizations, with assembly-level analysis, and control-flow verification. Use for auditing C\u002FC++\u002FRust code handling secrets, keys, passwords, or other sensitive data.","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fzeroize-audit\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":79,"licenseFileUrl":80,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":18},"01M75KR94KYQ30DTE1P9WNDAE0","yeet","Use only when the user explicitly asks to stage, commit, push, and open a GitHub pull request in one flow using the GitHub CLI (`gh`).","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fyeet\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fyeet\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":18},"01M75KR3H13YJ9QHMD49818FA1","yara-rule-authoring","Guides authoring of high-quality YARA-X detection rules for malware identification. Use when writing, reviewing, or optimizing YARA rules. Covers naming conventions, string selection, performance optimization, migration from legacy YARA, and false positive reduction. Triggers on: YARA, YARA-X, malware detection, threat hunting, IOC, signature, crx module, dex module.","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fyara-rule-authoring\u002FSKILL.md",[],[],{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":18},"01M75KQMPY8A4Y8XTDD2DT0M9T","x-twitter-growth","X\u002FTwitter growth engine for building audience, crafting viral content, and analyzing engagement. Use when the user wants to grow on X\u002FTwitter, write tweets or threads, analyze their X profile, research competitors on X, plan a posting strategy, or optimize engagement. Complements social-content (generic multi-platform) with X-specific depth: algorithm mechanics, thread engineering, reply strategy, profile optimization, and competitive intelligence via web search.","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fx-twitter-growth\u002FSKILL.md",[],[],{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":102,"categories":103,"keywords":104,"publishedAt":18},"01M75KQHNZ0ANZNJGZY6M8MDAK","x-api","X\u002FTwitter API integration for posting tweets, threads, reading timelines, search, and analytics. Covers OAuth auth patterns, rate limits, and platform-native content posting. Use when the user wants to interact with X programmatically.","https:\u002F\u002Fgithub.com\u002Fagisota\u002Fold-one\u002Fblob\u002Fmain\u002Fskills\u002Fx-api\u002FSKILL.md",[],[]]