Skip to content

Add gas/CPU instruction regression baselines per public entrypoint with CI diff gate #1192

@Baskarayelu

Description

@Baskarayelu

Description

QuickLendX exposes dozens of #[contractimpl] entrypoints in src/lib.rs (e.g. store_invoice, place_bid, accept_bid_and_fund, process_partial_payment, settle_invoice, distribute_revenue). Today there is no per-entrypoint Soroban CPU-instruction baseline checked into the repo, so silent gas regressions can slip through. This issue introduces a baseline table of (entrypoint, scenario) -> max_instructions/read_bytes/write_bytes captured via env.cost_estimate() / BudgetSnapshot, persisted in scripts/gas-baseline.toml, and enforced by a CI test that fails when any scenario exceeds the baseline by more than a configurable tolerance (default 3%).

Requirements and context

  • Secure: ensure budget probes do not change protocol behaviour or skip require_auth.
  • Tested: at least one baseline scenario per entrypoint listed in lib.rs #[contractimpl].
  • Documented: docs/gas-baselines.md explaining how to refresh baselines and review diffs.
  • Reference modules: src/lib.rs, src/escrow.rs, src/settlement.rs, src/bid.rs, src/profits.rs.

Suggested execution

git checkout -b feature/gas-regression-baselines

  • Add src/bench.rs helper exposing measure(env, label, || { ... }) that records Budget deltas.
  • Modify src/lib.rs only via #[cfg(test)] instrumentation (no behaviour change).
  • Persist baselines in scripts/gas-baseline.toml; add scripts/update-gas-baseline.sh.
  • Tests in tests/gas_regression.rs iterate scenarios and assert deltas within tolerance.
  • Docs: docs/gas-baselines.md with run/update workflow.
  • Use Rust doc /// NatSpec-style comments on the bench helpers.
  • Validate that the bench harness cannot bypass require_auth or pause checks.

Test and commit

Run cargo test --test gas_regression -- --nocapture and capture output. Cover edge cases: paused-state rejection paths, error paths, and the largest realistic invoice. Include a security note that baselines are non-load-bearing for correctness.

Example commit message

test(gas): add per-entrypoint Soroban instruction-budget regression baselines

Guidelines

  • Minimum 95% test coverage
  • Clear documentation in docs/gas-baselines.md
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    gas-optimizationGas / cost optimizationsmart-contractSoroban/Rust smart contract worksorobanStellar Soroban specifictestingTests and coverage

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions