Skip to main content

select_subtree_path

Function select_subtree_path 

Source
pub fn select_subtree_path(
    nonce: &[u8; 32],
    key_count: u32,
) -> Option<SubtreePath>
Expand description

Deterministically select one contiguous subtree from (nonce, key_count).

Picks one fixed-depth block of span = next_power_of_two(ceil(sqrt(N))) leaves, choosing the block uniformly by nonce_u64 % slot_count. Every block (including the short tail) is selectable with roughly equal probability, so the whole tree is covered over many audits, and a single request always reads at most span (≤ ~sqrt(N), ≤ 1024 at the cap) leaves — regardless of the nonce. This replaces the old nonce-bit descent, whose stop-at-parent rule let an adversarial nonce select a subtree far larger than sqrt(N) (up to the whole tree at 2^k + 1), an unbounded round-1 work amplification.

Unpredictability is preserved: the responder cannot know the selected slot until it receives the fresh nonce. For key_count <= SMALL_TREE_FULL_AUDIT_FLOOR the whole tree is selected.

Returns None only for an out-of-protocol key_count (caller rejects).