ethereum / consensus-specs

Ethereum Proof-of-Stake Consensus Specifications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

dankrad opened this issue · 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 #3557 (comment)

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