@@ -82,58 +82,40 @@ while
8282 rewrite E => H5 H6.
8383 split => [| /#]; by apply H5.
8484 + auto => /> &hr H0 H1 H2 H3 H4 H5 H6 H7 H8 H9.
85- rewrite ultE => H10 *.
86- do split; last by smt (@W64 pow2_64).
87- - rewrite to_uintD /#.
88- - rewrite to_uintD /#.
89- - ring.
90- - ring.
91- - apply (eq_from_nth witness); first by rewrite !size_load_buf // ; smt(@W64 pow2_64).
92- rewrite size_load_buf; first by smt (@W64 pow2_64).
93- have ->: to_uint (i{hr} + W64.one) = to_uint i{hr} + 1 by smt (@W64 pow2_64).
94- move => j?.
95- rewrite /load_buf !nth_mkseq // = !load_store_mem.
96- rewrite /valid_ptr in H5.
97- have ->: to_uint (dst_ptr + oo) = to_uint dst_ptr + to_uint oo by smt(@W64 pow2_64).
98- have ->: to_uint (dst_ptr + (oo + i{hr})) = to_uint dst_ptr + to_uint oo + to_uint i{hr} by smt (@W64 pow2_64).
99- have ->: to_uint (src_ptr + oi) = to_uint src_ptr + to_uint oi by smt(@W64 pow2_64).
100- have ->: (to_uint (src_ptr + (oi + i{hr}))) =
101- to_uint src_ptr + to_uint oi + to_uint i{hr} by smt (@W64 pow2_64).
102- case (j = to_uint i{hr}) => [/# | Hb].
103- rewrite ifF 1 :/#.
104- case (
85+ rewrite ultE to_uintD => H10 *.
86+ (do split; 1 ,2 ,7 : by smt ()); 1 ,2 : by ring.
87+ - apply (eq_from_nth witness); rewrite size_load_buf /= 1 :/# ?size_load_buf // => [/# | j?].
88+ rewrite /load_buf !nth_mkseq // = !load_store_mem.
89+ rewrite /valid_ptr in H5.
90+ have ->: to_uint (dst_ptr + oo) = to_uint dst_ptr + to_uint oo by rewrite to_uintD_small /#.
91+ have ->: to_uint (dst_ptr + (oo + i{hr})) = to_uint dst_ptr + to_uint oo + to_uint i{hr} by smt (@W64 pow2_64).
92+ have ->: to_uint (src_ptr + oi) = to_uint src_ptr + to_uint oi by rewrite to_uintD_small /#.
93+ have ->: (to_uint (src_ptr + (oi + i{hr}))) =
94+ to_uint src_ptr + to_uint oi + to_uint i{hr} by smt (@W64 pow2_64).
95+ case (j = to_uint i{hr}) => [/# | Hb].
96+ rewrite ifF 1 :/#.
97+ case (
10598 to_uint src_ptr + to_uint oi + j =
10699 to_uint dst_ptr + to_uint oo + to_uint i{hr}
107- ) => [Hx | Hy] .
108- * have ->: loadW8 Glob.mem{hr} (to_uint src_ptr + to_uint oi + to_uint i{hr}) =
100+ ) => ? .
101+ * have ->: loadW8 Glob.mem{hr} (to_uint src_ptr + to_uint oi + to_uint i{hr}) =
109102 nth witness (load_buf Glob.mem{hr} (src_ptr + oi) (to_uint i{hr})) (to_uint i{hr})
110103 by rewrite nth_load_buf /#.
111104 by rewrite -H8 nth_load_buf /#.
112105 * have ->: Glob.mem{hr}.[to_uint src_ptr + to_uint oi + j] =
113- nth witness (load_buf Glob.mem{hr} (src_ptr + oi) (to_uint i{hr})) j.
114- by rewrite nth_load_buf 1:/#; congr; smt(@W64 pow2_64) .
115- rewrite -H8 nth_load_buf 1 :/#; congr; smt(@W64 pow2_64) .
116- - move => k??Hk.
117- rewrite /storeW8 /loadW8 get_setE.
118- have ->: to_uint (dst_ptr + (oo + i{hr})) = to_uint dst_ptr + to_uint oo + to_uint i{hr} by smt (@W64 pow2_64).
106+ nth witness (load_buf Glob.mem{hr} (src_ptr + oi) (to_uint i{hr})) j
107+ by rewrite nth_load_buf 1:/#; congr; rewrite to_uintD_small /# .
108+ rewrite -H8 nth_load_buf 1 :/#; congr; rewrite to_uintD_small /# .
109+ - move => /= k??Hk.
110+ rewrite /storeW8 /loadW8 get_setE.
111+ have ->: to_uint (dst_ptr + (oo + i{hr})) = to_uint dst_ptr + to_uint oo + to_uint i{hr} by smt (@W64 pow2_64).
119112 have ->: (to_uint (src_ptr + (oi + i{hr}))) =
120113 to_uint src_ptr + to_uint oi + to_uint i{hr} by smt (@W64 pow2_64).
121114 case (k = to_uint dst_ptr + to_uint oo + to_uint i{hr}) => [Ha | Hb]; last first.
122115 * rewrite H9 1 :/#; smt(@W64 pow2_64).
123116 rewrite -H9 1 ,2 :/# Ha; smt(@W64 pow2_64).
124117qed.
125118
126- lemma nth_sub_list_dflt (x : nbytes list) (i l0 l1 : int ) :
127- 0 <= l0 =>
128- 0 <= l1 =>
129- nth witness (sub_list (nbytes_flatten x) l0 l1) i =
130- if 0 <= i < l1 then nth witness (nbytes_flatten x) (l0 + i) else witness.
131- proof.
132- move => ??.
133- case (0 <= i < l1) => [H_in | H_out].
134- + rewrite /sub_list nth_mkseq // =.
135- + rewrite /sub_list nth_out // size_mkseq /#.
136- qed.
137119
138120(*
139121 `nbytes_witness` is a witness value of type `nbytes`.
@@ -188,11 +170,6 @@ case (0 <= k < n) => [k_in | k_out].
188170rewrite nth_out // NBytes.valP /#.
189171qed.
190172
191- (* If the index is in bounds, the default value passed to nth does not matter *)
192- (* FIXME: Este lemma ja existe e esta da teoria de listas como nth_change_dfl *)
193- lemma nth_dflt ['a] (x : ' a list) (dflt1 dflt2 : ' a) (i : int ) :
194- 0 <= i < size x =>
195- nth dflt1 x i = nth dflt2 x i by smt(@List).
196173
197174(* Obs: Este lema precisa de ser phoare p ser usado na prova do treehash *)
198175lemma memcpy_treehash_node_2 (_stack_impl : W8.t Array352.t, o : W64.t) (stack_spec : nbytes list) :
@@ -224,19 +201,16 @@ conseq (: _ ==>
224201).
225202 + auto => /> &hr H0 H1 H2 out; split => Hout; rewrite Hout.
226203(** -------------------------------------------------------------------------------------------- **)
227- have ->: (to_uint (o - W64.one)) = to_uint o - 1 by smt(@W64 pow2_64) .
228- have ->: (to_uint (o - (of_int 2 )%W64)) = to_uint o - 2 by smt(@W64 pow2_64) .
204+ have ->: (to_uint (o - W64.one)) = to_uint o - 1 by rewrite to_uintB // uleE /=/# .
205+ have ->: (to_uint (o - (of_int 2 )%W64)) = to_uint o - 2 by rewrite to_uintB // uleE /=/# .
229206 case (0 <= to_uint o - 1 < size stack_spec) => [H_o_m_1_in | H_o_m_1_out].
230207 (* Cenario normal => tudo in bounds => todos os acessos sao validos *)
231208 - apply (eq_from_nth witness).
232209 + by rewrite size_sub_list 1:/# size_cat !NBytes.valP n_val.
233210 rewrite size_cat !NBytes.valP n_val /= => i?.
234- case (0 <= i < 32 ) => [Hfst | Hsnd];
235- rewrite nth_cat NBytes.valP n_val; [rewrite ifT 1 :/# | rewrite ifF 1 :/#].
236- + rewrite nth_sub_list 1 :/# nth_nbytes_flatten 1 :/#.
237- smt (nth_dflt).
238- + rewrite nth_sub_list 1:/# nth_nbytes_flatten 1 :/#.
239- smt (nth_dflt).
211+ (case (0 <= i < 32 ) => [Hfst | Hsnd]; rewrite nth_cat NBytes.valP n_val; [rewrite ifT 1 :/# | rewrite ifF 1 :/#]);
212+ rewrite nth_sub_list 1 :/# nth_nbytes_flatten 1 :/# ;smt(nth_change_dfl).
213+
240214 (* Daqui para a frente, stack_spec[o - 1 ] = witness *)
241215 have ->: nth nbytes_witness stack_spec (to_uint o - 1 ) = nbytes_witness
242216 by rewrite nth_out /#.
@@ -247,7 +221,7 @@ conseq (: _ ==>
247221 case (0 <= i < 32 ) => [Hfst | Hsnd];
248222 rewrite nth_cat NBytes.valP n_val; [rewrite ifT 1 :/# | rewrite ifF 1 :/#].
249223 + rewrite nth_sub_list 1 :/# nth_nbytes_flatten 1 :/#.
250- smt (nth_dflt ).
224+ smt (nth_change_dfl ).
251225 + rewrite nth_nbytes_witness.
252226 rewrite nth_sub_list 1:/#.
253227 rewrite nth_out // size_nbytes_flatten /#.
@@ -265,8 +239,8 @@ conseq (: _ ==>
265239 rewrite nth_sub_list // .
266240 rewrite nth_out // size_nbytes_flatten /#.
267241(** -------------------------------------------------------------------------------------------- **)
268- have ->: (to_uint (o - W64.one)) = to_uint o - 1 by smt(@W64 pow2_64) .
269- have ->: (to_uint (o - (of_int 2 )%W64)) = to_uint o - 2 by smt(@W64 pow2_64) .
242+ have ->: (to_uint (o - W64.one)) = to_uint o - 1 by rewrite to_uintB // uleE /# .
243+ have ->: (to_uint (o - (of_int 2 )%W64)) = to_uint o - 2 by rewrite to_uintB // uleE /# .
270244 case (0 <= to_uint o - 1 < size stack_spec) => [H_o_m_1_in | H_o_m_1_out].
271245 (* Cenario normal => tudo in bounds => todos os acessos sao validos *)
272246 - apply (eq_from_nth witness).
@@ -275,9 +249,9 @@ conseq (: _ ==>
275249 case (0 <= i < 32 ) => [Hfst | Hsnd];
276250 rewrite nth_cat NBytes.valP n_val; [rewrite ifT 1 :/# | rewrite ifF 1 :/#].
277251 + rewrite nth_sub_list 1 :/# nth_nbytes_flatten 1 :/#.
278- smt (nth_dflt ).
252+ smt (nth_change_dfl ).
279253 + rewrite nth_sub_list 1:/# nth_nbytes_flatten 1 :/#.
280- smt (nth_dflt ).
254+ smt (nth_change_dfl ).
281255 (* Daqui para a frente, stack_spec[o - 1 ] = witness *)
282256 have ->: nth nbytes_witness stack_spec (to_uint o - 1 ) = nbytes_witness
283257 by rewrite nth_out /#.
@@ -288,7 +262,7 @@ conseq (: _ ==>
288262 case (0 <= i < 32 ) => [Hfst | Hsnd];
289263 rewrite nth_cat NBytes.valP n_val; [rewrite ifT 1 :/# | rewrite ifF 1 :/#].
290264 + rewrite nth_sub_list 1 :/# nth_nbytes_flatten 1 :/#.
291- smt (nth_dflt ).
265+ smt (nth_change_dfl ).
292266 + rewrite nth_nbytes_witness.
293267 rewrite nth_sub_list 1:/#.
294268 rewrite nth_out // size_nbytes_flatten /#.
@@ -391,7 +365,7 @@ rewrite ultE of_uintK /= => H7.
391365have E: 2 ^h = 1048576 by rewrite h_val /#.
392366do split; 1 ,2 ,5 : by smt (@W64 pow2_64).
393367 + ring.
394- + have ->: to_uint (i{hr} + W64.one) = to_uint i{hr} + 1 by smt (@W64 pow2_64) .
368+ + have ->: to_uint (i{hr} + W64.one) = to_uint i{hr} + 1 by rewrite to_uintD_small /# .
395369 move => k??.
396370 rewrite get_setE 1 :/#.
397371 have E2 : to_uint ((o - (of_int 2 )%W64) * (of_int 32 )%W64) =
@@ -403,7 +377,7 @@ do split; 1,2,5: by smt(@W64 pow2_64).
403377 - rewrite to_uintD E2 /#.
404378 rewrite E2 .
405379 case (k = to_uint i{hr}) => [-> // | ?]. (* trivial solves the first goal *)
406- rewrite H6 1:/#; congr; smt(@W64 pow2_64) .
380+ rewrite H6 1:/#; congr; rewrite to_uintM of_uintK /= to_uintB ?of_uintK 2 :/# uleE of_uintK /# .
407381qed.
408382
409383lemma p_treehash_memcpy_0 (node : W8.t Array32.t) (stack : nbytes list) (_stack : W8.t Array352.t) (offset : W64.t) :
@@ -460,7 +434,7 @@ if 0 <= to_uint out_offset + k < 352 then in_0.[k] else witness) /\
460434 split => [/# |].
461435 move => H4 H5 H6.
462436 have ->: i0 = 32 by smt ().
463- have ->: to_uint (offset * (of_int 32 )%W64) = to_uint offset * 32 by smt(@W64 pow2_64) .
437+ have ->: to_uint (offset * (of_int 32 )%W64) = to_uint offset * 32 by rewrite to_uintM /=/# .
464438 move => H7 H8.
465439 apply (eq_from_nth witness); first by rewrite size_sub 1 :/# size_sub_list // /#.
466440 rewrite size_sub 1 :/# H2 => i Hi.
@@ -522,17 +496,15 @@ if 0 <= to_uint out_offset + k < 352 then in_0.[k] else witness) /\
522496(** -------------------------------------------------------------------------------------------- **)
523497auto => /> &hr H0 H1 H2 H3 H4 H5 H6 H7 H8.
524498
525- have E: to_uint (offset * (of_int 32 )%W64) = to_uint offset * 32 by smt(@W64 pow2_64).
526-
499+ have E: to_uint (offset * (of_int 32 )%W64) = to_uint offset * 32 by rewrite to_uintM /=/#.
527500do split; 1 ,2 ,5 : by smt ().
528-
529501 + move => k??.
530502 have ->: to_uint (offset * (of_int 32 )%W64 + (of_int i{hr})%W64) =
531- (to_uint offset * 32 ) + i{hr} by smt (@W64 pow2_64) .
503+ (to_uint offset * 32 ) + i{hr} by rewrite to_uintD to_uintM /= of_uintK /# .
532504 case (0 <= to_uint offset * 32 + i{hr} < 352 ) => ?; first by rewrite get_setE /#.
533505 by rewrite ifF 1 :/# get_out 1 :/#.
534506 + rewrite E => k???.
535- rewrite -H7 1 ,2 :/# get_set_if ifF // ; smt(@W64 pow2_64).
507+ rewrite -H7 1 ,2 :/# get_set_if ifF // to_uintD to_uintM of_uintK /= ; smt(@W64 pow2_64).
536508qed.
537509
538510
0 commit comments