Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first proof #25

Open
wants to merge 38 commits into
base: add-permissions
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e351be9
Add first proof
jaisnan Jul 10, 2024
fd1c9c2
Add contracts for Layout and Alignment (#33)
tautschnig Jul 11, 2024
af85a10
Move contracts out of library for now
celinval Jul 16, 2024
eea60ef
Record library patch and delete library/
celinval Jul 16, 2024
47a29de
Delete library folder so we can recreate subtree
celinval Jul 17, 2024
bf2766f
Merge commit '0cd155fda0d5b0b3ba666cd9df978d380f6c7067' as 'library'
celinval Jul 17, 2024
0cd155f
Squashed 'library/' content from commit 88f01060642
celinval Jul 17, 2024
d11fcb2
Move contracts back to library/contracts
celinval Jul 17, 2024
a70ad70
Reapply repository changes to library files
celinval Jul 17, 2024
dd0d265
Squashed 'library/' changes from 88f01060642..a2cf63619d7
jaisnan Jul 17, 2024
723914d
Merge commit 'dd0d2657eb2c8466bbd9fa6ea4bf2b094565c680' into sync-202…
jaisnan Jul 17, 2024
b0cc943
Update toolchain to 07-17
jaisnan Jul 18, 2024
4f4d032
Add a challenge for `btree::node` module (#26)
zhassan-aws Jul 19, 2024
0be79d6
char and ascii_char contracts (#48)
carolynzech Aug 1, 2024
ec6d98e
Add scripts for local subtree update (#46)
jaisnan Aug 12, 2024
01e4da0
prevent merge conflicts
carolynzech Aug 16, 2024
9d7b420
Squashed 'library/' changes from a2cf63619d7..9cc3bc6add3
carolynzech Aug 16, 2024
f5d8b9d
Merge commit '9d7b4208352e30d0e2a3090a964ef6f711c407e9' into sync-202…
carolynzech Aug 16, 2024
9cec589
put kani imports back
carolynzech Aug 16, 2024
1761d8a
Update toolchain to 2024-08-07
carolynzech Aug 16, 2024
24a0b16
remove unstable ptr-to-ref-cast-checks and update submodules
carolynzech Aug 16, 2024
262f391
Merge branch 'main' into add-result-contract
jaisnan Aug 16, 2024
c155b26
Contracts and harnesses for `ptr::Unique` (#45)
tautschnig Aug 20, 2024
03c735b
Add harnesses for all functions in Alignment (#42)
tautschnig Aug 20, 2024
cc2c94b
Merge branch 'main' into add-result-contract
tautschnig Aug 20, 2024
5595535
Challenge proposal: SmallSort (#57)
qinheping Aug 20, 2024
62e241a
Add MD extension to SmallSort challenge (#60)
carolynzech Aug 20, 2024
359fe20
Add challenge on memory safety of String (#55)
zhassan-aws Aug 20, 2024
8f3252f
Add self to pull_requests.toml (#65)
patricklam Aug 22, 2024
46352cf
Introduce tool template (#64)
rahulku Aug 22, 2024
b3fb221
Fix challenge number (#63)
zhassan-aws Aug 22, 2024
957d2bb
Add "ranjitjhala" and "carolynzech" to commitee (#68)
jaisnan Aug 22, 2024
962b36b
Challenge proposal: NonNull (#52)
tautschnig Aug 26, 2024
e0d6676
Challenge Proposal: `core::time::Duration` (#73)
feliperodri Aug 27, 2024
b588f71
`NonZero` Challenge (#70)
carolynzech Aug 27, 2024
c191318
Simplify pr workflow to require 2 approvals on all PR's (#74)
jaisnan Aug 27, 2024
1f0fc95
Challenge Proposal: Floats/Ints (#58)
carolynzech Aug 27, 2024
4b36a0e
Merge branch 'main' into add-result-contract
jaisnan Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
31 changes: 31 additions & 0 deletions .github/TOOL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
_The following form is designed to provide information for your tool that should be included in the effort to verify the Rust standard library. Please note that the tool will need to be **supported** if it is to be included._

## Tool Name
_Please enter your tool name here._

## Description
_Please enter a description for your tool and any information you deem relevant._

## Tool Information

* [ ] Does the tool perform Rust verification?
* [ ] Does the tool deal with *unsafe* Rust code?
* [ ] Does the tool run independently in CI?
* [ ] Is the tool open source?
* [ ] Is the tool under development?
* [ ] Will you or your team be able to provide support for the tool?

## Licenses
_Please list the license(s) that are used by your tool, and if to your knowledge they conflict with the Rust standard library license(s)._

## Steps to Use the Tool

1. [First Step]
2. [Second Step]
3. [and so on...]

## Artifacts
_If there are noteworthy examples of using the tool to perform verificaiton, please include them in this section.Links, papers, etc._

## CI & Versioning
_Please describe how you version the tool and how it will be supported in CI pipelines._
5 changes: 4 additions & 1 deletion .github/pull_requests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ members = [
"remi-delmas-3000",
"qinheping",
"tautschnig",
"jaisnan"
"jaisnan",
"patricklam",
"ranjitjhala",
"carolynzech"
]
31 changes: 4 additions & 27 deletions .github/workflows/kani.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
paths:
- 'library/**'
- '.github/workflows/kani.yml'
- 'scripts/check_kani.sh'

defaults:
run:
Expand All @@ -30,32 +31,8 @@ jobs:
- name: Checkout Library
uses: actions/checkout@v4
with:
path: verify-rust-std
path: head
submodules: true

# We currently build Kani from a branch that tracks a rustc version compatible with this library version.
- name: Checkout `Kani`
uses: actions/checkout@v4
with:
repository: model-checking/kani
path: kani
ref: features/verify-rust-std

- name: Setup Dependencies
working-directory: kani
run: |
./scripts/setup/${{ matrix.base }}/install_deps.sh

- name: Build `Kani`
working-directory: kani
run: |
cargo build-dev --release
echo "$(pwd)/scripts" >> $GITHUB_PATH

- name: Run tests
working-directory: verify-rust-std
env:
RUST_BACKTRACE: 1
run: |
kani verify-std -Z unstable-options ./library --target-dir ${{ runner.temp }} -Z function-contracts \
-Z mem-predicates -Z ptr-to-ref-cast-checks
- name: Run Kani Script
run: bash ./head/scripts/check_kani.sh ${{github.workspace}}/head
61 changes: 0 additions & 61 deletions .github/workflows/pr_approval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ name: Check PR Approvals
on:
pull_request_review:
types: [submitted]
workflow_dispatch:

# Without these permissions, we get a 403 error from github
# for trying to modify the pull request for newer project.
# Source: https://stackoverflow.com/a/76994510
permissions: write-all

jobs:
check-approvals:
Expand Down Expand Up @@ -51,22 +45,6 @@ jobs:
pull_number = context.issue.number;
}

// Get PR files
const files = await github.rest.pulls.listFiles({
owner,
repo,
pull_number
});

const relevantPaths = ['library/', 'doc/src/challenges/'];
const isRelevantPR = files.data.some(file =>
relevantPaths.some(path => file.filename.startsWith(path))
);

if (!isRelevantPR) {
console.log('PR does not touch relevant paths. Exiting workflow.');
return;
}

// Get parsed data
try {
Expand Down Expand Up @@ -117,45 +95,6 @@ jobs:
text: `Approvers: ${Array.from(approvers).join(', ')}\nRequired Approvers: ${requiredApprovers.join(', ')}`
};

// Get PR details
const pr = await github.rest.pulls.get({
owner,
repo,
pull_number
});

// Create or update check run
const checkRuns = await github.rest.checks.listForRef({
owner,
repo,
ref: pr.data.head.sha,
check_name: checkName
});

// Reuse the same workflow everytime there's a new review submitted
// instead of creating new workflows. Better efficiency and readability
// as the number of workflows is kept to a minimal number
if (checkRuns.data.total_count > 0) {
await github.rest.checks.update({
owner,
repo,
check_run_id: checkRuns.data.check_runs[0].id,
status: 'completed',
conclusion,
output
});
} else {
await github.rest.checks.create({
owner,
repo,
name: checkName,
head_sha: pr.data.head.sha,
status: 'completed',
conclusion,
output
});
}

if (conclusion === 'failure') {
core.setFailed(`PR needs at least ${requiredApprovals} total approvals and 2 required approvals. Current approvals: ${approvers.size}, Required approvals: ${requiredApprovals}`);
}
35 changes: 3 additions & 32 deletions .github/workflows/rustc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'library/**'
- 'rust-toolchain.toml'
- '.github/workflows/rustc.yml'
- 'scripts/check_rustc.sh'

defaults:
run:
Expand All @@ -29,35 +30,5 @@ jobs:
with:
path: head

- name: Checkout `upstream/master`
uses: actions/checkout@v4
with:
repository: rust-lang/rust
path: upstream
fetch-depth: 0
submodules: true

# Run rustc twice in case the toolchain needs to be installed.
# Retrieve the commit id from the `rustc --version`. Output looks like:
# `rustc 1.80.0-nightly (84b40fc90 2024-05-27)`
- name: Checkout matching commit
run: |
cd head
rustc --version
COMMIT_ID=$(rustc --version | sed -e "s/.*(\(.*\) .*/\1/")
cd ../upstream
git checkout ${COMMIT_ID}

- name: Copy Library
run: |
rm -rf upstream/library
cp -r head/library upstream

- name: Run tests
working-directory: upstream
env:
# Avoid error due to unexpected `cfg`.
RUSTFLAGS: "--check-cfg cfg(kani) --check-cfg cfg(feature,values(any()))"
run: |
./configure --set=llvm.download-ci-llvm=true
./x test --stage 0 library/std
- name: Run rustc script
run: bash ./head/scripts/check_rustc.sh ${{github.workspace}}/head
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
This repository is a fork of the official Rust programming
language repository, created solely to verify the Rust standard
library. It should not be used as an alternative to the official
Rust releases.
Rust releases. The repository is tool agnostic and welcomes the addition of
new tools.

The goal is to have a verified [Rust standard library](https://doc.rust-lang.org/std/) and prove that it is safe.
1. Contributing to the core mechanism of verifying the rust standard library
Expand Down Expand Up @@ -36,12 +37,14 @@ See [SECURITY](https://github.com/model-checking/kani/security/policy) for more
## License

### Kani

Kani is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See [LICENSE-APACHE](https://github.com/model-checking/kani/blob/main/LICENSE-APACHE) and [LICENSE-MIT](https://github.com/model-checking/kani/blob/main/LICENSE-MIT) for details.

## Rust

Rust is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.

See [the Rust repository](https://github.com/rust-lang/rust) for details.

## Introducing a New Tool

Please use the [template available in this repository](.github/TOOL_REQUEST_TEMPLATE.md) to introduce a new verification tool.
7 changes: 7 additions & 0 deletions doc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@
- [Core Transmutation](./challenges/0001-core-transmutation.md)
- [Memory safety of core intrinsics](./challenges/0002-intrinsics-memory.md)
- [Pointer Arithmetic](./challenges/0003-pointer-arithmentic.md)
- [Memory safety of BTreeMap's `btree::node` module](./challenges/0004-btree-node.md)
- [Inductive data type](./challenges/0005-linked-list.md)
- [Safety of NonNull](./challenges/0006-nonnull.md)
- [Contracts for SmallSort](./challenges/0008-smallsort.md)
- [Safe abstractions for `core::time::Duration`](./challenges/0009-duration.md)
- [Memory safety of String](./challenges/0010-string.md)
- [Safety of Methods for Numeric Primitive Types](./challenges/0011-floats-ints.md)
- [Safety of NonZero](./challenges/0012-nonzero.md)
68 changes: 68 additions & 0 deletions doc/src/challenges/0004-btree-node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Challenge 4: Memory safety of BTreeMap's `btree::node` module

- **Status:** Open
- **Tracking Issue:** [Link to issue](https://github.com/model-checking/verify-rust-std/issues/25)
- **Start date:** *2024-07-01*
- **End date:** *2024-12-10*

-------------------


## Goal

Verify the memory safety of the [`alloc::collections::btree::node` module](https://github.com/rust-lang/rust/blob/c290e9de32e8ba6a673ef125fde40eadd395d170/library/alloc/src/collections/btree/node.rs).
This is one of the main modules used for implementing the `BTreeMap` collection, and it includes a lot of unsafe code.

### Success Criteria

The memory safety of all public functions (especially safe ones) containing unsafe code must be verified, e.g.:

1. `LeafNode::new`
1. `NodeRef::as_internal_mut`
1. `NodeRef::len`
1. `NodeRef::ascend`
1. `NodeRef::first_edge`
1. `NodeRef::last_edge`
1. `NodeRef::first_kv`
1. `NodeRef::last_kv`
1. `NodeRef::into_leaf`
1. `NodeRef::keys`
1. `NodeRef::as_leaf_mut`
1. `NodeRef::into_leaf_mut`
1. `NodeRef::as_leaf_dying`
1. `NodeRef::pop_internal_level`
1. `NodeRef::push`
1. `Handle::left_edge`
1. `Handle::right_edge`
1. `Handle::left_kv`
1. `Handle::right_kv`
1. `Handle::descend`
1. `Handle::into_kv`
1. `Handle::key_mut`
1. `Handle::into_val_mut`
1. `Handle::into_kv_mut`
1. `Handle::into_kv_valmut`
1. `Handle::kv_mut`

Verification must be unbounded for functions that use recursion or contain loops, e.g.

1. `NodeRef::new_internal`
1. `Handle::insert_recursing`
1. `BalancingContext::do_merge`
1. `BalancingContext::merge_tracking_child_edge`
1. `BalancingContext::steal_left`
1. `BalancingContext::steal_right`
1. `BalancingContext::bulk_steal_left`
1. `BalancingContext::bulk_steal_right`

### List of UBs

All proofs must automatically ensure the absence of the following [undefined behaviors](https://github.com/rust-lang/reference/blob/142b2ed77d33f37a9973772bd95e6144ed9dce43/src/behavior-considered-undefined.md):

* Accessing (loading from or storing to) a place that is dangling or based on a misaligned pointer.
* Reading from uninitialized memory.
* Mutating immutable bytes.
* Producing an invalid value

Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](../general-rules.md)
in addition to the ones listed above.
Loading