Skip to content

Commit c06ac81

Browse files
authored
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
1 parent 0dcce40 commit c06ac81

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

consensus/swap_or_not_shuffle/src/shuffle_list.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ pub fn shuffle_list(
9696
loop {
9797
buf.set_round(r);
9898

99-
let pivot = buf.raw_pivot() as usize % list_size;
100-
99+
let pivot = (buf.raw_pivot() % list_size as u64) as usize;
101100
let mirror = (pivot + 1) >> 1;
102101

103102
buf.mix_in_position(pivot >> 8);

consensus/types/src/subnet_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const MAX_SUBNET_ID: usize = 64;
1111

1212
/// The number of bits in a Discovery `NodeId`. This is used for binary operations on the node-id
1313
/// data.
14-
const NODE_ID_BITS: u64 = 256;
14+
const NODE_ID_BITS: u32 = 256;
1515

1616
static SUBNET_ID_TO_STRING: LazyLock<Vec<String>> = LazyLock::new(|| {
1717
let mut v = Vec::with_capacity(MAX_SUBNET_ID);
@@ -102,7 +102,7 @@ impl SubnetId {
102102
spec: &ChainSpec,
103103
) -> impl Iterator<Item = SubnetId> {
104104
// The bits of the node-id we are using to define the subnets.
105-
let prefix_bits = spec.attestation_subnet_prefix_bits as u64;
105+
let prefix_bits = spec.attestation_subnet_prefix_bits as u32;
106106

107107
let node_id = U256::from_be_slice(&raw_node_id);
108108
// calculate the prefixes used to compute the subnet and shuffling

0 commit comments

Comments
 (0)