Skip to main content

solidity-fcg-tool

solidity-fcg-tool packages a Solidity static analysis workflow that extracts module/function source code and call graph data. The first release uses Slither under the hood, while keeping the analysis engine pluggable so Tree-sitter, Solar, or other backends can be added later.

Features

  • Engine abstraction – core.engine_base.AnalysisEngine defines the contract for all engines and allows hot-swapping implementations.
  • Rich data model – function source, parameters, state variable access, locations, and call relationships.
  • Service layer – services.query.QueryService exposes Python APIs plus a JSON-emitting CLI for downstream tooling (e.g., AI assistants).
  • Extensible registry – register additional engines without touching higher-level services.

Installation

Once published, install via pip:

pip install solidity-fcg-tool

For local development:

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e .[dev]

A compatible solc binary is required. Install with py-solc-x or reuse an existing compiler on your system.

CLI Usage

Function source lookup

python -m solidity_fcg_tool \
  --project samples/SimpleToken.sol \
  --engine slither \
  query \
  --contract SimpleToken \
  --function "transfer(address,uint256)"

Example (truncated) response:

{
  "contract": "SimpleToken",
  "function": "transfer(address,uint256)",
  "source": "    function transfer(address to, uint256 amount) external returns (bool) {\n        _performTransfer(msg.sender, to, amount);\n        return true;\n    }\n",
  "location": {
    "file": "/absolute/path/to/solidity-fcg-tool/samples/SimpleToken.sol",
    "start_line": 17,
    "end_line": 20
  },
  "parameter": [
    { "name": "to", "type": "address" },
    { "name": "amount", "type": "uint256" }
  ],
  "calls": [
    {
      "file": "/absolute/path/to/solidity-fcg-tool/samples/SimpleToken.sol",
      "module": "SimpleToken",
      "function": "_performTransfer(address,address,uint256)"
    }
  ]
}

Call graph extraction

python -m solidity_fcg_tool \
  --project samples/SimpleToken.sol \
  call-graph \
  --contract SimpleToken

Sample output:

{
  "edges": [
    {
      "caller": "SimpleToken.transfer(address,uint256)",
      "callee": "SimpleToken._performTransfer(address,address,uint256)"
    }
  ],
  "metadata": {
    "engine": "slither"
  }
}

Python API

from solidity_fcg_tool.services.query import get_function_source

result = get_function_source(
    project_path="samples/SimpleToken.sol",
    contract="SimpleToken",
    function_signature="transfer(address,uint256)",
)
print(result["source"])

For repeated queries, keep the service instance alive:

from solidity_fcg_tool.services.query import create_service

service = create_service("samples/SimpleToken.sol")
info = service.get_function_source("SimpleToken", "transfer(address,uint256)")
edges = service.get_call_graph(caller_contract="SimpleToken")

Project Layout

  • solidity_fcg_tool/core – engine abstractions and shared models.
  • solidity_fcg_tool/engines – registry and the Slither-backed engine.
  • solidity_fcg_tool/services – public query service and helpers.
  • samples/ – example Solidity contracts.
  • tests/ – pytest-based regression suite.

Extending Engines

  1. Implement AnalysisEngine, filling in load() and (optionally) _iter_call_graph_impl().
  2. Populate ProjectModel / ContractInfo / FunctionInfo with the new engine’s data.
  3. Register the engine via register_engine("my-engine", MyEngineClass).
  4. Use it through --engine my-engine (CLI) or create_service(..., engine_name="my-engine").

Release Notes

See the CHANGELOG for a detailed history of updates.

Development & Tests

pytest

If Slither or solc is missing, API/CLI tests will be skipped with an informative message.

For more details in Chinese, please read README_zh.md.

Publishing

To build and upload a release:

pip install -e .[dev]
python -m build
python -m twine check dist/*
python -m twine upload dist/*

Metadata

Release files for solidity-fcg-tool 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for solidity-fcg-tool 0.1.0
File Size Uploaded
solidity_fcg_tool-0.1.0.tar.gz 20.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for solidity-fcg-tool 0.1.0
File Interpreter ABI Platform
solidity_fcg_tool-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.8 kB

Release files / solidity_fcg_tool-0.1.0.tar.gz

Download URL solidity_fcg_tool-0.1.0.tar.gz
Size 20.5 kB
Tags Source
SHA-256 checksum
How to use checksums
594fb8ca128eb323be3043b6be02246e89331627c74f15be8396596389c344f7
BLAKE2b-256 checksum
How to use checksums
0848c59d81ad5294efe7d70b688e3cdebbc6379ca6eed8c3596f3e88e67085a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Release files / solidity_fcg_tool-0.1.0-py3-none-any.whl

Download URL solidity_fcg_tool-0.1.0-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af25598aac88ecf4fa67aa59a4538a45d20fef61ca39c84352d6faf8a82fdc33
BLAKE2b-256 checksum
How to use checksums
6c0fecb7b9296da0665f50be536349fa084ca67ba2cfbaae44cdcf46550b1e69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page