consensus-specs icon indicating copy to clipboard operation
consensus-specs copied to clipboard

`reverse_bits_limited` helper for `polynomial-commitments-sampling.md`

Open dankrad opened this issue 1 year ago • 1 comments

There's potential for a new helper function, which doesn't add much complexity, that could improve efficiency in a few spots, like here. Something like the following method might be a useful addition. Rather than BRP the list of roots, you can just compute the index/indices that you need.

def reverse_bits_limited(num_bits: int, value: int):
    reversed_bits = 0
    for _ in range(32): # 32-bit value
        reversed_bits = (reversed_bits << 1) | (value & 1)
        value >>= 1
    unused_bit_len = 32 - int(math.log2(num_bits))
    return reversed_bits >> unused_bit_len

Originally posted by @jtraglia in https://github.com/ethereum/consensus-specs/pull/3557#discussion_r1416551306

dankrad avatar Jan 11 '24 21:01 dankrad

I will try to make a PR for this later! This isn't a high priority addition IMO.

jtraglia avatar Jan 11 '24 21:01 jtraglia

I am closing this issue because it seems stale. Please, do not hesitate to reopen it if this is a mistake

leolara avatar Jun 10 '25 09:06 leolara