Re-enable balancer#2505
Conversation
🛡️ AI Review — Skeptic (security review)VERDICT: VULNERABLE BASELINE scrutiny: author has repo write permission and substantial prior subtensor activity; no Gittensor allowlist hit found; branch feat/balancer_swap -> devnet-ready. I found no Findings
Other findings
Prior-comment reconciliation
ConclusionI found no evidence of intentional backdoor, but this PR is not safe to merge while runtime upgrade state can still be lost/orphaned and build/runtime dependencies are sourced from unvetted Git repositories. 📜 Previous run (superseded)
# 🔍 AI Review — Auditor (domain review) has not yet run on this PR. |
|
🔄 AI review updated — Skeptic: VULNERABLE |
| zstd-sys = { git = "https://github.com/gztensor/zstd-sys" } | ||
| zstd-safe = { git = "https://github.com/gztensor/zstd-safe" } No newline at end of file |
There was a problem hiding this comment.
[HIGH] Do not globally patch zstd to author-controlled git forks
This globally replaces crates.io zstd-sys and zstd-safe with Git forks under the PR author's account. zstd-sys includes build-time native code, so once CI/builds are approved this is a supply-chain execution path that bypasses normal crates.io provenance. Remove the patch or replace it with a vetted upstream release or an organization-controlled, pinned fork with a documented reason.
| // Cleanup uniswap v3 and migrate to balancer | ||
| .saturating_add( | ||
| migrations::migrate_swapv3_to_balancer::migrate_swapv3_to_balancer::<T>(), |
There was a problem hiding this comment.
[HIGH] Migration drops old swap price state even when balancer initialization fails
This newly wires migrate_swapv3_to_balancer, but that migration calls maybe_initialize_palswap(...).unwrap_or_default() and then clears AlphaSqrtPrice and the rest of the V3 maps. If balancer initialization rejects an imbalanced subnet, the error is swallowed and the old price/liquidity state is still deleted, leaving that subnet migrated as if it succeeded. Make the migration fail-safe: only clear old state after successful initialization for every subnet, or preserve/record failures and do not mark the migration complete.
| pallet-subtensor-swap-runtime-api = { path = "pallets/swap/runtime-api", default-features = false } | ||
| pallet-subtensor-swap-rpc = { path = "pallets/swap/rpc", default-features = false } | ||
| procedural-fork = { path = "support/procedural-fork", default-features = false } | ||
| safe-bigmath = { package = "safe-bigmath", default-features = false, git = "https://github.com/sam0x17/safe-bigmath" } |
There was a problem hiding this comment.
[MEDIUM] New runtime math dependency is pulled from Git instead of a vetted release
safe-bigmath is introduced as a Git dependency and is used in runtime swap math. Cargo.lock currently pins a commit, but the dependency lacks normal crates.io provenance and review signals in the manifest. For runtime economic math, use a vetted release or vendor/audit the exact source under organization control before merging.
|
🔄 AI review updated — Skeptic: VULNERABLE |
| zstd-sys = { git = "https://github.com/gztensor/zstd-sys" } | ||
| zstd-safe = { git = "https://github.com/gztensor/zstd-safe" } No newline at end of file |
There was a problem hiding this comment.
[HIGH] Do not globally patch zstd to author-controlled Git forks
This workspace-wide [patch.crates-io] overrides every zstd-sys and zstd-safe consumer to build from github.com/gztensor/*. Those crates run native build logic during CI and developer builds, so this is a supply-chain execution path controlled by the PR author rather than by crates.io checksums or an opentensor-owned fork. Remove the patch or move any required zstd fix to a vetted release/opentensor-controlled source before merging.
| if let Err(error) = crate::Pallet::<T>::maybe_initialize_palswap(netuid, Some(price)) { | ||
| log::warn!( | ||
| "Migration '{}' failed to initialize balancer with V3 price for netuid {}: {:?}. Falling back to default balancer.", | ||
| String::from_utf8_lossy(&migration_name), | ||
| netuid, | ||
| error, | ||
| ); | ||
| SwapBalancer::<T>::insert(netuid, Balancer::default()); | ||
| PalSwapInitialized::<T>::insert(netuid, true); |
There was a problem hiding this comment.
[HIGH] Do not replace failed price initialization with default weights before deleting old price state
If maybe_initialize_palswap(netuid, Some(price)) rejects the V3 price/reserve combination, this fallback marks the subnet initialized with Balancer::default() and the migration then removes AlphaSqrtPrice below. That converts an initialization failure into a permanent price reset to default weights while deleting the only old price state that could be retried or diagnosed. Runtime migration should preserve the old state or fail/skip cleanup for that netuid instead of silently initializing a materially different pool.
There was a problem hiding this comment.
This is expected behavior: If the state of v3 pool is not representable with balancer, it will be set to default balancer. Additionally, this case does not appear neither on mainnet nor testnet currently and it is nearly impossible that liquidity balance shifts so much between now and next release.
| pallet-subtensor-swap-runtime-api = { path = "pallets/swap/runtime-api", default-features = false } | ||
| pallet-subtensor-swap-rpc = { path = "pallets/swap/rpc", default-features = false } | ||
| procedural-fork = { path = "support/procedural-fork", default-features = false } | ||
| safe-bigmath = { package = "safe-bigmath", default-features = false, git = "https://github.com/sam0x17/safe-bigmath" } |
There was a problem hiding this comment.
[MEDIUM] New runtime math dependency is pulled from Git instead of a vetted release
safe-bigmath is used in runtime swap math, but this adds it directly from Git. Even though Cargo.lock pins the current revision, this bypasses normal crates.io provenance and makes future lock refreshes depend on a Git source for consensus-critical arithmetic. Vendor it, use a reviewed crates.io release, or move the needed code into an audited internal primitive before enabling it in runtime code.
|
🔄 AI review updated — Skeptic: VULNERABLE |
Description
Reintroduce balancer swap. The main PR:
#2290
Type of Change
Breaking Change
See #2290
Checklist
./scripts/fix_rust.shto ensure my code is formatted and linted correctly