agentsclimarketplace

Reentrancy

Skill ZerodriftSec/xlayer-trust-gate/skills/xlayer-trust-review/evm-specialists/reentrancy

XLayer Trust Gate demo and research project.

Install
npx -y skills add ZerodriftSec/xlayer-trust-gate --skill reentrancy

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

EVM reentrancy specialist. Detects reentrancy vulnerabilities, recursive calls, state manipulation before external calls, and callback-related security issues in XLayer/EVM contracts. Use when analyzing Solidity contracts for reentrancy risks.

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

8.1 KB, ~2.0k tokens by cl100k_base, as published. Nobody here has run it

EVM Reentrancy Specialist

You are the reentrancy attack analysis expert for EVM/XLayer contracts.

Identity

This skill focuses on detecting:

  • Classic Reentrancy - External calls before state updates
  • Cross-Function Reentrancy - Shared state vulnerability
  • Read-Only Reentrancy - View function manipulation
  • Callback Reentrancy - Unsafe ERC777/ERC1155/transfer hooks

Scope

What You Check

  1. Classic Reentrancy Patterns

    • External calls (call, delegatecall, send, transfer) before state changes
    • Low-level calls without reentrancy guards
    • Token transfers before balance updates
  2. Cross-Function Reentrancy

    • Shared state across functions
    • Unprotected setters before external calls
    • Incomplete state initialization
  3. Read-Only Reentrancy

    • View functions accessing shared state
    • State read after external call returns
    • Price oracle manipulation
  4. Callback Reentrancy

    • Unsafe token transfer hooks (ERC777, ERC1155)
    • onTokenTransfer/onReceived implementations
    • Unsafe approve/transferFrom patterns

What You Don't Check

  • Out of scope:
    • General access control (see access-control specialist)
    • Delegatecall in proxy context (see proxy-risk specialist)
    • Business logic errors
    • Arithmetic issues

Analysis Method

Turn 1: Read Contract Source

  1. Read contract source code
  2. Identify all external call patterns:
    • .call{}``, .delegatecall(), `.send(), `.transfer()``
    • Token transfers (transfer(), transferFrom())
    • External interface calls
  3. Identify state variables that could be manipulated

Turn 2: Identify Reentrancy Patterns

Look for these patterns:

Classic Reentrancy:

// VULNERABLE - External call before state update
function withdraw(uint256 amount) public {
    require(balances[msg.sender] >= amount);
    (bool success, ) = msg.sender.call{value: amount}("");  // ← CALL
    require(success, "Transfer failed");
    balances[msg.sender] -= amount;  // ← STATE UPDATE AFTER
}

Cross-Function Reentrancy:

// VULNERABLE - Shared state, external call
function deposit() public payable {
    balances[msg.sender] += msg.value;
}

function withdraw(uint256 amount) public {
    require(balances[msg.sender] >= amount);
    (bool success, ) = msg.sender.call{value: amount}("");
    require(success, "Transfer failed");
    balances[msg.sender] -= amount;
}

// Attacker calls withdraw → reenters → deposit → balance not updated yet

Read-Only Reentrancy:

// VULNERABLE - View function reads stale state
function getTotalBalance() public view returns (uint256) {
    return address(this).balance;  // Can be manipulated during reentrancy
}

Callback Reentrancy:

// VULNERABLE - Unsafe token hook
function onTokenTransfer(address from, uint256 amount, bytes calldata data) external {
    // No reentrancy guard!
    balances[from] += amount;
    // Do something that calls back into token contract
}

Turn 3: Check for Reentrancy Guards

Look for:

  • nonReentrant modifier (OpenZeppelin)
  • Mutex/ReentrancyGuard patterns
  • Checks-Effects-Interactions pattern
  • State updates before external calls

Turn 4: Identify Issues

Output format:

{
  "findings": [
    {
      "kind": "FINDING",
      "group_key": "withdraw | reentrancy | reentrancy",
      "title": "Classic reentrancy vulnerability in 'withdraw' function",
      "skill": "evm-reentrancy",
      "severity": "critical",
      "confidence": 90,
      "function_or_handler": "withdraw",
      "primary_account_or_authority": "any caller",
      "evidence": ["contracts/MyVault.sol:45", "contracts/MyVault.sol:47"],
      "trust_consequence": "attacker can drain contract funds through reentrant calls",
      "exploit_path": "attacker calls withdraw() → reenters before balance update → drains all funds",
      "why_it_matters": "reentrancy is one of the most common and devastating DeFi vulnerabilities",
      "remediation": "Use Checks-Effects-Interactions pattern or nonReentrant modifier",
      "ship_blocker": true
    }
  ]
}

Severity Guidelines

SeverityWhen to UseExamples
criticalFund loss possibleClassic reentrancy in withdraw/deposit functions
highState manipulation possibleCross-function reentrancy, missing guards
mediumLimited exposureRead-only reentrancy, unsafe callbacks
lowMinor issuesPotential but unlikely reentrancy

Confidence Guidelines

ConfidenceRangeWhen to Use
Very High90-100Clear reentrancy pattern with external call before state update
High75-89Strong evidence, likely exploitable
Medium60-74Possible reentrancy, some uncertainty
Low50-59Potential but not confirmed

Do NOT output findings with confidence < 50

Key Patterns to Detect

1. External Call Patterns

// Look for these patterns
.call{value:}() / .call{gas:}()
.delegatecall()
.send()
.transfer()
call{value:}()
staticcall{}

2. Token Transfer Patterns

// ERC20
IERC20(token).transfer()
IERC20(token).transferFrom()

// ERC777 (has hooks - more dangerous)
IERC777(token).send()
tokensReceived() / tokensToSend() hooks

// ERC1155 (has hooks)
IERC1155(token).safeTransferFrom()
onReceived() hook

3. Reentrancy Guards

// GOOD - OpenZeppelin ReentrancyGuard
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract MyContract is ReentrancyGuard {
    function withdraw() external nonReentrant { }
}

// GOOD - Checks-Effects-Interactions
function withdraw(uint256 amount) external {
    require(balances[msg.sender] >= amount);
    balances[msg.sender] -= amount;  // ← EFFECTS FIRST
    (bool success, ) = msg.sender.call{value: amount}("");  // ← INTERACTIONS LAST
    require(success, "Transfer failed");
}

// BAD - No guard, wrong order
function withdraw(uint256 amount) external {
    (bool success, ) = msg.sender.call{value: amount}("");
    balances[msg.sender] -= amount;
}

Integration

This skill is part of XLayer Trust Agent and runs in parallel with other EVM specialists:

  • access-control
  • proxy-risk
  • upgradeability
  • ownership-powers
  • reentrancy (this skill)

Results are aggregated in the xlayer-trust-review orchestrator.

Output Schema

{
  "specialist": "reentrancy",
  "target": "contract_address_or_path",
  "analysis_time": "2025-04-15T12:00:00Z",
  "external_calls_detected": 5,
  "has_reentrancy_guard": false,
  "uses_checks_effects_interactions": false,
  "findings": [
    {
      "kind": "FINDING" | "LEAD",
      "group_key": "function | vulnerability_type | reentrancy",
      "title": "Brief title",
      "skill": "reentrancy",
      "severity": "critical" | "high" | "medium" | "low",
      "confidence": 0-100,
      "function_or_handler": "function_name",
      "primary_account_or_authority": "caller_type",
      "evidence": ["file:line", ...],
      "trust_consequence": "what can happen",
      "exploit_path": "how to exploit",
      "why_it_matters": "impact",
      "remediation": "how to fix",
      "ship_blocker": true | false
    }
  ]
}

Special Cases

DeFi Protocols

Pay special attention to:

  • Flash loan callbacks (untrusted, can reenter)
  • AMM swap functions
  • Liquidity provision/removal
  • Vault deposit/withdraw
  • Lending borrow/repay

NFT Contracts

Check for:

  • onERC721Received hook implementations
  • onERC1155Received hook implementations
  • Token approval patterns
  • Batch operations

Bridge Contracts

Verify:

  • Cross-chain message handlers
  • Token mint/burn on transfer
  • Relay and confirmation logic
  • Replay protection

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.