Skip to content

Commit c8a392e

Browse files
author
EchoBT
committed
fix: use u16 for NetUidStorageIndex in hash computation
Subtensor's NetUidStorageIndex is a newtype over u16, not u32. SCALE encoding: u16 = 2 bytes vs u32 = 4 bytes. This was the root cause of InvalidRevealCommitHashNotMatch errors. Updated bittensor-rs to 52e9c1f with the same fix.
1 parent 41e0a05 commit c8a392e

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ license = "MIT"
3030

3131
[workspace.dependencies]
3232
# Bittensor
33-
bittensor-rs = { git = "https://github.com/CortexLM/bittensor-rs", rev = "32c6bfa" }
33+
bittensor-rs = { git = "https://github.com/CortexLM/bittensor-rs", rev = "52e9c1f" }
3434

3535
# Async runtime
3636
tokio = { version = "1.40", features = ["full", "sync", "macros", "rt-multi-thread"] }

crates/challenge-sdk/src/weights.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,15 @@ pub fn compute_subtensor_hash(
247247
// In subtensor: netuid_index = get_mechanism_storage_index(netuid, mecid)
248248
// GLOBAL_MAX_SUBNET_COUNT = 4096
249249
// Formula: mecid * 4096 + netuid
250-
let mecid = mechanism_id.unwrap_or(0) as u32;
251-
let netuid_index: u32 = mecid * 4096 + (netuid as u32);
250+
// IMPORTANT: NetUidStorageIndex is u16 in subtensor, not u32!
251+
let mecid = mechanism_id.unwrap_or(0) as u16;
252+
let netuid_index: u16 = mecid.saturating_mul(4096).saturating_add(netuid);
252253

253254
// Create SCALE-encodable tuple matching subtensor's format
255+
// NetUidStorageIndex is a newtype over u16, so it SCALE encodes as u16
254256
let data = (
255257
account, // [u8; 32] - AccountId
256-
netuid_index, // u32 - NetUidStorageIndex
258+
netuid_index, // u16 - NetUidStorageIndex (NOT u32!)
257259
uids.to_vec(), // Vec<u16>
258260
values.to_vec(), // Vec<u16>
259261
salt.to_vec(), // Vec<u16>

0 commit comments

Comments
 (0)