theory Delivery imports Frontend begin definition checksum :: "nat list \ pixel" where "checksum bytes = foldl (\h b. (h XOR word_of_nat b) * 1099511628211) 14695981039346656037 bytes" definition delivery :: "string \ string \ (bool \ string) \ string" where "delivery sequence source = (case (number sequence,prepare source) of (Some revision,Some e) \ let emitted = artifact source; code = map nat_of_char (snd (fst emitted)); data = code @ map nat_of_char source @ concat (map (row e) [0..<512]); header = [82,77,89,49] @ octets 4 (length code) @ octets 4 (length source) @ octets 4 512 @ octets 4 revision in if fst (fst emitted) \ revision < 2 ^ 32 \ 0 < revision \ length code \ 65536 \ length source \ 65536 then ((True,map char_of_nat (header @ octets 8 (unat (checksum (header @ data))) @ data)),snd emitted) else ((False,[]),''invalid live payload limits'' @ newline) | (_,None) \ ((False,[]),source_error source) | _ \ ((False,[]),''invalid live revision'' @ newline))" lemma checksum_empty: "checksum [] = 14695981039346656037" by (simp add: checksum_def) lemma checksum_step: "checksum (bytes @ [b]) = (checksum bytes XOR word_of_nat b) * 1099511628211" by (simp add: checksum_def foldl_append) lemma row_size [simp]: "length (row e i) = 32" by (simp add: row_def) lemma rows_size [simp]: "length (concat (map (row e) xs)) = 32 * length xs" by (induction xs) auto theorem delivery_bounds: "delivery sequence source = ((True,packet),report) \ 16412 \ length packet \ length packet \ 147484" by (auto simp: delivery_def Let_def split: option.splits if_splits; linarith) end