Skip to content

Parse function natspec and add a missing-natspec detector - #3083

Open
ChrisJr404 wants to merge 1 commit into
crytic:masterfrom
ChrisJr404:detector/missing-natspec
Open

Parse function natspec and add a missing-natspec detector#3083
ChrisJr404 wants to merge 1 commit into
crytic:masterfrom
ChrisJr404:detector/missing-natspec

Conversation

@ChrisJr404

Copy link
Copy Markdown

Refs #1916. Functions now keep their natspec text so a detector can flag public/external functions that have none.

Today Function only carries a has_documentation bool the parser flips on, and the comment next to it says "To be improved". This wires it up properly. The solc parser already sees the documentation node solc emits per function, so I pull the actual text out of it (plain string on old solc, {"text": ...} on newer) and store it. has_documentation becomes a property derived from whether that text is present, so the existing caller (the natspec-generation tool) keeps working. Same treatment on the vyper side: doc_string now stores the text instead of just setting a flag.

The new missing-natspec detector (informational) walks derived contracts and reports public/external functions with no natspec. Constructors, fallback/receive, and internal/private functions are skipped to keep it quiet, and dependency code is ignored.

For tests I added test_function_comments to the parsing unit tests, which compiles a contract with a documented and an undocumented function and checks both the extracted text and the derived bool. There's also the usual e2e detector regression: a contract mixing a documented external fn, undocumented external/public fns, an internal fn, a constructor and a receive, plus the generated snapshot (only the two undocumented public/external fns get reported). Ran the detector e2e and the code-comments unit tests locally, both pass, ruff clean.

The issue also mentions events, errors and state variables. I kept this to functions so it stays a focused replacement of the existing stub. Happy to follow up on the rest if you'd like it in the same detector.

@ChrisJr404
ChrisJr404 requested a review from smonicas as a code owner August 18, 2026 03:34
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants