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+ specialized Soroban AST and HIR lints
  • ▹Detects blind storage writes and discarded reads
  • ▹Flags TTL extension in loops and inefficient byte concat
  • ▹Configurable severity (deny, warn, allow) via cargo config
cargo cost-lint --all-targets
warning: storage write inside loop
  --> contracts/pool/src/lib.rs:88:9
   |
88 |   env.storage().instance().set(&key, &val);
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: batch storage operations outside the loop
   = note: each write incurs 25k CPU instructions and ledger write fees

Unified Command Interface ​

Execute each tier through familiar Cargo subcommands with zero disruption to standard Rust workflows.

dev@tollcraft~/contracts/amm-pool$cargo cost-lint --all-targets
Building member crates for cost audit... warning: storage_in_loop detected --> contracts/amm-pool/src/lib.rs:94:13 | 94 | env.storage().instance().set(&key, &user_deposit); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: batch storage writes outside the loop iteration = cost impact: ~25,000 CPU instructions + 1 ledger write entry per cycle [OK] Finished analysis in 0.42s (1 warning, 0 errors)

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 instance_storage_write_in_loop 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 under Stellar Protocol 22:

Resource DimensionUnit of MeasurementHard Cap (Per Tx)Fee Impact
CPU InstructionsExecuted instruction count100,000,000 instructionsNon-refundable fee per million instructions
Memory AllocationsBytes allocated / resident40 MBEnforced limit (execution fails on breach)
Ledger Entry ReadsKey-value pairs accessed40 entriesNon-refundable fee per entry read
Ledger Entry WritesKey-value pairs mutated25 entriesNon-refundable fee per entry written
Ledger Read BytesSerialized payload bytes~200 KBNon-refundable fee per KB read
Ledger Write BytesSerialized payload bytes~100 KBNon-refundable fee per KB written
Ledger Space RentByte × Ledgers durationDynamicDynamic refundable rent based on entry TTL

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.