-
Notifications
You must be signed in to change notification settings - Fork 69
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
Support quantification over the Cryptol # kind #2209
Comments
That is not a thing in SMT-LIB as far as I am aware. |
Indeed, that's not a thing. If the range is bounded (as it is in the example) we could always expand it, but I don't think that should happen without someone saying so as it could end up expensive. |
It is also possibly feasible in some cases to prove it for e.g. bits == 3 and generalize the proof to larger bitvectors by rewriting and rechecking the proof itself; however, that's going to take real work 😐 |
A quick literature search yielded this paper from the Stanford / CVC5 folks: https://arxiv.org/pdf/1905.10434. It is possibly helpful in encoding symbolic bit-width statements into fixed bit-width. In any event, I agree 100% that it is not an easy fix. |
Cryptol refuses to let you prove things of this form, right? It'll complain they're polymorphic, IIRC. We should be able to fix the error message relatively soon; the rest is ... problematic, alas. |
Correct:
|
Another thought I had in passing... In contrast to having the SMT layer support bit-vector kinds with symbolic width, could you enhance SAWCore reasoning so the user could manually discharge any propositions over Cryptol types with symbolic widths before going to the SMT layer? I can't imagine what that reasoning would be. I was imagining a case analysis and induction principle. The case analysis would be for situations where the symbolic width is highly constrained (e.g., in AES It'd be valuable to punt on the more complicated situation (unconstrained) and implement the easier situation (highly constrained). The highly constrained situations show up everywhere (key sizes, elliptic curve choices, hash function choice, block cipher choice). There's rarely more than 5-10 choices for a lot of the parametric code in Cryptol. Thoughts? |
SAW includes an extremely experimental induction-based command called |
My experience mucking with bitvectors in Coq is that induction on the bitvector size is rarely workable. So splitting the goal into a smallish number of fixed sizes is reasonable (I think there's already a way to do that, but I can't find it now) but even if saw were good at induction, which it isn't, I don't think trying to prove things for all bitvector sizes is advisable. |
So, just to check my understanding...
Does that mean I can define a theorem like
and you believe there's some tactic which will allow me to prove it by doing case analysis on Note: I'm not sure if the Cryptol syntax I have above that includes constraints on an anonymous function is A Thing... but just pretend :) |
As a follow-up, I ran into this limitation again today while trying to do some proofs over SHA3. The top-level function provided by each instantiation (e.g.,
So, without some way to work around this limitation, I'm unsure how to prove any property (over all possible This was just a usability issue with AES, since the top-level functions for each instantiation were all monomorphic. But, here that isn't the case. |
Yes. If that tactic doesn't actually exist (or isn't general enough) it can be made to exist, not necessarily for free (especially as the constraints get more complex) but abstractly it's just a finite case analysis on n.
You don't really want to. Cryptol syntax is fine.
That's harder, yeah. But that one's not a bitvector size and it's definitely plausible to do it by induction on (also, you don't want to do it by proving each possible size separately, even if you could try) |
Update: I found it again, |
@sauclovian-g Should I not pay too much attention to the |
Hmm, no, it won't work, it operates on |
Yes, that's right. I'm imagining something of type |
I was thinking of something of the form [Theorem] -> ProofScript -> Theorem. As a tactic, you might be able to just construct a theorem and apply it rather than needing any specific support. Something like |
Example
Suppose we have a Cryptol module
Example
inExample.cry
below and the subsequent SAW script.The example above will cause SAW to produce an error:
As an aside, this error message probably also deserves a SAW issue for usability.
To confirm that this error is due to
Example::p
being parametric, we can instantiate the type parameter explicitly:In this case, SAW successfully proves the theorem.
Discussion
An example like this is surprising to me because the kind of the type variable in the Cryptol expression is
#
, which is the numeric kind. I'd sort of expect, at a high level, that quantifying over the numeric should be possible by (say) translating to SMT by introducing a symbolic variable for the type variable, and introducing SMT constraints corresponding to the type constraints (e.g,2 <= N
above). As I write this, it occurs to me that if a Cryptol sequence is encoded as an SMT bitvector then this would mean the SMT solver would need to support variables whose kind is "bitvector of lengthx
" wherex
is a symbolic Nat. Maybe that's not a thing?I don't think I have any recommendations for this. It is chiefly a usability issue since the user can always manually instantiate the property with all satisfying numerics. However, it does show up quite a bit in conjunction with #2208, because the mitigation for that is to make every declaration in the module parametric.
The text was updated successfully, but these errors were encountered: