Skip to content

TollcraftStop guessing your gas bill.

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.

INTEGRATED WORKFLOW

Interactive Cost Lifecycle

Select a stage to inspect its role, runtime mechanism, and telemetry output.

PHASE 01 • COMPILE TIMErustc / Dylint driver

Eliminate structural cost anti-patterns before execution

Intercepts expensive patterns like storage mutations inside loops, redundant clone allocations, and unbounded recursion at build time with zero gas cost.

CRITICAL CAPABILITIES
  • ▹40 Soroban HIR lints, registered as rustc lint checks
  • ▹Detects blind storage writes and discarded reads
  • ▹Flags TTL extension in loops and inefficient byte concat
  • ▹Severity is rustc's own: allow, warn, deny — set per lint with -A/-W/-D
cargo cost-lint
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 footprint

Two Ways In ​

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

dev@tollcraft~/contracts/amm-pool$cargo cost-lint
Building member crates for cost audit... error: storage operations inside a loop --> contracts/amm-pool/src/lib.rs:94:13 | 94 | env.storage().instance().set(&key, &user_deposit); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: [SOROBAN_STORAGE_IN_LOOP] is the driver's one Deny-level lint = help: batch storage writes outside the loop iteration [OK] Finished analysis in 0.42s (1 warning, 1 error)

The Three Tiers of Cost Awareness ​


SOROBAN METERING MATRIX

Operation Cost Telemetry

Inspect how common contract operations translate into protocol-level resource consumption and fees.

Storage & I/OTier 1 Caught

Storage Write in Loop

Mutating instance or persistent storage on every loop iteration re-serializes entries and consumes non-refundable write fees per cycle.

CPU INSTRUCTIONS
~25,000 / iter
Host storage invocation & XDR serialization overhead
MEMORY FOOTPRINT
~512 B / iter
Intermediate host Val and key allocation
LEDGER I/O
1 Write / iter
Ledger key modified N times per transaction
RENT / TTL
Repeated TTL hits
Increases state contention on ledger entries
●HAZARDOUS PATTERN
for item in items.iter() {
    // [HAZARD] Incurs N writes and N host cross-calls
    env.storage().instance().set(&item.key, &item.val);
}
●OPTIMAL TOLLCRAFT PATTERN
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);
GUARD
Tollcraft Protection:Linted at build-time by soroban_storage_in_loop (the driver's Deny-level lint) and asserted in tests via #[budget_write_bytes_lt].

The Cost of Soroban Operations ​

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 DimensionUnit of MeasurementCap (Per Tx)Fee Impact
CPU InstructionsMetered instruction count100,000,000Non-refundable fee per million instructions
MemoryBytes resident during execution41,943,040 (40 MiB)Enforced limit (execution fails on breach)
Ledger Read BytesSerialized payload bytes200,000Non-refundable fee per KB read
Ledger Write BytesSerialized payload bytes132,096Non-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.

Built for the Stellar & Soroban ecosystem.