Skip to content

Add min_childkey_take_per_subnet hyperparameter#2734

Open
gztensor wants to merge 10 commits into
devnet-readyfrom
feat/min-ck-take-hyperparam
Open

Add min_childkey_take_per_subnet hyperparameter#2734
gztensor wants to merge 10 commits into
devnet-readyfrom
feat/min-ck-take-hyperparam

Conversation

@gztensor

@gztensor gztensor commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Description

Add a new hyperparameter min_childkey_take_per_subnet for the existing admin util extrinsic with matching name.

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):

Breaking Change

Introduces a new min_childkey_take_per_subnet field in get_subnet_hyperparams_v3.

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 self-assigned this Jun 9, 2026
@gztensor gztensor added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🛡️ AI Review — Skeptic (security review)

VERDICT: SAFE

BASELINE scrutiny: write-permission author with substantive contribution history; no Gittensor allowlist hit found; branch feat/min-ck-take-hyperparam -> devnet-ready.

Static review found a narrow runtime/pallet diff: a read-only min_childkey_take_per_subnet hyperparameter exposure, a stricter new_hotkey ownership guard before hotkey swap state transfer, focused test updates, and a spec_version bump. No .github/ai-review/*, .github/copilot-instructions.md, workflow, build-script, dependency, or lockfile changes are present.

Findings

No findings.

Conclusion

No malicious pattern or security vulnerability was found. The changes do not introduce a runtime panic path, origin bypass, dependency surface, or build-time execution surface.


🔍 AI Review — Auditor (domain review)

VERDICT: 👍

Gittensor: LIKELY; author is not in the trusted allowlists but has write permission and substantial recent subtensor history.

Description discrepancies: the PR body describes adding min_childkey_take_per_subnet to get_subnet_hyperparams_v3, but the diff also changes do_swap_hotkey authorization behavior for existing new_hotkey owners. That swap behavior change should be documented in the PR body.

Auto-fix: none. git diff --check is clean, and runtime/src/lib.rs bumps spec_version from 417 to 418.

The prior weight-accounting concern is addressed in the current diff: the new new_hotkey existence read and conditional ownership reads are now accrued before those checks run.

Findings

No findings.

Prior-comment reconciliation

  • 5216a5a8: addressed — The current diff now accrues one read for hotkey_account_exists(new_hotkey) and two additional reads before coldkey_owns_hotkey(&coldkey, new_hotkey), matching the helper storage accesses on the successful existing-new-hotkey path.

Conclusion

The added hyperparameter surface is narrow and covered by the V3 hyperparameter tests. I did not find a remaining blocking domain issue in the current diff.


📜 Previous run (superseded)
Sev File Finding Status
HIGH pallets/subtensor/src/swap/swap_hotkey.rs:58 Account for the new hotkey-owner reads in swap weights ✅ Addressed
The current diff now accrues one read for hotkey_account_exists(new_hotkey) and two additional reads before coldkey_owns_hotkey(&coldkey, new_hotkey), matching the helper storage accesses on the successful existing-new-hotkey path.

@github-actions

github-actions Bot commented Jun 9, 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 on lines 49 to 58
// 3. If the new hotkey already exists globally, ensure the coldkey owns it
if Self::hotkey_account_exists(new_hotkey) {
ensure!(
Self::coldkey_owns_hotkey(&coldkey, new_hotkey),
Error::<T>::NonAssociatedColdKey
);
}

// 4. Initialize the weight for this operation
let mut weight = T::DbWeight::get().reads(2);

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] Account for the new hotkey-owner reads in swap weights

This new check performs extra Owner storage reads before weight is initialized: hotkey_account_exists(new_hotkey) reads once, and when it exists coldkey_owns_hotkey reads again via contains_key plus get. Those reads are not included in the returned post-dispatch weight, and the pre-dispatch weights for swap_hotkey / swap_hotkey_v2 were not updated or rebenchmarked. Since this is a runtime extrinsic, changed storage access must be reflected in weight. Initialize/accrue the dynamic weight before this check or collapse it into a single charged storage access, then update the generated swap_hotkey weight and the hardcoded swap_hotkey_v2 weight.

@github-actions

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 on lines 49 to 58
// 3. If the new hotkey already exists globally, ensure the coldkey owns it
if Self::hotkey_account_exists(new_hotkey) {
ensure!(
Self::coldkey_owns_hotkey(&coldkey, new_hotkey),
Error::<T>::NonAssociatedColdKey
);
}

// 4. Initialize the weight for this operation
let mut weight = T::DbWeight::get().reads(2);

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] Account for the new hotkey-owner reads in swap weights

This new ownership gate performs additional Owner storage reads before weight is initialized. On the successful path where new_hotkey already exists and is owned by the caller, hotkey_account_exists(new_hotkey) reads once and coldkey_owns_hotkey(&coldkey, new_hotkey) reads again via contains_key plus get, but the returned post-dispatch weight still starts at only the two reads for the old-hotkey ownership check. That under-reports the actual runtime work and can over-refund swap_hotkey / swap_hotkey_v2.

Suggested change
// 3. If the new hotkey already exists globally, ensure the coldkey owns it
if Self::hotkey_account_exists(new_hotkey) {
ensure!(
Self::coldkey_owns_hotkey(&coldkey, new_hotkey),
Error::<T>::NonAssociatedColdKey
);
}
// 4. Initialize the weight for this operation
let mut weight = T::DbWeight::get().reads(2);
// 3. Initialize the weight for ownership checks
let mut weight = T::DbWeight::get().reads(2);
// 4. If the new hotkey already exists globally, ensure the coldkey owns it
if Self::hotkey_account_exists(new_hotkey) {
weight.saturating_accrue(T::DbWeight::get().reads(1));
ensure!(
Self::coldkey_owns_hotkey(&coldkey, new_hotkey),
Error::<T>::NonAssociatedColdKey
);
weight.saturating_accrue(T::DbWeight::get().reads(2));
} else {
weight.saturating_accrue(T::DbWeight::get().reads(1));
}

@github-actions

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/swap/swap_hotkey.rs Outdated
@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants