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

fix(f*/lax): latest hax: fixes let-rec and types on empty lists #117

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions proofs/fstar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ create`) and regeneration of the `extraction` folder.

The lax checking patch mainly performs the following fixes which will become unnecessary with future hax fixes:

* Recursive functions are not produced with `let rec` in F*
* IndexMut implementations need to implemented by hand in F*
* Empty lists need type annotations in F*

Finally, we edit the code in `extraction-lax` by hand to obtain panic-freedom proofs in `extraction-panic-free`.
Eventually these hand-edits will be backported into Rust as pre- and post-conditions.
Expand Down
295 changes: 118 additions & 177 deletions proofs/fstar/extraction-lax.patch

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion proofs/fstar/extraction-lax/Bertie.Tls13formats.fst
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,7 @@ let parse_server_hello

let server_certificate (v__algs: Bertie.Tls13crypto.t_Algorithms) (cert: Bertie.Tls13utils.t_Bytes) =
match
Bertie.Tls13utils.encode_length_u8 (Rust_primitives.unsize (let list : list u8 = [] in
Bertie.Tls13utils.encode_length_u8 (Rust_primitives.unsize (let list:Prims.list u8 = [] in
FStar.Pervasives.assert_norm (Prims.eq2 (List.Tot.length list) 0);
Rust_primitives.Hax.array_of_list 0 list)
<:
Expand Down
669 changes: 328 additions & 341 deletions proofs/fstar/extraction-panic-free.patch

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ let impl__HandshakeData__from_bytes
| Core.Result.Result_Err err ->
Core.Result.Result_Err err <: Core.Result.t_Result t_HandshakeData u8

let impl__HandshakeData__find_handshake_message
let rec impl__HandshakeData__find_handshake_message
(self: t_HandshakeData)
(handshake_type: t_HandshakeType)
(start: usize)
Expand Down
8 changes: 4 additions & 4 deletions proofs/fstar/extraction/Bertie.Tls13formats.fst
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ let check_handshake_record (p: Bertie.Tls13utils.t_Bytes) =
(Core.Result.t_Result (Bertie.Tls13formats.Handshake_data.t_HandshakeData & usize) u8)
(Core.Result.t_Result (Bertie.Tls13formats.Handshake_data.t_HandshakeData & usize) u8))

let check_server_extensions (algs: Bertie.Tls13crypto.t_Algorithms) (b: t_Slice u8) =
let rec check_server_extensions (algs: Bertie.Tls13crypto.t_Algorithms) (b: t_Slice u8) =
match check_server_extension algs b with
| Core.Result.Result_Ok (len, out) ->
if len =. (Core.Slice.impl__len b <: usize)
Expand Down Expand Up @@ -1464,7 +1464,7 @@ let encrypted_extensions (v__algs: Bertie.Tls13crypto.t_Algorithms) =
<:
Core.Result.t_Result Bertie.Tls13formats.Handshake_data.t_HandshakeData u8

let find_key_share (g: Bertie.Tls13utils.t_Bytes) (ch: t_Slice u8) =
let rec find_key_share (g: Bertie.Tls13utils.t_Bytes) (ch: t_Slice u8) =
if (Core.Slice.impl__len ch <: usize) <. sz 4
then Bertie.Tls13utils.tlserr (Bertie.Tls13utils.parse_failed () <: u8)
else
Expand Down Expand Up @@ -2187,7 +2187,7 @@ let parse_server_hello

let server_certificate (v__algs: Bertie.Tls13crypto.t_Algorithms) (cert: Bertie.Tls13utils.t_Bytes) =
match
Bertie.Tls13utils.encode_length_u8 (Rust_primitives.unsize (let list = [] in
Bertie.Tls13utils.encode_length_u8 (Rust_primitives.unsize (let list:Prims.list u8 = [] in
FStar.Pervasives.assert_norm (Prims.eq2 (List.Tot.length list) 0);
Rust_primitives.Hax.array_of_list 0 list)
<:
Expand Down Expand Up @@ -2484,7 +2484,7 @@ let impl__Transcript__transcript_hash_without_client_hello
<:
Bertie.Tls13utils.t_Bytes)

let check_extensions_slice (algs: Bertie.Tls13crypto.t_Algorithms) (b: t_Slice u8) =
let rec check_extensions_slice (algs: Bertie.Tls13crypto.t_Algorithms) (b: t_Slice u8) =
match check_extension algs b with
| Core.Result.Result_Ok (len, out) ->
if len =. (Core.Slice.impl__len b <: usize)
Expand Down
2 changes: 1 addition & 1 deletion proofs/fstar/extraction/Bertie.Tls13record.fst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let derive_iv_ctr (iv: Bertie.Tls13utils.t_Bytes) (n: u64) =
in
iv_ctr

let padlen (b: Bertie.Tls13utils.t_Bytes) (n: usize) =
let rec padlen (b: Bertie.Tls13utils.t_Bytes) (n: usize) =
if n >. sz 0 && (Bertie.Tls13utils.f_declassify (b.[ n -! sz 1 <: usize ] <: u8) <: u8) =. 0uy
then sz 1 +! (padlen b (n -! sz 1 <: usize) <: usize)
else sz 0
Expand Down
7 changes: 6 additions & 1 deletion proofs/fstar/patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ cd "$SCRIPTPATH"

DENYLIST=""

CP="gcp"
if ! command -v gcp &> /dev/null; then
CP="cp"
fi

# `prepare_folder SRC DEST` copies F* files from SRC to DEST/<basename SRC>
prepare_folder() {
original="$1"
workdir="$2"
find "$original" \( -name '*.fst' -o -name '*.fsti' \) -exec gcp --parents \{\} "$workdir" \;
find "$original" \( -name '*.fst' -o -name '*.fsti' \) -exec "$CP" --parents \{\} "$workdir" \;
}

# `patch_folder ORIGINAL DESTINATION PATCH` creates the folder
Expand Down
Loading