Library QedkConcrete.curvevalidity
Curve invariants for the generated affine point operations
From Stdlib Require Import ZArith Bool Ring Field.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Ec.Curve
QedkConcrete.nativefieldbounds QedkConcrete.ellipticadditionmath.
Set Default Goal Selector "!".
Definition curvePointValid {A : Set} {C : @Curve.FArgs A}
(bounded : A → Prop) (point : @Curve.t A C) : Prop :=
@curvePointBound A C bounded point ∧
match point with
| Curve.Point x y ⇒ @Curve.in_curve A C x y = true
| Curve.Infinity ⇒ True
end.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Ec.Curve
QedkConcrete.nativefieldbounds QedkConcrete.ellipticadditionmath.
Set Default Goal Selector "!".
Definition curvePointValid {A : Set} {C : @Curve.FArgs A}
(bounded : A → Prop) (point : @Curve.t A C) : Prop :=
@curvePointBound A C bounded point ∧
match point with
| Curve.Point x y ⇒ @Curve.in_curve A C x y = true
| Curve.Infinity ⇒ True
end.
The scalar loop needs only closure of addition. Both its accumulator
and its repeatedly doubled point remain on the curve.
Lemma curve_mul_valid_from_add {A : Set} {C : @Curve.FArgs A}
{UN : Basics.Unreachable Support.UintN.t} (bounded : A → Prop) :
(∀ left right, @curvePointValid A C bounded left →
@curvePointValid A C bounded right →
@curvePointValid A C bounded (@Curve.op_plus A C left right)) →
∀ n point, @curvePointValid A C bounded point →
@curvePointValid A C bounded (@Curve.op_star A C n point).
Proof.
intros Hadd n point Hpoint. unfold Curve.op_star.
eapply fix_preserves with (I := fun item ⇒
@curvePointValid A C bounded (snd (fst item)) ∧
@curvePointValid A C bounded (snd item)).
- intros [[scalar current] acc] recur [Hcurrent Hacc] Hrecur. cbn beta iota zeta in ×.
eapply dependent_bool_property.
+ intros _. exact Hacc.
+ intro Hnonzero. eapply dependent_pair_property. intros next remainder Hdivision.
apply Hrecur. split.
× apply Hadd; assumption.
× destruct (Support.UintN.op_eq remainder (@Support.UintN.one));
[apply Hadd; assumption|exact Hacc].
- split; [exact Hpoint|split; exact I].
Qed.
Section Representation.
Context {A : Set} {C : @Curve.FArgs A} (bounded : A → Prop).
Context {R : Type} (zero one : R) (plus times minus : R → R → R)
(negative : R → R) (quotient : R → R → R) (inverse : R → R).
Variable laws : field_theory zero one plus times minus negative quotient inverse (@eq R).
Add Field coordinate_field : laws.
Local Notation "0" := zero.
Local Notation "1" := one.
Local Infix "+" := plus.
Local Infix "×" := times.
Local Infix "-" := minus.
Local Infix "/" := quotient.
Variable repr : A → R.
Local Abbreviation F := (@Curve.F A C).
Local Abbreviation rawZero := F.(Field.zero).
Local Abbreviation rawPlus := F.(Field.op_plus).
Local Abbreviation rawTimes := F.(Field.op_star).
Local Abbreviation rawMinus := F.(Field.op_minus).
Local Abbreviation rawQuotient := F.(Field.op_div).
Local Abbreviation rawEqual := F.(Field.op_eq).
Local Abbreviation rawDifferent := F.(Field.op_ltgt).
Local Abbreviation a := (@Curve.P A C).(Ec.Curve.Make_P_signature.a_value).
Local Abbreviation b := (@Curve.P A C).(Ec.Curve.Make_P_signature.b_value).
Local Abbreviation poly := (weierstrassPolynomial plus times).
Hypotheses
(closed : fieldClosed F bounded)
(aBound : bounded a) (bBound : bounded b)
(equal_true : ∀ x y, rawEqual x y = true ↔ x = y)
(different_false : ∀ x y, rawDifferent x y = false ↔ x = y)
(repr_injective : ∀ x y, bounded x → bounded y → repr x = repr y → x = y)
(repr_zero : repr rawZero = 0)
(repr_two : repr (@Curve.two A C) = 1+1)
(repr_three : repr (@Curve.three A C) = 1+1+1)
(two_nonzero : 1+1 ≠ 0)
(repr_plus : ∀ x y, bounded x → bounded y →
repr (rawPlus x y) = repr x + repr y)
(repr_times : ∀ x y, bounded x → bounded y →
repr (rawTimes x y) = repr x × repr y)
(repr_minus : ∀ x y, bounded x → bounded y →
repr (rawMinus x y) = repr x - repr y)
(repr_quotient : ∀ x y, bounded x → bounded y → repr y ≠ 0 →
repr (rawQuotient x y) = repr x / repr y).
Local Ltac bound :=
repeat first [assumption |
apply (field_zero_closed _ _ closed) |
apply (field_int_closed _ _ closed) |
apply (field_add_closed _ _ closed) |
apply (field_sub_closed _ _ closed) |
apply (field_mul_closed _ _ closed) |
apply (field_div_closed _ _ closed)].
Lemma represented_curve_equation x y : bounded x → bounded y →
(@Curve.in_curve A C x y = true ↔
repr y×repr y = poly (repr a) (repr b) (repr x)).
Proof.
intros Hx Hy.
change (rawEqual (rawTimes y y)
(rawPlus (rawTimes x (rawPlus (rawTimes x x) a)) b) = true ↔
repr y×repr y = repr x*(repr x×repr x+repr a)+repr b).
rewrite equal_true.
assert (Hleft : bounded (rawTimes y y)) by bound.
assert (Hright : bounded (rawPlus (rawTimes x (rawPlus (rawTimes x x) a)) b)) by bound.
assert (HleftR : repr (rawTimes y y) = repr y×repr y) by (apply repr_times; assumption).
assert (HrightR : repr (rawPlus (rawTimes x (rawPlus (rawTimes x x) a)) b) =
repr x*(repr x×repr x+repr a)+repr b).
{ rewrite repr_plus, repr_times, repr_plus, repr_times by bound. reflexivity. }
split.
- intro Heq. apply (f_equal repr) in Heq. rewrite HleftR, HrightR in Heq. exact Heq.
- intro Heq. apply repr_injective; [exact Hleft|exact Hright|].
rewrite HleftR, HrightR. exact Heq.
Qed.
Lemma represented_secant x1 y1 x2 y2 :
bounded x1 → bounded y1 → bounded x2 → bounded y2 →
@Curve.in_curve A C x1 y1 = true → @Curve.in_curve A C x2 y2 = true →
rawDifferent x1 x2 = true →
let m := rawQuotient (rawMinus y2 y1) (rawMinus x2 x1) in
let xx := rawMinus (rawMinus (rawTimes m m) x1) x2 in
let yy := rawMinus (rawTimes m (rawMinus x1 xx)) y1 in
bounded xx ∧ bounded yy ∧ @Curve.in_curve A C xx yy = true.
Proof.
intros Hx1 Hy1 Hx2 Hy2 Hleft Hright Hdifferent. cbv zeta.
assert (Hne : x1 ≠ x2).
{ intro Heq. apply different_false in Heq. congruence. }
assert (Hden : repr x2-repr x1 ≠ 0).
{ intro Hzero. apply Hne. apply repr_injective; [exact Hx1|exact Hx2|].
replace (repr x1) with (repr x2-(repr x2-repr x1)) by ring.
rewrite Hzero. ring. }
set (m := rawQuotient (rawMinus y2 y1) (rawMinus x2 x1)).
assert (Hm : bounded m) by (unfold m; bound).
assert (HmR : repr m = (repr y2-repr y1)/(repr x2-repr x1)).
{ unfold m. rewrite repr_quotient by
(solve [bound] || (rewrite repr_minus by bound; exact Hden)).
rewrite !repr_minus by bound. reflexivity. }
set (xx := rawMinus (rawMinus (rawTimes m m) x1) x2).
assert (Hxx : bounded xx) by (unfold xx; bound).
assert (HxxR : repr xx = repr m×repr m-repr x1-repr x2).
{ unfold xx. rewrite !repr_minus, repr_times by bound. reflexivity. }
set (yy := rawMinus (rawTimes m (rawMinus x1 xx)) y1).
assert (Hyy : bounded yy) by (unfold yy; bound).
assert (HyyR : repr yy = repr m*(repr x1-repr xx)-repr y1).
{ unfold yy. rewrite repr_minus, repr_times, repr_minus by bound. reflexivity. }
split; [exact Hxx|]. split; [exact Hyy|].
apply (proj2 (represented_curve_equation xx yy Hxx Hyy)).
rewrite HyyR, HxxR, HmR.
apply (weierstrass_secant zero one plus times minus negative quotient inverse laws).
- apply (proj1 (represented_curve_equation x1 y1 Hx1 Hy1)); exact Hleft.
- apply (proj1 (represented_curve_equation x2 y2 Hx2 Hy2)); exact Hright.
- exact Hden.
Qed.
Lemma represented_tangent x y : bounded x → bounded y →
@Curve.in_curve A C x y = true → rawDifferent y rawZero = true →
let m := rawQuotient
(rawPlus (rawTimes (rawTimes (@Curve.three A C) x) x) a)
(rawTimes (@Curve.two A C) y) in
let xx := rawMinus (rawMinus (rawTimes m m) x) x in
let yy := rawMinus (rawTimes m (rawMinus x xx)) y in
bounded xx ∧ bounded yy ∧ @Curve.in_curve A C xx yy = true.
Proof.
intros Hx Hy Hcurve Hdifferent. cbv zeta.
assert (HyR : repr y ≠ 0).
{ intro Hzero. assert (Heq : y = rawZero).
{ apply repr_injective; [exact Hy|bound|]. rewrite repr_zero; exact Hzero. }
apply different_false in Heq. congruence. }
assert (Hden : (1+1)*repr y ≠ 0).
{ intro Hzero. apply HyR.
replace (repr y) with (((1+1)*repr y)/(1+1)) by (field; exact two_nonzero).
rewrite Hzero. field; exact two_nonzero. }
set (m := rawQuotient
(rawPlus (rawTimes (rawTimes (@Curve.three A C) x) x) a)
(rawTimes (@Curve.two A C) y)).
assert (Hm : bounded m) by (unfold m; bound).
assert (HmR : repr m = ((1+1+1)*repr x×repr x+repr a)/((1+1)*repr y)).
{ unfold m. rewrite repr_quotient by
(solve [bound] || (rewrite repr_times, repr_two by bound; exact Hden)).
rewrite repr_plus, !repr_times, repr_two, repr_three by bound. reflexivity. }
set (xx := rawMinus (rawMinus (rawTimes m m) x) x).
assert (Hxx : bounded xx) by (unfold xx; bound).
assert (HxxR : repr xx = repr m×repr m-repr x-repr x).
{ unfold xx. rewrite !repr_minus, repr_times by bound. reflexivity. }
set (yy := rawMinus (rawTimes m (rawMinus x xx)) y).
assert (Hyy : bounded yy) by (unfold yy; bound).
assert (HyyR : repr yy = repr m*(repr x-repr xx)-repr y).
{ unfold yy. rewrite repr_minus, repr_times, repr_minus by bound. reflexivity. }
split; [exact Hxx|]. split; [exact Hyy|].
apply (proj2 (represented_curve_equation xx yy Hxx Hyy)).
rewrite HyyR, HxxR, HmR.
apply (weierstrass_tangent zero one plus times minus negative quotient inverse laws).
- apply (proj1 (represented_curve_equation x y Hx Hy)); exact Hcurve.
- exact Hden.
Qed.
{UN : Basics.Unreachable Support.UintN.t} (bounded : A → Prop) :
(∀ left right, @curvePointValid A C bounded left →
@curvePointValid A C bounded right →
@curvePointValid A C bounded (@Curve.op_plus A C left right)) →
∀ n point, @curvePointValid A C bounded point →
@curvePointValid A C bounded (@Curve.op_star A C n point).
Proof.
intros Hadd n point Hpoint. unfold Curve.op_star.
eapply fix_preserves with (I := fun item ⇒
@curvePointValid A C bounded (snd (fst item)) ∧
@curvePointValid A C bounded (snd item)).
- intros [[scalar current] acc] recur [Hcurrent Hacc] Hrecur. cbn beta iota zeta in ×.
eapply dependent_bool_property.
+ intros _. exact Hacc.
+ intro Hnonzero. eapply dependent_pair_property. intros next remainder Hdivision.
apply Hrecur. split.
× apply Hadd; assumption.
× destruct (Support.UintN.op_eq remainder (@Support.UintN.one));
[apply Hadd; assumption|exact Hacc].
- split; [exact Hpoint|split; exact I].
Qed.
Section Representation.
Context {A : Set} {C : @Curve.FArgs A} (bounded : A → Prop).
Context {R : Type} (zero one : R) (plus times minus : R → R → R)
(negative : R → R) (quotient : R → R → R) (inverse : R → R).
Variable laws : field_theory zero one plus times minus negative quotient inverse (@eq R).
Add Field coordinate_field : laws.
Local Notation "0" := zero.
Local Notation "1" := one.
Local Infix "+" := plus.
Local Infix "×" := times.
Local Infix "-" := minus.
Local Infix "/" := quotient.
Variable repr : A → R.
Local Abbreviation F := (@Curve.F A C).
Local Abbreviation rawZero := F.(Field.zero).
Local Abbreviation rawPlus := F.(Field.op_plus).
Local Abbreviation rawTimes := F.(Field.op_star).
Local Abbreviation rawMinus := F.(Field.op_minus).
Local Abbreviation rawQuotient := F.(Field.op_div).
Local Abbreviation rawEqual := F.(Field.op_eq).
Local Abbreviation rawDifferent := F.(Field.op_ltgt).
Local Abbreviation a := (@Curve.P A C).(Ec.Curve.Make_P_signature.a_value).
Local Abbreviation b := (@Curve.P A C).(Ec.Curve.Make_P_signature.b_value).
Local Abbreviation poly := (weierstrassPolynomial plus times).
Hypotheses
(closed : fieldClosed F bounded)
(aBound : bounded a) (bBound : bounded b)
(equal_true : ∀ x y, rawEqual x y = true ↔ x = y)
(different_false : ∀ x y, rawDifferent x y = false ↔ x = y)
(repr_injective : ∀ x y, bounded x → bounded y → repr x = repr y → x = y)
(repr_zero : repr rawZero = 0)
(repr_two : repr (@Curve.two A C) = 1+1)
(repr_three : repr (@Curve.three A C) = 1+1+1)
(two_nonzero : 1+1 ≠ 0)
(repr_plus : ∀ x y, bounded x → bounded y →
repr (rawPlus x y) = repr x + repr y)
(repr_times : ∀ x y, bounded x → bounded y →
repr (rawTimes x y) = repr x × repr y)
(repr_minus : ∀ x y, bounded x → bounded y →
repr (rawMinus x y) = repr x - repr y)
(repr_quotient : ∀ x y, bounded x → bounded y → repr y ≠ 0 →
repr (rawQuotient x y) = repr x / repr y).
Local Ltac bound :=
repeat first [assumption |
apply (field_zero_closed _ _ closed) |
apply (field_int_closed _ _ closed) |
apply (field_add_closed _ _ closed) |
apply (field_sub_closed _ _ closed) |
apply (field_mul_closed _ _ closed) |
apply (field_div_closed _ _ closed)].
Lemma represented_curve_equation x y : bounded x → bounded y →
(@Curve.in_curve A C x y = true ↔
repr y×repr y = poly (repr a) (repr b) (repr x)).
Proof.
intros Hx Hy.
change (rawEqual (rawTimes y y)
(rawPlus (rawTimes x (rawPlus (rawTimes x x) a)) b) = true ↔
repr y×repr y = repr x*(repr x×repr x+repr a)+repr b).
rewrite equal_true.
assert (Hleft : bounded (rawTimes y y)) by bound.
assert (Hright : bounded (rawPlus (rawTimes x (rawPlus (rawTimes x x) a)) b)) by bound.
assert (HleftR : repr (rawTimes y y) = repr y×repr y) by (apply repr_times; assumption).
assert (HrightR : repr (rawPlus (rawTimes x (rawPlus (rawTimes x x) a)) b) =
repr x*(repr x×repr x+repr a)+repr b).
{ rewrite repr_plus, repr_times, repr_plus, repr_times by bound. reflexivity. }
split.
- intro Heq. apply (f_equal repr) in Heq. rewrite HleftR, HrightR in Heq. exact Heq.
- intro Heq. apply repr_injective; [exact Hleft|exact Hright|].
rewrite HleftR, HrightR. exact Heq.
Qed.
Lemma represented_secant x1 y1 x2 y2 :
bounded x1 → bounded y1 → bounded x2 → bounded y2 →
@Curve.in_curve A C x1 y1 = true → @Curve.in_curve A C x2 y2 = true →
rawDifferent x1 x2 = true →
let m := rawQuotient (rawMinus y2 y1) (rawMinus x2 x1) in
let xx := rawMinus (rawMinus (rawTimes m m) x1) x2 in
let yy := rawMinus (rawTimes m (rawMinus x1 xx)) y1 in
bounded xx ∧ bounded yy ∧ @Curve.in_curve A C xx yy = true.
Proof.
intros Hx1 Hy1 Hx2 Hy2 Hleft Hright Hdifferent. cbv zeta.
assert (Hne : x1 ≠ x2).
{ intro Heq. apply different_false in Heq. congruence. }
assert (Hden : repr x2-repr x1 ≠ 0).
{ intro Hzero. apply Hne. apply repr_injective; [exact Hx1|exact Hx2|].
replace (repr x1) with (repr x2-(repr x2-repr x1)) by ring.
rewrite Hzero. ring. }
set (m := rawQuotient (rawMinus y2 y1) (rawMinus x2 x1)).
assert (Hm : bounded m) by (unfold m; bound).
assert (HmR : repr m = (repr y2-repr y1)/(repr x2-repr x1)).
{ unfold m. rewrite repr_quotient by
(solve [bound] || (rewrite repr_minus by bound; exact Hden)).
rewrite !repr_minus by bound. reflexivity. }
set (xx := rawMinus (rawMinus (rawTimes m m) x1) x2).
assert (Hxx : bounded xx) by (unfold xx; bound).
assert (HxxR : repr xx = repr m×repr m-repr x1-repr x2).
{ unfold xx. rewrite !repr_minus, repr_times by bound. reflexivity. }
set (yy := rawMinus (rawTimes m (rawMinus x1 xx)) y1).
assert (Hyy : bounded yy) by (unfold yy; bound).
assert (HyyR : repr yy = repr m*(repr x1-repr xx)-repr y1).
{ unfold yy. rewrite repr_minus, repr_times, repr_minus by bound. reflexivity. }
split; [exact Hxx|]. split; [exact Hyy|].
apply (proj2 (represented_curve_equation xx yy Hxx Hyy)).
rewrite HyyR, HxxR, HmR.
apply (weierstrass_secant zero one plus times minus negative quotient inverse laws).
- apply (proj1 (represented_curve_equation x1 y1 Hx1 Hy1)); exact Hleft.
- apply (proj1 (represented_curve_equation x2 y2 Hx2 Hy2)); exact Hright.
- exact Hden.
Qed.
Lemma represented_tangent x y : bounded x → bounded y →
@Curve.in_curve A C x y = true → rawDifferent y rawZero = true →
let m := rawQuotient
(rawPlus (rawTimes (rawTimes (@Curve.three A C) x) x) a)
(rawTimes (@Curve.two A C) y) in
let xx := rawMinus (rawMinus (rawTimes m m) x) x in
let yy := rawMinus (rawTimes m (rawMinus x xx)) y in
bounded xx ∧ bounded yy ∧ @Curve.in_curve A C xx yy = true.
Proof.
intros Hx Hy Hcurve Hdifferent. cbv zeta.
assert (HyR : repr y ≠ 0).
{ intro Hzero. assert (Heq : y = rawZero).
{ apply repr_injective; [exact Hy|bound|]. rewrite repr_zero; exact Hzero. }
apply different_false in Heq. congruence. }
assert (Hden : (1+1)*repr y ≠ 0).
{ intro Hzero. apply HyR.
replace (repr y) with (((1+1)*repr y)/(1+1)) by (field; exact two_nonzero).
rewrite Hzero. field; exact two_nonzero. }
set (m := rawQuotient
(rawPlus (rawTimes (rawTimes (@Curve.three A C) x) x) a)
(rawTimes (@Curve.two A C) y)).
assert (Hm : bounded m) by (unfold m; bound).
assert (HmR : repr m = ((1+1+1)*repr x×repr x+repr a)/((1+1)*repr y)).
{ unfold m. rewrite repr_quotient by
(solve [bound] || (rewrite repr_times, repr_two by bound; exact Hden)).
rewrite repr_plus, !repr_times, repr_two, repr_three by bound. reflexivity. }
set (xx := rawMinus (rawMinus (rawTimes m m) x) x).
assert (Hxx : bounded xx) by (unfold xx; bound).
assert (HxxR : repr xx = repr m×repr m-repr x-repr x).
{ unfold xx. rewrite !repr_minus, repr_times by bound. reflexivity. }
set (yy := rawMinus (rawTimes m (rawMinus x xx)) y).
assert (Hyy : bounded yy) by (unfold yy; bound).
assert (HyyR : repr yy = repr m*(repr x-repr xx)-repr y).
{ unfold yy. rewrite repr_minus, repr_times, repr_minus by bound. reflexivity. }
split; [exact Hxx|]. split; [exact Hyy|].
apply (proj2 (represented_curve_equation xx yy Hxx Hyy)).
rewrite HyyR, HxxR, HmR.
apply (weierstrass_tangent zero one plus times minus negative quotient inverse laws).
- apply (proj1 (represented_curve_equation x y Hx Hy)); exact Hcurve.
- exact Hden.
Qed.
Branch tests select secant, tangent, inverse points or infinity.
The proof follows those actual tests, including zero tangent divisors.
Theorem represented_curve_add_valid left right :
@curvePointValid A C bounded left → @curvePointValid A C bounded right →
@curvePointValid A C bounded (@Curve.op_plus A C left right).
Proof.
intros Hleft Hright.
destruct left as [x1 y1|], right as [x2 y2|];
try exact Hleft; try exact Hright.
destruct Hleft as [[Hx1 Hy1] Hleft], Hright as [[Hx2 Hy2] Hright].
unfold Curve.op_plus. cbn beta iota zeta.
unfold Curve.Underlying, Curve.Params.
destruct (rawDifferent x1 x2) eqn:Hx.
- destruct (represented_secant x1 y1 x2 y2 Hx1 Hy1 Hx2 Hy2 Hleft Hright Hx)
as [Hxx [Hyy Hcurve]].
split; [split; assumption|exact Hcurve].
- apply different_false in Hx. subst x2.
destruct (rawDifferent y1 y2) eqn:Hy; [split; exact I|].
apply different_false in Hy. subst y2.
destruct (rawDifferent y1 rawZero) eqn:Hz; [|split; exact I].
destruct (represented_tangent x1 y1 Hx1 Hy1 Hleft Hz) as [Hxx [Hyy Hcurve]].
split; [split; assumption|exact Hcurve].
Qed.
Theorem represented_curve_mul_valid {UN : Basics.Unreachable Support.UintN.t} n point :
@curvePointValid A C bounded point →
@curvePointValid A C bounded (@Curve.op_star A C n point).
Proof.
apply curve_mul_valid_from_add. exact represented_curve_add_valid.
Qed.
End Representation.
Lemma curve_construct_valid {A : Set} {C : @Curve.FArgs A}
(bounded : A → Prop) x y :
bounded x → bounded y → @Curve.in_curve A C x y = true →
∃ point, @Curve.of_coords A C x y = Some point ∧
@curvePointValid A C bounded point.
Proof.
intros Hx Hy Hcurve. unfold Curve.of_coords. rewrite Hcurve.
destruct (andb _ _).
- ∃ Curve.Infinity. split; [reflexivity|split; exact I].
- ∃ (Curve.Point x y). split; [reflexivity|].
split; [split; assumption|exact Hcurve].
Qed.
@curvePointValid A C bounded left → @curvePointValid A C bounded right →
@curvePointValid A C bounded (@Curve.op_plus A C left right).
Proof.
intros Hleft Hright.
destruct left as [x1 y1|], right as [x2 y2|];
try exact Hleft; try exact Hright.
destruct Hleft as [[Hx1 Hy1] Hleft], Hright as [[Hx2 Hy2] Hright].
unfold Curve.op_plus. cbn beta iota zeta.
unfold Curve.Underlying, Curve.Params.
destruct (rawDifferent x1 x2) eqn:Hx.
- destruct (represented_secant x1 y1 x2 y2 Hx1 Hy1 Hx2 Hy2 Hleft Hright Hx)
as [Hxx [Hyy Hcurve]].
split; [split; assumption|exact Hcurve].
- apply different_false in Hx. subst x2.
destruct (rawDifferent y1 y2) eqn:Hy; [split; exact I|].
apply different_false in Hy. subst y2.
destruct (rawDifferent y1 rawZero) eqn:Hz; [|split; exact I].
destruct (represented_tangent x1 y1 Hx1 Hy1 Hleft Hz) as [Hxx [Hyy Hcurve]].
split; [split; assumption|exact Hcurve].
Qed.
Theorem represented_curve_mul_valid {UN : Basics.Unreachable Support.UintN.t} n point :
@curvePointValid A C bounded point →
@curvePointValid A C bounded (@Curve.op_star A C n point).
Proof.
apply curve_mul_valid_from_add. exact represented_curve_add_valid.
Qed.
End Representation.
Lemma curve_construct_valid {A : Set} {C : @Curve.FArgs A}
(bounded : A → Prop) x y :
bounded x → bounded y → @Curve.in_curve A C x y = true →
∃ point, @Curve.of_coords A C x y = Some point ∧
@curvePointValid A C bounded point.
Proof.
intros Hx Hy Hcurve. unfold Curve.of_coords. rewrite Hcurve.
destruct (andb _ _).
- ∃ Curve.Infinity. split; [reflexivity|split; exact I].
- ∃ (Curve.Point x y). split; [reflexivity|].
split; [split; assumption|exact Hcurve].
Qed.