bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 35쪽 중 12쪽
computed again.
• A previous version of this specification did not have the requirement for the decoded pointpkd of a Sapling
noteto be in the set ofprime-orderpoints J(𝑟)* (i.e. “if ...pk d̸∈J (𝑟)*, return⊥”). That did not match the
implementation in zcashd. In fact the history is a little more complicated. The current specification matches
the implementation in librustzcash as of [librustzcash-109], which has been used in zcashd since zcashd v2.1.2.
However, there was another implementation of Saplingnote decryption used in zcashd for consensus checks,
specifically the check that ashieldedcoinbase output decrypts successfully with the zero ovk. This was
corrected to enforce the same restriction on the decrypted pkd in zcashd v5.5.0, originally set to activate in a
soft fork atblock height2121200 on bothMainnetandTestnet [zcashd-6459]. (OnTestnetthis height was
in the past as of thezcashd v5.5.0release, and so the change would have been immediately enforced on
upgrade.) Since the soft fork was observed to be retrospectively valid after that height, the implementation was
simplified in [zcashd-6725] to use the librustzcash implementation in all cases, which reflects the specification
above. zebra always used the librustzcash implementation.
• As explained in the note in §5.4.9.3 ‘Jubjub’ on p. 105, abstJ acceptsnon-canonicalcompressed encodings of
Jubjub curvepoints. Therefore, an implementationMUSTuse the original ephemeralKey field as encoded in the
transactionas input to PRFock and KDFSapling, and in the comparison againstreprG(︀KASapling.DerivePublic(esk,g d))︀.
For consistency this is also what is specified for Orchard.
• For Saplingoutgoing ciphertexts, pk⋆d could also benon-canonical. The above algorithm explicitly returns
⊥ if reprP
(︀
pkd
)︀
̸=pk⋆ d. However, this is technically redundant with the later check that returns ⊥ if pkd̸∈
J(𝑟)*, because onlysmall-order Jubjub curvepoints havenon-canonicalencodings. This check is enforced
retrospectively for consensus by current zcashd and zebra versions, and for wallet rescanning by current
zcashd. Versions of zcashd prior to [zcashd-6725] could however have acceptednotesfor which theoutgoing
ciphertextcontains either a canonical or anon-canonicalencoding of𝒪 J forpk d.
•[ NU5onward] For Orchardoutgoing ciphertexts, it is not possible forpk⋆ d to benon-canonical.
• [ NU5 onward] The domain separators [4] and [5] used in the input toPRFexpandrseed are swapped for Orchardrelative
to Sapling. This was due to an oversight and there is no good reason for it.
• The comments in §4.20.2 ‘Decryption using an Incoming Viewing Key (Sapling and Orchard)’ on p. 71 con-
cerning calculation of ρ, detection of spentnotes, and decryption oftransmitted note ciphertextsfortrans-
actionsin themempoolalso apply tonotesdecrypted by this procedure.
Non-normative note:Implementors should pay close attention to similarities and differences between this pro-
cedure and §4.20.2 ‘Decryption using an Incoming Viewing Key (Sapling and Orchard)’ on p. 71, especially that:
• in this procedure, the ephemeralprivate key esk′ derived from rseed is checked to be identical to that obtained
fromop(whenleadByte̸= 0x01);
•in this procedure,pk d is obtained fromoprather than being derived asKA Sapling.DerivePublic(ivk,g d);
• in this procedure, the check that KASapling.DerivePublic(esk,g d) =epk is unconditional rather than being
dependent onleadByte̸= 0x01, and it uses theeskobtained fromop;
•[ NU5onward] for the same reason as in §4.20.2 on p.71,epkcannot be𝒪 P.
4.21 Block Chain Scanning (Sprout) #sproutscan
Letℓ SproutPRF be as defined in §5.3 ‘Constants’ on p.77.
LetNote Sprout be as defined in §3.2 ‘Shielded Pools and Notes’ on p.15.
LetKA Sprout be as defined in §5.4.5.1 ‘Sprout Key Agreement’ on p.91.
Let ivk= (a pk B[ℓSproutPRF ],sk enc KASprout.Private) be theincoming viewing keycorresponding to ask, and let pkenc be
the associatedtransmission key, as specified in §4.2.1 ‘Sprout Key Components’ on p.38.
74
The following algorithm can be used, given theblock chainand a Sproutspending key ask, to obtain eachnotesent
to the correspondingshielded payment address, itsmemo field, and its final status (spent or unspent).
let mutableReceivedSet P
(︀
NoteSprout×B Y Y[512])︀←{}
let mutableSpentSet P
(︀
NoteSprout)︀←{}
let mutableNullifierMap B[ℓSproutPRF ]→Note Sprout←the empty mapping
for eachtransactiontx:
for eachJoinSplit descriptionintx:
let(epk,C enc1..Nnew)be thetransmitted notes ciphertextof theJoinSplit description
for𝑖in1..N new:
Attempt to decrypt thetransmitted notes ciphertextcomponent(epk,C enc𝑖 )usingivkwith the
algorithm in §4.19.2 ‘Decryption (Sprout)’ on p.69. If this succeeds with(n,memo):
Add(n,memo)toReceivedSet.
Calculate thenullifier nf of n using ask as in §4.16 ‘Computingρvalues and Nullifiers’ on p. 60.
Add the mappingnf→ntoNullifierMap.
letnf 1..Nold be thenullifiersof theJoinSplit description
for𝑖in1..N old: ifnf 𝑖 is present inNullifierMap, addNullifierMap(nf 𝑖)toSpentSet
return(ReceivedSet,SpentSet).
4.22 Block Chain Scanning (SaplingandOrchard) #scan
In Saplingand Orchard,block chainscanning requires only thenkandivkkey components, rather than aspending
keyas in Sprout. Typically, these components are derived from afull viewing key( §4.2.2 ‘Sapling Key Components’
on p.38 or §4.2.3 ‘Orchard Key Components’ on p.40).
Letℓ PRFnfSapling be as defined in §5.3 ‘Constants’ on p.77.
LetNotebeNote Sapling orNote Orchard as defined in §3.2 ‘Shielded Pools and Notes’ on p.15.
LetKAbe eitherKA Sapling as defined in §5.4.5.3 on p.92, orKA Orchard as defined in §5.4.5.5 on p.93.
LetNullifierTypebeB Y Y[ℓPRFnfSapling/8] for Sapling, orF 𝑞P for Orchard.
The following algorithm can be used, given theblock chainand (nk,ivk) , to obtain eachnotesent to the corre-
spondingshielded payment address, itsmemo field, and its final status (spent or unspent).
let mutableReceivedSet P
(︀
Note×B Y Y[512])︀←{}
let mutableSpentSet P
(︀
Note
)︀
←{}
let mutableNullifierMap (NullifierType→Note)←the empty mapping
for eachtransactiontx:
for eachOutput descriptionorAction descriptionintx:
Attempt to decrypt thetransmitted note ciphertextcomponents epk and Cenc using ivk with the algorithm
§4.20.2 ‘Decryption using an Incoming Viewing Key (Sapling and Orchard)’ on p.71.
If this succeeds with(n,memo):
Add(n,memo)toReceivedSet.
Calculate thenullifiernfofnusingnkas in §4.16 ‘Computingρvalues and Nullifiers’ on p.60.
(This also requiresposfrom theOutput descriptionforSapling-poolnotes.)
Add the mappingnf→ntoNullifierMap.
for eachnullifiernfof aSpend descriptionorAction descriptionintx:
ifnfis present inNullifierMap, addNullifierMap(nf)toSpentSet
return(ReceivedSet,SpentSet).
75
Non-normative notes:
• The above algorithm does not use the ovk key component, or theCout transmitted note ciphertextcomponent.
When scanning the wholeblock chain, these are indeed not necessary. The advantage of supporting decryp-
tion using ovk as described in §4.20.3 ‘Decryption using an Outgoing Viewing Key (Sapling and Orchard)’
on p. 73, is that it allows recovering information about thenote plaintextssent in atransactionfrom that
transactionalone.
• When scanning only part of ablock chain, it may be useful to augment the above algorithm with decryption
of Cout components for eachtransaction, in order to obtain information aboutnotesthat were spent in the
scanned period but received outside it.
•The above algorithm does not detectnotesthat were sent “out-of-band” or with incorrecttransmitted note
ciphertexts. It is possible to detect whether suchnoteswere spent only if theirnullifiersare known.
5 Concrete Protocol #concreteprotocol
5.1 Integers, Bit Sequences, and Endianness #endian
All integers inZcash-specific encodings are unsigned, have a fixed bit length, and are encoded in little-endian byte
order unless otherwise specified.
The following functions convert between sequences of bits, sequences of bytes, and integers:
•I2LEBSP (ℓ N)×{0..2 ℓ−1}→B [ℓ], such that I2LEBSPℓ(𝑥) is the sequence of ℓ bits representing 𝑥 in
little-endian order;
•I2LEOSP (ℓ N)×{0..2 ℓ−1}→B Y Y[ceiling(ℓ/8)], such that I2LEBSPℓ(𝑥) is the sequence of ceiling(ℓ/8) bytes
representing𝑥in little-endian order;
•I2BEBSP (ℓ N)×{0..2 ℓ−1}→B [ℓ] such that I2BEBSPℓ(𝑥) is the sequence of ℓ bits representing 𝑥 in
big-endian order.
•LEBS2IP (ℓ N)×B [ℓ]→{0..2 ℓ−1} such that LEBS2IPℓ(𝑆) is the integer represented in little-endian order
by thebit sequence𝑆of lengthℓ.
•LEOS2IP (ℓ N|ℓmod 8 = 0)×B Y Y[ℓ/8]→{0..2 ℓ−1} such that LEOS2IPℓ(𝑆) is the integer represented in
little-endian order by thebyte sequence𝑆of lengthℓ/8.
•BEOS2IP (ℓ N|ℓmod 8 = 0)×B Y Y[ℓ/8]→{0..2 ℓ−1} such that BEOS2IPℓ(𝑆) is the integer represented in
big-endian order by thebyte sequence𝑆of lengthℓ/8.
•LEBS2OSP (ℓ N)×B [ℓ]→B Y Y[ceiling(ℓ/8)] defined as follows: pad the input on the right with 8·ceiling(ℓ/8)−ℓ
zero bits so that its length is a multiple of 8 bits. Then convert each group of 8 bits to a byte value with the
least significant bit first, and concatenate the resulting bytes in the same order as the groups.
•LEOS2BSP (ℓ N|ℓmod 8 = 0)×B Y Y[ceiling(ℓ/8)]→B [ℓ] defined as follows: convert each byte to a group of 8
bits with the least significant bit first, and concatenate the resulting groups in the same order as the bytes.
5.2 Bit layout diagrams #bitlayout
We sometimes use bit layout diagrams, in which each box of the diagram represents a sequence of bits. Diagrams
are read from left to right, with lines read from top to bottom; the breaking of boxes across lines has no significance.
The bit length ℓ is given explicitly in each box, except when it is obvious (e.g. for a single bit, or for the notation[0]ℓ
representing the sequence ofℓzero bits, or for the output ofLEBS2OSP ℓ).
The entire diagram represents the sequence of bytes formed by first concatenating thesebit sequences, and then
treating each subsequence of 8 bits as a byte with the bits ordered frommost significant to least significant. Thus
the most significant bit in each byte is toward the left of a diagram. (This convention is used only in descriptions
of the Sproutdesign; in the Saplingand Orchardadditions,bit sequence/byte sequenceconversions are always
specified explicitly.) Where bit fields are used, the text will clarify their position in each case.
76
5.3 Constants #constants
Define:
MerkleDepthSprout N:= 29
MerkleDepthSapling N:= 32
MerkleDepthOrchard N:= 32
ℓSproutMerkle N:= 256
ℓSaplingMerkle N:= 255
ℓOrchardMerkle N:= 255
Nold N:= 2
Nnew N:= 2
ℓvalue N:= 64
ℓhSig N:= 256
ℓSproutPRF N:= 256
ℓPRFexpand N:= 512
ℓPRFnfSapling N:= 256
ℓSproutrcm N:= 256
ℓSeed N:= 256
ℓask N:= 252
ℓSproutφ N:= 252
ℓsk N:= 256
ℓd N:= 88
ℓdk N:= 256
ℓSaplingivk N:= 251
ℓovk N:= 256
ℓSaplingscalar N:= 252
ℓOrchardscalar N:= 255
ℓOrchardbase N:= 255
UncommittedSprout B[ℓSproutMerkle] := [0]ℓSproutMerkle
UncommittedSapling B[ℓSaplingMerkle ] :=I2LEBSP ℓSaplingMerkle (1)
UncommittedOrchard {0.. 𝑞P−1}:= 2
MAX_MONEY N:= 2.1·10 15 (zatoshi)
BlossomActivationHeight N:=
{︃
653600,forMainnet
584000,forTestnet
CanopyActivationHeight N:=
{︃
1046400,forMainnet
1028500,forTestnet
ZIP212GracePeriod N:= 32256
SlowStartInterval N:= 20000
77
PreBlossomHalvingInterval N:= 840000
MaxBlockSubsidy N:= 1.25·10 9 (zatoshi)
NumFounderAddresses N:= 48
FoundersFraction Q:= 15
PoWLimit N:=
{︃
2243−1,forMainnet
2251−1,forTestnet
PoWAveragingWindow N:= 17
PoWMedianBlockSpan N:= 11
PoWMaxAdjustDown Q:= 32100
PoWMaxAdjustUp Q:= 16100
PoWDampingFactor N:= 4
PreBlossomPoWTargetSpacing N:= 150(seconds).
PostBlossomPoWTargetSpacing N:= 75(seconds).
5.4 Concrete Cryptographic Schemes #concreteschemes
5.4.1 Hash Functions #concretehashes
5.4.1.1SHA-256,SHA-256d,SHA256Compress, andSHA-512Hash Functions #concretesha
SHA-256 and SHA-512 are defined by [NIST2015].
Zcashuses the fullSHA-256hash functionto instantiateNoteCommitment Sprout.
SHA-256 BY Y[N]→B Y Y[32]
[NIST2015] strictly speaking only specifies the application of SHA-256 to messages that arebit sequences, producing
outputs (“message digests”) that are alsobit sequences. In practice, SHA-256 is universally implemented with a
byte-sequence interface for messages and outputs, such that the most significant bit of each byte corresponds to
the first bit of the associatedbit sequence. (In the NIST specification “first” is conflated with “leftmost” .)
SHA-256d, defined as a double application ofSHA-256, is used to hashblock headers:
SHA-256d BY Y[N]→B Y Y[32]
Zcashalso uses the SHA-256 compression function, SHA256Compress. This operates on a single 512-bit block and
excludes the padding step specified in [NIST2015, section 5.1].
That is, the input to SHA256Compress is what [NIST2015, section 5.2] refers to as “the message and its padding” . The
Initial Hash Value is the same as for fullSHA-256.
SHA256Compressis used to instantiate severalPseudo Random FunctionsandMerkleCRH Sprout.
SHA256Compress B[512]→B [256]
The ordering of bits within words in the interface to SHA256Compress is consistent with [NIST2015, section 3.1], i.e.
big-endian.
Ed25519usesSHA-512:
SHA-512 BY Y[N]→B Y Y[64]
The comment above concerning bit vs byte-sequence interfaces also applies toSHA-512.
78
5.4.1.2 BLAKE2 Hash Functions #concreteblake2
BLAKE2 is defined by [ANWW2013].Zcashuses both theBLAKE2bandBLAKE2svariants.
BLAKE2b-ℓ(𝑝, 𝑥)refers to unkeyedBLAKE2b-ℓ in sequential mode, with an output digest length ofℓ/8 bytes, 16-byte
personalization string𝑝, and input𝑥.
BLAKE2b is used to instantiatehSigCRH, EquihashGen, and KDFSprout. FromOverwinteronward, it is used to compute
SIGHASH transaction hashesas specified in [ZIP-143], or as in [ZIP-243] after Sapling activation, or as in [ZIP-244]
for version 5transactions. For Sapling, it is also used to instantiate PRFexpand, PRFockSapling, KDFSapling, and in the
RedJubjubsignature schemewhich instantiatesSpendAuthSig Sapling andBindingSig Sapling.
BLAKE2b-ℓ BY Y[16]×B Y Y[N]→B Y Y[ℓ/8]
Note: BLAKE2b-ℓ is not the same as BLAKE2b-512 truncated to ℓ bits, because the digest length is encoded in the
parameter block.
BLAKE2s-ℓ(𝑝, 𝑥)refers to unkeyed BLAKE2s-ℓ in sequential mode, with an output digest length of ℓ/8 bytes, 8-byte
personalization string𝑝, and input𝑥.
BLAKE2sis used to instantiatePRF nfSapling,CRH ivk, andGroupHash J(𝑟)*.
BLAKE2s-ℓ BY Y[8]×B Y Y[N]→B Y Y[ℓ/8]
5.4.1.3 Merkle Tree Hash Function #merklecrh
MerkleCRHSprout and MerkleCRHSapling and MerkleCRHOrchard are used to hashincremental Merkle tree hash valuesfor
Sproutand Saplingand Orchardrespectively.
MerkleCRHSprout Hash Function #sproutmerklecrh
MerkleCRHSprout {0..MerkleDepth Sprout−1}×B [ℓSproutMerkle]×B [ℓSproutMerkle]→B [ℓSproutMerkle] is defined as follows:
MerkleCRHSprout(layer,left⋆,right⋆) :=SHA256Compress (︁ 256-bitleft⋆ 256-bitright⋆ )︁.
SHA256Compress is defined in §5.4.1.1 ‘SHA-256,SHA-256d,SHA256Compress, andSHA-512Hash Functions’ on
p.78.
Security requirement: SHA256Compress must becollision-resistant, and it must be infeasible to find a preimage
𝑥such thatSHA256Compress(𝑥) = [0] 256.
Notes:
•Thelayerargument does not affect the output.
•SHA256Compressis not the same as theSHA-256function, which hashes arbitrary-lengthbyte sequences.
MerkleCRHSapling Hash Function #saplingmerklecrh
LetPedersenHashbe as specified in §5.4.1.7 ‘Pedersen Hash Function’ on p.82.
MerkleCRHSapling {0..MerkleDepth Sapling−1}×B [ℓSaplingMerkle ]×B [ℓSaplingMerkle ]→B [ℓSaplingMerkle ] is defined as follows:
MerkleCRHSapling(layer,left⋆,right⋆) :=PedersenHash(“ Zcash_PH”, 𝑙⋆||left⋆||right⋆)
where𝑙⋆=I2LEBSP 6
(︀
MerkleDepthSapling−1−layer )︀.
Security requirement:PedersenHashmust becollision-resistant.
79
Note:The prefix 𝑙⋆ provides domain separation between inputs at different layers of thenote commitment
tree. NoteCommitSapling, like PedersenHash, is defined in terms of PedersenHashToPoint, but using a prefix that cannot
collide with a layer prefix, as noted in §5.4.8.2 ‘Windowed Pedersen commitments’ on p.99.
MerkleCRHOrchard Hash Function #orchardmerklecrh
LetSinsemillaHashbe as specified in §5.4.1.9 ‘Sinsemilla Hash Function’ on p.84.
MerkleCRHOrchard {0..MerkleDepth Orchard−1}×{0.. 𝑞 P−1}×{0.. 𝑞 P−1}→{0.. 𝑞 P−1}is defined as follows:
MerkleCRHOrchard(layer,left,right) :=
{︃
0,ifhash=⊥
hash,otherwise
wherehash=SinsemillaHash(“ z.cash:Orchard-MerkleCRH”, 𝑙⋆||left⋆||right⋆)
𝑙⋆=I2LEBSP 10
(︀
MerkleDepthOrchard−1−layer )︀
left⋆=I2LEBSP ℓOrchardMerkle
(︀
left
)︀
right⋆=I2LEBSP ℓOrchardMerkle
(︀
right
)︀
.
Security requirements:
•SinsemillaHashmust becollision-resistant.
•It must be infeasible to find a input of length10 + 2·ℓ OrchardMerkle bits toSinsemillaHashthat yields output⊥.
Note:The prefix 𝑙⋆ provides domain separation between inputs at different layers of thenote commitment tree.
5.4.1.4h Sig Hash Function #hsigcrh
hSigCRHis used to compute the valueh Sig in §4.3 ‘JoinSplit Descriptions’ on p.41.
hSigCRH(randomSeed,nf old1..Nold , joinSplitPubKey) :=BLAKE2b-256(“ ZcashComputehSig”,hSigInput)
where
hSigInput:= 256-bitrandomSeed 256-bitnf old1 ... 256-bitnf oldNold 256-bit joinSplitPubKey .
BLAKE2b-256(𝑝, 𝑥)is defined in §5.4.1.2 ‘BLAKE2 Hash Functions’ on p.79.
Security requirement:BLAKE2b-256(“ ZcashComputehSig”, 𝑥)must becollision-resistanton𝑥.
5.4.1.5CRH ivk Hash Function #concretecrhivk
CRHivk is used to derive theincoming viewing key ivk for a Saplingshielded payment address. For its use when
generating an address see §4.2.2 ‘Sapling Key Components’ on p. 38, and for its use in theSpend statementsee
§4.18.2 ‘Spend Statement (Sapling)’ on p.64.
It is defined as follows:
CRHivk(ak⋆,nk⋆) :=LEOS2IP 256(BLAKE2s-256(“Zcashivk”,crhInput)) mod 2 ℓSaplingivk
where
crhInput:= LEBS2OSP256(ak⋆) LEBS2OSP256(nk⋆)
BLAKE2s-256(𝑝, 𝑥)is defined in §5.4.1.2 ‘BLAKE2 Hash Functions’ on p.79.
80
Security requirement: LEOS2IP256(BLAKE2s-256(“Zcashivk”, 𝑥)) mod 2ℓSaplingivk must becollision-resistanton a 64-
byte input 𝑥. Note that this does not follow fromcollision resistanceof BLAKE2s-256 (and the best possible concrete
security is that of a 251-bit hash rather than a 256-bit hash), but it is a reasonable assumption given the design,
structure, and cryptanalysis to date ofBLAKE2s.
Non-normative note: BLAKE2s has a variable output digest length feature, but it does not support arbitrary
bit lengths, otherwise it would have been used rather than external truncation. However, the protocol-specific
personalization string together with truncation achieve essentially the same effect as using that feature.
5.4.1.6DiversifyHash Sapling andDiversifyHash Orchard Hash Functions #concretediversifyhash
DiversifyHashSapling B[ℓd]→J (𝑟)*∪{⊥} is used to derive adiversified basein §4.2.2 ‘Sapling Key Components’ on
p.38.
LetGroupHash J(𝑟)* and𝑈be as defined in §5.4.9.5 ‘Group Hash into Jubjub’ on p.107.
Define
DiversifyHashSapling(d) :=GroupHash J(𝑟)*𝑈 (︀“Zcash_gd”,LEBS2OSP ℓd(d))︀.
DiversifyHashOrchard B[ℓd]→P* is used to derive adiversified basein §4.2.3 ‘Orchard Key Components’ on p.40.
LetGroupHash P be as defined in §5.4.9.8 ‘Group Hash into Pallas and Vesta’ on p.110.
Define
DiversifyHashOrchard(d) :=
{︃
GroupHashP(“z.cash:Orchard-gd”,“ ”),if𝑃=𝒪 P
𝑃,otherwise
where𝑃=GroupHash P(︀“z.cash:Orchard-gd”,LEBS2OSP ℓd(d))︀.
The following security property and notes apply to both Saplingand Orchard.
Security requirement: Unlinkability:Given two randomly selectedshielded payment addressesfrom different
spend authorities, and a thirdshielded payment addresswhich could be derived from either of those authorities,
such that the three addresses use differentdiversifiers, it is not possible to tell which authority the third address
was derived from.
Non-normative notes:
• Suppose that GroupHashJ(𝑟)* (restricted to inputs for which it does not return⊥) is modelled as arandom oracle
fromdiversifiersto points of order 𝑟J on theJubjub curve. In this model, Unlinkability of DiversifyHashSapling
holds under theDecisional Diffie–Hellman assumptionon theprime-order subgroupof points on theJubjub
curve.
To prov프로젝트로 돌아가기