Theory ADS_Construction
theory ADS_Construction imports
Merkle_Interface
"HOL-Library.Simps_Case_Conv"
begin
section ‹ Building blocks for authenticated data structures on datatypes ›
subsection ‹ Building Block: Identity Functor ›
text ‹If nothing is blindable in a type, then the type itself is the hash and the ADS of itself.›
abbreviation (input) hash_discrete :: "('a, 'a) hash" where "hash_discrete ≡ id"
abbreviation (input) blinding_of_discrete :: "'a blinding_of" where
"blinding_of_discrete ≡ (=)"
definition merge_discrete :: "'a merge" where
"merge_discrete x y = (if x = y then Some y else None)"
lemma blinding_of_discrete_hash:
"blinding_of_discrete ≤ vimage2p hash_discrete hash_discrete (=)"
by(auto simp add: vimage2p_def)
lemma blinding_of_on_discrete [locale_witness]:
"blinding_of_on UNIV hash_discrete blinding_of_discrete"
by(unfold_locales)(simp_all add: OO_eq eq_onp_def blinding_of_discrete_hash)
lemma merge_on_discrete [locale_witness]:
"merge_on UNIV hash_discrete blinding_of_discrete merge_discrete"
by unfold_locales(auto simp add: merge_discrete_def)
lemma merkle_discrete [locale_witness]:
"merkle_interface hash_discrete blinding_of_discrete merge_discrete"
..
parametric_constant merge_discrete_parametric [transfer_rule]: merge_discrete_def
subsubsection ‹Example: instantiation for @{typ unit}›
abbreviation (input) hash_unit :: "(unit, unit) hash" where "hash_unit ≡ hash_discrete"
abbreviation blinding_of_unit :: "unit blinding_of" where
"blinding_of_unit ≡ blinding_of_discrete"
abbreviation merge_unit :: "unit merge" where "merge_unit ≡ merge_discrete"
lemma blinding_of_unit_hash:
"blinding_of_unit ≤ vimage2p hash_unit hash_unit (=)"
by(fact blinding_of_discrete_hash)
lemma blinding_of_on_unit:
"blinding_of_on UNIV hash_unit blinding_of_unit"
by(fact blinding_of_on_discrete)
lemma merge_on_unit:
"merge_on UNIV hash_unit blinding_of_unit merge_unit"
by(fact merge_on_discrete)
lemma merkle_interface_unit:
"merkle_interface hash_unit blinding_of_unit merge_unit"
by(intro merkle_interfaceI merge_on_unit)
subsection ‹ Building Block: Blindable Position ›
type_synonym 'a blindable = 'a
text ‹ The following type represents the hashes of a datatype. We model hashes as being injective,
but not surjective; some hashes do not correspond to any values of the original datatypes. We
model such values as "garbage" coming from a countable set (here, naturals). ›
type_synonym garbage = nat