cognis-digital/gasprofiler

GitHub: cognis-digital/gasprofiler

一款面向 Solidity 智能合约的 gas 分析与退化检测工具,按 opcode 和函数维度标记无界循环等高风险模式并支持 CI 基线拦截。

Stars: 0 | Forks: 0

GASPROFILER # GASPROFILER ### 按 opcode 和函数分析的 gas 分析器,可标记无界循环、易受 DoS 攻击的模式,以及相对于已提交基线的退化。 [![PyPI](https://img.shields.io/pypi/v/cognis-gasprofiler.svg?color=6b46c1)](https://pypi.org/project/cognis-gasprofiler/) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/a641045662163522.svg)](https://github.com/cognis-digital/gasprofiler/actions) [![License: COCL 1.0](https://img.shields.io/badge/License-COCL%201.0-2b6cb0.svg)](LICENSE) [![Suite](https://img.shields.io/badge/Cognis-Neural%20Suite-6b46c1.svg)](https://github.com/cognis-digital) *Web3 与智能合约安全 — 链上安全与分析。*
``` pip install cognis-gasprofiler gasprofiler scan . # → prioritized findings in seconds ``` ## 使用说明 — 逐步指南 1. 安装 (Python 3.9+): pip install gasprofiler 2. 分析 Solidity 合约并打印每个函数的 gas 表: gasprofiler profile contracts/Token.sol 3. 为 CI 保存基线快照(支持通配符): gasprofiler profile "contracts/*.sol" --out .gas-baseline.json 4. 当任何函数相对于基线的退化超过容差时,使 PR 失败: gasprofiler check "contracts/*.sol" --baseline .gas-baseline.json --tolerance 0.05 5. 阅读输出:该表按估计的 gas 对函数进行排序,并标记 `UNBOUNDED` 循环;`check` 会打印退化/改进情况。使用 `--format json | jq .` 以便工具集成。退出代码:`0` 正常,`1` 发现无界循环(profile)或退化(check),`2` 使用/IO 错误。 ## 目录 - [为什么选择 gasprofiler?](#why) · [功能](#features) · [快速开始](#quick-start) · [示例](#example) · [架构](#architecture) · [AI 技术栈](#ai-stack) · [对比](#how-it-compares) · [集成](#integrations) · [随处安装](#install-anywhere) · [相关工具](#related) · [贡献](#contributing) ## 为什么选择 gasprofiler? 将 Gas-griefing DoS 作为一种安全类别,再加上能够在退化时使 PR 失败的 CI 基线 —— 融合了性能与安全,对广大开发者极具吸引力。 `gasprofiler` 是单一用途、可脚本化且可自托管的:将其指向目标,即可通过您的工作流已有的格式(表格 · JSON · SARIF)获取已排定优先级的结果,通过它来拦截 CI,并让 agent 通过 MCP 驱动它。
↑ 回到顶部
## 功能 - ✅ 分析源码 - ✅ 分析路径 - ✅ 构建快照 - ✅ 快照转为字典 - ✅ 加载快照 - ✅ 比较快照 - ✅ 可在 Linux/macOS/Windows · Docker · devcontainer 上运行 - ✅ 提供 Python, JavaScript, Go 和 Rust 移植版 (`ports/`)
↑ 回到顶部
## 快速开始 ``` pip install cognis-gasprofiler gasprofiler --version gasprofiler scan . # scan current project gasprofiler scan . --format json # machine-readable gasprofiler scan . --fail-on high # CI gate (non-zero exit) ```
↑ 回到顶部
## 示例 ``` $ gasprofiler scan . [HIGH ] GAS-001 example finding (./src/app.py) [MEDIUM ] GAS-002 another signal (./config.yaml) 2 findings · risk score 5 · 38ms ```
↑ 回到顶部
## 架构 ``` flowchart LR IN[input] --> P[gasprofiler
analyze + score] P --> OUT[report] ```
↑ 回到顶部
## 从任何 AI 技术栈中使用 `gasprofiler` 可以与所有流行的 AI 使用方式互操作: - **MCP server** — `gasprofiler mcp` (Claude Desktop, Cursor, Cognis.Studio, [uncensored-fleet](https://github.com/cognis-digital/uncensored-fleet)) - **OpenAI 兼容 / JSON** — 将 `gasprofiler scan . --format json` 通过管道传递给任何 agent 或 LLM - **LangChain · CrewAI · AutoGen · LlamaIndex** — 用一行代码将 CLI/JSON 封装为工具 - **CI / 脚本** — 为非 AI 流水线提供退出代码 + SARIF
↑ 回到顶部
## 对比 | | **Cognis gasprofiler** | Foundry gas snapshots | |---|:---:|:---:| | 可自托管,无需账户 | ✅ | 视情况而定 | | 单一命令,零配置 | ✅ | ⚠️ | | 用于 CI 的 JSON + SARIF | ✅ | 视情况而定 | | MCP 原生支持(AI agent) | ✅ | ❌ | | 多语言移植(JS/Go/Rust) | ✅ | ❌ | | 开源许可 | ✅ COCL | 视情况而定 | *秉承 **Foundry gas snapshots / hardhat-gas-reporter** 的精神,以 Cognis 的方式重新构建。漏掉了谁的致谢?提交一个 PR 吧。*
↑ 回到顶部
## 集成 接入您的技术栈:用于代码扫描的 **SARIF**,用于任何场景的 **JSON**,用于 AI agent 的 **MCP server**(`gasprofiler mcp`),以及用于 SIEM/Slack/Jira 的 webhook 转发器。参见 [`docs/INTEGRATIONS.md`](docs/INTEGRATIONS.md)。
↑ 回到顶部
## 安装 — 各种方式,各个平台 ``` pip install "git+https://github.com/cognis-digital/gasprofiler.git" # pip (works today) pipx install "git+https://github.com/cognis-digital/gasprofiler.git" # isolated CLI uv tool install "git+https://github.com/cognis-digital/gasprofiler.git" # uv pip install cognis-gasprofiler # PyPI (when published) docker run --rm ghcr.io/cognis-digital/gasprofiler:latest --help # Docker brew install cognis-digital/tap/gasprofiler # Homebrew tap curl -fsSL https://raw.githubusercontent.com/cognis-digital/gasprofiler/main/install.sh | sh ``` | Linux | macOS | Windows | Docker | 云平台 | |---|---|---|---|---| | `scripts/setup-linux.sh` | `scripts/setup-macos.sh` | `scripts/setup-windows.ps1` | `docker run ghcr.io/cognis-digital/gasprofiler` | [DEPLOY.md](docs/DEPLOY.md) (AWS/Azure/GCP/k8s) |
↑ 回到顶部
## 相关 Cognis 工具 - [`reentryx`](https://github.com/cognis-digital/reentryx) — 静态 + 符号化检测器,可标记 Solidity/Vyper 中的重入、跨函数和只读重入路径,并输出支持 CI 拦截的 SARIF。 - [`forkfuzz`](https://github.com/cognis-digital/forkfuzz) — 主网分叉的不变性模糊测试工具,针对实时状态和有状态序列重放您的合约,在部署前打破协议不变性。 - [`approvewarden`](https://github.com/cognis-digital/approvewarden) — 扫描任何钱包中危险的 ERC-20/721/1155 代币授权和无限额度,评估资产被盗风险并生成撤销交易。 - [`mevscope`](https://github.com/cognis-digital/mevscope) — 重放交易或地址历史,以归因三明治攻击、抢跑和尾跑的 MEV 提取,并进行每笔交易的损失核算。 - [`rugradar`](https://github.com/cognis-digital/rugradar) — 代币合约风险扫描器,在您盲目投资前检测蜜罐、隐藏的 mint/blacklist 函数、所有者后门以及未锁定的流动性。 - [`storagelens`](https://github.com/cognis-digital/storagelens) — 在代理升级期间对比和解码合约存储布局,以捕获存储冲突和未初始化插槽漏洞。 **探索全套工具 →** [🗂️ 全部 170+ 工具](https://github.com/cognis-digital/cognis-neural-suite) · [⭐ awesome-cognis](https://github.com/cognis-digital/awesome-cognis) · [🔗 cognis-sources](https://github.com/cognis-digital/cognis-sources) · [🤖 uncensored-fleet](https://github.com/cognis-digital/uncensored-fleet) · [🧠 engram](https://github.com/cognis-digital/engram)
↑ 回到顶部
## 互操作性 `{}` 与包含 300+ 工具的 Cognis 套件组合使用 — JSON 输入/输出以及共享的 OpenAI 兼容 `/v1` 骨干网络。参见 **[INTEROP.md](INTEROP.md)** 获取 套件图谱、组合模式和参考技术栈。 ## 许可证 在 **Cognis 开放协作许可证 (COCL) v1.0** 下提供源码 — 可免费用于个人、内部评估、研究和教育用途;**商业/生产环境使用需要获得许可证** (licensing@cognis.digital)。参见 [LICENSE](LICENSE)。
Cognis Digital · 包含 170+ 工具的 Cognis Neural Suite 之一 · Making Tomorrow Better Today
标签:Gas优化, Solidity, 以太坊, 可视化界面, 性能分析, 数据可视化, 日志审计, 智能合约, 请求拦截, 逆向工具