Skip to content

Commit ee1e322

Browse files
Merge pull request #1954 from andres-erbsen/CoZJoyeBedrock
Bedrock2 End2End field and co-Z operations for secp256k1
2 parents e3b837c + 735c000 commit ee1e322

File tree

8 files changed

+2533
-61
lines changed

8 files changed

+2533
-61
lines changed

Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ endif
8787
EXCLUDED_VOFILES := $(filter $(EXCLUDE_PATTERN),$(VOFILES))
8888
# add files to this list to prevent them from being built as final
8989
# targets by the "lite" target
90-
LITE_UNMADE_VOFILES := src/Curves/Weierstrass/AffineProofs.vo \
90+
LITE_UNMADE_VOFILES := \
91+
src/Bedrock/Secp256k1/Addchain.vo \
92+
src/Bedrock/Secp256k1/Field256k1.vo \
93+
src/Bedrock/Secp256k1/JacobianCoZ.vo \
94+
src/Bedrock/Secp256k1/JoyeLadder.vo \
95+
src/Curves/Weierstrass/AffineProofs.vo \
9196
src/Curves/Weierstrass/Jacobian/Jacobian.vo \
9297
src/Curves/Weierstrass/Jacobian/CoZ.vo \
9398
src/Curves/Weierstrass/Jacobian/ScalarMult.vo \

src/Bedrock/Field/Synthesis/New/WordByWordMontgomery.v

+41-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ Class word_by_word_Montgomery_ops
5555
(WordByWordMontgomery.square m width)
5656
Field.square
5757
list_unop_insizes list_unop_outsizes (list_unop_inlengths n);
58+
felem_copy_op :
59+
computed_op
60+
(WordByWordMontgomery.copy m width) Field.felem_copy
61+
list_unop_insizes list_unop_outsizes (list_unop_inlengths n);
5862
from_bytes_op :
5963
computed_op
6064
(WordByWordMontgomery.from_bytes m width)
@@ -165,13 +169,14 @@ Section WordByWordMontgomery.
165169
(to_mont : string)
166170
(ops : word_by_word_Montgomery_ops n m)
167171
mul_func add_func sub_func opp_func square_func
168-
from_bytes_func to_bytes_func
172+
felem_copy_func from_bytes_func to_bytes_func
169173
from_mont_func to_mont_func select_znz_func
170174
(mul_func_eq : mul_func = b2_func mul_op)
171175
(add_func_eq : add_func = b2_func add_op)
172176
(sub_func_eq : sub_func = b2_func sub_op)
173177
(opp_func_eq : opp_func = b2_func opp_op)
174178
(square_func_eq : square_func = b2_func square_op)
179+
(felem_copy_func_eq : felem_copy_func = b2_func felem_copy_op)
175180
(from_bytes_func_eq : from_bytes_func = b2_func from_bytes_op)
176181
(to_bytes_func_eq : to_bytes_func = b2_func to_bytes_op)
177182
(from_mont_func_eq : from_mont_func = b2_func from_mont_op)
@@ -492,6 +497,41 @@ Qed.
492497
intros. apply Hcorrect; auto. }
493498
Qed.
494499

500+
Lemma list_Z_bounded_by_unsigned (xs : list (@Interface.word.rep _ word)) :
501+
list_Z_bounded_by
502+
(Primitives.saturated_bounds (List.length xs) width)
503+
(map Interface.word.unsigned xs).
504+
Proof using parameters_sentinel ok.
505+
induction xs; cbn; [reflexivity|].
506+
eapply list_Z_bounded_by_cons; split; [|assumption].
507+
eapply Bool.andb_true_iff; split; eapply Z.leb_le;
508+
cbv [Primitives.word_bound]; cbn.
509+
{ eapply Properties.word.unsigned_range. }
510+
{ eapply Le.Z.le_sub_1_iff, Properties.word.unsigned_range. }
511+
Qed.
512+
513+
Lemma felem_copy_func_correct :
514+
valid_func (res felem_copy_op _) ->
515+
forall functions,
516+
Interface.map.get functions Field.felem_copy = Some felem_copy_func ->
517+
(@spec_of_felem_copy _ _ _ _ _ _ _ field_representation_raw) functions.
518+
Proof using M_eq check_args_ok felem_copy_func_eq ok.
519+
cbv [spec_of_felem_copy]. rewrite felem_copy_func_eq. intros.
520+
pose proof copy_correct
521+
_ _ _ ltac:(eassumption) _ (res_eq felem_copy_op)
522+
as Hcorrect.
523+
524+
eapply felem_copy_correct; [ .. | eassumption | eassumption ];
525+
repeat handle_side_conditions; [ | ]; intros.
526+
{ (* output *value* is correct *)
527+
unshelve erewrite (proj1 (Hcorrect _ _)); cycle 1.
528+
{ rewrite map_map, List.map_ext_id; trivial; intros.
529+
rewrite ?Word.Interface.word.of_Z_unsigned; trivial. }
530+
{ rewrite <- H2. exact (list_Z_bounded_by_unsigned x0). } }
531+
{ (* output *bounds* are correct *)
532+
intros. apply Hcorrect; auto. }
533+
Qed.
534+
495535
Lemma from_bytes_func_correct :
496536
valid_func (res from_bytes_op _) ->
497537
forall functions,

0 commit comments

Comments
 (0)