Loading...
Loading...
Compare original and translation side by side
sequenceDiagram.pv.spthydiagramming-codediagramming-codesequenceDiagram.pv.spthydiagramming-codediagramming-codediagramming-codemermaid-to-proverifdiagramming-codemermaid-to-proverif| Rationalization | Why It's Wrong | Required Action |
|---|---|---|
| "The protocol is simple, I can diagram from memory" | Memory-based diagrams miss steps and invert arrows | Read the source or spec systematically |
| "I'll skip the spec path since code exists" | Code may diverge from the spec — both paths catch different bugs | When both exist, run spec workflow first, then annotate code divergences |
| "Crypto annotations are optional decoration" | Without crypto annotations, the diagram is just a message flow — useless for security review | Annotate every cryptographic operation |
| "The abort path is obvious, no need for alt blocks" | Implicit abort handling hides missing error checks | Show every abort/error path with |
| "I don't need to check the examples first" | The examples define the expected output quality bar | Study the relevant example before working on unfamiliar input |
| "ProVerif/Tamarin models are code, not specs" | Formal models are specifications — they describe intended behavior, not implementation | Use the spec workflow (S1–S5) for |
| 拒绝理由 | 错误原因 | 所需操作 |
|---|---|---|
| "这个协议很简单,我凭记忆就能画出来" | 基于记忆绘制的示意图会遗漏步骤、箭头方向倒置 | 系统地阅读源代码或规范文档 |
| "既然有代码,我就不看规范了" | 代码可能与规范存在差异——两种路径能发现不同的问题 | 如果两者都存在,先运行规范工作流,再标注代码与规范的差异 |
| "密码学注解是可选的装饰内容" | 没有密码学注解的示意图只是单纯的消息流,对安全审查毫无用处 | 为每一个密码学操作添加注解 |
| "中止路径很明显,不需要用alt块标注" | 隐式的中止处理会隐藏缺失的错误检查 | 使用 |
| "我不需要先看示例" | 示例定义了预期的输出质量标准 | 处理不熟悉的输入前,先学习相关示例 |
| "ProVerif/Tamarin模型是代码,不是规范" | 形式化模型属于规范——它们描述的是预期行为,而非实现 | 对 |
Protocol Diagram Progress:
- [ ] Step 0: Determine input type (code / spec / both)
- [ ] Step 1 (code) or S1–S5 (spec): Extract protocol structure
- [ ] Step 6: Generate sequenceDiagram
- [ ] Step 7: Verify and deliver协议示意图绘制进度:
- [ ] 步骤0:确定输入类型(代码/规范/两者都有)
- [ ] 步骤1(代码)或S1–S5(规范):提取协议结构
- [ ] 步骤6:生成sequenceDiagram
- [ ] 步骤7:验证并交付| Signal | Input type |
|---|---|
Source file extensions ( | Code |
| Function/class definitions, import statements | Code |
RFC-style section headers ( | Spec |
| Spec |
ProVerif file ( | Spec |
Tamarin file ( | Spec |
| Plain prose or numbered steps describing a protocol | Spec |
| Both source files and a spec document | Both (annotate divergences with |
⚠️| 特征 | 输入类型 |
|---|---|
源文件扩展名( | 代码 |
| 函数/类定义、import语句 | 代码 |
RFC风格的章节标题( | 规范 |
| 规范 |
包含 | 规范 |
包含 | 规范 |
| 描述协议的纯文本或编号步骤 | 规范 |
| 同时提供源文件和规范文档 | 两者都有(用 |
⚠️undefinedundefined
Start reading from the highest-level orchestration function — the one that calls
into handshake phases or the main protocol loop.
从最高层的编排函数开始阅读——也就是调用握手阶段或主协议循环的函数。ClientServerInitiatorResponderProverVerifierDealerPartyCoordinatorparticipantparticipant I as Initiator
participant R as ResponderClientServerInitiatorResponderProverVerifierDealerPartyCoordinatorparticipantparticipant I as Initiator
participant R as Responder| Pattern | Meaning |
|---|---|
| Direct message exchange |
| Structured message sent |
| Return value passed to other party's function | Logical message (in-process) |
| Round-based MPC step |
Struct fields named | Message contents |
| 模式 | 含义 |
|---|---|
| 直接消息交换 |
| 发送结构化消息 |
| 传递给另一方函数的返回值 | 逻辑消息(进程内) |
| 基于轮次的MPC步骤 |
名为 | 消息内容 |
| Operation | Diagram annotation |
|---|---|
| Key generation | |
| DH / ECDH | |
| KDF / HKDF | |
| Signing | |
| Verification | |
| Encryption | |
| Decryption | |
| Commitment | |
| Hash | |
| Secret sharing | |
| Threshold combine | |
| 操作 | 示意图注解 |
|---|---|
| 密钥生成 | |
| DH / ECDH | |
| KDF / HKDF | |
| 签名 | |
| 验签 | |
| 加密 | |
| 解密 | |
| 承诺 | |
| 哈希 | |
| 秘密共享 | |
| 阈值合并 | |
rectNotealtrectNotealt| Format | Signals |
|---|---|
| RFC | |
| Academic paper / pseudocode | |
| Informal prose | Numbered lists, "A sends B ...", plain English descriptions |
ProVerif ( | |
Tamarin ( | |
| 格式 | 特征 |
|---|---|
| RFC | |
| 学术论文/伪代码 | |
| 非正式文本 | 编号列表、"A sends B ..."、纯英文描述 |
ProVerif( | |
Tamarin( | |
AliceBobClientServerInitiatorResponderProverVerifierDealerParty_iCoordinatorSignerlet ClientProc(...)let ServerProc(...)!Pk($A, pk)$AparticipantAliceBobClientServerInitiatorResponderProverVerifierDealerParty_iCoordinatorSignerlet ClientProc(...)let ServerProc(...)!Pk($A, pk)$AparticipantA → B: msgA -> Bsenderreceiversend(party, msg)receive(party).pvout(ch, msg)chin(ch, x)chxoutin!.spthyIn(m)mOut(m)mFr(~x)--[ Label ]->parA → B: msgA -> Bsenderreceiversend(party, msg)receive(party).pvout(ch, msg)chin(ch, x)chxoutin!.spthyIn(m)mOut(m)mFr(~x)--[ Label ]->par| Spec notation | Operation | Diagram annotation |
|---|---|---|
| Key generation | |
| DH / ECDH | |
| Key derivation | |
| Signing | |
| Verification | |
| Encryption | |
| Decryption | |
| Hash | |
| Commitment | |
ProVerif | Symmetric encryption | |
ProVerif | Public key derivation | |
ProVerif | Signing | |
assertrequireif ... abortif m = expected then ... else 0alt| 规范符号 | 操作 | 示意图注解 |
|---|---|---|
| 密钥生成 | |
| DH / ECDH | |
| 密钥派生 | |
| 签名 | |
| 验签 | |
| 加密 | |
| 解密 | |
| 哈希 | |
| 承诺 | |
ProVerif | 对称加密 | |
ProVerif | 公钥派生 | |
ProVerif | 签名 | |
assertrequireif ... abortif m = expected then ... else 0alt⚠️ ordering inferred from spec structure⚠️ spec omits [step] — canonical protocol requires it⚠️ encryption scheme not specifiedcnew c⚠️ ordering inferred from spec structure⚠️ spec omits [step] — canonical protocol requires itloopNote over A,B: ⚠️ spec requires MAC here — implementation omits itloopNote over A,B: ⚠️ spec requires MAC here — implementation omits italt⚠️noise-xx-handshake.mdx3dh-key-agreement.mdundefinedalt⚠️noise-xx-handshake.mdx3dh-key-agreement.mdundefined
After writing the file, print an **ASCII sequence diagram** inline in the
response, followed by the Protocol Summary. State the output filename so the
user knows where to find the Mermaid source.
Follow all drawing conventions in
[references/ascii-sequence-diagram.md](references/ascii-sequence-diagram.md),
including the inline output format.
---
写入文件后,在响应中直接输出**ASCII时序图**,随后附上协议摘要。说明输出文件名,方便用户找到Mermaid源文件。
遵循[references/ascii-sequence-diagram.md](references/ascii-sequence-diagram.md)中的所有绘制规范,包括内联输出格式。
---── Input is a spec document (not code)?
│ └─ Step S1: identify format, read references/spec-parsing-patterns.md
│
── Input is source code (not a spec)?
│ └─ Step 1: grep for handshake/round/send/recv entry points
│
── Both spec and code provided?
│ └─ Run Spec Workflow (S1–S5) first to build canonical diagram,
│ then read code and annotate divergences with ⚠️
│
── Spec is a known protocol (TLS, Noise, Signal, X3DH, FROST)?
│ └─ Read references/protocol-patterns.md and use canonical flow as skeleton
│
── Spec is ProVerif (.pv) or Tamarin (.spthy)?
│ └─ Read references/spec-parsing-patterns.md → Formal Models section
│
── Spec message ordering is ambiguous?
│ └─ Infer from round/section structure, annotate with ⚠️
│
── Can't identify parties from spec?
│ └─ Check "Parties"/"Notation" sections; for ProVerif read process names;
│ for Tamarin read rule names and fact arguments
│
── Don't know which code files implement the protocol?
│ └─ Step 1: grep for handshake/round/send/recv entry points
│
── Can't identify parties from struct names?
│ └─ Read test files — test setup reveals roles
│
── Protocol runs in-process (no network calls)?
│ └─ Treat function argument passing at role boundaries as messages
│
── MPC / threshold protocol with N parties?
│ └─ Read references/protocol-patterns.md → MPC section
│
── Mermaid syntax error?
│ └─ Read references/mermaid-sequence-syntax.md → Common Pitfalls
│
└─ ASCII drawing conventions?
└─ Read references/ascii-sequence-diagram.md── 输入是规范文档(非代码)?
│ └─ 步骤S1:识别格式,阅读references/spec-parsing-patterns.md
│
── 输入是源代码(非规范)?
│ └─ 步骤1:grep查找handshake/round/send/recv入口点
│
── 同时提供了规范和代码?
│ └─ 先运行规范工作流(S1–S5)构建标准示意图,再阅读代码并用⚠️标注差异
│
── 规范是已知协议(TLS、Noise、Signal、X3DH、FROST)?
│ └─ 阅读references/protocol-patterns.md,使用标准流程作为骨架
│
── 规范是ProVerif(.pv)或Tamarin(.spthy)?
│ └─ 阅读references/spec-parsing-patterns.md → 形式化模型章节
│
── 规范的消息顺序不明确?
│ └─ 从轮次/章节结构推断,用⚠️标注
│
── 无法从规范中识别参与方?
│ └─ 检查"Parties"/"Notation"章节;ProVerif读取进程名;Tamarin读取规则名和事实参数
│
── 不知道哪些代码文件实现了协议?
│ └─ 步骤1:grep查找handshake/round/send/recv入口点
│
── 无法从结构体名识别参与方?
│ └─ 阅读测试文件——测试设置会体现角色
│
── 协议在进程内运行(无网络调用)?
│ └─ 将角色边界处的函数参数传递视为消息
│
── 多方计算/阈值协议,包含N个参与方?
│ └─ 阅读references/protocol-patterns.md → MPC章节
│
── Mermaid语法错误?
│ └─ 阅读references/mermaid-sequence-syntax.md → 常见问题
│
└─ ASCII绘制规范?
└─ 阅读references/ascii-sequence-diagram.mdexamples/simple-handshake/protocol.pyexpected-output.mdexamples/simple-proverif/model.pvexpected-output.mdexamples/simple-handshake/protocol.pyexpected-output.mdexamples/simple-proverif/model.pvexpected-output.md