Skip to content

feat: reject debug WASM contracts at publish time #2257

@sanity

Description

@sanity

Problem

Debug-compiled WASM contracts are ~65x larger than release builds (e.g., 12MB vs 186KB for the ping contract). When clients attempt to PUT these contracts, they can exceed WebSocket message size limits, causing confusing "Message too long" errors.

This was discovered when test contracts were accidentally being compiled in debug mode, producing 12MB WASM files that serialized to ~21MB over WebSocket.

Proposed Solution

Add validation in the contract PUT handler to detect debug WASM and return a clear error message.

Detection Method

Debug WASM files contain .debug_* custom sections:

  • .debug_abbrev
  • .debug_info
  • .debug_ranges
  • .debug_str
  • .debug_line
  • .debug_loc

Release builds have none of these sections.

Implementation

  1. Use wasmparser (already available via wasmer) to scan custom sections
  2. Check if any custom section name starts with .debug_
  3. If found, return an error like:
    Contract appears to be compiled in debug mode (contains .debug_* sections).
    Debug WASM is typically 10-100x larger than release builds.
    Please compile with --release for production use.
    

Alternative: Warning vs Error

Could make this a warning instead of an error, logged server-side, to avoid breaking existing workflows. However, an error at publish time is cleaner since debug contracts shouldn't be deployed to production.

Where to Add

The validation should be in crates/core/src/client_events/mod.rs or crates/core/src/contract/handler.rs where PUT requests are processed.

Context

[AI-assisted - Claude]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-contractsArea: Contract runtime, SDK, and executionA-developer-xpArea: developer experienceE-easyExperience needed to fix/implement: Easy / not muchP-mediumMedium priorityT-featureType: New functionality request

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions