Library QedkConcrete.blsisogeny3
The generated BLS degree-three isogeny preserves the curve equation
From Stdlib Require Import ZArith Lia List Field Zmod.Zmod.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Ec.Bls12_381
QedkConcrete.nativefieldbounds QedkConcrete.nativecomplexbounds
QedkConcrete.primefieldarith QedkConcrete.blscomplexsqrt
QedkConcrete.blscomplexresidues QedkConcrete.complexresiduefield
QedkConcrete.isogeny3math QedkConcrete.swucomplex QedkConcrete.blsswu2map
QedkConcrete.curvevalidity QedkConcrete.blscurvevalidity QedkConcrete.nativeindices.
Import ListNotations.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Module Bls := Ec.Bls12_381.
Module QR := QuadraticResidue.
Module Poly := Algebra.Polynomial_ring.
Definition quadraticHorner p (coeffs : list (QR.t p)) (x : QR.t p) :=
Lists.List.fold_right (fun c acc ⇒ QR.add p c (QR.mul p x acc)) (QR.zero p) coeffs.
Section Horner.
Variable p : Z.
Add Ring quadratic_ring : (QR.quadratic_ring p).
Lemma quadratic_horner_scale c coeffs x :
QR.mul p c (quadraticHorner p coeffs x) =
quadraticHorner p (Lists.List.map (QR.mul p c) coeffs) x.
Proof.
induction coeffs as [|a tl IH]; cbn [quadraticHorner Lists.List.fold_right Lists.List.map].
- ring.
- change (QR.mul p c (QR.add p a (QR.mul p x (quadraticHorner p tl x))) =
QR.add p (QR.mul p c a) (QR.mul p x (quadraticHorner p (Lists.List.map (QR.mul p c) tl) x))).
rewrite <- IH. ring.
Qed.
End Horner.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Ec.Bls12_381
QedkConcrete.nativefieldbounds QedkConcrete.nativecomplexbounds
QedkConcrete.primefieldarith QedkConcrete.blscomplexsqrt
QedkConcrete.blscomplexresidues QedkConcrete.complexresiduefield
QedkConcrete.isogeny3math QedkConcrete.swucomplex QedkConcrete.blsswu2map
QedkConcrete.curvevalidity QedkConcrete.blscurvevalidity QedkConcrete.nativeindices.
Import ListNotations.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Module Bls := Ec.Bls12_381.
Module QR := QuadraticResidue.
Module Poly := Algebra.Polynomial_ring.
Definition quadraticHorner p (coeffs : list (QR.t p)) (x : QR.t p) :=
Lists.List.fold_right (fun c acc ⇒ QR.add p c (QR.mul p x acc)) (QR.zero p) coeffs.
Section Horner.
Variable p : Z.
Add Ring quadratic_ring : (QR.quadratic_ring p).
Lemma quadratic_horner_scale c coeffs x :
QR.mul p c (quadraticHorner p coeffs x) =
quadraticHorner p (Lists.List.map (QR.mul p c) coeffs) x.
Proof.
induction coeffs as [|a tl IH]; cbn [quadraticHorner Lists.List.fold_right Lists.List.map].
- ring.
- change (QR.mul p c (QR.add p a (QR.mul p x (quadraticHorner p tl x))) =
QR.add p (QR.mul p c a) (QR.mul p x (quadraticHorner p (Lists.List.map (QR.mul p c) tl) x))).
rewrite <- IH. ring.
Qed.
End Horner.
A nonzero final coefficient prevents trimming. The length bound is the
native index domain; the concrete BLS coefficient tables satisfy it.
Lemma polynomial_coefficients_nonzero {A : Set} {F : @Poly.FArgs A}
{UX : A} coeffs :
OCamlIarray.length coeffs < 2^62 →
(@Poly.F _ F).(Algebra.FIELD.op_eq)
(@OCamlIarray.get _ (Opaque.legacy_witness UX) coeffs (OCamlIarray.length coeffs - 1))
(@Poly.F _ F).(Algebra.FIELD.zero) = false →
@Poly.of_coeffs _ F UX coeffs = coeffs.
Proof.
intros Hlength Hlast.
set (eqzero := fun c ⇒ (@Poly.F _ F).(Algebra.FIELD.op_eq) c
(@Poly.F _ F).(Algebra.FIELD.zero)).
set (step := fun '(degree, index) (c : A) ⇒
(if eqzero c then degree else index, OCamlInt.add index 1)).
assert (Hfold : ∀ prefix last degree index,
0 ≤ index → index + Z.of_nat (Lists.List.length prefix) + 1 < 2^62 →
eqzero last = false →
OCamlIarray.fold_left step (degree,index) (prefix ++ [last]) =
(index + Z.of_nat (Lists.List.length prefix), index + Z.of_nat (Lists.List.length prefix) + 1)).
{ induction prefix as [|c rest IH]; intros last degree index Hindex Hlimit Hnonzero.
- cbn [app OCamlIarray.fold_left Lists.List.length]. unfold step.
cbn [fst snd]. rewrite Hnonzero.
unfold OCamlInt.add. rewrite native_repr_small by lia.
f_equal; lia.
- cbn [Lists.List.length] in Hlimit.
cbn [app OCamlIarray.fold_left Lists.List.length].
change (OCamlIarray.fold_left step
(if eqzero c then degree else index, OCamlInt.add index 1)
(rest ++ [last]) =
(index + Z.of_nat (S (Lists.List.length rest)),
index + Z.of_nat (S (Lists.List.length rest)) + 1)).
unfold OCamlInt.add. rewrite native_repr_small by
(rewrite Nat2Z.inj_succ in Hlimit; lia).
rewrite IH by (try exact Hnonzero; rewrite Nat2Z.inj_succ in Hlimit; lia).
rewrite Nat2Z.inj_succ. f_equal; lia. }
induction coeffs as [|head tail IH] using rev_ind.
- reflexivity.
- assert (Hfinal : eqzero head = false).
{ unfold OCamlIarray.length in Hlast.
replace (Z.of_nat (Lists.List.length (tail ++ [head])) - 1) with (Z.of_nat (Lists.List.length tail))
in Hlast by (rewrite length_app; cbn [Lists.List.length]; rewrite Nat2Z.inj_add; lia).
unfold OCamlIarray.get in Hlast.
rewrite (proj2 (Z.ltb_ge _ _) (Nat2Z.is_nonneg _)), Nat2Z.id in Hlast.
rewrite nth_error_app2, Nat.sub_diag in Hlast by lia. exact Hlast. }
unfold Poly.of_coeffs, Poly.Impl, Poly.Impl.module.
cbn [Poly.Impl.Impl_signature.of_coeffs]. unfold Poly.Impl.of_coeffs.
fold eqzero. fold step.
rewrite Hfold by (try exact Hfinal; unfold OCamlIarray.length in Hlength;
rewrite length_app, Nat2Z.inj_add in Hlength; cbn [Lists.List.length] in Hlength; lia).
cbn zeta iota. unfold OCamlIarray.length, OCamlInt.sub.
rewrite length_app, Nat2Z.inj_add. cbn [Lists.List.length].
rewrite native_repr_small by (unfold OCamlIarray.length in Hlength;
rewrite length_app, Nat2Z.inj_add in Hlength; cbn [Lists.List.length] in Hlength; lia).
replace (Z.of_nat (Lists.List.length tail) + Z.of_nat 1 - 1) with
(0 + Z.of_nat (Lists.List.length tail)) by lia.
rewrite Z.eqb_refl. reflexivity.
Qed.
Section Generated.
Context {UZ : Basics.Unreachable Z} {UU : Basics.Unreachable Support.UintN.t}
{UI : Basics.Unreachable Numeric.Integer.t}
{UB : Basics.Unreachable Numeric.IntegerBase.(Numeric.Make.Make_result.t)}
{UF : Basics.Unreachable Z}.
Local Notation field := (@blscomplexresidues.field).
Local Notation complex := (@blscomplexresidues.complex).
Local Notation p := (@PF.modulus field).
Local Notation elt := (@Complex.t _ complex).
Local Notation bounded := (@complexBound _ complex (@primeFieldBound field)).
Local Notation residue := (@blsComplexResidue).
Local Notation poly := (@Bls.F_p2_SWU_curve.F_p2x_fargs).
Local Notation eval := (@Poly.eval _ poly).
Local Notation mul := (@Complex.op_star _ complex).
Local Notation add := (@Complex.op_plus _ complex).
Local Notation divide := (@Complex.op_div _ complex).
Local Notation c := (iso3Constant p).
Add Field extension_field : (QR.quadratic_field p
(@blsprimality.bls_generated_modulus_prime)
(@legendretests.bls_modulus_three_mod_four)).
Lemma bls_complex_polynomial_bound coeffs x :
Forall bounded coeffs → bounded (eval coeffs x).
Proof.
intro Hcoeffs. induction Hcoeffs as [|a tl Ha Htl IH].
- apply complex_zero_bound. exact (@bls_complex_base_closed).
- change (bounded (add a (mul x (eval tl x)))).
apply complex_add_bound; [exact (@bls_complex_base_closed)|exact Ha|].
apply (@bls_complex_mul_bound).
Qed.
Lemma bls_complex_polynomial_residue coeffs x :
Forall bounded coeffs →
residue (eval coeffs x) = quadraticHorner p (Lists.List.map residue coeffs) (residue x).
Proof.
intro Hcoeffs. induction Hcoeffs as [|a tl Ha Htl IH].
- apply (@bls_complex_residue_zero).
- change (residue (add a (mul x (eval tl x))) =
QR.add p (residue a) (QR.mul p (residue x) (quadraticHorner p (Lists.List.map residue tl) (residue x)))).
rewrite (@bls_complex_residue_add) by
(try exact Ha; apply (@bls_complex_mul_bound)).
rewrite (@bls_complex_residue_mul), IH. reflexivity.
Qed.
Context {UA : Basics.Unreachable (list elt)} {UX : Basics.Unreachable elt}.
Local Definition xnum := @Bls.F_p2_SWU_curve.x_num .
Local Definition xden := @Bls.F_p2_SWU_curve.x_den .
Local Definition ynum := @Bls.F_p2_SWU_curve.y_num .
Local Definition yden := @Bls.F_p2_SWU_curve.y_den .
Lemma bls_iso3_coefficients_bounded :
Forall bounded xnum ∧ Forall bounded xden ∧ Forall bounded ynum ∧ Forall bounded yden.
Proof.
unfold xnum, xden, ynum, yden.
unfold Bls.F_p2_SWU_curve.x_num, Bls.F_p2_SWU_curve.x_den,
Bls.F_p2_SWU_curve.y_num, Bls.F_p2_SWU_curve.y_den.
cbn beta iota zeta delta [Bls.F_p2_SWU_curve.F_p2x Poly.functor
Poly.Polynomial_ring_result.of_coeffs].
rewrite !polynomial_coefficients_nonzero by (vm_compute; reflexivity).
repeat first [apply conj | apply Forall_cons | apply Forall_nil].
all: vm_compute; congruence.
Qed.
Lemma bls_iso3_coefficients :
Lists.List.map (fun v ⇒ QR.mul p (c 9 0) (residue v)) xnum =
[c 304 304; c 0 (-24); c 12 (-12); QR.one p] ∧
Lists.List.map residue xden = [c 0 (-72); c 12 (-12); QR.one p] ∧
Lists.List.map (fun v ⇒ QR.mul p (c 27 0) (residue v)) ynum =
[c 752 752; c 0 264; c (-18) 18; QR.opp p (QR.one p)] ∧
Lists.List.map residue yden = [c (-432) (-432); c 0 (-216); c 18 (-18); QR.one p].
Proof.
unfold xnum, xden, ynum, yden.
unfold Bls.F_p2_SWU_curve.x_num, Bls.F_p2_SWU_curve.x_den,
Bls.F_p2_SWU_curve.y_num, Bls.F_p2_SWU_curve.y_den.
cbn beta iota zeta delta [Bls.F_p2_SWU_curve.F_p2x Poly.functor
Poly.Polynomial_ring_result.of_coeffs].
rewrite !polynomial_coefficients_nonzero by (vm_compute; reflexivity).
vm_compute. repeat split; reflexivity.
Qed.
Lemma bls_iso3_evaluation x :
QR.mul p (c 9 0) (residue (eval xnum x)) = iso3XNumerator p (residue x) ∧
residue (eval xden x) = iso3XDenominator p (residue x) ∧
QR.mul p (c 27 0) (residue (eval ynum x)) = iso3YNumerator p (residue x) ∧
residue (eval yden x) = iso3YDenominator p (residue x).
Proof.
destruct bls_iso3_coefficients_bounded as [Hxn [Hxd [Hyn Hyd]]].
destruct bls_iso3_coefficients as [HxnR [HxdR [HynR HydR]]].
repeat split.
- rewrite (bls_complex_polynomial_residue _ _ Hxn), quadratic_horner_scale, map_map.
rewrite HxnR. cbn [quadraticHorner Lists.List.fold_right]. unfold iso3XNumerator. ring.
- rewrite (bls_complex_polynomial_residue _ _ Hxd), HxdR.
cbn [quadraticHorner Lists.List.fold_right]. unfold iso3XDenominator. ring.
- rewrite (bls_complex_polynomial_residue _ _ Hyn), quadratic_horner_scale, map_map.
rewrite HynR. cbn [quadraticHorner Lists.List.fold_right]. unfold iso3YNumerator. ring.
- rewrite (bls_complex_polynomial_residue _ _ Hyd), HydR.
cbn [quadraticHorner Lists.List.fold_right]. unfold iso3YDenominator. ring.
Qed.
Local Definition auxiliary := @Bls.F_p2_SWU_curve.MonadVM_Ec_Curve_Make_include_fargs .
Local Definition target := @Bls.C_2_fargs .
Local Definition sourceA := (@Curve.P _ auxiliary).(Ec.Curve.Make_P_signature.a_value).
Local Definition sourceB := (@Curve.P _ auxiliary).(Ec.Curve.Make_P_signature.b_value).
Lemma bls_iso3_parameters :
bounded sourceA ∧ bounded sourceB ∧
residue sourceA = c 0 240 ∧ residue sourceB = c 1012 1012 ∧
residue (@Curve.P _ target).(Ec.Curve.Make_P_signature.b_value) = c 4 4.
Proof. vm_compute. repeat split; congruence. Qed.
{UX : A} coeffs :
OCamlIarray.length coeffs < 2^62 →
(@Poly.F _ F).(Algebra.FIELD.op_eq)
(@OCamlIarray.get _ (Opaque.legacy_witness UX) coeffs (OCamlIarray.length coeffs - 1))
(@Poly.F _ F).(Algebra.FIELD.zero) = false →
@Poly.of_coeffs _ F UX coeffs = coeffs.
Proof.
intros Hlength Hlast.
set (eqzero := fun c ⇒ (@Poly.F _ F).(Algebra.FIELD.op_eq) c
(@Poly.F _ F).(Algebra.FIELD.zero)).
set (step := fun '(degree, index) (c : A) ⇒
(if eqzero c then degree else index, OCamlInt.add index 1)).
assert (Hfold : ∀ prefix last degree index,
0 ≤ index → index + Z.of_nat (Lists.List.length prefix) + 1 < 2^62 →
eqzero last = false →
OCamlIarray.fold_left step (degree,index) (prefix ++ [last]) =
(index + Z.of_nat (Lists.List.length prefix), index + Z.of_nat (Lists.List.length prefix) + 1)).
{ induction prefix as [|c rest IH]; intros last degree index Hindex Hlimit Hnonzero.
- cbn [app OCamlIarray.fold_left Lists.List.length]. unfold step.
cbn [fst snd]. rewrite Hnonzero.
unfold OCamlInt.add. rewrite native_repr_small by lia.
f_equal; lia.
- cbn [Lists.List.length] in Hlimit.
cbn [app OCamlIarray.fold_left Lists.List.length].
change (OCamlIarray.fold_left step
(if eqzero c then degree else index, OCamlInt.add index 1)
(rest ++ [last]) =
(index + Z.of_nat (S (Lists.List.length rest)),
index + Z.of_nat (S (Lists.List.length rest)) + 1)).
unfold OCamlInt.add. rewrite native_repr_small by
(rewrite Nat2Z.inj_succ in Hlimit; lia).
rewrite IH by (try exact Hnonzero; rewrite Nat2Z.inj_succ in Hlimit; lia).
rewrite Nat2Z.inj_succ. f_equal; lia. }
induction coeffs as [|head tail IH] using rev_ind.
- reflexivity.
- assert (Hfinal : eqzero head = false).
{ unfold OCamlIarray.length in Hlast.
replace (Z.of_nat (Lists.List.length (tail ++ [head])) - 1) with (Z.of_nat (Lists.List.length tail))
in Hlast by (rewrite length_app; cbn [Lists.List.length]; rewrite Nat2Z.inj_add; lia).
unfold OCamlIarray.get in Hlast.
rewrite (proj2 (Z.ltb_ge _ _) (Nat2Z.is_nonneg _)), Nat2Z.id in Hlast.
rewrite nth_error_app2, Nat.sub_diag in Hlast by lia. exact Hlast. }
unfold Poly.of_coeffs, Poly.Impl, Poly.Impl.module.
cbn [Poly.Impl.Impl_signature.of_coeffs]. unfold Poly.Impl.of_coeffs.
fold eqzero. fold step.
rewrite Hfold by (try exact Hfinal; unfold OCamlIarray.length in Hlength;
rewrite length_app, Nat2Z.inj_add in Hlength; cbn [Lists.List.length] in Hlength; lia).
cbn zeta iota. unfold OCamlIarray.length, OCamlInt.sub.
rewrite length_app, Nat2Z.inj_add. cbn [Lists.List.length].
rewrite native_repr_small by (unfold OCamlIarray.length in Hlength;
rewrite length_app, Nat2Z.inj_add in Hlength; cbn [Lists.List.length] in Hlength; lia).
replace (Z.of_nat (Lists.List.length tail) + Z.of_nat 1 - 1) with
(0 + Z.of_nat (Lists.List.length tail)) by lia.
rewrite Z.eqb_refl. reflexivity.
Qed.
Section Generated.
Context {UZ : Basics.Unreachable Z} {UU : Basics.Unreachable Support.UintN.t}
{UI : Basics.Unreachable Numeric.Integer.t}
{UB : Basics.Unreachable Numeric.IntegerBase.(Numeric.Make.Make_result.t)}
{UF : Basics.Unreachable Z}.
Local Notation field := (@blscomplexresidues.field).
Local Notation complex := (@blscomplexresidues.complex).
Local Notation p := (@PF.modulus field).
Local Notation elt := (@Complex.t _ complex).
Local Notation bounded := (@complexBound _ complex (@primeFieldBound field)).
Local Notation residue := (@blsComplexResidue).
Local Notation poly := (@Bls.F_p2_SWU_curve.F_p2x_fargs).
Local Notation eval := (@Poly.eval _ poly).
Local Notation mul := (@Complex.op_star _ complex).
Local Notation add := (@Complex.op_plus _ complex).
Local Notation divide := (@Complex.op_div _ complex).
Local Notation c := (iso3Constant p).
Add Field extension_field : (QR.quadratic_field p
(@blsprimality.bls_generated_modulus_prime)
(@legendretests.bls_modulus_three_mod_four)).
Lemma bls_complex_polynomial_bound coeffs x :
Forall bounded coeffs → bounded (eval coeffs x).
Proof.
intro Hcoeffs. induction Hcoeffs as [|a tl Ha Htl IH].
- apply complex_zero_bound. exact (@bls_complex_base_closed).
- change (bounded (add a (mul x (eval tl x)))).
apply complex_add_bound; [exact (@bls_complex_base_closed)|exact Ha|].
apply (@bls_complex_mul_bound).
Qed.
Lemma bls_complex_polynomial_residue coeffs x :
Forall bounded coeffs →
residue (eval coeffs x) = quadraticHorner p (Lists.List.map residue coeffs) (residue x).
Proof.
intro Hcoeffs. induction Hcoeffs as [|a tl Ha Htl IH].
- apply (@bls_complex_residue_zero).
- change (residue (add a (mul x (eval tl x))) =
QR.add p (residue a) (QR.mul p (residue x) (quadraticHorner p (Lists.List.map residue tl) (residue x)))).
rewrite (@bls_complex_residue_add) by
(try exact Ha; apply (@bls_complex_mul_bound)).
rewrite (@bls_complex_residue_mul), IH. reflexivity.
Qed.
Context {UA : Basics.Unreachable (list elt)} {UX : Basics.Unreachable elt}.
Local Definition xnum := @Bls.F_p2_SWU_curve.x_num .
Local Definition xden := @Bls.F_p2_SWU_curve.x_den .
Local Definition ynum := @Bls.F_p2_SWU_curve.y_num .
Local Definition yden := @Bls.F_p2_SWU_curve.y_den .
Lemma bls_iso3_coefficients_bounded :
Forall bounded xnum ∧ Forall bounded xden ∧ Forall bounded ynum ∧ Forall bounded yden.
Proof.
unfold xnum, xden, ynum, yden.
unfold Bls.F_p2_SWU_curve.x_num, Bls.F_p2_SWU_curve.x_den,
Bls.F_p2_SWU_curve.y_num, Bls.F_p2_SWU_curve.y_den.
cbn beta iota zeta delta [Bls.F_p2_SWU_curve.F_p2x Poly.functor
Poly.Polynomial_ring_result.of_coeffs].
rewrite !polynomial_coefficients_nonzero by (vm_compute; reflexivity).
repeat first [apply conj | apply Forall_cons | apply Forall_nil].
all: vm_compute; congruence.
Qed.
Lemma bls_iso3_coefficients :
Lists.List.map (fun v ⇒ QR.mul p (c 9 0) (residue v)) xnum =
[c 304 304; c 0 (-24); c 12 (-12); QR.one p] ∧
Lists.List.map residue xden = [c 0 (-72); c 12 (-12); QR.one p] ∧
Lists.List.map (fun v ⇒ QR.mul p (c 27 0) (residue v)) ynum =
[c 752 752; c 0 264; c (-18) 18; QR.opp p (QR.one p)] ∧
Lists.List.map residue yden = [c (-432) (-432); c 0 (-216); c 18 (-18); QR.one p].
Proof.
unfold xnum, xden, ynum, yden.
unfold Bls.F_p2_SWU_curve.x_num, Bls.F_p2_SWU_curve.x_den,
Bls.F_p2_SWU_curve.y_num, Bls.F_p2_SWU_curve.y_den.
cbn beta iota zeta delta [Bls.F_p2_SWU_curve.F_p2x Poly.functor
Poly.Polynomial_ring_result.of_coeffs].
rewrite !polynomial_coefficients_nonzero by (vm_compute; reflexivity).
vm_compute. repeat split; reflexivity.
Qed.
Lemma bls_iso3_evaluation x :
QR.mul p (c 9 0) (residue (eval xnum x)) = iso3XNumerator p (residue x) ∧
residue (eval xden x) = iso3XDenominator p (residue x) ∧
QR.mul p (c 27 0) (residue (eval ynum x)) = iso3YNumerator p (residue x) ∧
residue (eval yden x) = iso3YDenominator p (residue x).
Proof.
destruct bls_iso3_coefficients_bounded as [Hxn [Hxd [Hyn Hyd]]].
destruct bls_iso3_coefficients as [HxnR [HxdR [HynR HydR]]].
repeat split.
- rewrite (bls_complex_polynomial_residue _ _ Hxn), quadratic_horner_scale, map_map.
rewrite HxnR. cbn [quadraticHorner Lists.List.fold_right]. unfold iso3XNumerator. ring.
- rewrite (bls_complex_polynomial_residue _ _ Hxd), HxdR.
cbn [quadraticHorner Lists.List.fold_right]. unfold iso3XDenominator. ring.
- rewrite (bls_complex_polynomial_residue _ _ Hyn), quadratic_horner_scale, map_map.
rewrite HynR. cbn [quadraticHorner Lists.List.fold_right]. unfold iso3YNumerator. ring.
- rewrite (bls_complex_polynomial_residue _ _ Hyd), HydR.
cbn [quadraticHorner Lists.List.fold_right]. unfold iso3YDenominator. ring.
Qed.
Local Definition auxiliary := @Bls.F_p2_SWU_curve.MonadVM_Ec_Curve_Make_include_fargs .
Local Definition target := @Bls.C_2_fargs .
Local Definition sourceA := (@Curve.P _ auxiliary).(Ec.Curve.Make_P_signature.a_value).
Local Definition sourceB := (@Curve.P _ auxiliary).(Ec.Curve.Make_P_signature.b_value).
Lemma bls_iso3_parameters :
bounded sourceA ∧ bounded sourceB ∧
residue sourceA = c 0 240 ∧ residue sourceB = c 1012 1012 ∧
residue (@Curve.P _ target).(Ec.Curve.Make_P_signature.b_value) = c 4 4.
Proof. vm_compute. repeat split; congruence. Qed.
Convert the residue-field equation back to the generated curve test.
Keeping coordinates abstract here avoids reducing whole isogeny expressions
during each field-operation conversion in the calling proof.
Lemma bls_iso3_target_from_residues x y :
bounded x → bounded y →
QR.mul p (residue y) (residue y) = iso3TargetCurve p (residue x) →
@Curve.in_curve _ target x y = true.
Proof.
intros Hxb Hyb Htarget.
destruct bls_iso3_parameters as [_ [_ [_ [_ HtargetR]]]].
assert (Htb : bounded (@Curve.P _ target).(Ec.Curve.Make_P_signature.b_value))
by (vm_compute; repeat split; congruence).
assert (H0 : bounded (@Complex.zero _ complex)) by
(apply complex_zero_bound; exact (@bls_complex_base_closed)).
change (@Complex.op_eq _ complex (mul y y)
(add (mul x (add (mul x x) (@Complex.zero _ complex)))
(@Curve.P _ target).(Ec.Curve.Make_P_signature.b_value)) = true).
apply (@swucomplex.equal_true).
apply (@bls_complex_residue_injective).
- apply (@bls_complex_mul_bound).
- apply complex_add_bound; [exact (@bls_complex_base_closed)|
apply (@bls_complex_mul_bound)|].
exact Htb.
- rewrite (@bls_complex_residue_mul).
rewrite (@bls_complex_residue_add) by
(first [assumption | apply (@bls_complex_mul_bound)]).
rewrite (@bls_complex_residue_mul),
(@bls_complex_residue_add) by
(first [assumption | apply (@bls_complex_mul_bound)]).
rewrite (@bls_complex_residue_mul),
(@bls_complex_residue_zero), HtargetR.
rewrite Htarget. unfold iso3TargetCurve. ring.
Qed.
Lemma bls_iso3_source_test x y :
@Curve.in_curve _ auxiliary x y =
@Complex.op_eq _ complex (mul y y)
(add (mul x (add (mul x x) sourceA)) sourceB).
Proof.
cbv beta iota zeta delta [Curve.in_curve Curve.g_value Curve.Underlying Curve.Params
auxiliary sourceA sourceB Bls.F_p2_SWU_curve.MonadVM_Ec_Curve_Make_include_fargs
Bls.F_p2.op_eq Bls.F_p2.op_plus Bls.F_p2.op_star
Bls.F_p2.MonadVM_Ec_Algebra_Complex_extension_include Complex.functor].
reflexivity.
Qed.
Lemma bls_iso3_source_residues x y :
@Curve.in_curve _ auxiliary x y = true →
QR.mul p (residue y) (residue y) = iso3SourceCurve p (residue x).
Proof.
intro Hsource.
destruct bls_iso3_parameters as [Ha [Hb [HaR [HbR _]]]].
rewrite bls_iso3_source_test in Hsource.
apply (@swucomplex.equal_true) in Hsource.
apply (f_equal residue) in Hsource.
rewrite (@bls_complex_residue_mul) in Hsource.
repeat first [rewrite (@bls_complex_residue_add) in Hsource by
(repeat first [assumption | apply (@bls_complex_mul_bound)]) |
rewrite (@bls_complex_residue_mul) in Hsource].
rewrite HaR, HbR in Hsource. exact Hsource.
Qed.
bounded x → bounded y →
QR.mul p (residue y) (residue y) = iso3TargetCurve p (residue x) →
@Curve.in_curve _ target x y = true.
Proof.
intros Hxb Hyb Htarget.
destruct bls_iso3_parameters as [_ [_ [_ [_ HtargetR]]]].
assert (Htb : bounded (@Curve.P _ target).(Ec.Curve.Make_P_signature.b_value))
by (vm_compute; repeat split; congruence).
assert (H0 : bounded (@Complex.zero _ complex)) by
(apply complex_zero_bound; exact (@bls_complex_base_closed)).
change (@Complex.op_eq _ complex (mul y y)
(add (mul x (add (mul x x) (@Complex.zero _ complex)))
(@Curve.P _ target).(Ec.Curve.Make_P_signature.b_value)) = true).
apply (@swucomplex.equal_true).
apply (@bls_complex_residue_injective).
- apply (@bls_complex_mul_bound).
- apply complex_add_bound; [exact (@bls_complex_base_closed)|
apply (@bls_complex_mul_bound)|].
exact Htb.
- rewrite (@bls_complex_residue_mul).
rewrite (@bls_complex_residue_add) by
(first [assumption | apply (@bls_complex_mul_bound)]).
rewrite (@bls_complex_residue_mul),
(@bls_complex_residue_add) by
(first [assumption | apply (@bls_complex_mul_bound)]).
rewrite (@bls_complex_residue_mul),
(@bls_complex_residue_zero), HtargetR.
rewrite Htarget. unfold iso3TargetCurve. ring.
Qed.
Lemma bls_iso3_source_test x y :
@Curve.in_curve _ auxiliary x y =
@Complex.op_eq _ complex (mul y y)
(add (mul x (add (mul x x) sourceA)) sourceB).
Proof.
cbv beta iota zeta delta [Curve.in_curve Curve.g_value Curve.Underlying Curve.Params
auxiliary sourceA sourceB Bls.F_p2_SWU_curve.MonadVM_Ec_Curve_Make_include_fargs
Bls.F_p2.op_eq Bls.F_p2.op_plus Bls.F_p2.op_star
Bls.F_p2.MonadVM_Ec_Algebra_Complex_extension_include Complex.functor].
reflexivity.
Qed.
Lemma bls_iso3_source_residues x y :
@Curve.in_curve _ auxiliary x y = true →
QR.mul p (residue y) (residue y) = iso3SourceCurve p (residue x).
Proof.
intro Hsource.
destruct bls_iso3_parameters as [Ha [Hb [HaR [HbR _]]]].
rewrite bls_iso3_source_test in Hsource.
apply (@swucomplex.equal_true) in Hsource.
apply (f_equal residue) in Hsource.
rewrite (@bls_complex_residue_mul) in Hsource.
repeat first [rewrite (@bls_complex_residue_add) in Hsource by
(repeat first [assumption | apply (@bls_complex_mul_bound)]) |
rewrite (@bls_complex_residue_mul) in Hsource].
rewrite HaR, HbR in Hsource. exact Hsource.
Qed.
This is the exact rational formula evaluated in the non-kernel branch
of the generated isogeny, before cofactor multiplication.
Theorem bls_iso3_coordinates_valid x y :
@Curve.in_curve _ auxiliary x y = true →
@Complex.op_eq _ complex (eval xden x) (@Complex.zero _ complex) = false →
let xx := divide (eval xnum x) (eval xden x) in
let yy := mul (divide (eval ynum x) (eval yden x)) y in
bounded xx ∧ bounded yy ∧ @Curve.in_curve _ target xx yy = true.
Proof.
intros Hsource Hnonkernel. cbv zeta.
destruct bls_iso3_coefficients_bounded as [Hxn [Hxd [Hyn Hyd]]].
destruct (bls_iso3_evaluation x) as [HxnR [HxdR [HynR HydR]]].
destruct bls_iso3_parameters as [Ha [Hb [HaR [HbR HtargetR]]]].
assert (Hxdnz : residue (eval xden x) ≠ QR.zero p).
{ intro Hzero.
assert (Heq : eval xden x = @Complex.zero _ complex).
{ apply (@bls_complex_residue_injective).
- apply bls_complex_polynomial_bound; exact Hxd.
- apply complex_zero_bound; exact (@bls_complex_base_closed).
- rewrite (@bls_complex_residue_zero). exact Hzero. }
apply (@swucomplex.equal_true) in Heq. congruence. }
assert (Hydnz : residue (eval yden x) ≠ QR.zero p).
{ rewrite HydR. apply iso3_y_denominator_nonzero.
- exact (@blsprimality.bls_generated_modulus_prime).
- exact (@legendretests.bls_modulus_three_mod_four).
- rewrite <- HxdR. exact Hxdnz. }
assert (H9 : c 9 0 ≠ QR.zero p) by (vm_compute; congruence).
assert (H27 : c 27 0 ≠ QR.zero p) by (vm_compute; congruence).
assert (Hxx : residue (divide (eval xnum x) (eval xden x)) =
QR.divide p (iso3XNumerator p (residue x)) (QR.mul p (c 9 0) (iso3XDenominator p (residue x)))).
{ rewrite (@bls_complex_residue_div) by
(try exact Hxdnz; apply bls_complex_polynomial_bound; exact Hxd).
rewrite <- HxnR, <- HxdR.
apply (iso3_scaled_division p (@blsprimality.bls_generated_modulus_prime)
(@legendretests.bls_modulus_three_mod_four)); assumption. }
assert (Hyy : residue (mul (divide (eval ynum x) (eval yden x)) y) =
QR.mul p (QR.divide p (iso3YNumerator p (residue x))
(QR.mul p (c 27 0) (iso3YDenominator p (residue x)))) (residue y)).
{ rewrite (@bls_complex_residue_mul),
(@bls_complex_residue_div) by
(try exact Hydnz; apply bls_complex_polynomial_bound; exact Hyd).
rewrite <- HynR, <- HydR. f_equal.
apply (iso3_scaled_division p (@blsprimality.bls_generated_modulus_prime)
(@legendretests.bls_modulus_three_mod_four)); assumption. }
pose proof (bls_iso3_source_residues x y Hsource) as HcurveR.
set (xx := divide (eval xnum x) (eval xden x)) in ×.
set (yy := mul (divide (eval ynum x) (eval yden x)) y) in ×.
assert (Hxb : bounded xx) by (apply (@bls_complex_mul_bound)).
assert (Hyb : bounded yy) by (apply (@bls_complex_mul_bound)).
split; [exact Hxb|]. split; [exact Hyb|].
assert (Htarget : QR.mul p (residue yy) (residue yy) = iso3TargetCurve p (residue xx)).
{ rewrite Hxx, Hyy. apply iso3_curve_map.
- exact (@blsprimality.bls_generated_modulus_prime).
- exact (@legendretests.bls_modulus_three_mod_four).
- vm_compute; congruence.
- rewrite <- HxdR. exact Hxdnz.
- exact HcurveR. }
apply bls_iso3_target_from_residues; assumption.
Qed.
@Curve.in_curve _ auxiliary x y = true →
@Complex.op_eq _ complex (eval xden x) (@Complex.zero _ complex) = false →
let xx := divide (eval xnum x) (eval xden x) in
let yy := mul (divide (eval ynum x) (eval yden x)) y in
bounded xx ∧ bounded yy ∧ @Curve.in_curve _ target xx yy = true.
Proof.
intros Hsource Hnonkernel. cbv zeta.
destruct bls_iso3_coefficients_bounded as [Hxn [Hxd [Hyn Hyd]]].
destruct (bls_iso3_evaluation x) as [HxnR [HxdR [HynR HydR]]].
destruct bls_iso3_parameters as [Ha [Hb [HaR [HbR HtargetR]]]].
assert (Hxdnz : residue (eval xden x) ≠ QR.zero p).
{ intro Hzero.
assert (Heq : eval xden x = @Complex.zero _ complex).
{ apply (@bls_complex_residue_injective).
- apply bls_complex_polynomial_bound; exact Hxd.
- apply complex_zero_bound; exact (@bls_complex_base_closed).
- rewrite (@bls_complex_residue_zero). exact Hzero. }
apply (@swucomplex.equal_true) in Heq. congruence. }
assert (Hydnz : residue (eval yden x) ≠ QR.zero p).
{ rewrite HydR. apply iso3_y_denominator_nonzero.
- exact (@blsprimality.bls_generated_modulus_prime).
- exact (@legendretests.bls_modulus_three_mod_four).
- rewrite <- HxdR. exact Hxdnz. }
assert (H9 : c 9 0 ≠ QR.zero p) by (vm_compute; congruence).
assert (H27 : c 27 0 ≠ QR.zero p) by (vm_compute; congruence).
assert (Hxx : residue (divide (eval xnum x) (eval xden x)) =
QR.divide p (iso3XNumerator p (residue x)) (QR.mul p (c 9 0) (iso3XDenominator p (residue x)))).
{ rewrite (@bls_complex_residue_div) by
(try exact Hxdnz; apply bls_complex_polynomial_bound; exact Hxd).
rewrite <- HxnR, <- HxdR.
apply (iso3_scaled_division p (@blsprimality.bls_generated_modulus_prime)
(@legendretests.bls_modulus_three_mod_four)); assumption. }
assert (Hyy : residue (mul (divide (eval ynum x) (eval yden x)) y) =
QR.mul p (QR.divide p (iso3YNumerator p (residue x))
(QR.mul p (c 27 0) (iso3YDenominator p (residue x)))) (residue y)).
{ rewrite (@bls_complex_residue_mul),
(@bls_complex_residue_div) by
(try exact Hydnz; apply bls_complex_polynomial_bound; exact Hyd).
rewrite <- HynR, <- HydR. f_equal.
apply (iso3_scaled_division p (@blsprimality.bls_generated_modulus_prime)
(@legendretests.bls_modulus_three_mod_four)); assumption. }
pose proof (bls_iso3_source_residues x y Hsource) as HcurveR.
set (xx := divide (eval xnum x) (eval xden x)) in ×.
set (yy := mul (divide (eval ynum x) (eval yden x)) y) in ×.
assert (Hxb : bounded xx) by (apply (@bls_complex_mul_bound)).
assert (Hyb : bounded yy) by (apply (@bls_complex_mul_bound)).
split; [exact Hxb|]. split; [exact Hyb|].
assert (Htarget : QR.mul p (residue yy) (residue yy) = iso3TargetCurve p (residue xx)).
{ rewrite Hxx, Hyy. apply iso3_curve_map.
- exact (@blsprimality.bls_generated_modulus_prime).
- exact (@legendretests.bls_modulus_three_mod_four).
- vm_compute; congruence.
- rewrite <- HxdR. exact Hxdnz.
- exact HcurveR. }
apply bls_iso3_target_from_residues; assumption.
Qed.
The partial coordinate constructor in the actual isogeny succeeds.
Cofactor multiplication preserves both coordinate bounds and the curve equation. Its
subsequent subgroup test is a separate, still unproved obligation.
Theorem bls_iso3_construct_and_clear_valid x y :
@Curve.in_curve _ auxiliary x y = true →
@Complex.op_eq _ complex (eval xden x) (@Complex.zero _ complex) = false →
let xx := divide (eval xnum x) (eval xden x) in
let yy := mul (divide (eval ynum x) (eval yden x)) y in
∃ point,
@Curve.of_coords _ target xx yy = Some point ∧
@curvePointValid _ target bounded
(@Curve.op_star _ target (@Bls.F_p2_SWU_curve.h_eff) point).
Proof.
intros Hcurve Hkernel. cbv zeta.
destruct (bls_iso3_coordinates_valid x y Hcurve Hkernel) as [Hxx [Hyy Htarget]].
destruct (curve_construct_valid bounded _ _ Hxx Hyy Htarget)
as [point [Hparse Hvalid]].
∃ point. split; [exact Hparse|].
apply bls_g2_mul_valid. exact Hvalid.
Qed.
Theorem bls_iso3_construct_and_clear x y :
@Curve.in_curve _ auxiliary x y = true →
@Complex.op_eq _ complex (eval xden x) (@Complex.zero _ complex) = false →
let xx := divide (eval xnum x) (eval xden x) in
let yy := mul (divide (eval ynum x) (eval yden x)) y in
∃ point,
@Curve.of_coords _ target xx yy = Some point ∧
@curvePointBound _ target bounded
(@Curve.op_star _ target (@Bls.F_p2_SWU_curve.h_eff) point).
Proof.
intros Hcurve Hkernel.
destruct (bls_iso3_construct_and_clear_valid x y Hcurve Hkernel)
as [point [Hparse [Hbound _]]].
∃ point. split; assumption.
Qed.
@Curve.in_curve _ auxiliary x y = true →
@Complex.op_eq _ complex (eval xden x) (@Complex.zero _ complex) = false →
let xx := divide (eval xnum x) (eval xden x) in
let yy := mul (divide (eval ynum x) (eval yden x)) y in
∃ point,
@Curve.of_coords _ target xx yy = Some point ∧
@curvePointValid _ target bounded
(@Curve.op_star _ target (@Bls.F_p2_SWU_curve.h_eff) point).
Proof.
intros Hcurve Hkernel. cbv zeta.
destruct (bls_iso3_coordinates_valid x y Hcurve Hkernel) as [Hxx [Hyy Htarget]].
destruct (curve_construct_valid bounded _ _ Hxx Hyy Htarget)
as [point [Hparse Hvalid]].
∃ point. split; [exact Hparse|].
apply bls_g2_mul_valid. exact Hvalid.
Qed.
Theorem bls_iso3_construct_and_clear x y :
@Curve.in_curve _ auxiliary x y = true →
@Complex.op_eq _ complex (eval xden x) (@Complex.zero _ complex) = false →
let xx := divide (eval xnum x) (eval xden x) in
let yy := mul (divide (eval ynum x) (eval yden x)) y in
∃ point,
@Curve.of_coords _ target xx yy = Some point ∧
@curvePointBound _ target bounded
(@Curve.op_star _ target (@Bls.F_p2_SWU_curve.h_eff) point).
Proof.
intros Hcurve Hkernel.
destruct (bls_iso3_construct_and_clear_valid x y Hcurve Hkernel)
as [point [Hparse [Hbound _]]].
∃ point. split; assumption.
Qed.
Composition uses the generated SWU output, not arbitrary auxiliary-curve
input assumed valid. Only the final subgroup conversion remains.
Corollary bls_swu2_isogeny_construct_and_clear_valid
{USX : elt} {UP : @Curve.t _ auxiliary} u :
let swu := @Bls.F_p2_SWU_fargs in
let '(x,y) := @Curve.coords _ auxiliary
(@Ec.Curve.SWU_method.map_to_curve_simple_swu _ _ swu USX UP u) in
@Complex.op_eq _ complex (eval xden x) (@Complex.zero _ complex) = false →
∃ point,
@Curve.of_coords _ target (divide (eval xnum x) (eval xden x))
(mul (divide (eval ynum x) (eval yden x)) y) = Some point ∧
@curvePointValid _ target bounded
(@Curve.op_star _ target (@Bls.F_p2_SWU_curve.h_eff) point).
Proof.
pose proof (@bls_swu2_map_coordinates USX UP u) as Hcoords.
cbv zeta.
destruct (@Curve.coords _ auxiliary
(@Ec.Curve.SWU_method.map_to_curve_simple_swu _ _
(@Bls.F_p2_SWU_fargs) USX UP u)) as [x y] eqn:Hxy.
change (let '(x,y) := @Curve.coords _ auxiliary
(@Ec.Curve.SWU_method.map_to_curve_simple_swu _ _
(@Bls.F_p2_SWU_fargs) USX UP u) in
bounded x ∧ bounded y ∧ @Curve.in_curve _ auxiliary x y = true) in Hcoords.
rewrite Hxy in Hcoords. destruct Hcoords as [_ [_ Hcurve]].
exact (bls_iso3_construct_and_clear_valid x y Hcurve).
Qed.
Corollary bls_swu2_isogeny_construct_and_clear
{USX : elt} {UP : @Curve.t _ auxiliary} u :
let swu := @Bls.F_p2_SWU_fargs in
let '(x,y) := @Curve.coords _ auxiliary
(@Ec.Curve.SWU_method.map_to_curve_simple_swu _ _ swu USX UP u) in
@Complex.op_eq _ complex (eval xden x) (@Complex.zero _ complex) = false →
∃ point,
@Curve.of_coords _ target (divide (eval xnum x) (eval xden x))
(mul (divide (eval ynum x) (eval yden x)) y) = Some point ∧
@curvePointBound _ target bounded
(@Curve.op_star _ target (@Bls.F_p2_SWU_curve.h_eff) point).
Proof.
cbv zeta.
destruct (@Curve.coords _ auxiliary
(@Ec.Curve.SWU_method.map_to_curve_simple_swu _ _
(@Bls.F_p2_SWU_fargs) USX UP u)) as [x y] eqn:Hxy.
intro Hkernel.
pose proof (@bls_swu2_isogeny_construct_and_clear_valid USX UP u) as Hvalid.
cbv zeta in Hvalid. rewrite Hxy in Hvalid.
destruct (Hvalid Hkernel) as [point [Hparse [Hbound _]]].
∃ point. split; assumption.
Qed.
End Generated.
Print Assumptions bls_iso3_coordinates_valid.
Print Assumptions bls_swu2_isogeny_construct_and_clear.
Print Assumptions bls_swu2_isogeny_construct_and_clear_valid.
{USX : elt} {UP : @Curve.t _ auxiliary} u :
let swu := @Bls.F_p2_SWU_fargs in
let '(x,y) := @Curve.coords _ auxiliary
(@Ec.Curve.SWU_method.map_to_curve_simple_swu _ _ swu USX UP u) in
@Complex.op_eq _ complex (eval xden x) (@Complex.zero _ complex) = false →
∃ point,
@Curve.of_coords _ target (divide (eval xnum x) (eval xden x))
(mul (divide (eval ynum x) (eval yden x)) y) = Some point ∧
@curvePointValid _ target bounded
(@Curve.op_star _ target (@Bls.F_p2_SWU_curve.h_eff) point).
Proof.
pose proof (@bls_swu2_map_coordinates USX UP u) as Hcoords.
cbv zeta.
destruct (@Curve.coords _ auxiliary
(@Ec.Curve.SWU_method.map_to_curve_simple_swu _ _
(@Bls.F_p2_SWU_fargs) USX UP u)) as [x y] eqn:Hxy.
change (let '(x,y) := @Curve.coords _ auxiliary
(@Ec.Curve.SWU_method.map_to_curve_simple_swu _ _
(@Bls.F_p2_SWU_fargs) USX UP u) in
bounded x ∧ bounded y ∧ @Curve.in_curve _ auxiliary x y = true) in Hcoords.
rewrite Hxy in Hcoords. destruct Hcoords as [_ [_ Hcurve]].
exact (bls_iso3_construct_and_clear_valid x y Hcurve).
Qed.
Corollary bls_swu2_isogeny_construct_and_clear
{USX : elt} {UP : @Curve.t _ auxiliary} u :
let swu := @Bls.F_p2_SWU_fargs in
let '(x,y) := @Curve.coords _ auxiliary
(@Ec.Curve.SWU_method.map_to_curve_simple_swu _ _ swu USX UP u) in
@Complex.op_eq _ complex (eval xden x) (@Complex.zero _ complex) = false →
∃ point,
@Curve.of_coords _ target (divide (eval xnum x) (eval xden x))
(mul (divide (eval ynum x) (eval yden x)) y) = Some point ∧
@curvePointBound _ target bounded
(@Curve.op_star _ target (@Bls.F_p2_SWU_curve.h_eff) point).
Proof.
cbv zeta.
destruct (@Curve.coords _ auxiliary
(@Ec.Curve.SWU_method.map_to_curve_simple_swu _ _
(@Bls.F_p2_SWU_fargs) USX UP u)) as [x y] eqn:Hxy.
intro Hkernel.
pose proof (@bls_swu2_isogeny_construct_and_clear_valid USX UP u) as Hvalid.
cbv zeta in Hvalid. rewrite Hxy in Hvalid.
destruct (Hvalid Hkernel) as [point [Hparse [Hbound _]]].
∃ point. split; assumption.
Qed.
End Generated.
Print Assumptions bls_iso3_coordinates_valid.
Print Assumptions bls_swu2_isogeny_construct_and_clear.
Print Assumptions bls_swu2_isogeny_construct_and_clear_valid.