Overview
The Spec-to-Code Compliance plugin performs systematic comparison between specification documents (whitepapers, design docs) and actual implementation code, producing audit-grade compliance reports with:- Zero speculation - Every claim backed by exact quotes or line numbers
- Structured IR workflow - Spec Intent → Code Behavior → Alignment → Divergence
- Confidence scoring - All mappings include 0-1 confidence scores
- Exploit scenarios - Critical findings include attack vectors and economic impact
When to Use
Protocol Audits
Smart contracts being verified against whitepapers or protocol specifications
Compliance Checks
Finding gaps between intended behavior and actual implementation
Spec Divergence
Identifying undocumented code behavior or unimplemented spec claims
Documentation Drift
Discovering where code has evolved beyond original design documents
Concrete Triggers
- User provides both specification documents AND codebase
- Questions like “does this code match the spec?” or “what’s missing from the implementation?”
- Audit engagements requiring spec-to-code alignment analysis
- Protocol implementations being verified against whitepapers
When NOT to Use
Analysis Workflow
The plugin executes a rigorous 7-phase workflow:1
Documentation Discovery
Identifies all spec sources (whitepapers, READMEs, design notes, Notion exports, meeting transcripts)
2
Format Normalization
Converts PDF, Markdown, DOCX, HTML, TXT to clean canonical format preserving structure
3
Spec Intent IR
Extracts all intended behavior (invariants, formulas, flows, security requirements) into structured Spec-IR
4
Code Behavior IR
Line-by-line semantic analysis of implementation producing Code-IR with full traceability
5
Alignment IR
Compares Spec-IR to Code-IR, generates alignment records with match types and confidence scores
6
Divergence Classification
Categorizes misalignments by severity (Critical/High/Medium/Low) with exploit scenarios
7
Final Report
Produces audit-grade compliance report with evidence links and remediation guidance
Match Types
The plugin classifies spec-to-code alignment into six categories:Severity Classification
- Critical
- High
- Medium
- Low
Indicators:
- Spec says X, code does Y
- Missing invariant enabling exploits
- Math divergence involving funds
- Trust boundary mismatches
IR Structure Examples
Spec-IR Record
Code-IR Record
Alignment Record
Divergence Finding (Critical)
Anti-Hallucination Requirements
Rationalizations to Reject
The plugin rejects these common shortcuts:Output Report Structure
The final compliance report includes:- Executive Summary - Finding counts, overall compliance metrics
- Documentation Sources - All spec documents analyzed
- Spec Intent Breakdown - Extracted Spec-IR with full citations
- Code Behavior Summary - Code-IR semantic map
- Full Alignment Matrix - Every spec item mapped to code status
- Divergence Findings - Critical/High/Medium/Low with evidence
- Missing Invariants - Spec requirements not implemented
- Incorrect Logic - Code behavior contradicting spec
- Math Inconsistencies - Formula divergence
- Flow Mismatches - State machine divergence
- Access Control Drift - Permission misalignment
- Undocumented Behavior - Code paths not in spec
- Ambiguity Hotspots - Unclear spec or code sections
- Recommendations - Remediation guidance
- Documentation Updates - Suggested spec improvements
- Final Risk Assessment - Overall compliance rating
Quality Standards
Spec-IR Completeness
Spec-IR Completeness
- All invariants extracted and normalized
- All formulas in canonical symbolic form
- All security requirements documented
- Minimum 80% confidence on critical items
Code-IR Completeness
Code-IR Completeness
- Every function analyzed with control flow
- All state changes tracked
- All external calls documented
- Line numbers for all evidence
Alignment Quality
Alignment Quality
- Every spec item has alignment record
- Match types accurately classified
- Confidence scores justified
- Evidence links verified
Divergence Findings
Divergence Findings
- Exploit scenarios for critical issues
- Economic impact analysis
- Remediation with code examples
- Citations to both spec and code
Agent Usage
Thespec-compliance-checker agent performs the full 7-phase workflow autonomously:
- Structured IR artifacts (Spec-IR, Code-IR, Alignment-IR)
- Divergence findings with severity classification
- Final compliance report in markdown format
Example Use Cases
DeFi Protocol Audit
Whitepaper specifies constant product formula
x * y = k. Code uses x * y = k + fee, enabling economic exploit.Governance Compliance
Spec requires 7-day timelock on proposals. Code implements 3-day timelock, violating governance security model.
Access Control Gap
Documentation describes admin-only emergency pause. Implementation missing
onlyAdmin modifier.Undocumented Upgrade
Code implements proxy upgrade pattern not mentioned in specification, introducing trust assumptions.
Related Resources
The plugin includes detailed reference documentation:resources/IR_EXAMPLES.md- Complete IR workflow examples with DEX patternsresources/OUTPUT_REQUIREMENTS.md- IR production standards and quality thresholdsresources/COMPLETENESS_CHECKLIST.md- Verification checklist for all phases
Integration Points
- Property-Based Testing - Verify extracted invariants hold in practice
- Zeroize Audit - Cross-check sensitive data handling against spec
- Constant-Time Analysis - Validate timing requirements from spec
Author: Omar Inuwa (Trail of Bits)Version: 1.1.0