sc-ingest
Skill1 starsChanged 5 months agoMITView on GitHub
Stage 1 of the ProofHound smart-contract audit pipeline. Deterministically chunks a Solidity codebase into per-function semantic units with storage read/write sets, external/internal calls, modifiers, access-control, and exact source locations. Produces .audit/chunks/*.json and .audit/manifest.json with a function-coverage guarantee that every declared function maps to exactly one chunk. Use before sc-map, sc-graph, sc-hypothesize.
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 6 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 34
If chunk IDs change between runs, the dependency graph, hypotheses, and findings all break.
- Very specific: line 45
Check whether solc is available: solc --version.
- Distinctive: line 58
Default behavior excludes tests, scripts, and third-party dependencies from the audit set (they are tagged, not chunked, unless flags are …
- Very specific: line 68
If it prints MISMATCH or exits non-zero, stop and investigate before proceeding.
- Distinctive: line 76
Read 2–3 representative chunks (especially the most complex external functions) and confirm:
- Very specific: line 82
If a chunk has a warnings entry (e.g.
- Distinctive: line 91
Never rewrite IDs, source spans, or hashes during enrichment.
- Very specific: line 128
No silently-skipped in-scope .sol files (cross-check Glob vs manifest.files).
- Very specific: line 129
Every chunk has a non-empty source and a source_hash.
- Distinctive: line 131
If any gate fails, the downstream audit is unsound — fix ingestion first.
- Distinctive: line 141
Decimals/type inference: read/write detection is name-based, not type-checked.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
sc-ingest — Semantic Chunker (Pipeline Stage 1)
Splits a Solidity codebase into semantic chunks — one per function, modifier,
constructor, fallback, receive, plus one __state__ chunk per contract for its
storage layout. Each chunk is self-describing so that later stages never need to
re-read whole files: they read chunks and the dependency graph instead. This is
how the pipeline keeps the context window small while reasoning about a large
codebase — the chunk bank is the "one big context file", normalized and
machine-readable.
When to Use
- Starting an audit of a Solidity / EVM codebase (Foundry, Hardhat, plain
.sol). - The orchestrator (
sc-audit) calls this first. - User says: "chunk this codebase", "build the audit context", "ingest the contracts".
Announce
Begin with: "I'm using the sc-ingest skill to chunk this codebase into the audit context bank..."
Why deterministic (read before changing anything)
Downstream skills reference chunks by stable ID (Contract.func(arg1,arg2)).
If chunk IDs change between runs, the dependency graph, hypotheses, and findings
all break. The chunker is therefore a deterministic script — do not replace it
with ad-hoc LLM chunking. LLM judgement is applied later (sc-map enrichment),
never to the cut points themselves.
Workflow
1. Locate the project & toolchain
- Confirm the target directory holds
.solfiles (Glob "**/*.sol"). - Detect Foundry (
foundry.toml,lib/,remappings.txt) or Hardhat (hardhat.config.*,node_modules/). Notesrc/,contracts/layout. - Check whether
solcis available:solc --version. If present, you may pass--use-solcfor an extra high-fidelity AST dump (optional; the chunker works fully without it).
2. Run the chunker
python skills/sc-ingest/scripts/chunk_solidity.py <project_dir>
# options:
# --out <dir> default <project_dir>/.audit
# --use-solc also dump solc --ast-compact-json per file (if solc present)
# --include-tests include *.t.sol / *.s.sol (default: excluded from audit set)
# --include-deps include lib/ node_modules/ dependencies (default: excluded)Default behavior excludes tests, scripts, and third-party dependencies from the audit set (they are tagged, not chunked, unless flags are passed). Audit in-scope code first; pull in dependencies only when a hypothesis crosses into them.
3. Enforce the coverage gate (MANDATORY)
The script prints a coverage line and exits non-zero on mismatch:
coverage: 41/41 functions chunked (OK)- If it prints
MISMATCHor exits non-zero, stop and investigate before proceeding. A function that did not chunk is a function that will never be audited. Readmanifest.json→coverage, find the offending file, and check for unusual syntax (assembly-heavy, exotic formatting, parse-defeating macros). - Open
manifest.jsonand sanity-checkcounts.contractsagainst what you see in the repo. A contract count of 0 means the source layout wasn't found.
4. Spot-check extraction quality
Read 2–3 representative chunks (especially the most complex external functions) and confirm:
storage_reads/storage_writeslook right.external_callscaptured the real calls.access_controlpicked up the privilege modifiers.tagsinclude the expected signals (see Tag Vocabulary below). If a chunk has awarningsentry (e.g. inline assembly), note it — those chunks need extra human/LLM attention later because heuristics are weaker there.
5. (Optional) Semantic enrichment
The script's read/write/call sets are heuristic (extraction: "heuristic").
You MAY enrich a chunk's JSON in place (set extraction: "llm-enriched") when:
- A chunk has inline assembly and you can determine the real storage touched.
- An external call was missed because it went through a function pointer or
using X for Ylibrary binding. Never rewrite IDs, source spans, or hashes during enrichment.
Output Artifacts
.audit/
manifest.json # index: files, contracts, inheritance, state vars, coverage
chunks/<sanitized-id>.json # one file per chunk
ast/<file>.ast.json # only with --use-solc, if solc presentThe chunk schema is documented in templates/chunk.schema.json; the manifest in
templates/manifest.schema.json. Full field reference in reference.md.
Tag Vocabulary (the signals downstream stages route on)
| tag | meaning |
externally-callable | public/external function — an attack entry point |
unprivileged-reachable | externally-callable with no access-control modifier |
access-controlled | guarded by an owner/role/governance modifier |
writes-storage | mutates contract state |
read-only | view/pure |
has-external-call | calls out to another address/contract |
low-level-call | uses .call/.delegatecall/.staticcall/.transfer/.send |
reentrancy-surface | external call and storage write and no reentrancy guard |
reentrancy-guarded | protected by a nonReentrant-style modifier |
payable | accepts ETH |
pausable | guarded by a whenNotPaused-style modifier |
test-or-mock / script / dependency | out of primary audit scope |
duplicate-or-overload-id | ID collision (overload); disambiguated with #N |
reentrancy-surface and unprivileged-reachable are the highest-signal tags for
stage 4 (hypothesis generation) — they mark unguarded, state-mutating entry
points that make external calls.
Coverage & Quality Gate (the contract this skill must honor)
MANDATORY before reporting stage 1 complete:
coverage.all_functions_covered == trueinmanifest.json.counts.contracts > 0and matches the visible source layout.- No silently-skipped in-scope
.solfiles (cross-checkGlobvsmanifest.files). - Every chunk has a non-empty
sourceand asource_hash.
If any gate fails, the downstream audit is unsound — fix ingestion first.
Known Limitations (documented honestly; surfaced as chunk warnings where detectable)
- Inline assembly: storage reads/writes inside
assembly {}blocks are not fully resolved → chunk carries a warning. - Function pointers /
using ... for: calls dispatched through these may be classified as internal or missed. - Inheritance shadowing: a
__state__chunk lists a contract's own declarations; inherited storage is recorded viainherits_fromand resolved in sc-graph, not here. - Decimals/type inference: read/write detection is name-based, not type-checked. Treat as a strong hint, not proof.
- Overloaded functions: same canonical signature ⇒ later ones get
#Nsuffix and aduplicate-or-overload-idtag.
These are intentional v1 trade-offs: determinism and offline operation over a full type-checker. sc-graph and sc-map layer semantic resolution on top.
Handoff
On success, tell the orchestrator: chunk count, contract count, coverage = OK,
and the location of .audit/. Next stage: sc-map (build project-map.md).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

