Solidity function call graph and source extraction toolkit with pluggable engines.
Project description
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.AnalysisEnginedefines 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.QueryServiceexposes 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
solcbinary is required. Install withpy-solc-xor 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
- Implement
AnalysisEngine, filling inload()and (optionally)_iter_call_graph_impl(). - Populate
ProjectModel/ContractInfo/FunctionInfowith the new engine’s data. - Register the engine via
register_engine("my-engine", MyEngineClass). - Use it through
--engine my-engine(CLI) orcreate_service(..., engine_name="my-engine").
Release Notes
See the CHANGELOG for a detailed history of updates.
Development & Tests
pytest
If Slither or
solcis 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/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file solidity_fcg_tool-0.1.0.tar.gz.
File metadata
- Download URL: solidity_fcg_tool-0.1.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
594fb8ca128eb323be3043b6be02246e89331627c74f15be8396596389c344f7
|
|
| MD5 |
e024c02d32f371d43dabc29f85f14dd8
|
|
| BLAKE2b-256 |
0848c59d81ad5294efe7d70b688e3cdebbc6379ca6eed8c3596f3e88e67085a7
|
File details
Details for the file solidity_fcg_tool-0.1.0-py3-none-any.whl.
File metadata
- Download URL: solidity_fcg_tool-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af25598aac88ecf4fa67aa59a4538a45d20fef61ca39c84352d6faf8a82fdc33
|
|
| MD5 |
e9a4f89272bb6e8b2bea5a54edea5752
|
|
| BLAKE2b-256 |
6c0fecb7b9296da0665f50be536349fa084ca67ba2cfbaae44cdcf46550b1e69
|