Skip to content
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

fix(discv5): flip exact bit in node id #7763

Closed
emhane opened this issue Apr 19, 2024 · 0 comments · Fixed by #7764
Closed

fix(discv5): flip exact bit in node id #7763

emhane opened this issue Apr 19, 2024 · 0 comments · Fixed by #7764
Assignees
Labels
A-discv5 Related to discv5 discovery C-debt A section of code is hard to understand or change

Comments

@emhane
Copy link
Member

emhane commented Apr 19, 2024

Describe the feature

Rn FINDNODE target selection in discv5, flips a whole byte. Actually it should flip only the specific bit at the given kbucket_index in the local node id. The bits[kbucket_index + 1..] should all be random.

/// Gets the next lookup target, based on which bucket is currently being targeted.
pub fn get_lookup_target(
kbucket_index: usize,
local_node_id: discv5::enr::NodeId,
) -> discv5::enr::NodeId {
// init target
let mut target = local_node_id.raw();
// make sure target has a 'log2distance'-long suffix that differs from local node id
if kbucket_index != 0 {
let suffix_bit_offset = MAX_KBUCKET_INDEX.saturating_sub(kbucket_index);
let suffix_byte_offset = suffix_bit_offset / 8;
// todo: flip the precise bit
// let rel_suffix_bit_offset = suffix_bit_offset % 8;
target[suffix_byte_offset] = !target[suffix_byte_offset];
if suffix_byte_offset != 31 {
for b in target.iter_mut().take(31).skip(suffix_byte_offset + 1) {
*b = rand::random::<u8>();
}
}
}

Additional context

No response

@emhane emhane added C-debt A section of code is hard to understand or change A-discv5 Related to discv5 discovery labels Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-discv5 Related to discv5 discovery C-debt A section of code is hard to understand or change
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants