译自 halo2 book:https://zcash.github.io/halo2/design/gadgets/ecc/addition.html
我们将使用短 Weierstrass 曲线上仿射坐标(affine coordinates)的曲线算术公式, 推导自 Hüseyin Hışıl 博士论文 的第 4.1 节。
不完全加法(Incomplete addition)
- 输入:P=(xp,yp),Q=(xq,yq)
- 输出:R=P⸭Q=(xr,yr)
Hışıl 论文中的公式为:
- x3=(x1−x2y1−y2)2−x1−x2
- y3=x1−x2y1−y2⋅(x1−x3)−y1.
把 (x1,y1) 重命名为 (xq,yq),把 (x2,y2) 重命名为 (xp,yp),把 (x3,y3) 重命名为 (xr,yr),得到
- xr=(xq−xpyq−yp)2−xq−xp
- yr=xq−xpyq−yp⋅(xq−xr)−yq
这等价于
- xr+xq+xp=(xp−xqyp−yq)2
- yr+yq=xp−xqyp−yq⋅(xq−xr).
假设 xp=xq,我们有
and⟺⟺⟺⟺xr+xq+xp(xr+xq+xp)⋅(xp−xq)2(xr+xq+xp)⋅(xp−xq)2−(yp−yq)2yr+yq(yr+yq)⋅(xp−xq)(yr+yq)⋅(xp−xq)−(yp−yq)⋅(xq−xr)======(xp−xqyp−yq)2(yp−yq)20xp−xqyp−yq⋅(xq−xr)(yp−yq)⋅(xq−xr)0.
于是我们得到约束:
- (xr+xq+xp)⋅(xp−xq)2−(yp−yq)2=0
- 注意此约束对于 P⸭(−P)(当 P=O 时)是不可满足的, 因此不能用于任意输入。
- (yr+yq)⋅(xp−xq)−(yp−yq)⋅(xq−xr)=0.
约束(Constraints)
Degree43Constraintqadd-incomplete⋅((xr+xq+xp)⋅(xp−xq)2−(yp−yq)2)=0qadd-incomplete⋅((yr+yq)⋅(xp−xq)−(yp−yq)⋅(xq−xr))=0
完全加法(Complete addition)
OO(xp,yp)(x,y)(x,y)(xp,yp)++++++O(xq,yq)O(x,y)(x,−y)(xq,yq)=O=(xq,yq)=(xp,yp)=[2](x,y)=O=(xp,yp)⸭(xq,yq), if xp=xq.
假设我们把 O 表示为 (0,0)。(0 不是有效点的 x 坐标,因为那将需要 y2=x3+5,而 5 在 Fq 中不是平方数。同样 0 也不是有效点的 y 坐标,因为 −5 在 Fq 中不是立方数。)
P+Q(xp,yp)+(xq,yq)λxryr=R=(xr,yr)=xq−xpyq−yp=λ2−xp−xq=λ(xp−xr)−yp
对于倍点(doubling)情形,Hışıl 的论文告诉我们 λ 必须改为计算为 2y3x2。
定义 inv0(x)={0,1/x,if x=0otherwise.
见证(Witness)α,β,γ,δ,λ,其中:
α=β=γ=δ=λ=inv0(xq−xp)inv0(xp)inv0(xq){inv0(yq+yp),0,if xq=xpotherwise⎩⎨⎧xq−xpyq−yp,2yp3xp20,if xq=xpif xq=xp∧yp=0otherwise.
约束(Constraints)
Degree456666444444Constraintqadd⋅(xq−xp)⋅((xq−xp)⋅λ−(yq−yp))qadd⋅(1−(xq−xp)⋅α)⋅(2yp⋅λ−3xp2)qadd⋅xp⋅xq⋅(xq−xp)⋅(λ2−xp−xq−xr)qadd⋅xp⋅xq⋅(xq−xp)⋅(λ⋅(xp−xr)−yp−yr)qadd⋅xp⋅xq⋅(yq+yp)⋅(λ2−xp−xq−xr)qadd⋅xp⋅xq⋅(yq+yp)⋅(λ⋅(xp−xr)−yp−yr)qadd⋅(1−xp⋅β)⋅(xr−xq)qadd⋅(1−xp⋅β)⋅(yr−yq)qadd⋅(1−xq⋅γ)⋅(xr−xp)qadd⋅(1−xq⋅γ)⋅(yr−yp)qadd⋅(1−(xq−xp)⋅α−(yq+yp)⋅δ)⋅xrqadd⋅(1−(xq−xp)⋅α−(yq+yp)⋅δ)⋅yr============000000000000Meaningxq=xp⟹λ=xq−xpyq−yp{xq=xp∧yp=0⟹λ=2yp3xp2xq=xp∧yp=0⟹xp=0xp=0∧xq=0∧xq=xp⟹xr=λ2−xp−xqxp=0∧xq=0∧xq=xp⟹yr=λ⋅(xp−xr)−ypxp=0∧xq=0∧yq=−yp⟹xr=λ2−xp−xqxp=0∧xq=0∧yq=−yp⟹yr=λ⋅(xp−xr)−ypxp=0⟹xr=xqxp=0⟹yr=yqxq=0⟹xr=xpxq=0⟹yr=ypxq=xp∧yq=−yp⟹xr=0xq=xp∧yq=−yp⟹yr=0
最大次数(Max degree):6
约束分析(Analysis of constraints)
1.2.3. a) b) c) d)4. a) b)5. a) b)6. a) b)(xq−xp)⋅((xq−xp)⋅λ−(yq−yp))=0At least one of or xq−xp=0(xq−xp)⋅λ−(yq−yp)=0must be satisfied for the constraint to be satisfied.If xq−xp=0, then (xq−xp)⋅λ−(yq−yp)=0, andby rearranging both sides we get λ=(yq−yp)/(xq−xp).Therefore:xq=xp⟹λ=(yq−yp)/(xq−xp).(1−(xq−xp)⋅α)⋅(2yp⋅λ−3xp2)=0At least one of or (1−(xq−xp)⋅α)=0(2yp⋅λ−3xp2)=0must be satisfied for the constraint to be satisfied.If xq=xp, then 1−(xq−xp)⋅α=0 has no solution for α,so it must be that 2yp⋅λ−3xp2=0.If xq=xp and yp=0 then xp=0, and the constraint is satisfied.If xq=xp and yp=0 then by rearranging both sideswe get λ=3xp2/2yp.Therefore:(xq=xp)∧yp=0⟹λ=3xp2/2yp.xp⋅xq⋅(xq−xp)⋅(λ2−xp−xq−xr)=0xp⋅xq⋅(xq−xp)⋅(λ⋅(xp−xr)−yp−yr)=0xp⋅xq⋅(yq+yp)⋅(λ2−xp−xq−xr)=0xp⋅xq⋅(yq+yp)⋅(λ⋅(xp−xr)−yp−yr)=0At least one of or or or xp=0xp=0(xq−xp)=0(λ2−xp−xq−xr)=0must be satisfied for constraint (a) to be satisfied.If xp=0∧xq=0∧xq=xp,• Constraint (a) imposes that xr=λ2−xp−xq.• Constraint (b) imposes that yr=λ⋅(xp−xr)−yp.If xp=0∧xq=0∧yq=−yp,• Constraint (c) imposes that xr=λ2−xp−xq.• Constraint (d) imposes that yr=λ⋅(xp−xr)−yp.Therefore:⟹(xp=0)∧(xq=0)∧((xq=xp)∨(yq=−yp))(xr=λ2−xp−xq)∧(yr=λ⋅(xp−xr)−yp).(1−xp⋅β)⋅(xr−xq)=0(1−xp⋅β)⋅(yr−yq)=0At least one of 1−xp⋅βor xr−xq=0=0must be satisfied for constraint (a) to be satisfied.If xp=0 then 1−xp⋅β=0 has no solutions for β,and so it must be that xr−xq=0.Similarly, constraint (b) imposes that if xp=0then yr−yq=0.Therefore:xp=0⟹(xr,yr)=(xq,yq).(1−xq⋅γ)⋅(xr−xp)=0(1−xq⋅γ)⋅(yr−yp)=0At least one of 1−xq⋅γor xr−xp=0=0must be satisfied for constraint (a) to be satisfied.If xq=0 then 1−xq⋅γ=0 has no solutions for γ,and so it must be that xr−xp=0.Similarly, constraint (b) imposes that if xq=0then yr−yp=0.Therefore:xq=0⟹(xr,yr)=(xp,yp).(1−(xq−xp)⋅α−(yq+yp)⋅δ)⋅xr=0(1−(xq−xp)⋅α−(yq+yp)⋅δ)⋅yr=0At least one of or 1−(xq−xp)⋅α−(yq+yp)⋅δ=0xr=0must be satisfied for constraint (a) to be satisfied,and similarly replacing xr by yr.If xr=0 or yr=0, then it must be that 1−(xq−xp)⋅α−(yq+yp)⋅δ=0.However, if xq=xp∧yq=−yp, then there are no solutions for α and δ.Therefore: xq=xp∧yq=−yp⟹(xr,yr)=(0,0).
命题(Propositions):
(1)(2)(3)(4)(5)(6)xq=xp⟹λ=(yq−yp)/(xq−xp)(xq=xp)∧yp=0⟹λ=3xp2/2yp(xp=0)∧(xq=0)∧((xq=xp)∨(yq=−yp))⟹(xr=λ2−xp−xq)∧(yr=λ⋅(xp−xr)−yp)xp=0⟹(xr,yr)=(xq,yq)xq=0⟹(xr,yr)=(xp,yp)xq=xp∧yq=−yp⟹(xr,yr)=(0,0)
情形(Cases):
(xp,yp)+(xq,yq)=(xr,yr)
注意我们依赖于这样一个事实:0 不是 Pallas 曲线上除 O 之外任何点的有效 x 坐标或 y 坐标。
-
(0,0)+(0,0)
-
完备性(Completeness):
(1)(2)(3)(4)(5)(6)holds because xq=xpholds because yp=0holds because xp=0holds because (xr,yr)=(xq,yq)=(0,0)holds because (xr,yr)=(xp,yp)=(0,0)holds because (xr,yr)=(0,0).
-
可靠性(Soundness):(xr,yr)=(0,0) 是 (6) 的唯一解。
-
-
(x,y)+(0,0),其中 (x,y)=(0,0)
-
完备性(Completeness):
(1)(2)(3)(4)(5)(6)holds because xq=xp, therefore λ=(yq−yp)/(xq−xp) is a solutionholds because xq=xp, therefore α=(xq−xp)−1 is a solutionholds because xq=0holds because xp=0, therefore β=xp−1 is a solutionholds because (xr,yr)=(xp,yp)holds because xq=xp, therefore α=(xq−xp)−1 and δ=0 is a solution.
-
可靠性(Soundness):(xr,yr)=(xp,yp) 是 (5) 的唯一解。
-
-
(0,0)+(x,y),其中 (x,y)=(0,0)
-
完备性(Completeness):
(1)(2)(3)(4)(5)(6)holds because xq=xp, therefore λ=(yq−yp)/(xq−xp) is a solutionholds because xq=xp, therefore α=(xq−xp)−1 is a solutionholds because xp=0holds because xp=0 only when (xr,yr)=(xq,yq)holds because xq=0, therefore γ=xq−1 is a solutionholds because xq=xp, therefore α=(xq−xp)−1 and δ=0 is a solution.
-
可靠性(Soundness):(xr,yr)=(xq,yq) 是 (4) 的唯一解。
-
-
(x,y)+(x,y),其中 (x,y)=(0,0)
-
完备性(Completeness):
(1)(2)(3)(4)(5)(6)holds because xq=xpholds because xq=xp∧yp=0, therefore λ=3xp2/2yp is a solutionholds because xr=λ2−xp−xq∧yr=λ⋅(xp−xr)−yp in this caseholds because xp=0, therefore β=xp−1 is a solutionholds because xp=0, therefore γ=xq−1 is a solutionholds because xq=xp and yq=−yp, therefore α=0 and δ=(yq+yp)−1 is a solution.
-
可靠性(Soundness):λ 被正确计算,且 (xr,yr)=(λ2−xp−xq,λ⋅(xp−xr)−yp) 是唯一解。
-
-
(x,y)+(x,−y),其中 (x,y)=(0,0)
-
完备性(Completeness):
(1)(2)(3)(4)(5)(6)holds because xq=xpholds because xq=xp∧yp=0, therefore λ=3xp2/2yp is a solution(although λ is not used in this case)holds because xq=xp and yq=−ypholds because xp=0, therefore β=xp−1 is a solutionholds because xq=0, therefore γ=xq−1 is a solutionholds because (xr,yr)=(0,0)
-
可靠性(Soundness):(xr,yr)=(0,0) 是 (6) 的唯一解。
-
-
(xp,yp)+(xq,yq),其中 (xp,yp)=(0,0) 且 (xq,yq)=(0,0) 且 xp=xq
-
完备性(Completeness):
(1)(2)(3)(4)(5)(6)holds because xq=xp, therefore λ=(yq−yp)/(xq−xp) is a solutionholds because xq=xp, therefore α=(xq−xp)−1 is a solutionholds because xr=λ2−xp−xq∧yr=λ⋅(xp−xr)−yp in this caseholds because xp=0, therefore β=xp−1 is a solutionholds because xq=0, therefore γ=xq−1 is a solutionholds because xq=xp, therefore α=(xq−xp)−1 and δ=0 is a solution.
-
可靠性(Soundness):λ 被正确计算,且 (xr,yr)=(λ2−xp−xq,λ⋅(xp−xr)−yp) 是唯一解。
-