Budget Assert Overview
Tier 2 • Detect
Empirical runtime cost enforcement for Soroban smart contracts — simulate invocations against live network metering inside
cargo testand gate pull requests against resource regressions.
Part of the Tollcraft initiative:
- Tier 1: Prevent — Cost Linter: Catch structurally expensive anti-patterns before compilation.
- Tier 2: Detect — Budget Assert: Measure network-simulated costs and enforce budgets in CI.
- Tier 3: Diagnose — Cost Profiler: Trace execution and generate visual flamegraphs down to Rust lines.
The Divergence Problem
soroban-budget-assert solves a critical failure mode in Soroban smart contract engineering: local resource estimates do not match real network costs, and the error can point in either direction.
Measured on an example contract (do_expensive_work(10_000)):
The only trustworthy number is a live network simulation
A developer who trusts local numbers either deploys a contract that exhausts its budget on the public network, or over-provisions against costs that aren't real. Both mistakes come from the same root cause: mock environments do not execute the exact Stellar Core metering VM.
The Solution: Two-Tier Verification
soroban-budget-assert gives you the best of both worlds:
- Tier A (Local Fast Assertions): Deterministic test assertions via
#[budget_cpu_lt(N)]that run in milliseconds in your normalcargo testsuite. - Tier B (Network-Verified CI Gating):
cargo budget-reportdeploys the exact compiled WASM to a test network, simulates RPC invocations, and fails CI on any regression beyond a configured tolerance threshold.
# Check your workspace against budget limits
cargo budget-report --check --network testnetDocumentation Navigation
Getting Started
To wire assertions into your test suite, start with the End-User Guide. To set up automated CI budget gating, see the CI/CD Integration Guide.
- End-User Guide — Step-by-step walkthrough of macros, baseline snapshots, and commands
- Complete CLI & Config Reference — All flags,
budget.tomlschema, and environment variables - Deriving Limits — How to calculate safe Tier A local limits from Tier B network measurements
- CI/CD Integration Guide — GitHub Actions workflow and PR summary generation
- Testnet Troubleshooting — Handling RPC timeouts, sequence numbers, and funding
- Developer Guide — Architecture, internals, and building from source