Library QedkConcrete.hashwords
The approved primitive Keccak output-size contract
From Stdlib Require Import ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Crypto MonadVM.Host QedkConcrete.bytewords
QedkConcrete.wordrange QedkConcrete.hostframe.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Definition keccak256OutputSize : Prop :=
∀ bytes, OCamlString.length
(Digestif.KECCAK_256.(Digestif.S.to_raw_string)
(Digestif.KECCAK_256.(Digestif.S.digest_string) None None bytes)) = 32.
Section Hashes.
Context (Hsize : keccak256OutputSize).
Context {US : Basics.Unreachable string} {UI : Basics.Unreachable int}.
Lemma keccak_length bytes : OCamlString.length (@Crypto.keccak_256 bytes) = 32.
Proof.
unfold Crypto.keccak_256. rewrite b32_checked_identity by apply Hsize. apply Hsize.
Qed.
Lemma keccak_word bytes :
wordRange (@U.of_repr (@Crypto.keccak_256 bytes)).
Proof. apply word_repr. rewrite keccak_length. lia. Qed.
Lemma get_code_hash_length {F : H.FArgs}
s addr hash :
fst (@H.get_code_hash F addr s) = Some hash → OCamlString.length hash = 32.
Proof.
unfold H.get_code_hash. cbn -[Crypto.keccak_256 Chain.Ethereum.Account.is_empty].
match goal with |- (if ?test then _ else _) = _ → _ ⇒ destruct test end;
intro Hhash; [discriminate|].
injection Hhash as <-. apply keccak_length.
Qed.
Lemma block_hash_length
block :
OCamlString.length (@Chain.Ethereum.Block.hash block) = 32.
Proof. apply keccak_length. Qed.
Lemma get_block_hash_length {F : H.FArgs}
s number hash :
fst (@H.get_block_hash F number s) = Some hash → OCamlString.length hash = 32.
Proof.
unfold H.get_block_hash.
cbn -[Chain.Ethereum.Block.hash OCamlList.find_opt Support.UintN.of_uint64].
match goal with |- Monad.Make_Monad.Option.map _ ?found = _ → _ ⇒
destruct found as [block|] end; intro Hhash; [|discriminate].
injection Hhash as <-. apply block_hash_length.
Qed.
End Hashes.
Print Assumptions keccak_word.
Print Assumptions get_code_hash_length.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Crypto MonadVM.Host QedkConcrete.bytewords
QedkConcrete.wordrange QedkConcrete.hostframe.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Definition keccak256OutputSize : Prop :=
∀ bytes, OCamlString.length
(Digestif.KECCAK_256.(Digestif.S.to_raw_string)
(Digestif.KECCAK_256.(Digestif.S.digest_string) None None bytes)) = 32.
Section Hashes.
Context (Hsize : keccak256OutputSize).
Context {US : Basics.Unreachable string} {UI : Basics.Unreachable int}.
Lemma keccak_length bytes : OCamlString.length (@Crypto.keccak_256 bytes) = 32.
Proof.
unfold Crypto.keccak_256. rewrite b32_checked_identity by apply Hsize. apply Hsize.
Qed.
Lemma keccak_word bytes :
wordRange (@U.of_repr (@Crypto.keccak_256 bytes)).
Proof. apply word_repr. rewrite keccak_length. lia. Qed.
Lemma get_code_hash_length {F : H.FArgs}
s addr hash :
fst (@H.get_code_hash F addr s) = Some hash → OCamlString.length hash = 32.
Proof.
unfold H.get_code_hash. cbn -[Crypto.keccak_256 Chain.Ethereum.Account.is_empty].
match goal with |- (if ?test then _ else _) = _ → _ ⇒ destruct test end;
intro Hhash; [discriminate|].
injection Hhash as <-. apply keccak_length.
Qed.
Lemma block_hash_length
block :
OCamlString.length (@Chain.Ethereum.Block.hash block) = 32.
Proof. apply keccak_length. Qed.
Lemma get_block_hash_length {F : H.FArgs}
s number hash :
fst (@H.get_block_hash F number s) = Some hash → OCamlString.length hash = 32.
Proof.
unfold H.get_block_hash.
cbn -[Chain.Ethereum.Block.hash OCamlList.find_opt Support.UintN.of_uint64].
match goal with |- Monad.Make_Monad.Option.map _ ?found = _ → _ ⇒
destruct found as [block|] end; intro Hhash; [|discriminate].
injection Hhash as <-. apply block_hash_length.
Qed.
End Hashes.
Print Assumptions keccak_word.
Print Assumptions get_code_hash_length.