Tier 1 — Prevent
Catch structurally expensive anti-patterns (storage in loops, redundant clones) before your code compiles using rustc and Dylint static analysis.
Cost Linter Docs →
A three-tier cost awareness pipeline for Stellar smart contracts. Lint at compile time, assert at test time, profile when the budget fails — so every CPU instruction and storage byte is accounted for before mainnet.
Select a stage to inspect its role, runtime mechanism, and telemetry output.
error: storage operations inside a loop
--> contracts/pool/src/lib.rs:88:9
|
88 | env.storage().instance().set(&key, &val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: [SOROBAN_STORAGE_IN_LOOP]
= help: each iteration pays a ledger write fee and grows the transaction footprintTier 1 and Tier 2 run as Cargo subcommands — cargo cost-lint and cargo budget-report — inside your contract's own build. Tier 3 is a standalone binary you point at a compiled .wasm; it needs no macro, no test hook and no change to your contract's source.
A static analysis shield for Soroban smart contracts. Hooks directly into rustc to catch expensive patterns before compilation.
An empirical runtime test harness. Measures network-simulated resource consumption and fails CI when budget limits are breached.
Runs one contract export under a traced engine and names its frames from the binary's DWARF line tables, writing collapsed-stack text speedscope.app and flamegraph.pl read.
Inspect how common contract operations translate into protocol-level resource consumption and fees.
Mutating instance or persistent storage on every loop iteration re-serializes entries and consumes non-refundable write fees per cycle.
for item in items.iter() {
// [HAZARD] Incurs N writes and N host cross-calls
env.storage().instance().set(&item.key, &item.val);
}let mut batch = env.storage().instance().get(&BATCH_KEY).unwrap_or(...);
for item in items.iter() {
batch.push_back(item);
}
// [OPTIMAL] Commit once at loop completion
env.storage().instance().set(&BATCH_KEY, &batch);Soroban charges for every hardware resource your contract consumes on-chain. These are the per-transaction caps the budget macros read from tier-a-limits.env, as configured for Protocol 23 (source: Stellar Lab network limits):
| Resource Dimension | Unit of Measurement | Cap (Per Tx) | Fee Impact |
|---|---|---|---|
| CPU Instructions | Metered instruction count | 100,000,000 | Non-refundable fee per million instructions |
| Memory | Bytes resident during execution | 41,943,040 (40 MiB) | Enforced limit (execution fails on breach) |
| Ledger Read Bytes | Serialized payload bytes | 200,000 | Non-refundable fee per KB read |
| Ledger Write Bytes | Serialized payload bytes | 132,096 | Non-refundable fee per KB written |
Limits move with the protocol
Validator consensus sets these numbers and they change between protocol versions. soroban-budget-assert pins soroban-sdk 27.0.3 / stellar-xdr 27.0.0 and targets Protocol 27; soroban-cost-profiler's host is soroban-env-host 28.0.2, i.e. Protocol 28. Treat the table above as the configuration the tools derive percentage budgets from, not as a guarantee for the network you deploy to — re-derive it against the limits your target protocol actually ships (stellar network settings prints them).
Every wasted instruction is a fee your users pay
Cost bugs don't fail standard unit tests — they silently inflate transaction fees in production. Use the Tollcraft pipeline to audit, gate, and diagnose your contracts before deployment.