semgrep-solidity

Write and run custom Semgrep rules to detect Solidity smart contract vulnerabilities.

6|20|Updated Mar 14, 2026
One-click install
npx skills add https://github.com/andresdefi/cryptoskills --skill semgrep-solidity-andresdefi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: semgrep-solidity
Source: https://github.com/andresdefi/cryptoskills/tree/main/skills/semgrep-solidity
Command: npx skills add https://github.com/andresdefi/cryptoskills --skill semgrep-solidity-andresdefi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires semgrep, and includes references (resource) components.

What problem does it solve? Generic static analyzers miss project-specific bugs and anti-patterns in Solidity code, and LLMs often hallucinate Semgrep's Solidity capabilities. This Skill provides accurate guidance for writing custom Semgrep detection rules, taint tracking, autofixes, and CI/CD integration tailored to smart contract security. ## Core Features & Use Cases - Custom Rule Authoring: Write YAML rules using patterns, metavariables, pattern-either/not/inside operators, and taint tracking to detect reentrancy, tx.origin auth, unsafe delegatecall, unchecked return values, and unsafe downcasts. - Community Rulesets & Testing: Run the decurity/semgrep-smart-contracts ruleset, validate rules with annotated ruleid:/ok: test files, and apply autofix replacements. - CI/CD Integration: Set up GitHub Actions with SARIF upload, pre-commit hooks, Makefile targets, and differential PR scanning. - Use Case: While auditing a DeFi vault, write a taint-tracking rule that traces user-controlled addresses into delegatecall sinks, test it against annotated Solidity fixtures, then gate pull requests on ERROR-severity findings in GitHub Actions. ## Quick Start Ask the agent to write a Semgrep rule that detects block.timestamp used as randomness in your contracts directory and test it with semgrep --test.

Frequently Asked Questions about semgrep-solidity

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a custom Semgrep rule for Solidity?

Define a YAML rule with a unique id, a pattern using metavariables like $X and ellipsis, a message, languages: [solidity], and a severity. Combine conditions with patterns, pattern-either, pattern-not, and pattern-inside, then validate it with semgrep --test against an annotated .sol file.

How do I detect reentrancy with Semgrep taint tracking?

Set mode: taint and define pattern-sources (e.g., external function parameters) and pattern-sinks (e.g., $ADDR.call{value: ...}(...)), optionally adding pattern-sanitizers for validation checks. Semgrep then traces data flow from untrusted input to the dangerous call.

Semgrep vs Slither for smart contract security?

Slither ships 90+ built-in detectors with deep Solidity understanding of inheritance and control flow, while Semgrep excels at custom YAML rules for your project's specific patterns and fast CI gating. The recommended workflow uses both together.

Does Semgrep officially support Solidity?

Solidity support is community-driven via the tree-sitter-solidity parser, not officially maintained by Semgrep Inc. It works well for pattern matching but can lag behind bleeding-edge Solidity syntax, so keep Semgrep updated.

Why does my Semgrep rule match nothing on Solidity code?

The pattern's AST structure likely differs from the code—common causes are missing ellipsis between statements, visibility mismatches like external versus public, or wrong languages setting. Debug with semgrep --debug or --verbose to see matching details.

How do I run Semgrep in GitHub Actions for Solidity?

Install Semgrep via pip, clone the decurity/semgrep-smart-contracts ruleset, run semgrep with --sarif output, and upload results with github/codeql-action/upload-sarif. Gate merges by rerunning with --error --severity ERROR.