kcolbchain / docs / stylus-profiler

stylus-profiler

WASM binary analyzer for Arbitrum Stylus contracts. Function-level gas costs, size breakdown, optimization suggestions.

Why this exists

Stylus smart contracts compile Rust to WASM, with hard size limits: 128KB uncompressed, 24KB compressed. Developers constantly hit the 24KB limit with no tooling to diagnose which functions are eating the budget. This tool tells you.

Install

cargo install --git https://github.com/kcolbchain/stylus-profiler

Commands

# Full analysis: size, structure, top functions, gas estimates
stylus-profiler analyze target/wasm32-unknown-unknown/release/my_contract.wasm

# Size breakdown: which functions are largest
stylus-profiler size my_contract.wasm --top 20

# Compare builds: catch size regressions
stylus-profiler compare old_build.wasm new_build.wasm

# Optimization suggestions
stylus-profiler optimize my_contract.wasm

Example output

  WASM Analysis
  ──────────────────────────────────────────────────
  ✓ File size:         18.2KB
    Est. compressed:   4.5KB (limit: 24.0KB)
    Headroom:          19.5KB remaining

  Structure
    Functions:   47
    Code size:   12.1KB
    Imports:     8
    Exports:     5
    Memory:      16 pages (1.0MB)

  Top functions by size
      #      Size  Instrs      ~Gas  Name
  ──────────────────────────────────────────────────
      1    2.1KB     312       340  transfer
      2    1.8KB     267       298  approve
      3    1.4KB     189       210  balance_of

What it checks

GitHub Repository

Source code, issues, contributions

arbitrum-cli

Agent-first Arbitrum chain access

gas-oracle

L2 gas cost prediction