Skip to content

[Medium-2] Unbounded memory allocation in key generation #133

@this-vishalsingh

Description

@this-vishalsingh

Context: crates/xmss/src/xmss.rs

Details

The xmss_key_gen function constructs a merkle tree by allocating and storing all leaves and intermediate nodes in memory.

With XMSS_MAX_LOG_LIFETIME set to 30, a log_lifetime of 30 causes (1 << 30) ≈ 1 billion leaves, leading to tens of gigabytes of allocations and potential out-of-memory crashes (Denial of Service).

Recommendation

Limit the maximum allowed log_lifetime to a value that prevents excessive memory usage or switch to a streaming/on-the-fly Merkle tree computation that does not require storing the entire tree in memory.

Impact

  • Bug type: Resource Management

  • Code:

let leaves = (first_slot..first_slot + (1 << log_lifetime))
    .into_par_iter()
    .map(|slot| {
        let wots = gen_wots_secret_key(&seed, slot);
        wots.public_key().hash()
    })
    .collect::<Vec<_>>();
let mut merkle_tree = vec![leaves];
for _ in 0..log_lifetime {
    merkle_tree.push(
        merkle_tree
            .last()
            .unwrap()
            .par_chunks(2)
            .map(|chunk| poseidon16_compress(&chunk[0], &chunk[1]))
            .collect(),
    );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions