Skip to content

Task/resolution authsnap #162

Task/resolution authsnap

Task/resolution authsnap #162

Workflow file for this run

name: WASM Size Budget
# Enforces per-contract WASM size budgets so accidental bloat is caught in CI
# before it reaches mainnet deployment. Budgets are intentionally conservative
# and should be updated via a deliberate PR if a contract genuinely needs more
# space (e.g. a new feature module).
#
# Budget table (release build, wasm32v1-none, opt-level=z + LTO):
# hello-world : 20 KB – toy example, must stay tiny
# governance-events : 24 KB – pure event types + emitters, no logic
# predictify-hybrid : 900 KB – full prediction-market contract
#
# The governance-events crate was added in FWC26 (Stellar Wave).
on:
push:
branches: [ "master", "main" ]
pull_request:
branches: [ "master", "main" ]
jobs:
check-size:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
rustup target add wasm32v1-none
- name: Install Stellar CLI
run: |
brew update
brew install stellar-cli
- name: Build contracts (release, wasm32v1-none)
run: |
source $HOME/.cargo/env
stellar contract build
# ── Per-contract size gates ──────────────────────────────────────────────
# Each WASM is checked against its own budget. Any file that does not
# match a known contract name triggers a strict 20 KB fallback so unknown
# contracts cannot sneak through with unbounded size.
- name: Check WASM sizes
run: |
set -euo pipefail
source $HOME/.cargo/env
# Budgets in bytes (release + opt-level=z + LTO)
BUDGET_HELLO_WORLD=20480 # 20 KB
BUDGET_GOVERNANCE_EVENTS=24576 # 24 KB (FWC26 governance-events crate)
BUDGET_PREDICTIFY_HYBRID=921600 # 900 KB
BUDGET_FALLBACK=20480 # 20 KB (any unknown contract)
FAIL=0
for wasm_file in target/wasm32v1-none/release/*.wasm; do
[ -f "$wasm_file" ] || continue
SIZE=$(stat -f%z "$wasm_file")
BASE=$(basename "$wasm_file" .wasm)
case "$BASE" in
hello_world)
BUDGET=$BUDGET_HELLO_WORLD ;;
governance_events)
BUDGET=$BUDGET_GOVERNANCE_EVENTS ;;
predictify_hybrid)
BUDGET=$BUDGET_PREDICTIFY_HYBRID ;;
*)
BUDGET=$BUDGET_FALLBACK ;;
esac
BUDGET_KB=$(( BUDGET / 1024 ))
SIZE_KB=$(echo "scale=1; $SIZE / 1024" | bc)
if [ "$SIZE" -gt "$BUDGET" ]; then
echo "::error file=$wasm_file::WASM size budget exceeded: $BASE = ${SIZE_KB} KB (budget ${BUDGET_KB} KB)"
FAIL=1
else
echo "OK $BASE: ${SIZE_KB} KB / ${BUDGET_KB} KB"
fi
done
if [ "$FAIL" -eq 1 ]; then
echo ""
echo "One or more contracts exceeded their WASM size budget."
echo "If the growth is intentional, update the budget table in"
echo ".github/workflows/wasm-size.yml with a justification comment."
exit 1
fi
echo ""
echo "All contracts are within their WASM size budgets."
# ── Size report (informational, never fails the build) ───────────────────
- name: Report WASM sizes
if: always()
run: |
echo "### WASM size report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Contract | Size |" >> $GITHUB_STEP_SUMMARY
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
for wasm_file in target/wasm32v1-none/release/*.wasm; do
[ -f "$wasm_file" ] || continue
SIZE=$(stat -f%z "$wasm_file")
SIZE_KB=$(echo "scale=1; $SIZE / 1024" | bc)
BASE=$(basename "$wasm_file" .wasm)
echo "| \`$BASE\` | ${SIZE_KB} KB |" >> $GITHUB_STEP_SUMMARY
done