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
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.
_Originally posted by @jtraglia in https://github.com/ethereum/consensus-specs/pull/3557#discussion_r1416551306_