~james/remy

remy/src/Delivery.thy -rw-r--r--1.8 KiB ViewLogBlameView rawPermalink 76b7f307a1 — feat(live): validate and swap compiled shaders between guest frames 12 days ago
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
theory Delivery
  imports Frontend
begin

definition checksum :: "nat list \<Rightarrow> pixel" where
  "checksum bytes = foldl (\<lambda>h b. (h XOR word_of_nat b) * 1099511628211) 14695981039346656037 bytes"

definition delivery :: "string \<Rightarrow> string \<Rightarrow> (bool \<times> string) \<times> string" where
  "delivery sequence source = (case (number sequence,prepare source) of
    (Some revision,Some e) \<Rightarrow>
      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) \<and> revision < 2 ^ 32 \<and> 0 < revision \<and>
        length code \<le> 65536 \<and> length source \<le> 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) \<Rightarrow> ((False,[]),source_error source)
    | _ \<Rightarrow> ((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) \<Longrightarrow>
    16412 \<le> length packet \<and> length packet \<le> 147484"
  by (auto simp: delivery_def Let_def split: option.splits if_splits; linarith)

end