Agent skill

Reentrancy Patterns

by ccashwell in ccashwell/evm-cortex

Comprehensive reentrancy attack patterns and defenses for Solidity.

MITAuto-check passedSecurity

Install Reentrancy Patterns

skills CLI
$ npx skills add ccashwell/evm-cortex --skill reentrancy-patterns -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install ccashwell/evm-cortex reentrancy-patterns --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/ccashwell/evm-cortex.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/reentrancy-patterns .claude/skills/reentrancy-patterns && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
reentrancy-patterns
GitHub stars
131
Token cost
~1.9k tokens
SKILL.md length
209 words
Files
1
Skills in repo
89
Repo updated
First seen
Licence
MIT

At a glance

Comprehensive reentrancy attack patterns and defenses for Solidity.

  • Writing contracts with external calls
  • SKILL.md covers Single-Function Reentrancy, Cross-Function Reentrancy, Cross-Contract Reentrancy and Read-Only Reentrancy, plus 5 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Integrating tokens with callbacks (ERC-777

What it does

Reentrancy Patterns is an agent skill from ccashwell/evm-cortex. Comprehensive reentrancy attack patterns and defenses for Solidity. Use when writing contracts with external calls, integrating tokens with callbacks (ERC-777, ERC-1363), or auditing for reentrancy vulnerabilities. Covers all variants including read-only reentrancy.

Its SKILL.md is about 1.9k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Security, covering Smart contract auditing. It works with Solidity. The repository describes itself as: Ethereum protocol engineering squad for AI coding assistants. The licence is MIT.

When your agent uses it

  • Writing contracts with external calls
  • Integrating tokens with callbacks (ERC-777
  • Auditing for reentrancy vulnerabilities

Example prompts

  • “/reentrancy-patterns”

What it can do on your machine

Read from SKILL.md and the folder at commit f8f3301. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are solidity).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Reentrancy Patterns loads about 1.9k tokens when it runs. Until then it costs about 72 tokens; SKILL.md has 209 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~72
When it runs · the whole SKILL.md, loaded when a task matches
~1.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from ccashwell/evm-cortex at commit f8f3301, republished under its MIT licence (© ccashwell). 209 words, ~1,850 tokens.

Download SKILL.mdSave it as .claude/skills/reentrancy-patterns/SKILL.md (or your agent's skills folder).
name
reentrancy-patterns
description
Comprehensive reentrancy attack patterns and defenses for Solidity. Use when writing contracts with external calls, integrating tokens with callbacks (ERC-777, ERC-1363), or auditing for reentrancy vulnerabilities. Covers all variants including read-only reentrancy.

Reentrancy Patterns

Single-Function Reentrancy

The classic variant. An external call re-enters the same function before state is updated.

solidity
// VULNERABLE: state update after external call
contract VulnerableVault {
    mapping(address => uint256) public balances;

    function withdraw(uint256 amount) external {
        require(balances[msg.sender] >= amount);

        (bool success,) = msg.sender.call{value: amount}(""); // ← re-entry point
        require(success);

        balances[msg.sender] -= amount; // ← too late, attacker already re-entered
    }
}

// FIXED: checks-effects-interactions
contract FixedVault {
    mapping(address => uint256) public balances;

    function withdraw(uint256 amount) external {
        if (balances[msg.sender] < amount) revert InsufficientBalance();

        balances[msg.sender] -= amount; // effect BEFORE interaction

        (bool success,) = msg.sender.call{value: amount}("");
        if (!success) revert TransferFailed();
    }
}

Cross-Function Reentrancy

Attacker re-enters a different function that reads stale state.

solidity
// VULNERABLE: withdraw and transfer share state
contract Vulnerable {
    mapping(address => uint256) public balances;

    function withdraw(uint256 amount) external {
        require(balances[msg.sender] >= amount);
        (bool success,) = msg.sender.call{value: amount}(""); // ← attacker calls transfer() here
        require(success);
        balances[msg.sender] -= amount;
    }

    function transfer(address to, uint256 amount) external {
        require(balances[msg.sender] >= amount);
        balances[msg.sender] -= amount; // uses stale balance
        balances[to] += amount;
    }
}

Defense: ReentrancyGuard on all functions sharing state, plus CEI ordering.

Cross-Contract Reentrancy

Attacker re-enters a different contract that reads stale state from the first.

solidity
// Contract A: Lending pool that updates user balance
// Contract B: Reads user balance from A for collateral check
// Attack: Borrow from A → callback during withdrawal → B reads stale (higher) balance → over-borrow

// Defense: ReentrancyGuard + cross-contract state synchronization
// OR: use a protocol-wide reentrancy lock
Protocol-Wide Reentrancy Lock
solidity
contract ReentrancyLock {
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;
    uint256 private _status = _NOT_ENTERED;

    error ReentrancyGuard_ReentrantCall();

    modifier globalNonReentrant() {
        if (_status == _ENTERED) revert ReentrancyGuard_ReentrantCall();
        _status = _ENTERED;
        _;
        _status = _NOT_ENTERED;
    }
}

// All contracts in the protocol inherit from or check the same lock
contract LendingPool is ReentrancyLock {
    function borrow(uint256 amount) external globalNonReentrant { ... }
}

contract CollateralManager is ReentrancyLock {
    function checkCollateral(address user) external globalNonReentrant { ... }
}

Read-Only Reentrancy

The most subtle variant. A view function returns stale state during a callback, and a different protocol reads that stale state.

solidity
// Scenario: Curve pool with removeLiquidity that triggers a callback
// 1. Attacker calls removeLiquidity() on Curve pool
// 2. Curve sends ETH to attacker (callback)
// 3. During callback, pool's internal accounting is stale
// 4. Attacker calls a lending protocol that reads Curve's get_virtual_price()
// 5. Virtual price is inflated (stale state) → attacker borrows more than they should

// Defense in the reading protocol:
function getCollateralValue(address pool) internal view returns (uint256) {
    // Check if the Curve pool is mid-operation
    // Many Curve pools have a reentrancy lock that can be checked
    try ICurvePool(pool).claim_admin_fees() {
        // If this succeeds, pool is not locked — safe to read
    } catch {
        revert PoolReentrant();
    }

    return ICurvePool(pool).get_virtual_price();
}

Key insight: Read-only reentrancy doesn't attack the contract making the callback. It attacks other contracts that read the first contract's stale view functions.

ERC-777 Callback Reentrancy

ERC-777 tokens call tokensReceived() on the recipient, creating a reentrancy vector on every transfer.

solidity
// VULNERABLE: ERC-777 token triggers callback on transfer
function deposit(uint256 amount) external {
    shares[msg.sender] += calculateShares(amount);
    IERC777(token).send(address(this), amount, ""); // callback before state finalized
}

// SAFE: use ReentrancyGuard + CEI
function deposit(uint256 amount) external nonReentrant {
    uint256 shareAmount = calculateShares(amount);
    shares[msg.sender] += shareAmount;
    IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
    emit Deposited(msg.sender, amount, shareAmount);
}

ERC-1363 Callback Reentrancy

Similar to ERC-777 — onTransferReceived() is called on the recipient.

solidity
// Any token implementing ERC-1363 transferAndCall will trigger onTransferReceived
// Always use ReentrancyGuard when accepting arbitrary tokens

OpenZeppelin ReentrancyGuard

solidity
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

contract Vault is ReentrancyGuard {
    // Apply to ALL functions that:
    // 1. Make external calls
    // 2. Share state with functions that make external calls
    // 3. Are called by other protocols that might read your state

    function deposit(uint256 amount) external nonReentrant {
        // safe from reentrancy
    }

    function withdraw(uint256 amount) external nonReentrant {
        // safe from reentrancy
    }

    // View functions don't need nonReentrant unless read-only reentrancy is a concern
    // In that case, add a reentrancy check without the mutex reset:
    function getSharePrice() external view returns (uint256) {
        // Consider if stale reads during reentrancy could be exploited
    }
}

Transient Storage Reentrancy Lock (EIP-1153)

Post-Cancun, use transient storage for cheaper reentrancy locks (~100 gas vs ~2,900 gas).

solidity
contract TransientReentrancyGuard {
    bytes32 constant REENTRANCY_SLOT = keccak256("reentrancy.lock");

    modifier nonReentrant() {
        assembly {
            if tload(REENTRANCY_SLOT) { revert(0, 0) }
            tstore(REENTRANCY_SLOT, 1)
        }
        _;
        assembly {
            tstore(REENTRANCY_SLOT, 0)
        }
    }
}

Reentrancy Checklist

  • All functions with external calls have nonReentrant
  • CEI ordering followed even with ReentrancyGuard (defense in depth)
  • Cross-function reentrancy: all functions sharing state are guarded
  • Cross-contract reentrancy: protocol-wide lock if contracts share state
  • Read-only reentrancy: view functions considered for stale state exposure
  • ERC-777/ERC-1363 tokens: callbacks accounted for in deposit/transfer flows
  • Transient storage lock considered for post-Cancun deployments

© ccashwell, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/reentrancy-patterns of ccashwell/evm-cortex.

Open the folder on GitHubat commit f8f3301

Compare with similar skills

Reentrancy Patterns next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Reentrancy Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Reentrancy Patterns this skillccashwell/evm-cortex131—~1.9kAutomated safety check: PassMIT
Ethereum Smart Contract Vulnerability Analysistradecatlabs/vibe-coding-cn17k1 repos~738Automated safety check: PassApache-2.0
Reentrancy Auditoralt-research2/SolidityGuard104—~1.8kAutomated safety check: PassCustom licence
Smart Contract Auditforefy/.context1521 repos~5.1kAutomated safety check: PassMIT
Smart Contract Auditelophanto/EloPhanto106—~2.7kAutomated safety check: PassCustom licence
Securityaustintgriffith/ethskills294—~4.9kAutomated safety check: PassNone

Similar skills

  • Runs Slither and Mythril against Solidity contracts to find reentrancy, overflow and access-control bugs before mainnet deployment, then triages and reports findings.

    17k GitHub starsUsed in 1 repo~738 tokens
    SecurityAuto-check passed
  • Reentrancy Auditor

    alt-research2/SolidityGuard

    Deep reentrancy vulnerability analysis for Solidity contracts.

    104 GitHub stars~1.8k tokensUpdated 3 mo ago
    SecurityAuto-check passed
  • Smart Contract Audit

    forefy/.context

    Comprehensive smart contract security audit framework with multi-expert analysis.

    152 GitHub starsUsed in 1 repo~5.1k tokens
    SecurityAuto-check passed
  • Smart Contract Audit

    elophanto/EloPhanto

    A skill your agent uses when reviewing a Solidity, Vyper, or Rust (Solana/Anchor) smart contract for paid audit work or pre-launch sanity check.

    106 GitHub stars~2.7k tokensUpdated 8 days ago
    SecurityAuto-check passed
  • Security

    austintgriffith/ethskills

    Solidity security patterns, common vulnerabilities, and pre-deploy audit checklist.

    294 GitHub stars~4.9k tokensUpdated 1 mo ago
    SecurityAuto-check passed
  • Web3 Smart Contract Audit

    awarexone/Agentic-Bug-Hunter

    Guides smart contract audits and bounty target selection with ten DeFi bug classes, kill signals, a Foundry PoC template and grep patterns.

    5.3k GitHub starsUsed in 3 repos~4.5k tokens
    SecurityAuto-check passed

More from ccashwell/evm-cortex

All 89 skills in this repo
  • Xray Pre Audit

    ccashwell/evm-cortex

    A skill your agent uses when preparing for a security audit, performing reconnaissance on a new codebase, or creating a protocol overview.

    131 GitHub stars~25k tokensUpdated 9 days ago
    Auto-check passed
  • Aave Integration

    ccashwell/evm-cortex

    A skill your agent uses when integrating with Aave V3 for lending, borrowing, flash loans, or building on top of Aave markets.

    131 GitHub stars~1.3k tokensUpdated 9 days ago
    Auto-check passed
  • Access Control Patterns

    ccashwell/evm-cortex

    Access control design patterns for Solidity protocols. An agent skill from ccashwell/evm-cortex.

    131 GitHub stars~1.8k tokensUpdated 9 days ago
    Auto-check passed
  • Anvil Patterns

    ccashwell/evm-cortex

    A skill your agent uses when running a local Ethereum node with Anvil.

    131 GitHub stars~1.3k tokensUpdated 9 days ago
    Auto-check passed
  • Audit Breadth Scan

    ccashwell/evm-cortex

    A skill your agent uses when performing systematic breadth-first review of all contracts during a security audit.

    131 GitHub stars~1.4k tokensUpdated 9 days ago
    Auto-check passed
  • Audit Depth Analysis

    ccashwell/evm-cortex

    A skill your agent uses when performing deep analysis of specific findings or high-risk areas during a security audit.

    131 GitHub stars~1.6k tokensUpdated 9 days ago
    Auto-check passed

Works with

Questions about Reentrancy Patterns

What does Reentrancy Patterns do?

Comprehensive reentrancy attack patterns and defenses for Solidity. Reentrancy Patterns is an agent skill from ccashwell/evm-cortex. Comprehensive reentrancy attack patterns and defenses for Solidity.

When should I use Reentrancy Patterns?

Reentrancy Patterns fits situations like: writing contracts with external calls; integrating tokens with callbacks (ERC-777; auditing for reentrancy vulnerabilities.

How do I install Reentrancy Patterns in Claude Code?

Run `npx skills add ccashwell/evm-cortex --skill reentrancy-patterns -a claude-code`. Or copy the skill folder (skills/reentrancy-patterns in ccashwell/evm-cortex) into .claude/skills/reentrancy-patterns in your project. Claude Code loads it when a task matches its description.

How do I install Reentrancy Patterns in Codex?

Run `npx skills add ccashwell/evm-cortex --skill reentrancy-patterns -a codex`. Or copy the skill folder (skills/reentrancy-patterns in ccashwell/evm-cortex) into .agents/skills/reentrancy-patterns in your project. Codex loads it when a task matches its description.

Can I use Reentrancy Patterns in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add ccashwell/evm-cortex --skill reentrancy-patterns -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/reentrancy-patterns, .gemini/skills/reentrancy-patterns, .github/skills/reentrancy-patterns and .opencode/skills/reentrancy-patterns in your project.

What does Reentrancy Patterns need to run?

SKILL.md names no scripts, command-line tools or credentials: Reentrancy Patterns is instructions for the agent only.

Does Reentrancy Patterns access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Reentrancy Patterns safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Reentrancy Patterns use?

Reentrancy Patterns is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Reentrancy Patterns use?

About 1.9k tokens (SKILL.md is roughly 7.4k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Reentrancy Patterns?

Skills that share tags, products or a category with Reentrancy Patterns: Ethereum Smart Contract Vulnerability Analysis (tradecatlabs/vibe-coding-cn, 17k stars), Reentrancy Auditor (alt-research2/SolidityGuard, 104 stars), Smart Contract Audit (forefy/.context, 152 stars) and Smart Contract Audit (elophanto/EloPhanto, 106 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Reentrancy Patterns?

ccashwell (a GitHub user) maintains it in ccashwell/evm-cortex, which has 131 GitHub stars. The repository holds 89 skills in this directory. The repository was last updated on September 30, 2026.

Source: ccashwell/evm-cortex on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.