Skip to content

extend subtensor extension#2569

Merged
sam0x17 merged 18 commits into
devnet-readyfrom
subtensor-dispatch
May 19, 2026
Merged

extend subtensor extension#2569
sam0x17 merged 18 commits into
devnet-readyfrom
subtensor-dispatch

Conversation

@open-junius
Copy link
Copy Markdown
Contributor

Description

The PR try to add extension for all Pays::no extrinsic, to guarantee no one misuse it as malicious attack.

Related Issue(s)

  • Closes #[issue number]

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

If this PR introduces a breaking change, please provide a detailed description of the impact and the migration path for existing applications.

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

Screenshots (if applicable)

Please include any relevant screenshots or GIFs that demonstrate the changes made.

Additional Notes

Please provide any additional information or context that may be helpful for reviewers.

@open-junius open-junius self-assigned this Apr 7, 2026
@open-junius open-junius added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Apr 15, 2026
setup_reserves(
netuid,
1_000_000_000_000_u64.into(),
1_000_000_000_000_u64.into(),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's start adding TypeScript tests for newly added extrinsics, maybe as a separate PR, for previously added.
You can check examples of those tests here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't get your point. The PR doesn't add any new extrinsic. setup_reserves is a helper function in test.

@open-junius open-junius marked this pull request as ready for review April 17, 2026 03:10
Copy link
Copy Markdown
Collaborator

@shamil-gadelshin shamil-gadelshin left a comment

Choose a reason for hiding this comment

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

Looks good overall. I found a minor issue.

Ok(())
}

/// Same checks as [`Self::do_serve_prometheus`] before storage writes (for transaction extension).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It makes sense to use validate_serve_prometheus within do_serve_prometheus if it is the same code to remove a duplication.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will remove the redundant part.

Copy link
Copy Markdown
Contributor

@thewhaleking thewhaleking left a comment

Choose a reason for hiding this comment

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

edited

Copy link
Copy Markdown
Contributor

@thewhaleking thewhaleking left a comment

Choose a reason for hiding this comment

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

One blocking bug in the new reveal_mechanism_weights SignedExtension arm — it discards mecid and looks up the commit hash under the wrong storage index, so any reveal under mecid != MechId::MAIN is rejected at the pool as CommitNotFound. Inline suggestion attached. Caught by bittensor e2e test_commit_and_reveal_weights_legacy.

Comment on lines +168 to +198
Some(Call::reveal_mechanism_weights {
netuid,
mecid: _,
uids,
values,
salt,
version_key,
}) => {
if Self::check_weights_min_stake(who, *netuid) {
let provided_hash = Pallet::<T>::get_commit_hash(
who,
NetUidStorageIndex::from(*netuid),
uids,
values,
salt,
*version_key,
);
match Pallet::<T>::find_commit_block_via_hash(provided_hash) {
Some(commit_block) => {
if Pallet::<T>::is_reveal_block_range(*netuid, commit_block) {
Ok((Default::default(), (), origin))
} else {
Err(CustomTransactionError::CommitBlockNotInRevealRange.into())
}
}
None => Err(CustomTransactionError::CommitNotFound.into()),
}
} else {
Err(CustomTransactionError::StakeAmountTooLow.into())
}
}
Copy link
Copy Markdown
Contributor

@thewhaleking thewhaleking May 14, 2026

Choose a reason for hiding this comment

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

.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you! will fix it.

@open-junius
Copy link
Copy Markdown
Contributor Author

@thewhaleking there are two failed test cases now.

  • commit_and_reveal need to reveal at a valid block range
  • change_take hotkey should exist and valid coldkey-hotkey relation.
    please check again.

@thewhaleking
Copy link
Copy Markdown
Contributor

@thewhaleking there are two failed test cases now.

  • commit_and_reveal need to reveal at a valid block range
  • change_take hotkey should exist and valid coldkey-hotkey relation.
    please check again.

Great. bittensor#3352 will fix these aswell. Thanks!

thewhaleking
thewhaleking previously approved these changes May 15, 2026
.map(|validity| (validity, (), origin.clone()))
}

Some(Call::swap_hotkey_v2 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This one is Pays::Yes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will remove this call.

}
Some(Call::increase_take { hotkey, take: _ })
| Some(Call::decrease_take { hotkey, take: _ }) => {
Self::result_to_validity(Pallet::<T>::do_take_checks(who, hotkey), 0u64)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We also check if the take is in range, so probably it makes sense to add this check as well, otherwise we don't check the whole thing we do in the extrinsic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It makes sense to add the check for value scope. I will add it.

l0r1s
l0r1s previously approved these changes May 15, 2026
Comment on lines +176 to +197
if Self::check_weights_min_stake(who, *netuid) {
let provided_hash = Pallet::<T>::get_commit_hash(
who,
Pallet::<T>::get_mechanism_storage_index(*netuid, *mecid),
uids,
values,
salt,
*version_key,
);
match Pallet::<T>::find_commit_block_via_hash(provided_hash) {
Some(commit_block) => {
if Pallet::<T>::is_reveal_block_range(*netuid, commit_block) {
Ok((Default::default(), (), origin))
} else {
Err(CustomTransactionError::CommitBlockNotInRevealRange.into())
}
}
None => Err(CustomTransactionError::CommitNotFound.into()),
}
} else {
Err(CustomTransactionError::StakeAmountTooLow.into())
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nesting could be reduced, only a suggestion

Suggested change
if Self::check_weights_min_stake(who, *netuid) {
let provided_hash = Pallet::<T>::get_commit_hash(
who,
Pallet::<T>::get_mechanism_storage_index(*netuid, *mecid),
uids,
values,
salt,
*version_key,
);
match Pallet::<T>::find_commit_block_via_hash(provided_hash) {
Some(commit_block) => {
if Pallet::<T>::is_reveal_block_range(*netuid, commit_block) {
Ok((Default::default(), (), origin))
} else {
Err(CustomTransactionError::CommitBlockNotInRevealRange.into())
}
}
None => Err(CustomTransactionError::CommitNotFound.into()),
}
} else {
Err(CustomTransactionError::StakeAmountTooLow.into())
}
if !Self::check_weights_min_stake(who, *netuid) {
return Err(CustomTransactionError::StakeAmountTooLow.into());
}
let provided_hash = Pallet::<T>::get_commit_hash(
who,
NetUidStorageIndex::from(*netuid),
uids,
values,
salt,
*version_key,
);
let Some(commit_block) = Pallet::<T>::find_commit_block_via_hash(provided_hash)
else {
return Err(CustomTransactionError::CommitNotFound.into());
};
if !Pallet::<T>::is_reveal_block_range(*netuid, commit_block) {
return Err(CustomTransactionError::CommitBlockNotInRevealRange.into());
}
Ok((Default::default(), (), origin))

@open-junius
Copy link
Copy Markdown
Contributor Author

@thewhaleking add the value scope check for delegate take. need to update e2e tests. thanks!

Some(Call::increase_take { hotkey, take })
            | Some(Call::decrease_take { hotkey, take }) => {
                if *take < Pallet::<T>::get_min_delegate_take() {
                    return Err(CustomTransactionError::DelegateTakeTooLow.into());
                }
                if *take > Pallet::<T>::get_max_delegate_take() {
                    return Err(CustomTransactionError::DelegateTakeTooHigh.into());
                }

@open-junius open-junius requested review from evgeny-s and l0r1s May 18, 2026 23:49
@sam0x17 sam0x17 merged commit 0c90190 into devnet-ready May 19, 2026
387 of 392 checks passed
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.

7 participants