Fix balancer performance#2803
Conversation
🚨🚨🚨 HOTFIX DETECTED 🚨🚨🚨It looks like you are trying to merge a hotfix PR into If you are trying to merge a hotfix PR, please complete the following essential steps:
If you do not complete these steps, your hotfix may be inadvertently removed in the future when branches are promoted to |
🛡️ AI Review — Skeptic (security review)VERDICT: SAFE BASELINE scrutiny: repo write permission, established contributor history, no trusted Gittensor allowlist match; fix/balancer-performance -> main is labeled and described as a hotfix. No The prior simulated-swap bypass is addressed: the input-reserve guard now runs before FindingsNo findings. Prior-comment reconciliation
ConclusionI did not find malicious intent or a remaining security vulnerability in the latest diff. The previously flagged oversized-input simulation path is now covered. 📜 Previous run (superseded)
🔍 AI Review — Auditor (domain review)VERDICT: 👍 Gittensor: LIKELY by recent subtensor-heavy contribution history; author has write permission and this main-target PR is labeled hotfix. PR body is substantive, FindingsNo findings. Prior-comment reconciliation
ConclusionApproving: the previous simulated-swap bypass is now covered before 📜 Previous run (superseded)
|
|
🔄 AI review updated — Skeptic: SAFE Auditor: 👎 |
…ensor into fix/balancer-performance
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
🔄 AI review updated — Skeptic: SAFE Auditor: 👎 |
|
🔄 AI review updated — Skeptic: SAFE Auditor: 👍 |
|
🔄 AI review updated — Skeptic: SAFE Auditor: 👎 |
…g back the initial stake when the recycle or burn leg fails.
|
🔄 AI review updated — Skeptic: VULNERABLE |
|
🔄 AI review updated — Skeptic: SAFE Auditor: 👍 |
Description
This hotfix reduces the precision used by the swap balancer exponentiation path and adds a hard guard that rejects swaps whose net input exceeds 1000x the current input-side reserve. The goal is to avoid pathological swap calculations for extremely large inputs while preserving the existing swap behavior for normal-sized orders.
Files of interest:
pallets/swap/src/pallet/balancer.rs: lowers exponentiation precision and caps positive-delta exponent results.pallets/swap/src/pallet/swap_step.rs: makes swap-step construction fallible and enforces the input-vs-reserve limit before and after limit-price adjustment.pallets/swap/src/pallet/mod.rs: addsSwapInputTooLarge.pallets/swap/src/pallet/tests.rs: adds boundary tests for the 1000x reserve limit in both swap directions.Runtime impact: swaps above the 1000x input reserve threshold now fail with
SwapInputTooLarge; swaps at the threshold remain allowed. This is runtime-affecting and requires aspec_versionbump.Testing: the PR adds unit coverage for rejecting over-limit inputs and allowing exactly-at-limit inputs in both swap directions. The author checklist states
./scripts/fix_rust.shand unit tests were run locally.Additional side-effect fix: Enforce atomic add-stake recycle/burn operations by rolling back the initial stake when the recycle or burn leg fails.