Agent skill

Assembly Patterns

by ccashwell in ccashwell/evm-cortex

Yul/inline assembly patterns for advanced Solidity optimization.

MITAuto-check passedBackend & APIs

Install Assembly Patterns

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

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

GitHub CLI
$ gh skill install ccashwell/evm-cortex assembly-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/assembly-patterns .claude/skills/assembly-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
assembly-patterns
GitHub stars
131
Token cost
~1.7k tokens
SKILL.md length
275 words
Files
1
Skills in repo
89
Repo updated
First seen
Licence
MIT

At a glance

Yul/inline assembly patterns for advanced Solidity optimization.

  • Works in 4 steps: Gas savings are measured (not assumed)… → The optimization is in a hot path… → Solidity cannot express the operation… → …
  • Tasks that involve Smart contracts
  • SKILL.md covers When to Use Assembly, Memory Management, Efficient Hashing and Bitwise Packing and Unpacking, plus 7 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Assembly Patterns is an agent skill from ccashwell/evm-cortex. Yul/inline assembly patterns for advanced Solidity optimization. Use only when gas savings are significant and measured. Covers memory management, efficient hashing, bitwise operations, custom errors, low-level calls, and returndata handling.

Its SKILL.md is about 1.7k 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 Backend & APIs, covering Smart contracts. 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

  • Tasks that involve Smart contracts

Example prompts

  • “/assembly-patterns”

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  1. Gas savings are measured (not assumed) via forge test --gas-report
  2. The optimization is in a hot path (called frequently)
  3. Solidity cannot express the operation (e.g., specific memory layout)
  4. Savings exceed 500 gas per call for the added complexity

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

Assembly Patterns loads about 1.7k tokens when it runs. Until then it costs about 65 tokens; SKILL.md has 275 words of instructions outside code blocks.

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

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). 275 words, ~1,659 tokens.

Download SKILL.mdSave it as .claude/skills/assembly-patterns/SKILL.md (or your agent's skills folder).
name
assembly-patterns
description
Yul/inline assembly patterns for advanced Solidity optimization. Use only when gas savings are significant and measured. Covers memory management, efficient hashing, bitwise operations, custom errors, low-level calls, and returndata handling.

Assembly Patterns

When to Use Assembly

Only use assembly when:

  1. Gas savings are measured (not assumed) via forge test --gas-report
  2. The optimization is in a hot path (called frequently)
  3. Solidity cannot express the operation (e.g., specific memory layout)
  4. Savings exceed 500 gas per call for the added complexity

Always add @dev NatSpec explaining why assembly is used and what it does.

Memory Management

EVM memory layout:

  • 0x00-0x3f (64 bytes): Scratch space for hashing
  • 0x40-0x5f (32 bytes): Free memory pointer
  • 0x60-0x7f (32 bytes): Zero slot
solidity
/// @dev Efficiently computes keccak256(abi.encodePacked(a, b)) using scratch space.
function efficientHash(bytes32 a, bytes32 b) internal pure returns (bytes32 result) {
    assembly {
        mstore(0x00, a)
        mstore(0x20, b)
        result := keccak256(0x00, 0x40)
    }
}

Efficient Hashing

Hashing pairs for Merkle trees — avoids memory allocation overhead.

solidity
/// @dev Hashes a leaf pair for Merkle tree construction. Sorts to ensure
///      consistent ordering regardless of input order.
function hashPair(bytes32 a, bytes32 b) internal pure returns (bytes32 result) {
    assembly {
        // Sort to produce canonical ordering
        switch lt(a, b)
        case 1 {
            mstore(0x00, a)
            mstore(0x20, b)
        }
        default {
            mstore(0x00, b)
            mstore(0x20, a)
        }
        result := keccak256(0x00, 0x40)
    }
}

Bitwise Packing and Unpacking

Pack multiple values into a single uint256 for storage efficiency.

solidity
/// @dev Packs owner (160 bits), amount (80 bits), timestamp (16 bits) into uint256.
function pack(address owner, uint80 amount, uint16 ts) internal pure returns (uint256 packed) {
    assembly {
        packed := or(or(shl(96, owner), shl(16, amount)), ts)
    }
}

function unpackOwner(uint256 packed) internal pure returns (address owner) {
    assembly {
        owner := shr(96, packed)
    }
}

function unpackAmount(uint256 packed) internal pure returns (uint80 amount) {
    assembly {
        amount := and(shr(16, packed), 0xffffffffffffffffffff) // 80-bit mask
    }
}

function unpackTimestamp(uint256 packed) internal pure returns (uint16 ts) {
    assembly {
        ts := and(packed, 0xffff)
    }
}

Custom Errors in Assembly

Revert with custom error selectors without Solidity overhead.

solidity
error Unauthorized();           // selector: 0x82b42900
error InsufficientBalance(uint256 available, uint256 required);

/// @dev Reverts with Unauthorized() using minimal gas.
function _revertUnauthorized() internal pure {
    assembly {
        mstore(0x00, 0x82b42900) // Unauthorized() selector
        revert(0x1c, 0x04)       // offset to align 4-byte selector
    }
}

/// @dev Reverts with InsufficientBalance(available, required).
function _revertInsufficientBalance(uint256 available, uint256 required) internal pure {
    assembly {
        let ptr := mload(0x40)
        mstore(ptr, 0xf4d678b8)           // InsufficientBalance selector
        mstore(add(ptr, 0x04), available)
        mstore(add(ptr, 0x24), required)
        revert(add(ptr, 0x1c), 0x44)      // 4 + 32 + 32 = 68 bytes
    }
}

Low-Level Calls

solidity
/// @dev Performs a low-level call and bubbles up revert data on failure.
function _call(address target, bytes memory data) internal returns (bytes memory) {
    (bool success, bytes memory returndata) = target.call(data);

    if (!success) {
        assembly {
            // Bubble up the revert reason
            revert(add(returndata, 0x20), mload(returndata))
        }
    }

    return returndata;
}

Return Data Handling

solidity
/// @dev Checks if a call returned true (for ERC-20 compatibility).
///      Handles tokens that return nothing (USDT), false, or true.
function _callOptionalReturn(address token, bytes memory data) internal {
    (bool success, bytes memory returndata) = token.call(data);

    if (!success) {
        assembly {
            revert(add(returndata, 0x20), mload(returndata))
        }
    }

    // If returndata is present, it must decode to true
    if (returndata.length > 0) {
        if (abi.decode(returndata, (bool)) == false) {
            revert TokenCallFailed();
        }
    }
}

Efficient Address Checks

solidity
/// @dev Checks if an address is a contract (has code). Uses extcodesize.
function isContract(address account) internal view returns (bool result) {
    assembly {
        result := gt(extcodesize(account), 0)
    }
}

/// @dev Reverts if addr is the zero address.
function _requireNonZero(address addr) internal pure {
    assembly {
        if iszero(addr) {
            mstore(0x00, 0xd92e233d) // ZeroAddress() selector
            revert(0x1c, 0x04)
        }
    }
}

Efficient Event Emission

solidity
/// @dev Emits Transfer(from, to, amount) without Solidity ABI encoding overhead.
function _emitTransfer(address from, address to, uint256 amount) internal {
    assembly {
        // Transfer(address,address,uint256) topic
        let sig := 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
        mstore(0x00, amount)
        log3(0x00, 0x20, sig, from, to)
    }
}

Safety Rules

  1. Never use assembly for simple operations that Solidity handles well
  2. Always validate inputs before assembly blocks — assembly skips Solidity's type safety
  3. Document every assembly block with NatSpec explaining the operation
  4. Test extensively — assembly bugs are silent and devastating
  5. Use returndatasize() instead of hardcoded sizes when reading return data
  6. Avoid mstore past the free memory pointer without updating it
  7. Never use selfdestruct in assembly (deprecated, behavior changes post-Dencun)

Assembly Checklist

  • Gas savings measured with forge test --gas-report (before/after)
  • Savings exceed 500 gas in a hot path
  • NatSpec @dev comment explains why assembly is used
  • All memory operations respect the free memory pointer
  • No writes to reserved memory areas (0x00-0x3f) that persist beyond scratch use
  • Return data handling uses returndatasize() not hardcoded lengths
  • Edge cases tested: zero values, max values, empty calldata

© 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/assembly-patterns of ccashwell/evm-cortex.

Open the folder on GitHubat commit f8f3301

Compare with similar skills

Assembly 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.

Assembly Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Assembly Patterns this skillccashwell/evm-cortex131—~1.7kAutomated safety check: PassMIT
Fizz Convertpashov/skills1.2k2 repos~3.7kAutomated safety check: PassMIT
Feynman Auditor0xiehnnkta/nemesis-auditor2431 repos~11kAutomated safety check: PassMIT
Smart Contract Auditgreatpie/smart-contract-audit-skill101—~1.1kAutomated safety check: PassNone
RadarAuditware/radar154—~2.1kAutomated safety check: PassGPL-3.0
Solidity AuditorGabson0x/bountyforge443—~3.7kAutomated safety check: PassNone

Similar skills

  • Fizz Convert

    pashov/skills

    Convert English-language properties in PROPERTIES.md (produced by the Fizz skill) into Solidity assertions inside the existing fuzz harness, then flip their checkboxes.

    1.2k GitHub starsUsed in 2 repos~3.7k tokens
    Backend & APIsAuto-check passed
  • Feynman Auditor

    0xiehnnkta/nemesis-auditor

    Deep business logic bug finder using the Feynman technique. An agent skill from 0xiehnnkta/nemesis-auditor.

    243 GitHub starsUsed in 1 repo~11k tokens
    Backend & APIsAuto-check passed
  • Smart Contract Audit

    greatpie/smart-contract-audit-skill

    Script-backed, out-of-box auditing workflow for Solidity/EVM repositories based on EVMbench detect/patch/exploit methodology.

    101 GitHub stars~1.1k tokensUpdated 7 mo ago
    Backend & APIsAuto-check passed
  • Radar

    Auditware/radar

    Use radar for smart contract security analysis, AST generation, and detection template development.

    154 GitHub stars~2.1k tokensUpdated 1 mo ago
    Backend & APIsAuto-check passed
  • Solidity Auditor

    Gabson0x/bountyforge

    Security audit of Solidity code while you develop. An agent skill from Gabson0x/bountyforge.

    443 GitHub stars~3.7k tokensUpdated 21 days ago
    Backend & APIsAuto-check passed
  • Solidity Auditor

    pashov/skills

    Security audit of Solidity code while you develop. An agent skill from pashov/skills.

    1.2k GitHub starsUsed in 1 repo~9.9k tokens
    Backend & APIsAuto-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 8 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 8 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 8 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 8 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 8 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 8 days ago
    Auto-check passed

Works with

Categories

Questions about Assembly Patterns

What does Assembly Patterns do?

Yul/inline assembly patterns for advanced Solidity optimization. Assembly Patterns is an agent skill from ccashwell/evm-cortex. Yul/inline assembly patterns for advanced Solidity optimization.

When should I use Assembly Patterns?

Assembly Patterns fits situations like: tasks that involve Smart contracts.

How do I install Assembly Patterns in Claude Code?

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

How do I install Assembly Patterns in Codex?

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

Can I use Assembly 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 assembly-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/assembly-patterns, .gemini/skills/assembly-patterns, .github/skills/assembly-patterns and .opencode/skills/assembly-patterns in your project.

What does Assembly Patterns need to run?

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

Does Assembly 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 Assembly 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 Assembly Patterns use?

Assembly 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 Assembly Patterns use?

About 1.7k tokens (SKILL.md is roughly 6.6k 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 Assembly Patterns?

Skills that share tags, products or a category with Assembly Patterns: Fizz Convert (pashov/skills, 1.2k stars), Feynman Auditor (0xiehnnkta/nemesis-auditor, 243 stars), Smart Contract Audit (greatpie/smart-contract-audit-skill, 101 stars) and Radar (Auditware/radar, 154 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Assembly 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.