Skip to content
Back to skills

2587 Asserting Contract From Code Size 53dd37d1

ASecurity

- Contract uses `extcodesize` or `address.code.length` to check whether an address is an EOA vs. a contract - This check gates access control, anti-bot logic, or security-sensitive operations - The check assumes that code size == 0 means EOA

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
blockchainsecurity

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 2587-asserting-contract-from-code-size_53dd37d1 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 2587 Asserting Contract From Code Size 53dd37d1?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 2587 Asserting Contract From Code Size 53dd37d1
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-2587-asserting-contract-from-code-size-53dd37d1/badge)](https://www.skillsdirectory.com/skills/tools-only-2587-asserting-contract-from-code-size-53dd37d1)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
# Asserting Contract from Code Size

## Preconditions
- Contract uses `extcodesize` or `address.code.length` to check whether an address is an EOA vs. a contract
- This check gates access control, anti-bot logic, or security-sensitive operations
- The check assumes that code size == 0 means EOA

## Vulnerable Pattern
```solidity
modifier onlyEOA() {
    // During constructor execution, extcodesize returns 0
    // An attacker calling from their constructor bypasses this check
    require(msg.sender.code.length == 0, "no contracts");
    _;
}

function mint() external onlyEOA {
    _mint(msg.sender, 1);
}

// Assembly variant
function isContract(address addr) internal view returns (bool) {
    uint256 size;
    assembly { size := extcodesize(addr) }
    return size > 0; // Returns false during constructor
}
```

## Detection Heuristics
1. Search for `extcodesize`, `.code.length`, or helper functions named `isContract`
2. Check if the result is used to gate access (e.g., `require(... == 0)` to allow only EOAs)
3. If used for EOA-only enforcement, flag it — contracts calling from their constructor have code size 0
4. Also check for `tx.origin == msg.sender` as an alternative EOA check — flag it as incompatible with account abstraction (ERC-4337) and smart contract wallets
5. Check if the "no contracts" logic protects anything security-sensitive (minting limits, anti-bot, etc.)

## False Positives
- `extcodesize` is used to check if a contract EXISTS at an address (not to distinguish EOA vs contract)
- The check is combined with other protections that don't rely solely on code size
- The function has no security implications if called by a contract

## Remediation
- There is no fully reliable on-chain method to distinguish EOAs from contracts
- Redesign logic to not depend on this distinction — make the system work correctly regardless of caller type
- If EOA-only behavior is truly needed, consider off-chain verification (e.g., signed messages from known EOAs)
- Remove `isContract` checks from security-critical paths
```solidity
// Instead of gating by caller type, use per-address limits
mapping(address => bool) public hasMinted;

function mint() external {
    require(!hasMinted[msg.sender], "already minted");
    hasMinted[msg.sender] = true;
    _mint(msg.sender, 1);
}
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…