Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add lock-aware stake transfer extrinsic#2717

Open
gztensor wants to merge 12 commits into
devnet-ready from
feat/transfer-free-locked-alpha
Open

Add lock-aware stake transfer extrinsic #2717
gztensor wants to merge 12 commits into
devnet-ready from
feat/transfer-free-locked-alpha

Conversation

@gztensor

@gztensor gztensor commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Description

This change adds transfer_stake_lock_aware extrinsic, a variant of transfer_stake that lets callers choose whether to transfer from the locked or unlocked portion of stake via a new locked boolean. The transition path now caps the requested amount to the selected bucket, so it transfers the maximum available amount without erroring when the request exceeds locked or unlocked alpha. For locked transfers, the existing lock state follows the moved stake and preserves the lock hotkey and proportional conviction; for unlocked transfers, only free stake moves and lock state remains untouched.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run ./scripts/fix_rust.sh to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@gztensor gztensor added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Jun 4, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment on lines +371 to +379
let alpha_amount = lock_aware_transfer
.map(|locked| {
alpha_amount.min(Self::lock_aware_transferable_alpha(
origin_coldkey,
origin_netuid,
locked,
))
})
.unwrap_or(alpha_amount);

@github-actions github-actions Bot Jun 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] Capped lock-aware amount can mutate stake before failing minimum check

For same-subnet lock-aware transfers, this cap can reduce a caller-supplied alpha_amount to a dust-sized selected bucket after any transaction-extension or input-level minimum checks have seen the original amount. The capped value then reaches transfer_stake_within_subnet, which calls transfer_lock and decreases/increases stake before computing tao_equivalent and returning AmountTooLow for sub-minimum transfers. A caller can submit a large alpha_amount, have it capped to a below-minimum locked/unlocked remainder, and still move stake/lock state through a dispatch that reports failure. Validate the capped move_amount against DefaultMinStake before any lock/stake mutation, or move the same-netuid minimum check ahead of transfer_lock and the stake balance updates.

github-actions Bot commented Jun 4, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

🛡️ AI Review — Skeptic (security review)

VERDICT: VULNERABLE

BASELINE scrutiny: author has write permission and substantial prior subtensor activity; no Gittensor allowlist hit; branch feat/transfer-free-locked-alpha -> devnet-ready.

No .github, dependency, lockfile, or build-script changes were present. Static review focused on the new runtime staking path and lock accounting.

Findings

Sev File Finding
HIGH pallets/subtensor/src/staking/move_stake.rs:366 Lock-aware cap is not bound to the selected hotkey inline

Prior-comment reconciliation

  • 9b61b93b: not addressed — The latest diff still caps using coldkey-level locked/unlocked alpha and passes only coldkey/netuid into lock_aware_transferable_alpha, so the selected-hotkey mismatch remains reachable.

Conclusion

The prior HIGH issue remains: the new lock-aware transfer path caps against coldkey-level lock state while debiting the caller-selected hotkey. This can detach lock state from the stake it is meant to constrain, so the PR remains vulnerable until the cap and lock movement are bound to the selected hotkey.


📜 Previous run (superseded)
(削除) Sev (削除ここまで) (削除) File (削除ここまで) (削除) Finding (削除ここまで) Status
(削除) HIGH (削除ここまで) (削除) pallets/subtensor/src/staking/move_stake.rs:366 (削除ここまで) (削除) Lock-aware cap is not bound to the selected hotkey (削除ここまで) ➡️ Carried forward to current findings
The latest diff still caps using coldkey-level locked/unlocked alpha and passes only coldkey/netuid into lock_aware_transferable_alpha, so the selected-hotkey mismatch remains reachable.

🔍 AI Review — Auditor (domain review)

VERDICT: 👎

Gittensor: LIKELY by recent subtensor-focused PR history; established contributor with write permission. Prior cross-subnet lock finding remains.

PR description is substantive. I did not run builds/tests; the blocking issue is visible statically. I checked local runtime/src/lib.rs (spec_version: 416) but the devnet spec-version RPC could not be resolved in this environment, so I left the workspace unchanged.

Findings

Sev File Finding
HIGH pallets/subtensor/src/staking/move_stake.rs:407 Cross-subnet locked transfers still do not move lock state (post-failed)

Prior-comment reconciliation

  • 04404794: not addressed — The same-subnet path now passes lock_aware_transfer into transfer_lock, but the cross-subnet branch still swaps/restakes without migrating or rejecting lock state.

Conclusion

Blocking because transfer_stake_lock_aware(..., locked: true) still advertises cross-subnet locked transfers without migrating or rejecting the lock state on that path. The implementation should either reject locked cross-subnet transfers or move the lock/conviction state with targeted coverage.


📜 Previous run (superseded)
(削除) Sev (削除ここまで) (削除) File (削除ここまで) (削除) Finding (削除ここまで) Status
(削除) HIGH (削除ここまで) (削除) pallets/subtensor/src/staking/move_stake.rs:195 (削除ここまで) (削除) Cross-subnet locked transfers do not move lock state (削除ここまで) ➡️ Carried forward to current findings
The same-subnet path now passes lock_aware_transfer into transfer_lock, but the cross-subnet branch still swaps/restakes without migrating or rejecting lock state.

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: VULNERABLE

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment on lines +183 to +195
let tao_moved = Self::transition_stake_internal(
&coldkey,
&destination_coldkey,
&hotkey,
&hotkey,
origin_netuid,
destination_netuid,
alpha_amount,
None,
None,
true,
false,
Some(locked),

@github-actions github-actions Bot Jun 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] Cross-subnet locked transfers do not move lock state

Some(locked) is passed into the generic transition path even when origin_netuid != destination_netuid, but the cross-subnet branch later uses unstake_from_subnet and stake_into_subnet rather than transfer_lock. That means no lock state is moved to the destination subnet/coldkey. Worse, validate_stake_transition still enforces ensure_available_to_unstake for cross-subnet moves, so a fully locked position fails with StakeUnavailable, while a partially locked position with enough unlocked alpha can succeed by moving unlocked stake and leaving the source lock behind. This contradicts the new extrinsic docs and the PR body claim that locked transfers preserve/move the lock state. Either reject origin_netuid != destination_netuid for this extrinsic, or implement explicit cross-subnet lock migration and add a test that locked=true moves lock state across netuids.

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment thread pallets/subtensor/src/staking/move_stake.rs

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: VULNERABLE

@gztensor gztensor self-assigned this Jun 5, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment thread pallets/subtensor/src/staking/move_stake.rs

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: VULNERABLE

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment thread pallets/subtensor/src/staking/move_stake.rs

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: VULNERABLE

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment thread pallets/subtensor/src/staking/move_stake.rs

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: VULNERABLE

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

Reviewers

@github-actions github-actions[bot] github-actions[bot] left review comments

At least 2 approving reviews are required to merge this pull request.

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /