Skip to content

Important: finalize_hackathon insertion sort is O(n²) #18

@0xdevcollins

Description

@0xdevcollins

Severity: Important (performance)

Current sort:

// contract.rs:474
let mut inserted = false;
for j in 0..leads.len() {
    if avg > scores.get(j).unwrap() {
        leads.insert(j, lead.clone());   // O(n) per insert
        scores.insert(j, avg);
        inserted = true;
        break;
    }
}

For 100 submissions: ~10,000 Vec operations. For 1,000: 1M ops. Soroban resource fees scale with this — finalize for a popular hackathon could become prohibitively expensive or fail resource limits.

Fix

Collect into Vec, then use sort_by once with explicit tiebreaker (see related issue on stable sort).

Tests

  • Benchmark 100 submissions before/after
  • Verify ordering matches previous behavior on small inputs

Metadata

Metadata

Assignees

No one assigned

    Labels

    audit-findingSurfaced during internal audit / reviewenhancementNew feature or request

    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