Skip to content

[FEAT] Automated Smart Contract Gas Profiling & WASM Size Optimization CI Gateway #444

Description

@jotel-dev

telegram link : t.me/nullifiersystem


1. Summary & Core Promise

Soroban smart contracts in contracts/ (such as escrow, htlc-core, and zk-credential) must adhere to strict CPU instruction and memory footprint limits. Currently, developers must manually run gas benchmarks in contracts/atomic-swap/src/benchmarks.rs, and PRs can introduce unnoticed WASM size bloat.

This feature implements an Automated Smart Contract Gas Profiling & WASM Size Optimization CI Gateway. It adds an automated GitHub Actions step in .github/workflows/contracts-ci.yml, enforces automated WASM binary optimization (wasm-opt -O4), builds a gas footprint reporter in contracts/soroban-lint, and fails CI builds if contract WASM binaries exceed configured size thresholds.


2. Background & Architectural Risks

  • WASM Size Bloat: Un-optimized Rust contract dependencies can cause WASM binaries to exceed Stellar testnet size limits (>50 KB), blocking deployment.
  • Unnoticed Gas Regressions: Code changes introducing inefficient loops or storage key allocations increase transaction fees for users.

3. Database Layer Specifications

(Not Applicable - Tooling & CI Build System)


4. Backend Route & Service Layer Specifications

(CI Pipeline & CLI Benchmarking Tooling)


5. Background Processors / Workers

GitHub Actions CI Runner (.github/workflows/contracts-ci.yml)

  • Runs cargo build --target wasm32-unknown-unknown --release, executes wasm-opt -O4, measures WASM size, and posts benchmark summary comments to PRs.

6. Frontend / UI Component Specifications

(Not Applicable - CI / CLI Tooling)


7. Rigor & Test Plan

  1. CI Benchmark Test Script (scripts/check-wasm-size.sh): Test size measurement and assertion failure triggers when WASM exceeds threshold.
  2. Soroban Lint Rule Test (contracts/soroban-lint): Assert static analyzer flags un-optimized storage key calls.

8. Relevant Files Inventory

New Files to Create

  • scripts/check-wasm-size.sh
  • scripts/benchmark-contract-gas.sh
  • contracts/soroban-lint/src/rules/gas_optimization.rs

Existing Files to Modify

  • .github/workflows/contracts-ci.yml
  • contracts/atomic-swap/src/benchmarks.rs
  • contracts/Cargo.toml
  • turbo.json

9. Acceptance Criteria

  • CI workflow executes wasm-opt -O4 on all compiled Soroban WASM binaries.
  • Automatically fails PR builds if any contract binary exceeds 50 KB.
  • Generates PR comment table summarizing WASM size and CPU instruction changes.

10. Contributor Notes

  • ⚠️ CI Rule: ALWAYS run wasm-opt -O4 before measuring binary sizes for release deployments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions