Skip to content

Gas & reentrancy optimizations, calldata batch liquidation, gas forecasting (close #705 #835 #840 #717) - #885

Open
Cyberking99 wants to merge 6 commits into
Smartdevs17:mainfrom
Cyberking99:feat/gas-reentrancy-optimizations
Open

Gas & reentrancy optimizations, calldata batch liquidation, gas forecasting (close #705 #835 #840 #717)#885
Cyberking99 wants to merge 6 commits into
Smartdevs17:mainfrom
Cyberking99:feat/gas-reentrancy-optimizations

Conversation

@Cyberking99

Copy link
Copy Markdown
Contributor

Summary

Closes the following four issues:

  • Refactor reentrancy guard into reusable security primitive #705 — Extract a reusable reentrancy-guard crate (stellar-lend/contracts/security/) and rewrite the hello-world and lending reentrancy modules as thin wrappers over the shared stellarlend-security crate. Adds docs + 9 passing unit tests (builds, cargo test -p stellarlend-security).
  • Optimize liquidation gas costs with early exit and batched operations #835 — Reduce redundant storage reads in batch_liquidate (cache multi-asset-collateral flag, lazily load oracle prices and reuse them across collateral-value/seized computations, reuse aggregate collateral balance). Adds bench_batch_liquidate benchmark.
  • Implement calldata optimization for batched operations #840 — Upgrade the calldata-encoding lib to SDK-27 (alloc, u32 op type, no_std, 4 passing tests) and integrate it via batch_liquidate_compressed, decoding a packed byte blob (flag byte + varint-length-prefixed StrKey addresses + varint amount).
  • Implement gas estimation model for user transaction cost prediction #717 — Add a gas-forecasting model (Holt-Winters + linear-regression with trend-robust seasonality detection), a walk-forward backtester that scores within-10% accuracy, and a GET /gas/forecast/:operation endpoint that returns forecast points plus a confidence rating. 11 new tests pass, including a >=90% within-10% backtest-accuracy assertion.

Commits (one per issue)

  1. feat(security): … (close #705)
  2. perf(liquidate): … (close #835)
  3. feat(calldata): … (close #840)
  4. feat(gas): … (close #717)
  5. fix(risk-params): complete truncated get_legacy_risk_params (out-of-scope baseline build fix)

Verification

  • stellarlend-security: cargo test passes (default + testutils).
  • calldata-encoding: cargo test passes.
  • Gas forecast: npx jest api/src/__tests__/gas.forecast.test.ts — 11/11 pass.
  • Full api suite: 448/453 pass; the 5 failures are pre-existing baseline issues unrelated to this work (missing lending.controller.relayDelegated, etc.).

⚠️ Pre-existing Rust build breakage (NOT caused by this PR)

The Rust workspace does not compile at main due to unrelated SDK-27 version-drift errors (missing Symbol/Val, MultisigConfig, Address::zero, CircuitBreakerStatus::{Emergency,Paused}, reserve::get_reserve_balance, etc.). Only stellarlend-security and calldata-encoding build locally. No CI gate runs the Rust build (see ci.yml); gas-benchmarks.yml builds sequentially. This is documented here so reviewers are aware the full contract build cannot be verified in this environment.

…curity crate (close Smartdevs17#705)

Add a reusable Soroban reentrancy-guard crate at contracts/security with guard,
error, keys, macros, and test-utils modules. Rewrite the hello-world and lending
reentrancy modules as thin wrappers over the shared crate, and document the
reusable pattern. Fixes a pre-existing truncated get_legacy_risk_params baseline.
…lose Smartdevs17#835)

Cache the multi-asset-collateral check into a local, lazy-load oracle prices as
Options and reuse them across the collateral-value and seized computations, and
reuse the aggregate collateral balance for non-multi-asset users to avoid a
redundant storage read. Add bench_batch_liquidate benchmark and setup helper.
The legacy risk-params getter was cut off mid-return, which broke the Rust
build. Restore the missing instruction, enabling baseline compilation.
…_compressed (close Smartdevs17#840)

Upgrade the calldata-encoding lib to SDK-27 (alloc, u32 op_type, no_std) and
integrate it into hello-world via batch_liquidate_compressed, which decodes a
packed byte blob (flag byte, varint-length-prefixed StrKey addresses, varint
amount) into batch liquidation requests.
…lose Smartdevs17#717)

Add a Holt-Winters + linear-regression forecast model with trend-robust
seasonality detection, a walk-forward backtester that scores within-10%
accuracy, and a GET /gas/forecast/:operation endpoint returning points plus a
confidence rating. New tests cover model selection, >=90% backtest accuracy,
and endpoint shape.
@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

@Cyberking99 is attempting to deploy a commit to the smartdevs17's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@Cyberking99 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant