bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 35쪽 중 32쪽
ing successively longer prefixes
of thebig-endianbinary representations of𝑎and𝑐.
Base case 𝑚=𝑛−1 : since 𝑐𝑛−1 = 1, the constraint system has just one boolean constraint on 𝑎𝑛−1, which fulfils
the theorem since𝐴 𝑛−1≤𝐶 𝑛−1 is always satisfied.
Inductive case𝑚 < 𝑛−1:
• If 𝐴𝑚+1 > 𝐶𝑚+1, then by the inductive hypothesis the constraint system must fail, which fulfils the theorem
regardless of the value of𝑎 𝑚.
• If 𝐴𝑚+1≤𝐶 𝑚+1, then by the inductive hypothesis the constraint system restricted to 𝑖∈{𝑚+ 1.. 𝑛−1}
succeeds. We haveΠ 𝑚+1 =
∏︀𝑛−1
𝑖=𝑚+1(𝑐𝑖 = 0∨𝑎 𝑖 = 1) =
∏︀𝑛−1
𝑖=𝑚+1(𝑎𝑖≥𝑐 𝑖).
– If 𝐴𝑚+1 =𝐶 𝑚+1, then 𝑎𝑖 =𝑐 𝑖 for all 𝑖∈{𝑚+ 1.. 𝑛−1} and so Π𝑚+1 = 1. Also 𝐴𝑚≤𝐶 𝑚 if and only if
𝑎𝑚≤𝑐 𝑚.
When𝑐 𝑚 = 1, only a boolean constraint is added for𝑎 𝑚 which fulfils the theorem.
When𝑐 𝑚 = 0,𝑎 𝑚 is constrained to be0which fulfils the theorem.
–If𝐴 𝑚+1 < 𝐶𝑚+1, then it cannot be the case that𝑎 𝑖≥𝑐 𝑖 for all𝑖∈{𝑚+ 1.. 𝑛−1}, soΠ 𝑚+1 = 0.
This implies that the constraint on 𝑎𝑚 is always equivalent to a boolean constraint, which fulfils the
theorem because𝐴 𝑚≤𝐶 𝑚 must be true regardless of the value of𝑎 𝑚.
This covers all cases.
Correctness of the full constraint system follows by taking𝑚= 0in the above theorem.
The algorithm in §A.3.3.2 ‘ctEdwards [de]compression and validation’ on p. 212 uses range checks with 𝑐=𝑟 S−1
to validatectEdwards compressed encodings. In that case 𝑛= 255 and 𝑘= 132 , so the cost of each such range
check is387constraints.
Non-normative note:It is possible to optimize the computation of Π𝑡 .. 𝑛−2further. Notice that Π𝑚 is only used
when 𝑚 is the index of the last bit of a run of 1 bits in 𝑐. So for each such run of 1 bits 𝑐𝑚 .. 𝑚+𝑁−2of length 𝑁−1 ,
it is sufficient to compute an 𝑁-ary AND of 𝑎𝑚 .. 𝑚+𝑁−2and Π𝑚+𝑁−1 : 𝑅=
∏︀𝑁−1
𝑖=0 𝑋𝑖. This can be computed in 3
constraints for any𝑁; boolean-constrain the output𝑅, and then add constraints
(︁
𝑁−
∑︀𝑁−1
𝑖=0 𝑋𝑖
)︁ (︀
inv
)︀
=
(︀
1−𝑅
)︀
to enforce that
∑︀𝑁−1
𝑖=0 𝑋𝑖̸=𝑁when𝑅= 0;
(︁
𝑁−
∑︀𝑁−1
𝑖=0 𝑋𝑖
)︁ (︀
𝑅
)︀
=
(︀
0
)︀
to enforce that
∑︀𝑁−1
𝑖=0 𝑋𝑖 =𝑁when𝑅= 1.
where inv is witnessed as
(︁
𝑁−
∑︀𝑁−1
𝑖=0 𝑋𝑖
)︁
−1 if 𝑅= 0 or is unconstrained otherwise. (Since 𝑁 < 𝑟S, the sums cannot
overflow.)
In fact the last constraint is not needed in this context because it is sufficient to compute an upper bound on each
Π𝑚 (i.e. it does not benefit a malicious prover to witness 𝑅= 1 when the result of the AND should be 0). So the
cost of computing Π variables for an arbitrarily long run of 1 bits can be reduced to 2 constraints. For example, for
𝑐=𝑟 S−1the overall cost would be reduced to255 + 68 = 323constraints.
These optimizations are not used in Sapling.
211
A.3.3 Elliptic curve operations #cctelliptic
A.3.3.1 Checking that Affine-ctEdwards coordinates are on the curve #cctedvalidate
To check that(𝑢,v)is a point on thectEdwards curve, the Saplingcircuit uses4constraints:
(︀
𝑢
)︀ (︀
𝑢
)︀
=
(︀
𝑢𝑢
)︀
(︀
v
)︀ (︀
v
)︀
=
(︀
vv
)︀
(︀
𝑢𝑢
)︀ (︀
vv
)︀
=
(︀
𝑢𝑢vv
)︀
(︀
𝑎J·𝑢𝑢+vv
)︀ (︀
1
)︀
=
(︀
1 +𝑑 J·𝑢𝑢vv
)︀
Non-normative note:The last two constraints can be combined into
(︀
𝑑J·𝑢𝑢
)︀ (︀
vv
)︀
=
(︀
𝑎J·𝑢𝑢+vv−1
)︀
. The
Saplingcircuit does not use this optimization.
A.3.3.2 ctEdwards [de]compression and validation #ccteddecompressvalidate
DefineDecompressValidate CompressedCtEdwardsJubjub→AffineCtEdwardsJubjubas follows:
DecompressValidate(˜𝑢,v) :
/ / Prover supplies the𝑢-coordinate.
Let𝑢 F𝑟S.
/ / §A.3.3.1 ‘Checking that Affine-ctEdwards coordinates are on the curve’ on p.212.
Check that(𝑢,v)is a point on thectEdwards curve.
/ / §A.3.2.1 ‘[Un]packing modulo𝑟 S’ on p.209.
Unpack𝑢to
∑︀254
𝑖=0𝑢𝑖·2 𝑖, equating˜𝑢with𝑢 0.
/ / §A.3.2.2 ‘Range check’ on p.210.
Check that
∑︀254
𝑖=0𝑢𝑖·2 𝑖≤𝑟 S−1.
Return(𝑢,v).
This costs 4 constraints for the curve equation check, 1 constraint for the unpacking, and 387 constraints for the
range check (as computed in §A.3.2.2 ‘Range check’ on p. 210) for a total of 392 constraints. The cost of the range
check includes boolean-constraining𝑢 0..254 .
The samequadratic constraint programis used for compression and decompression.
Non-normative note:The point-on-curve check could be omitted if (𝑢,v) were already known to be on the
curve. However, the Saplingcircuit never omits it; this provides a consistency check on the elliptic curve arithmetic.
A.3.3.3 ctEdwards↔Montgomery conversion #cctconversion
Define the notation +√∙ as in §2 ‘Notation’ on p.11.
DefineCtEdwardsToMont AffineCtEdwardsJubjub→AffineMontJubjubas follows:
CtEdwardsToMont(𝑢,v) =
(︁1 +v
1−v , +√−40964· 1 +v(1−v)·𝑢 )︁ [1−v̸= 0and𝑢̸= 0]
DefineMontToCtEdwards AffineMontJubjub→AffineCtEdwardsJubjubas follows:
MontToCtEdwards(𝑥, 𝑦) =
(︁
+√−40964· 𝑥𝑦 , 𝑥−1𝑥+ 1 )︁ [𝑥+ 1̸= 0and𝑦̸= 0]
212
Either of these conversions can be implemented by the samequadratic constraint program:
(︀
𝑦
)︀ (︀
𝑢
)︀
=
(︁
+√−40964·𝑥 )︁
(︀
𝑥+ 1
)︀ (︀
v
)︀
=
(︀
𝑥−1
)︀
The above conversions should only be used if the input is guaranteed to be a point on the relevant curve. If that is
the case, the theorems below enumerate all exceptional inputs that may violate the side-conditions.
Theorem A.3.2.Exceptional points (ctEdwards→Montgomery). #thmconversiontomontnoexcept
Let (𝑢,v) be an affine point on a ctEdwards curve 𝐸ctEdwards(𝑎,𝑑). Then the only points with 𝑢= 0 or 1−v= 0 are
(0,1) =𝒪 J, and(0,−1)of order2.
Proof. The curve equation is 𝑎·𝑢 2 +v 2 = 1 +𝑑·𝑢 2·v2 with 𝑎̸=𝑑 (see [BBJLP2008, Definition 2.1]). By substituting
𝑢= 0we obtainv=±1, and by substitutingv= 1and using𝑎̸=𝑑we obtain𝑢= 0.
Theorem A.3.3.Exceptional points (Montgomery→ctEdwards). #thmconversiontoedwardsnoexcept
Let (𝑥, 𝑦)be an affine point on a Montgomery curve 𝐸Mont(𝐴,𝐵) over F𝑟 with parameters 𝐴 and 𝐵 such that 𝐴2−4 is
a nonsquare in F𝑟, that is birationally equivalent to a ctEdwards curve. Then 𝑥+ 1̸= 0 , and the only point (𝑥, 𝑦)
with𝑦= 0is(0,0)of order 2.
Proof.That the only point with𝑦= 0is(0,0)is proven by Theorem A.2.1 on p.208.
If 𝑥+1 = 0 , then subtituting 𝑥=−1 into theMontgomery curveequation gives 𝐵·𝑦 2 =𝑥 3 +𝐴·𝑥 2 +𝑥=𝐴−2 . So in
that case 𝑦2 = (𝐴−2)/𝐵 . The right-hand-side is equal to the parameter𝑑 of a particularctEdwards curvebirationally
equivalent to theMontgomery curve(see [BL2017, section 4.3.5]). For allctEdwards curves,𝑑is nonsquare, so this
equation has no solutions for𝑦, hence𝑥+ 1̸= 0.
(When the theorem is applied with 𝐸Mont(𝐴,𝐵) =M defined in §A.2 ‘Elliptic curve background’ on p. 207, the
ctEdwards curvereferred to in the proof is an isomorphic rescaling of theJubjub curve.)
A.3.3.4 Affine-Montgomery arithmetic #cctmontarithmetic
The incompleteaffine-Montgomeryaddition formulae given in [BL2017, section 4.3.2] are:
𝑥3 =𝐵 M·𝜆2−𝐴 M−𝑥 1−𝑥 2
𝑦3 = (𝑥1−𝑥 3)·𝜆−𝑦 1
where𝜆=
⎧
⎪⎨
⎪⎩
3·𝑥21 + 2·𝐴 M·𝑥1 + 1
2·𝐵 M·𝑦1
,if𝑥 1 =𝑥 2
𝑦2−𝑦 1
𝑥2−𝑥 1
,otherwise.
The following theorem helps to determine when these incomplete addition formulae can be safely used:
Theorem A.3.4.Distinct-𝑥theorem. #thmdistinctx
Let 𝑄 be a point of odd-prime order 𝑠 on a Montgomery curve M=𝐸 Mont(𝐴M,𝐵M) over F𝑟S. Let 𝑘1..2 be integers
in
{︀
− 𝑠−12 .. 𝑠−12 }︀∖{0} . Let 𝑃𝑖 =[𝑘 𝑖]𝑄= (𝑥 𝑖, 𝑦𝑖) for 𝑖∈{1..2} , with 𝑘2̸=±𝑘 1. Then the non-unified addition
constraints(︀
𝑥2−𝑥 1
)︀ (︀
𝜆
)︀
=
(︀
𝑦2−𝑦 1
)︀
(︀
𝐵M·𝜆
)︀ (︀
𝜆
)︀
=
(︀
𝐴M +𝑥 1 +𝑥 2 +𝑥 3
)︀
(︀
𝑥1−𝑥 3
)︀ (︀
𝜆
)︀
=
(︀
𝑦3 +𝑦 1
)︀
implement the affine-Montgomery addition𝑃 1 +𝑃 2 = (𝑥3, 𝑦3)for all such𝑃 1..2 .
213
Proof. The given constraints are equivalent to the Montgomery addition formulae under the side condition that
𝑥1̸=𝑥 2. (Note that neither 𝑃𝑖 can be the zero point since 𝑘1..2 ̸= 0 (mod𝑠) .) Assume for a contradiction that
𝑥1 =𝑥 2. For any 𝑃1 =[𝑘 1]𝑄 , there can be only one other point−𝑃1 with the same 𝑥-coordinate. (This follows
from the fact that the curve equation determines±𝑦 as a function of 𝑥.) But−𝑃1 =[−1] [𝑘 1]𝑄=[−𝑘 1]𝑄 . Since
𝑘
{︀
− 𝑠−12 .. 𝑠−12 }︀↦→[𝑘]𝑄 Mis injective and𝑘 1..2 are in {︀− 𝑠−12 .. 𝑠−12 }︀, then𝑘 2 =±𝑘 1 (contradiction).
The conditions of this theorem are called thedistinct-𝑥criterion.
In particular, if𝑘 1..2 are integers in
{︀
1.. 𝑠−12 }︀ then it is sufficient to require𝑘 2̸=𝑘 1, since that implies𝑘 2̸=±𝑘 1.
Affine-Montgomerydoubling can be implemented as:
(︀
𝑥
)︀ (︀
𝑥
)︀
=
(︀
𝑥𝑥
)︀
(︀
2·𝐵 M·𝑦
)︀ (︀
𝜆
)︀
=
(︀
3·𝑥𝑥+ 2·𝐴 M·𝑥+ 1
)︀
(︀
𝐵M·𝜆
)︀ (︀
𝜆
)︀
=
(︀
𝐴M + 2·𝑥+𝑥 3
)︀
(︀
𝑥−𝑥 3
)︀ (︀
𝜆
)︀
=
(︀
𝑦3 +𝑦
)︀
This doubling formula is valid when 𝑦̸= 0 , which is the case when (𝑥, 𝑦)is not the point (0,0) (the only point of
order2), as proven in Theorem A.2.1 on p.208.
A.3.3.5 Affine-ctEdwards arithmetic #cctedarithmetic
Formulae foraffine-ctEdwardsaddition are given in [BBJLP2008, section 6]. With a change of variable names to
match our convention, the formulae for(𝑢 1,v 1) + (𝑢2,v 2) = (𝑢3,v 3)are:
𝑢3 = 𝑢1·v2 +v 1·𝑢21 +𝑑 J·𝑢1·𝑢2·v1·v2
v3 = v1·v2−𝑎 J·𝑢1·𝑢21−𝑑 J·𝑢1·𝑢2·v1·v2
We use an optimized implementation found by Daira-Emma Hopwood making use of an observation by Bernstein
and Lange in [BL2017, last paragraph of section 4.5.2]:
(︀
𝑢1 +v 1
)︀ (︀
v2−𝑎 J·𝑢2
)︀
=
(︀
𝑇
)︀
(︀
𝑢1
)︀ (︀
v2
)︀
=
(︀
𝐴
)︀
(︀
v1
)︀ (︀
𝑢2
)︀
=
(︀
𝐵
)︀
(︀
𝑑J·𝐴
)︀ (︀
𝐵
)︀
=
(︀
𝐶
)︀
(︀
1 +𝐶
)︀ (︀
𝑢3
)︀
=
(︀
𝐴+𝐵
)︀
(︀
1−𝐶
)︀ (︀
v3
)︀
=
(︀
𝑇−𝐴+𝑎 J·𝐵
)︀
The correctness of this implementation can be seen by expanding𝑇−𝐴+𝑎 J·𝐵:
𝑇−𝐴+𝑎 J·𝐵= (𝑢 1 +v 1)·(v 2−𝑎 J·𝑢2)−𝑢 1·v2 +𝑎 J·v1·𝑢2
=v 1·v2−𝑎 J·𝑢1·𝑢2 +𝑢 1·v2−𝑎 J·v1·𝑢2−𝑢 1·v2 +𝑎 J·v1·𝑢2
=v 1·v2−𝑎 J·𝑢1·𝑢2
214
The above addition formulae are “unified” , that is, they can also be used for doubling.Affine-ctEdwardsdoubling
[2](𝑢,v) = (𝑢 3,v 3)can also be implemented slightly more efficiently as:
(︀
𝑢+v
)︀ (︀
v−𝑎 J·𝑢
)︀
=
(︀
𝑇
)︀
(︀
𝑢
)︀ (︀
v
)︀
=
(︀
𝐴
)︀
(︀
𝑑J·𝐴
)︀ (︀
𝐴
)︀
=
(︀
𝐶
)︀
(︀
1 +𝐶
)︀ (︀
𝑢3
)︀
=
(︀
2·𝐴
)︀
(︀
1−𝐶
)︀ (︀
v3
)︀
=
(︀
𝑇+ (𝑎 J−1)·𝐴
)︀
This implementation is obtained by specializing the addition formulae to (𝑢,v) = (𝑢 1,v 1) = (𝑢2,v 2) and observing
that𝑢·v=𝐴=𝐵.
A.3.3.6 Affine-ctEdwards nonsmall-order check #cctednonsmallorder
In order to avoid small-subgroup attacks, we check that certain points used in the circuit are not ofsmall order. In
practice the Saplingcircuit uses this in combination with a check that the coordinates are on the curve ( §A.3.3.1
‘Checking that Affine-ctEdwards coordinates are on the curve’ on p.212), so we combine the two operations.
TheJubjub curvehas a largeprime-order subgroupwith a cofactor of 8. To check for a point 𝑃 of order 8 or less,
the Saplingcircuit doubles three times (as in §A.3.3.5 ‘Affine-ctEdwards arithmetic’ on p. 214) and checks that the
resulting𝑢-coordinate is not0(as in §A.3.1.4 ‘Nonzero constraints’ on p.209).
On actEdwards curve, only the zero point𝒪J, and the unique point of order 2 at (0,−1) have zero 𝑢-coordinate.
The point of order2cannot occur as the result of three doublings. So this𝑢-coordinate check rejects only𝒪 J.
The total cost, including the curve check, is4 + 3·5 + 1 = 20constraints.
Note:This does not ensure that the point is in theprime-order subgroup.
Non-normative notes:
• It would have been sufficient to do two doublings rather than three, because the check that the 𝑢-coordinate
is nonzero would reject both𝒪 J and the point of order2.
• It is possible to reduce the cost to 8 constraints by eliminating the redundant constraint in the curve point
check (as mentioned in §A.3.3.1 ‘Checking that Affine-ctEdwards coordinates are on the curve’ on p. 212);
merging the first doubling with the curve point check; and then optimizing the second doubling based on the
fact that we only need to check whether the resulting 𝑢-coordinate is zero. The Saplingcircuit does not use
these optimizations.
A.3.3.7 Fixed-base Affine-ctEdwards scalar multiplication #cctfixedscalarmult
If the base point 𝐵 is fixed for a given scalar multiplication [𝑘]𝐵 , we can fully precompute window tables for each
window position.
It is most efficient to use3-bit fixed windows. Since the length of𝑟 J is252bits, we need84windows.
Express𝑘in base8, i.e.𝑘=
83∑︁
𝑖=0
𝑘𝑖·8𝑖.
Then[𝑘]𝐵=
83∑︁
𝑖=0
𝑤(𝐵, 𝑖, 𝑘𝑖), where𝑤 (𝐵, 𝑖, 𝑘𝑖) =[𝑘 𝑖·8𝑖]𝐵.
We precompute all of𝑤 (𝐵, 𝑖, 𝑠)for𝑖∈{0..83}, 𝑠∈{0..7}.
215
To look up a given window entry𝑤(𝐵, 𝑖, 𝑠)= (𝑢𝑠,v 𝑠), where𝑠= 4·𝑠 2 + 2·𝑠1 +𝑠 0, we use:
(︀
𝑠1
)︀ (︀
𝑠2
)︀
=
(︀
𝑠î
)︀
(︀
𝑠0
)︀ (︀
−𝑢 0·𝑠î +𝑢 0·𝑠2 +𝑢 0·𝑠1−𝑢 0 +𝑢 2·𝑠î −𝑢 2·𝑠1 +𝑢 4·𝑠î −𝑢 4·𝑠2−𝑢 6·𝑠î
+𝑢 1·𝑠î −𝑢 1·𝑠2−𝑢 1·𝑠1 +𝑢 1−𝑢 3·𝑠î +𝑢 3·𝑠1−𝑢 5·𝑠î +𝑢 5·𝑠2 +𝑢 7·𝑠î
)︀
=(︀
𝑢𝑠−𝑢 0·𝑠î +𝑢 0·𝑠2 +𝑢 0·𝑠1−𝑢 0 +𝑢 2·𝑠î −𝑢 2·𝑠1 +𝑢 4·𝑠î −𝑢 4·𝑠2−𝑢 6·𝑠î
)︀
(︀
𝑠0
)︀ (︀
−v 0·𝑠î +v 0·𝑠2 +v 0·𝑠1−v 0 +v 2·𝑠î −v 2·𝑠1 +v 4·𝑠î −v 4·𝑠2−v 6·𝑠î
+v 1·𝑠î −v 1·𝑠2−v 1·𝑠1 +v 1−v 3·𝑠î +v 3·𝑠1−v 5·𝑠î +v 5·𝑠2 +v 7·𝑠î
)︀
=(︀
v𝑠−v 0·𝑠î +v 0·𝑠2 +v 0·𝑠1−v 0 +v 2·𝑠î −v 2·𝑠1 +v 4·𝑠î −v 4·𝑠2−v 6·𝑠î
)︀
For a full-length (252-bit) scalar this costs 3 constraints for each of 84 window lookups, plus 6 constraints for each
of83ctEdwardsadditions (as in §A.3.3.5 ‘Affine-ctEdwards arithmetic’ on p.214), for a total of750constraints.
Fixed-base scalar multiplication is also used in two places with shorter scalars:
• §A.3.6 ‘Homomorphic Pedersen Commitment’ on p. 220 uses 64 bits for the v input to ValueCommitSapling,
requiring22windows at a cost of3·22−1 + 6·21 = 191constraints;
• §A.3.3.10 ‘Mixing Pedersen hash’ on p. 219 uses 32 bits for the pos input to MixingPedersenHash, requiring 11
windows at a cost of3·11−1 + 6·10 = 92constraints.
None of these costs include the cost of boolean-constraining the scalar.
Non-normative notes:
• It would be more efficient to use arithmetic on theMontgomery curve, as in §A.3.3.9 ‘Pedersen hash’ on
p. 217. However since there are only three instances of fixed-base scalar multiplication in theSpend circuit
and two in theOutput circuit 16, the additional complexity was not considered justified for Sapling.
• For the multiplications with 64-bit and 32-bit scalars, the scalar is padded to a multiple of 3 bits with zeros.
This causes the computation of 𝑠î in the lookup for the most significant window to be optimized out, which
is where the “−1 ” comes from in the above cost calculations. No further optimization is done for this lookup.
A.3.3.8 Variable-base Affine-ctEdwards scalar multiplication #cctvarscalarmult
When the base point 𝐵 is not fixed, the method in the preceding section cannot be used. Instead we use a naïve
double-and-add method.
Given𝑘=
∑︀250
𝑖=0𝑘𝑖·2𝑖, we calculate𝑅=[𝑘]𝐵using:
/ /Base𝑖 =[2 𝑖]𝐵
letBase 0 =𝐵
letAcc 𝑢0 =𝑘 0 ? Base𝑢0 : 0
letAcc v0 =𝑘 0 ? Base v0 : 1
for𝑖from1up to250:
letBase 𝑖 =[2]Base 𝑖−1
/ / selectBase𝑖 or𝒪 J depending on the bit𝑘 𝑖
letAddend 𝑢𝑖 =𝑘 𝑖 ? Base𝑢𝑖 : 0
letAddend v𝑖 =𝑘 𝑖 ? Base v𝑖 : 1
letAcc 𝑖 =Acc 𝑖−1 +Addend 𝑖
let𝑅=Acc 250.
This costs 5 constraints for each of 250 ctEdwardsdoublings, 6 constraints for each of 250 ctEdwardsadditions, and
2constraints for each of251point selections, for a total of3252constraints.
16APedersen commitmentuses fixed-base scalar multiplication as a subcomponent.
216
Non-normative note:It would be more efficient to use 2-bit fixed windows, and/or to use arithmetic on the
Montgomery curvein a similar way to §A.3.3.9 ‘Pedersen hash’ on p. 217. However since there are only two instances
of variable-base scalar multiplication in theSpend circuitand one in theOutput circuit, the additional complexity
was not considered justified for Sapling.
A.3.3.9 Pedersen hash #cctpedersenhash
The specification of thePedersen hashesused in Saplingis given in §5.4.1.7 ‘Pedersen Hash Function’ on p. 82. It is
based on the scheme from [CvHP1991, section 5.2] –for which a tighter security reduction to theDiscrete Logarithm
Problemwas given in [BGG1995]– but tailored to allow several optimizations in the circuit implementation.
Pedersen hashesare the single most commonly used primitive in the Saplingcircuits. MerkleDepthSapling Pedersen
hashinstances are used in theSpend circuitto check aMerkle pathto thenote commitmentof thenotebeing spent.
We also reuse thePedersen hashimplementation to construct thenote commitment schemeNoteCommit Sapling.
This motivates considerable attention to optimizing this circuit implementation of this primitive, even at the cost of
complexity.
First, we use a windowed scalar multiplication algorithm with signed digits. Each 3-bit message chunk corresponds
to a window; the chunk is encoded as an integer from the set Digits={−4..4}∖{0} . This allows a more efficient
lookup of the window entry for each chunk than if the set{1..8} had been used, because a point can be conditionally
negated using only a single constraint.
Next, we optimize the cost of point addition by allowing as many additions as possible to be performed on the
Montgomery curve. An incomplete Montgomery addition costs 3 constraints, in comparison with a ctEdwards
addition which costs6constraints.
However, we cannot do all additions on theMontgomery curvebecause the Montgomery addition is incomplete. In
order to be able to prove that exceptional cases do not occur, we need to ensure that thedistinct- 𝑥 criterionfrom
§A.3.3.4 ‘Affine-Montgomery arithmetic’ on p. 213 is met. This requires splitting the input into segments (each
using an independent generator), calculating an intermediate result for each segment, and then converting to the
ctEdwards curveand summing the intermediate results using ctEdwards addition.
Abstracting away the changes of curve, this calculation can be written as:
PedersenHashToPoint(𝐷, 𝑀) =
𝑁∑︁
𝑗=1
[⟨𝑀𝑗⟩]ℐ(𝐷, 𝑗)
where⟨∙⟩andℐ(𝐷, 𝑗)are defined as in §5.4.1.7 ‘Pedersen Hash Function’ on p.82.
We have to prove that:
•the Montgomery-to-ctEdwardsconversions can be implemented without exceptional cases;
•thedistinct-𝑥criterionis met for all Montgomery additions within a segment.
The proof of Theorem 5.4.1 on p. 83 showed that all indices of addition inputs are in the range
{︀
− 𝑟J−12 .. 𝑟J−12 }︀∖{0} .
Because theℐ(𝐷, 𝑗)(which are outputs of GroupHashJ(𝑟)*) are all ofprime order, and ⟨𝑀𝑗⟩ ̸= 0 (mod𝑟 J), it is
guaranteed that all of the terms [⟨𝑀𝑗⟩]ℐ(𝐷, 𝑗) to be converted toctEdwardsform are ofprime order. From
Theorem A.3.3 on p.213, we can infer that the conversions will not encounter exceptional cases.
We also need to show that the indices of addition inputs are all distinct disregarding sign.
217
Theorem A.3.5.Concerning addition inputs in the Pedersen circuit. #thmpedersendistinctabsindices
For all disjoint nonempty subsets𝑆and𝑆 ′ of{1.. 𝑐}, all𝑚∈B [3][𝑐], and allΘ∈{−1,1}:
∑︁
𝑗∈𝑆
enc(𝑚𝑗)·2 4·(𝑗−1)̸=Θ· ∑︁
𝑗′∈𝑆′
enc(𝑚𝑗′)·2 4·(𝑗′−1).
Proof. Suppose for a contradiction that 𝑆, 𝑆′, 𝑚, Θ is a counterexample. Taking the multiplication by Θ on the right
hand side inside the summation, we have:
∑︁
𝑗∈𝑆
enc(𝑚𝑗)·2 4·(𝑗−1) = ∑︁
𝑗′∈𝑆′
Θ·enc(𝑚 𝑗′)·2 4·(𝑗′−1).
Defineenc′ {−1,1}×B [3]→{0..8}∖{4}asenc ′𝜃(𝑚𝑖) := 4 +𝜃·enc(𝑚 𝑖).
LetΔ= 4·
∑︀𝑐
𝑖=124·(𝑖−1) as in the proof of Theorem 5.4.1 on p.83. By addingΔto both sides, we get
∑︁
𝑗∈𝑆
enc′1(𝑚𝑗)·2 4·(𝑗−1) + ∑︁
𝑗∈{1.. 𝑐}∖𝑆
4·2 4·(𝑗−1) = ∑︁
𝑗′∈𝑆′
enc′Θ(𝑚𝑗′)·2 4·(𝑗′−1) + ∑︁
𝑗′∈{1.. 𝑐}∖𝑆′
4·2 4·(𝑗′−1)
where all of theenc′1(𝑚𝑗)andenc ′Θ(𝑚𝑗′)are in{0..8}∖{4}.
Each term on the left and on the right affects the single hex digit indexed by 𝑗 and 𝑗′ respectively. Since 𝑆 and 𝑆′
are disjoint subsets of{1.. 𝑐}and 𝑆 is nonempty, 𝑆∩({1.. 𝑐}∖𝑆 ′) is nonempty. Therefore the left hand side has at
least one hex digit not equal to4such that the corresponding right hand side digit is4; contradiction.
This implies that the terms in the Montgomery addition –as well as any intermediate results formed from adding a
distinct subset of terms– have distinct indices disregarding sign, hence distinct 𝑥-coordinates by Theorem A.3.4 on
p.213. (We make no assumption about the order of additions.)
We now describe the subcircuit used to process each chunk, which contributes most of the constraint cost of the
hash. This subcircuit is used to perform a lookup of a Montgomery point in a 2-bit window table, conditionally
negate the result, and add it to an accumulator holding another Montgomery point.
Suppose that the bits of the chunk,[𝑠 0, 𝑠1, 𝑠2], are already boolean-constrained.
We aim to compute 𝐶=𝐴+[(1−2·𝑠 2)·(1 +𝑠 0 + 2·𝑠 1)]𝑃 for some fixed base point 𝑃 and accumulated sum 𝐴.
We first compute𝑠 î =𝑠 0 î𝑠 1:
(︀
𝑠0
)︀ (︀
𝑠1
)︀
=
(︀
𝑠î
)︀
Let (𝑥𝑘, 𝑦𝑘) =[𝑘]𝑃 for 𝑘∈{1..4} . Define 프로젝트로 돌아가기