Skip to content

Budget Assert Overview ​

Tier 2 • Detect

Empirical runtime cost enforcement for Soroban smart contracts — simulate invocations against live network metering inside cargo test and 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: Run one contract export under a traced engine and name its frames from the binary's DWARF line tables.

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)), and recorded with its build context in MEASUREMENTS.md (local estimate from Env::cost_estimate(), network figure from simulateTransaction, rustc 1.81, 2025-Q1; a third build of the same function on the default release profile measures 767,049 against 832,006 — −7.8%, the gap pointing the other way):

Empirical Resource Divergence vs. Network Truth
RAW RUST TEST
-81%
143,887 inst. (Dangerously under-estimates CPU!)
SIZE-OPT WASM
+19%
901,816 inst. (Over-provisions against phantom costs)
TESTNET GROUND TRUTH
756,678
Network truth from `simulateTransaction` on Soroban testnet

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:

  1. Tier A (Local Fast Assertions): Deterministic test assertions via #[budget_cpu_lt(N)] that run in milliseconds in your normal cargo test suite.
  2. Tier B (Network-Verified CI Gating): cargo budget-report deploys the exact compiled WASM to a test network, simulates RPC invocations, and fails CI on any regression beyond a configured tolerance threshold.
bash
# Check your workspace against budget limits
cargo budget-report --check --network testnet

Documentation 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.

Built for the Stellar & Soroban ecosystem.