Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ jobs:
- run: cargo fmt --all --check
- run: cargo test --workspace

stellar-size-check:
needs: changes
if: needs.changes.outputs.stellar == 'true'
runs-on: ubuntu-latest
defaults:
run:
working-directory: stellar
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: rustup target add wasm32-unknown-unknown
- run: cargo build --target wasm32-unknown-unknown --release
- name: Check Wasm sizes
run: |
BUDGET=112640 # 110 KB in bytes
for wasm in target/wasm32-unknown-unknown/release/*.wasm; do
size=$(stat -c%s "$wasm")
name=$(basename "$wasm" .wasm)
echo "Contract $name size: $size bytes (Budget: $BUDGET bytes)"
if [ "$size" -gt "$BUDGET" ]; then
echo "Error: Contract $name exceeds Wasm size budget!"
exit 1
fi
done

solana:
needs: changes
if: needs.changes.outputs.solana == 'true'
Expand Down
7 changes: 7 additions & 0 deletions stellar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ resolver = "2"

[workspace.dependencies]
soroban-sdk = "22.0.0"

[profile.release]
opt-level = "z" # Optimize for size
lto = "fat" # Enable Link Time Optimization (LTO)
codegen-units = 1 # Reduce parallel code generation units to increase optimization
panic = "abort" # Remove panic landing pads
strip = "symbols" # Strip symbols from the binary
30 changes: 30 additions & 0 deletions stellar/SIZE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Stellar Contract Wasm Size Budget

This document tracks the Wasm binary sizes of the Stellar contracts and sets budgets to ensure they remain within Soroban limits.

## Current Measurements (Initial)

| Contract | Debug | Release | Optimized | Budget | Headroom |
|---|---|---|---|---|---|
| `stealth-announcer` | 2.6 MB | 2.9 KB | 1.3 KB | 110 KB | 108.7 KB |
| `stealth-registry` | 2.6 MB | 5.5 KB | 2.1 KB | 110 KB | 107.9 KB |
| `stealth-sender` | 2.7 MB | 13 KB | 4.1 KB | 110 KB | 105.9 KB |
| `wraith-names` | 2.7 MB | 18 KB | 6.0 KB | 110 KB | 104 KB |

*\* `stellar contract optimize` is currently unavailable in the environment due to missing `wasm-opt`. Initial optimizations will focus on build profile settings.*

## Wasm Size Budget

Soroban has a hard limit on contract Wasm size (currently ~140 KB for some operations, but upload limits can be higher). We aim for a budget of **110 KB** per contract to allow for ~20% headroom.

## What to do if you exceed the budget

If a contract exceeds its budget, follow these steps:

1. **Audit Dependencies**: Check `Cargo.toml` for unused features or heavy dependencies. Use `cargo tree`.
2. **Profile Build**: Ensure `lto = "fat"`, `codegen-units = 1`, and `opt-level = "z"` are set in `Cargo.toml`.
3. **Refactor Code**:
* Replace `panic!`, `assert!`, and `unwrap()` with `Result` or `panic_with_error!`.
* Avoid `std::string::String` and `std::vec::Vec` where possible; use `soroban_sdk` equivalents.
* Minimize use of `format!` and complex formatting.
4. **Use `wasm-opt`**: If not already done, run `stellar contract optimize`.