Automatically audit smart contracts on every pull request using 4 AI agents (SecurityAuditor, EconomicAttacker, GasOptimizer, AuditReporter) via the SwarmX API.
name: Contract Audit
on:
pull_request:
paths:
- 'contracts/**/*.sol'
permissions:
contents: read
pull-requests: write
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: SolTwizzy/swarmx-audit@v1
with:
files: 'contracts/**/*.sol'
fail-on-critical: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}| Input | Required | Default | Description |
|---|---|---|---|
files |
No | **/*.sol |
Glob pattern for contract files to audit |
language |
No | solidity |
Contract language (solidity or rust) |
api-url |
No | https://api.swarmx.io |
SwarmX API URL |
fail-on-critical |
No | true |
Fail the check if critical issues found |
wallet-private-key |
No | -- | Solana private key for paid audits (uses free tier if not set) |
| Output | Description |
|---|---|
risk-score |
Overall risk score (0-100) |
findings-count |
Total number of findings |
report-url |
URL to the PR comment with the full audit report |
The action posts a PR comment with a structured audit report:
- Summary table with risk scores and finding counts per file
- Security findings with severity levels (critical, high, medium, low)
- Economic attack vectors with attack scenario descriptions
- Gas optimizations with estimated savings
The check fails if any critical-severity security issue is found (configurable via fail-on-critical).
By default the action uses the SwarmX free tier (10 calls/day per IP). For higher volume:
- Add your Solana private key as a repository secret:
SWARMX_WALLET_KEY - Reference it in your workflow:
- uses: SolTwizzy/swarmx-audit@v1
with:
files: 'contracts/**/*.sol'
wallet-private-key: ${{ secrets.SWARMX_WALLET_KEY }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}Each paid audit costs $0.10 USDC, settled via the x402 protocol.
- uses: SolTwizzy/swarmx-audit@v1
with:
files: 'programs/**/*.rs'
language: rustThis action's dist/index.js is built with @vercel/ncc. To rebuild after modifying src/index.ts:
cd github-action
npm install
npm run buildThis bundles all dependencies into a single dist/index.js file that GitHub Actions can execute directly. The compiled dist/ directory must be committed to the repository for the action to work.
- Finds contract files matching the glob pattern
- Sends each file to the SwarmX
/x402/contract-auditendpoint - 4 AI agents analyze the contract in parallel (ConcurrentWorkflow):
- SecurityAuditor -- reentrancy, overflow, access control, etc.
- EconomicAttacker -- flash loans, sandwich attacks, oracle manipulation
- GasOptimizer -- storage patterns, loop efficiency, calldata usage
- AuditReporter -- synthesizes findings into a structured risk report
- Posts the audit report as a PR comment (updates existing comment on re-runs)
- Fails the check if critical issues are found
MIT