hacspec / hax

A Rust verification tool
https://hacspec.org/blog
Apache License 2.0
198 stars 20 forks source link

Double return bug #720

Open mamonet opened 5 months ago

mamonet commented 5 months ago

There are cases where extracted F files in libcrux-ml-kem have redundant third return value where just double are supposed to be at the receiving side. This breaks lax-check of affected F files. Here is an example of this bug https://github.com/cryspen/libcrux/blob/dev/libcrux-ml-kem/proofs/fstar/extraction/Libcrux_ml_kem.Ntt.fst#L34

It's fixed manually here https://github.com/cryspen/libcrux/blob/dev_ml_kem_lax/libcrux-ml-kem/proofs/fstar/extraction/Libcrux_ml_kem.Ntt.fst#L34

Workaround: add () at the end of your function, see the comment below.

W95Psp commented 4 months ago

Thanks for the bug report Mamone!

I'm looking at it now, here is a minimized reproducer:

fn f(n: &mut usize) {
    for _ in 0..10 {
        *n += 1;
    }
}

The problem shows up only when n is a &mut.

W95Psp commented 4 months ago

Thanks for the issue! I spent a few hours on that, I don't have a fix yet.

I think this issue shows up mainly in functions that ends with a loop. A workaround is to add a () at the end of the function, e.g.:

fn f(n: &mut usize) {
    for _ in 0..10 {
        *n += 1;
    }
}

becomes:

fn f(n: &mut usize) {
    for _ in 0..10 {
        *n += 1;
    };
   ()
}
franziskuskiefer commented 3 months ago

@W95Psp this is overdue for a while now. What's the status and plan to get it fixed?

W95Psp commented 3 months ago

I removed the due date and set the priority to low. We have a workaround, and loads of other things to do, so let's pick that whenever we have time.

karthikbhargavan commented 3 weeks ago

I found a few other instances of this. I think this has to have a higher priority since the bug and its fix are quite obscure.