Skip to content

Challenge 8: Contracts for SmallSort #56

Description

@qinheping

Activity

  1. changed the title [-]Tracking issue for verification of SmallSort[/-] [+]Challenge 8: Contracts for `SmallSort`[/+] on Sep 5, 2024
  2. BusyBeaver-42 commented on Jan 9, 2025

    @BusyBeaver-42

    Hi, I have a few questions about this challenge.

    Missing safety requirement

    I believe merge_down is missing a requirement in the SAFETY comment. Specifically, dst.sub(1) is called, but the SAFETY comment does not guarantee that the resulting pointer remains within the same allocated object. This is not a significant issue since it's a private function, and when it is called, dst.sub(1) is indeed within the same allocated object.

    EDIT: I've opened the following issue: rust-lang#135984.

    Can the absence of "invalid values" be verified with a separate tool?

    "Invalid values" refer to the following scenario: If the input array is [1, 2, 3] and the output array is [1, 1, 1], then although the output array is sorted, an "invalid value" is created. In this example, it is not a safety concern, but it could become one for non-Copy types.

    I believe this requires a separate tool because verifying with kani that the multiset (like a set but counting repetitions) of inputs matches the multiset of outputs is extremely slow. For example, sort4_stable already takes approximately 6 minutes to verify.

    How arbitrary does is_less have to be when verifying correctness?

    To verify safety, since the sorting methods are safe and are called with a user-provided is_less, verification has to be done with a function that returns a random boolean (kani::any()).

    However, what is_less should be used when verifying correctness? For example, is it sufficient to verify correctness only for the default ordering of integers? Alternatively, should verification be conducted on a custom type with 32 distinct values, allowing for testing of any weak total ordering on these 32 values? This second approach is likely to perform poorly.

    Additionally, what types T should be tested?

    What is the limit for memory and runtime?

    I need to use stub_verified on sort13_optimal because the code that kani analyzes becomes too large when verifying the sorting methods. However, verifying sort13_optimal is very resource-intensive due to the large number of statements it contains, as explained in this comment. It requires 50 GB of memory and takes 40 minutes (38 GB of this is swap memory, which might explain the lengthy runtime on my laptop).

  3. qinheping commented on Jan 24, 2025

    @qinheping
    Author

    Missing safety requirement

    Thank you. The safety comments should be updated in the upstream if the proof shows that the current comments is actually not enough.

    Can the absence of "invalid values" be verified with a separate tool?

    Yes, other tools are welcome.

    How arbitrary does is_less have to be when verifying correctness?

    The ultimate goal is to prove the correctness for arbitrary types and arbitrary ordering. However, we understand that model arbitrary ordering itself is very challenging. So proofs for primitive types with default ordering will be considered as a solid solutions.

  4. qinheping commented on Jan 24, 2025

    @qinheping
    Author

    What is the limit for memory and runtime?

    We expect to run all proof on CI. So ideally the running time of a single proof should be less than ~2 minutes on a GitHub standard runner. However, if the proof is running into the limitation of Kani/CBMC, we suggest you to open a PR with the proof so that we could merge it once we have made performance improvements that get the CI time down to a reasonable amount.

  5. added a commit that references this issue on Mar 28, 2026
    26382a9
  6. TheodorNEngoy commented on Sep 5, 2026

    @TheodorNEngoy

    I'm assessing a possible contribution to Challenge 8. Before investing in a complete solution, could you clarify:

    1. Does the USD 10,000 award remain available to a new contributor submitting a complete accepted solution, given the existing work on this challenge? How would prior or overlapping contributions affect award allocation?
    2. Following the review of Challenge 8: Verify safety and sorting correctness of SmallSort #576, would complete i32 coverage for every length up to each SmallSort variant's threshold, including sortedness and multiset preservation, satisfy the intended sorting-correctness scope? For insertion_sort_shift_left as a standalone helper, is proof beyond those thresholds required?
    3. Are human-reviewed, AI-assisted contributions eligible, and is there a published eligibility/payment process for an individual based in Norway?

    I have a local draft harness with tested assertion helpers, but have not yet run the Kani proof and am not claiming a completed solution.

  7. Tiramisu-Cake commented on Oct 23, 2026

    @Tiramisu-Cake

    Hi!
    We are working on a Challenge 8 solution and want to make sure we target the right domain before submitting. The challenge text asks for verification "for all possible slices with arbitrary valid length"; the review on #678 clarifies that length means up to the specialization thresholds (16 for the fallback path, 32 for the general/network paths) and that sort13_optimal, bidirectional_merge and contract-form correctness are expected. Two points are still unclear to us:

    1. Element types. Is coverage by a set of representative element types that exercises every specialization (Freeze / non-Freeze, Copy / non-Copy, size_of <= 16 and > 16, ZST, interior mutability) sufficient for acceptance, or is a proof that is generic over T (e.g. with a deductive tool) required for the memory-safety part?

    2. Comparator behavior. For the no-UB criterion, is it sufficient to verify with a pure, total, non-panicking is_less, or must the proofs also cover comparators that may panic or keep state (the CopyOnDrop-style unwind recovery paths in insert_tail / small_sort_general)? If panicking comparators are required, is a proof of "no UB on unwind" enough, without any functional guarantee after a panic?

    A short answer on these two points would let us scope the submission correctly. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ChallengeUsed to tag a challenge

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions