-
Notifications
You must be signed in to change notification settings - Fork 45
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
design: core functionality of RecordPredicates? #370
Comments
Contrary to many other approaches that I stopped using, I still believe that I don't particularly like |
Seems like we are almost on the same page here; let's talk through the last few details.
The same question shows up for field elements in fiat cryptography, and there we settled on the following solution. We first define a "overprecise" Gallina type to represent all low-level configurations of the object and right after that we define a relation between that type and Z (actually Zmod). Code that manipulates the low-level representation directly can use the first Gallina type (which has an encoding function), but callers of the library use a separation-logic predicate that takes a Z and uses an existential quantifier (treating it opaquely like an arbitrary Prop). The first predicate is also used when calling memcpy-like functions that manipulate bytes directly. Pointers to field elements use the imprecise predicate; we currently do not have structs of field elements, but we want to, and I think they should use the first predicate and have their own representation relation that refers to the field-element representation relation.
Ha, I actually agree with this sentence! But what I think the main (only?) difference in my suggestion is that we'd define the representation relation first, and then use separation logic to say "these bytes are in memory". In case of a record with pointers in it, the representation relation would treat the pointers as integers, whereas the "handle" to this object would likely also assert the separation-logic predicates of the objects it owns.
I am proposing to concatenate the representations, not the values themselves. It would be that concatenation that the proof automation would recognize, perhaps indeed keeping the parts being concatenated themselves in a list (so |
This sounds interesting, could you please elaborate? In particular: How would you want to define records with members using an imprecise predicate? How do you bring them into a sufficiently structured form so that sepcalls automation can pass a record member to a callee that expects an imprecise predicate, and assemble back the updated record after the call? And more concretely, where is the existential going to show up, relative to the concatenation? (I hope we're not confusing record fields and with elements of finite fields, but so far it seems fine...) |
I agree these are the important questions. First, some definitions, slightly simplified, but hopefully sufficient to answer the two simple questions.
Definition CoordinateRepr := tuple word32 10.
Definition c_to_bytes (x : CoordinateRepr) := flat_map (le_split 4) x.
Definition to_Z (x : CoordinateRepr) : Z. Admitted.
Definition FElemAt x a : mem -> Prop := ex1 (fun x' => (to_bytes x')$@a /\ to_Z x' = x).
Record PointRepr := { X: CoordinateRepr; Y : CoordinateRepr; Z : CoordinateRepr; T : CoordinateRepr }.
Definition p_to_bytes (p : PointRper) := flat_map c_to_bytes [X; Y; Z; T].
Definition to_point (x : PointRepr) : Edwards.point. Admitted. (* calls to_Z and then Edwards.XYZT.to_affine *)
Definition PointAt (x : Point) a : mem -> Prop := ex1 (fun x' => (p_to_bytes x')$@a /\ to_point x' = x).
I am assuming sepcalls would run
Sepcalls would proceed in two passes, roughly corresponding to memory safety (separation logic) and functional correctness (representaiton-relation update). It is by design that the second one may fail after the first one succeeds, but we usually want to assert that both succeed. After updating one coordinate of the point and running the first sepcalls pass,the separation-logic state would contain |
The RecordPredicates system seems pretty neat and I am interested in doing something similar in not that distant future. Do you still think this approach, or some aspects of it are a good enough idea to build upon?
I also read that the definition seems to be based on sepapp which I find unconvincing, and the same file also contains LiveVerif notations. The alternative I'd like to contemplate is
(to_bytes field1 ++ to_bytes field2 ++ to_bytes field3)$@recordptr
. But perhaps I'd become more sold if we talked about the considerations here :).The text was updated successfully, but these errors were encountered: