From c06ac81c671a01965c0ff31fdac01267405e79d8 Mon Sep 17 00:00:00 2001 From: Eric Tu <6364934+ec2@users.noreply.github.com> Date: Tue, 5 Aug 2025 22:37:07 -0400 Subject: [PATCH] Shuffling for 32 bit platforms (#7725) - In shuffling, a the raw_pivot (u64) is cast to a usize which will break on 32 bit systems. Now it is modulo'ed with the list_size first then cast to a usize. - ruint doesn't implement shifting with u64's on 32-bit arch. Since `prefix_bits` is u8 and NODE_ID_BITS = 256, we use them as u32's instead. See: https://docs.rs/ruint/latest/src/ruint/bits.rs.html#711 --- consensus/swap_or_not_shuffle/src/shuffle_list.rs | 3 +-- consensus/types/src/subnet_id.rs | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/consensus/swap_or_not_shuffle/src/shuffle_list.rs b/consensus/swap_or_not_shuffle/src/shuffle_list.rs index 3e93974fe0..8202b35cde 100644 --- a/consensus/swap_or_not_shuffle/src/shuffle_list.rs +++ b/consensus/swap_or_not_shuffle/src/shuffle_list.rs @@ -96,8 +96,7 @@ pub fn shuffle_list( loop { buf.set_round(r); - let pivot = buf.raw_pivot() as usize % list_size; - + let pivot = (buf.raw_pivot() % list_size as u64) as usize; let mirror = (pivot + 1) >> 1; buf.mix_in_position(pivot >> 8); diff --git a/consensus/types/src/subnet_id.rs b/consensus/types/src/subnet_id.rs index 7289a817a3..2a5d183a50 100644 --- a/consensus/types/src/subnet_id.rs +++ b/consensus/types/src/subnet_id.rs @@ -11,7 +11,7 @@ const MAX_SUBNET_ID: usize = 64; /// The number of bits in a Discovery `NodeId`. This is used for binary operations on the node-id /// data. -const NODE_ID_BITS: u64 = 256; +const NODE_ID_BITS: u32 = 256; static SUBNET_ID_TO_STRING: LazyLock> = LazyLock::new(|| { let mut v = Vec::with_capacity(MAX_SUBNET_ID); @@ -102,7 +102,7 @@ impl SubnetId { spec: &ChainSpec, ) -> impl Iterator { // The bits of the node-id we are using to define the subnets. - let prefix_bits = spec.attestation_subnet_prefix_bits as u64; + let prefix_bits = spec.attestation_subnet_prefix_bits as u32; let node_id = U256::from_be_slice(&raw_node_id); // calculate the prefixes used to compute the subnet and shuffling