Challenge 2: Verify the memory safety of core intrinsics using raw pointers

  • Status: Open
  • Tracking Issue: #16
  • Start date: 2024/06/12
  • End date: 2025/04/10
  • Reward: N/A

Goal

Annotate Rust core::intrinsics functions that manipulate raw pointers with their safety contract. Verify their usage in the standard library is in fact safe.

Success Criteria

  1. All the following intrinsic functions must be annotated with safety contracts.
  2. Any fallback intrinsic implementation must be verified.
  3. For intrinsics modeled in the tool of choice, explain how their implementation matches the intrinsics definition. This can either be done in the PR description or as an entry to the contest book as part of the “Tools” chapter.
  4. For each function, contestants must state clearly the list of assumptions for each proof, how the proofs can be audited, and the list of (implicit and explicit) properties that are guaranteed.
  5. The verification of each intrinsic should ensure all the documented safety conditions are met, and that meeting them is enough to guarantee safe usage.

Intrinsic functions to be annotated with safety contracts

FunctionLocation
typed_swapcore::intrisics
vtable_sizecore::intrisics
vtable_aligncore::intrisics
copy_nonoverlappingcore::intrisics
copycore::intrisics
write_bytescore::intrisics
size_of_valcore::intrisics
arith_offsetcore::intrisics
volatile_copy_nonoverlapping_memorycore::intrisics
volatile_copy_memorycore::intrisics
volatile_set_memorycore::intrisics
volatile_loadcore::intrisics
volatile_storecore::intrisics
unaligned_volatile_loadcore::intrisics
unaligned_volatile_storecore::intrisics
compare_bytescore::intrisics
min_align_of_valcore::intrisics
ptr_offset_fromcore::intrisics
ptr_offset_from_unsignedcore::intrisics
read_via_copycore::intrisics
write_via_movecore::intrisics

All the following usages of intrinsics were proven safe:

FunctionLocation
copy_from_slicecore::slice
parse_u64_intostd::fmt
swapcore::mem
align_of_valcore::mem
zeroedcore::mem::maybe_uninit

Annotate and verify all the functions below that expose intrinsics with safety contracts

FunctionLocation
copy_from_slicestd::ptr
parse_u64_intostd::ptr
swapstd::ptr
align_of_valstd::ptr
zeroedstd::ptr

List of UBs

All proofs must automatically ensure the absence of the following undefined behaviors ref:

  • Invoking undefined behavior via compiler intrinsics.
  • Accessing (loading from or storing to) a place that is dangling or based on a misaligned pointer.
  • Reading from uninitialized memory except for padding or unions.
  • Mutating immutable bytes.
  • Producing an invalid value

Note: All solutions to verification challenges need to satisfy the criteria established in the challenge book in addition to the ones listed above.