Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

I need to know that BitVec's are bounded by 2^n. #927

Open
fshaked opened this issue Sep 7, 2021 · 2 comments
Open

I need to know that BitVec's are bounded by 2^n. #927

fshaked opened this issue Sep 7, 2021 · 2 comments
Assignees

Comments

@fshaked
Copy link
Contributor

fshaked commented Sep 7, 2021

I need the following information about the representation of BitVec.

Axiom denote_bv_max : forall (n : N) (m : denote_type (BitVec (N.to_nat n))),
      m < 2 ^ n.

I need this axiom to prove the land_shiftr lemma, which I use in the proof of step_tlul_adapter_reg in CavaIncrementDevice.v.

@blaxill
Copy link
Contributor

blaxill commented Sep 7, 2021

This is not currently derivable, but it should be fine to require this as a precondition:

72a0eb7

All the primitive operations effectively have such implicit preconditions and should be closed under this precondition (given inputs satisfy the correct bounds, output from a primitive should satisfy the correct bounds). e.g. BinBitVecAddU BinBitVecSubU UnBitVecShiftLeft are all defined _ mod [relevant bound].

An alternative could be to use coqutil's word or similar, but it would be a big change at this point.

@jadephilipoom
Copy link
Contributor

Another strategy I've found helpful, especially if you want to avoid the precondition, is to just truncate the number in the spec, e.g.:

Lemma step_bvconcat {n m} (x : denote_type (BitVec n)) (y : denote_type (BitVec m)) :
step (bvconcat (n:=n) (m:=m)) tt (x, (y, tt))
= (tt, N.lor (N.shiftl (N.land x (N.ones (N.of_nat n))) (N.of_nat m))
(N.land y (N.ones (N.of_nat (n + m))))).

Might be hard to read here because it's in terms of bitwise operations, but N.land x (N.ones n) is exactly the same as x mod 2 ^ n; both input bit-vectors are truncated to the expected size. You can easily rewrite this as the identity if you can prove in your context that x < 2 ^ n.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants