Skip to content

feat: implement automated threat modeling system and CLI integration - #70

Open
BigFundz wants to merge 1 commit into
StellarChainproof:masterfrom
BigFundz:feat/threat-modeling
Open

feat: implement automated threat modeling system and CLI integration#70
BigFundz wants to merge 1 commit into
StellarChainproof:masterfrom
BigFundz:feat/threat-modeling

Conversation

@BigFundz

Copy link
Copy Markdown

Closes #51

Issue: Implement Automated Threat Modeling System for Smart Contracts

Problem Statement

Currently, the ChainProof scanner detects code-level vulnerabilities, but it lacks a holistic, architecture-level security view. Developers and auditors need a way to automatically model smart contracts' security architectures—identifying what assets exist, who might attack them, where the trust boundaries lie, and how code-level findings impact the overall system risk.

To bridge this gap, we need to implement an automated AI Threat Modeling System integrated into the ChainProof core and CLI.

Requirements

1. Asset Extraction & Valuation Engine

  • Traverse Solidity ASTs to identify key components: vaults, token ledgers, roles/access controllers, and price oracle feeds.
  • Assign relative criticality values (high, medium, low) to these assets.

2. Threat Agent Database & Modeling

  • Model threat agents (e.g., anonymous external attackers, compromised administrators, MEV searchers) along with their capabilities and motivations.

3. Attack Surface & Trust Boundary Mapping

  • Group entrypoints and modifiers (like onlyOwner) to outline logical trust boundaries.
  • Map attack surfaces based on public-facing functions and cross-contract interactions.

4. Risk Prioritization & Framework Mapping

  • Implement a risk priority scoring algorithm based on STRIDE (Spoofing, Tampering, Repudiation, Information Disclosure, Denial of Service, Elevation of Privilege) and DeFi-specific attack vectors (Oracle Manipulation, Reentrancy, Access Control).
  • Support sorting and filtering by minimum severity levels.

5. Team Collaboration & Overrides

  • Allow loading custom overrides (such as marking a threat as mitigated or adding custom assets) using a local JSON assumptions file.

6. Visual Representations & Multi-Format Reporting

  • Generate threat model diagrams utilizing Mermaid.js flowcharts and terminal-friendly ASCII boundary maps.
  • Output results to Markdown reports and structured JSON.

7. CLI & CI Integration

  • Expose this functionality via a new CLI command (chainproof threat-model).
  • Ensure code and docs build and test successfully within GitHub Actions.

Solution Implemented

  1. Core Threat Engine (packages/core/src/threat-model/): Created custom AST visitor engines, risk calculators with expert category weighting, configuration merger, and visual layout generators.
  2. CLI Integration (packages/cli/src/cli.ts): Built a fully featured threat-model command that supports options like --format json, --output, and --assumptions.
  3. CI Pipeline Repair: Resolved a missing test:ci script issue and added TypeDoc peer dependencies to prevent docs/tests pipeline failures.
  4. Validation: Built a mock DeFi system fixture (DeFiSystemFixture.sol) and wrote comprehensive Jest unit and integration test suites.

@BigFundz

Copy link
Copy Markdown
Author

@Nanle-code Please review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI-Powered Threat Modeling System

2 participants