-
Notifications
You must be signed in to change notification settings - Fork 317
Added root_claim_for #2784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devnet-ready
Are you sure you want to change the base?
Added root_claim_for #2784
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -345,6 +345,21 @@ impl<T: Config> Pallet<T> { | |
| } | ||
| } | ||
|
|
||
| pub fn do_root_claim_checked( | ||
| coldkey: T::AccountId, | ||
| subnets: BTreeSet<NetUid>, | ||
| ) -> Result<Weight, DispatchError> { | ||
| ensure!(!subnets.is_empty(), Error::<T>::InvalidSubnetNumber); | ||
| ensure!( | ||
| subnets.len() <= crate::MAX_SUBNET_CLAIMS, | ||
| Error::<T>::InvalidSubnetNumber | ||
| ); | ||
|
|
||
| Self::maybe_add_coldkey_index(&coldkey); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [HIGH] Arbitrary coldkeys can pollute the root auto-claim index
|
||
|
|
||
| Self::do_root_claim(coldkey, Some(subnets)) | ||
| } | ||
|
|
||
| pub fn do_root_claim( | ||
| coldkey: T::AccountId, | ||
| subnets: Option<BTreeSet<NetUid>>, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { beforeAll, describeSuite, expect } from "@moonwall/cli"; | ||
| import { subtensor } from "@polkadot-api/descriptors"; | ||
| import { ethers } from "ethers"; | ||
| import type { TypedApi } from "polkadot-api"; | ||
| import { | ||
| convertH160ToSS58, | ||
| createEthersWallet, | ||
| disableWhiteListCheck, | ||
| forceSetBalance, | ||
| ISTAKING_V2_ADDRESS, | ||
| IStakingV2ABI, | ||
| waitForFinalizedBlocks, | ||
| } from "../../utils"; | ||
|
|
||
| describeSuite({ | ||
| id: "claim-root-precompile", | ||
| title: "Staking V2 precompile: claimRoot", | ||
| foundationMethods: "zombie", | ||
| testCases: ({ it, context }) => { | ||
| let api: TypedApi<typeof subtensor>; | ||
| let ethWallet: ethers.Wallet; | ||
|
|
||
| beforeAll(async () => { | ||
| api = context.papi("Node").getTypedApi(subtensor); | ||
| const provider = context.ethers("EVM").provider as ethers.JsonRpcProvider; | ||
| ethWallet = createEthersWallet(provider); | ||
|
|
||
| await forceSetBalance(api, convertH160ToSS58(ethWallet.address)); | ||
| await disableWhiteListCheck(api, true); | ||
| await waitForFinalizedBlocks(api, 1); | ||
| }, 300000); | ||
|
|
||
| it({ | ||
| id: "T01", | ||
| title: "claimRoot self-claim dispatches successfully (no-op for an unstaked caller)", | ||
| test: async () => { | ||
| const staking = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, ethWallet); | ||
|
|
||
| // The precompile dispatches the self `claim_root` under the caller's derived | ||
| // coldkey. | ||
| const tx = await staking.claimRoot([1, 2, 3]); | ||
| const receipt = await tx.wait(); | ||
| expect(receipt?.status).toBe(1); | ||
| }, | ||
| }); | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[HIGH] Arbitrary coldkeys can pollute the root auto-claim index
claim_root_foraccepts any signed origin and passes an arbitrarycoldkeyinto this shared helper. The helper indexes that coldkey beforedo_root_claimproves the coldkey has any root stake; for a coldkey with no staking hotkeys,try_do_root_claimsimply iterates an empty vector, depositsRootClaimed, and commits. A caller can therefore pay only transaction fees to persistently growStakingColdkeys,StakingColdkeysByIndex, andNumStakingColdkeyswith arbitrary accounts, dilutingrun_auto_claim_root_divsselection and creating unbounded state bloat. Gate the index insertion on actual root stake, or makeclaim_root_forreject targets without root stake before callingmaybe_add_coldkey_index.