Skip to content

Commit

Permalink
Merge pull request #2788 from subspace/fix-pos
Browse files Browse the repository at this point in the history
Revert "Find the actual first matching element when generating PoS proofs or finding quality"
  • Loading branch information
nazar-pc authored May 24, 2024
2 parents 43db71a + d39047a commit b27d113
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions crates/subspace-proof-of-space/src/chiapos/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,20 @@ where
.try_into()
.expect("Challenge is known to statically have enough bytes; qed"),
) >> (u32::BITS as usize - usize::from(K));
let mut first_matching_element = ys
let first_matching_element = ys
.binary_search_by(|&y| y.first_k_bits::<K>().cmp(&first_k_challenge_bits))
.unwrap_or_else(|insert| insert);

// We only compare first K bits above, which is why `binary_search_by` is not guaranteed to
// find the very first match in case there are multiple
for index in (0..first_matching_element).rev() {
if ys[index].first_k_bits::<K>() == first_k_challenge_bits {
first_matching_element = index;
} else {
break;
}
}
// TODO: Restore this when making a breaking change to the protocol
// // We only compare first K bits above, which is why `binary_search_by` is not guaranteed to
// // find the very first match in case there are multiple
// for index in (0..first_matching_element).rev() {
// if ys[index].first_k_bits::<K>() == first_k_challenge_bits {
// first_matching_element = index;
// } else {
// break;
// }
// }

// Iterate just over elements that are matching `first_k_challenge_bits` prefix
ys[first_matching_element..]
Expand Down Expand Up @@ -207,19 +208,20 @@ where
.try_into()
.expect("Challenge is known to statically have enough bytes; qed"),
) >> (u32::BITS as usize - usize::from(K));
let mut first_matching_element = ys
let first_matching_element = ys
.binary_search_by(|&y| y.first_k_bits::<K>().cmp(&first_k_challenge_bits))
.unwrap_or_else(|insert| insert);

// We only compare first K bits above, which is why `binary_search_by` is not guaranteed to
// find the very first match in case there are multiple
for index in (0..first_matching_element).rev() {
if ys[index].first_k_bits::<K>() == first_k_challenge_bits {
first_matching_element = index;
} else {
break;
}
}
// TODO: Restore this when making a breaking change to the protocol
// // We only compare first K bits above, which is why `binary_search_by` is not guaranteed to
// // find the very first match in case there are multiple
// for index in (0..first_matching_element).rev() {
// if ys[index].first_k_bits::<K>() == first_k_challenge_bits {
// first_matching_element = index;
// } else {
// break;
// }
// }

// Iterate just over elements that are matching `first_k_challenge_bits` prefix
ys[first_matching_element..]
Expand Down

0 comments on commit b27d113

Please sign in to comment.