aeneas icon indicating copy to clipboard operation
aeneas copied to clipboard

Use `Nat` and `Int` instead of `Usize` and `Isize`

Open sonmarcho opened this issue 1 year ago • 0 comments
trafficstars

In many situations, reasoning about the bounds of Usize and Isize is very cumbersome (and sometimes, it leads to proof obligations that we don't know how to discharge), while reasoning about those bounds often doesn't really make sense.

For instance, the type Usize is often used to count the length of an array, a vector or a string, or the number of elements in a collection. If, say, we have a function which repeatedly adds elements in a vector, it can be hard (if not really possible) to properly state the precondition which will give us that the length of the vector will not overflow Usize.max. On the other hand, reasoning about this overflow often doesn't make sense: because of hardware limitations (that we don't model), it is likely that the Rust program will have run out of memory long before the length of the vector reaches Usize.max.

For this reason, we need to implement alternative definitions for Usize and Isize to model them as unbounded integers (this requires writing alternative definitions for Vec, Vec.len, Vec.push, etc.), as well as a way of switching (when calling Aeneas) between the bounded and the unbounded models.

In order to make the two versions of the definitions coexist in Lean, a possibility is maybe to use namespaces, and open the proper namespaces at the top of the generated files.

sonmarcho avatar Aug 20 '24 14:08 sonmarcho