Zcash 백서

Zcash

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 35쪽 중 8쪽

activation height, fromzcashd v6.12.1 and zebra v4.3.1 [ZIP-256]. It was introduced in response to a panic that rk encoding the zero point caused during proof verification, in bothzcashd and zebra. The bug occurred in conversion of the rk Pallas curvepoint to the corresponding circuit public inputs. The underlying circuit implementation did and does support rk=𝒪 P, represented with coordinates (0,0) , and that case would have been harmless had it been handled correctly, but excluding it was the simpler and safer response under the circumstances. •nf and cm𝑥 are not checked to be validaffine-short-Weierstrass 𝑥-coordinates on thePallas curve; they are only checked to encode integers in{0.. 𝑞P−1}. 4.7 Sending Notes #send 4.7.1 Sending Notes (Sprout) #sproutsend In order to sendSprout-pool funds, the sender constructs atransactioncontaining one or moreJoinSplit descriptions. LetJoinSplitSigbe as specified in §4.1.7 ‘Signature’ on p.29. LetNoteCommit Sprout be as specified in §4.1.8 ‘Commitment’ on p.32. Letℓ Seed andℓ Sproutφ be as specified in §5.3 ‘Constants’ on p.77. Sending atransactioncontainingJoinSplit descriptionsinvolves first generating a newJoinSplitSigkey pair: joinSplitPrivKey←R JoinSplitSig.GenPrivate() joinSplitPubKey :=JoinSplitSig.DerivePublic( joinSplitPrivKey). For eachJoinSplit description, the sender chooses randomSeed uniformly at random on B[ℓSeed], and selects the input notes. At this point there is sufficient information to compute hSig, as described in the previous section. The sender also choosesφuniformly at random onB [ℓSproutφ ]. Then it creates each outputnotewith index𝑖 {1..Nnew}: •Choose uniformly randomrcm 𝑖←R NoteCommitSprout.GenTrapdoor(). •Computeρ 𝑖 =PRF ρφ(𝑖,h Sig). •Computecm 𝑖 =NoteCommit Sproutrcm𝑖 (apk,𝑖,v 𝑖,ρ 𝑖). •Letnp 𝑖 = (0x00,v 𝑖,ρ 𝑖,rcm 𝑖,memo 𝑖). 46 np1..Nnew are then encrypted to the recipienttransmission keys pkenc,1..Nnew, giving thetransmitted notes ciphertext(︀ epk,C enc1..Nnew )︀, as described in §4.19 ‘In-band secret distribution (Sprout)’ on p.68. In order to minimize information leakage, the senderSHOULDrandomize the order of the inputnotesand of the outputnotes. Other considerations relating to information leakage from the structure oftransactionsare beyond the scope of this specification. After generating all of theJoinSplit descriptions, the sender obtains dataToBeSigned BY Y[N] as described in §4.11 ‘Non-malleability (Sprout)’ on p.54, and signs it with the privateJoinSplit signing key: joinSplitSig←R JoinSplitSig.SignjoinSplitPrivKey(dataToBeSigned) Then the encodedtransactionincluding joinSplitSig is submitted to thepeer-to-peer network. [Canopyonward]Note: [ZIP-211] specifies that nodes and walletsMUSTdisable any facilities to send to Sprout addresses. ThisSHOULDbe made clear in user interfaces and API documentation. The facility to send to Sproutaddresses is in any caseOPTIONALfor a particular node or wallet implementation. 4.7.2 Sending Notes (Sapling) #saplingsend In order to send Sapling-pool shieldedvalue, the sender constructs atransactionwith one or moreOutput descriptions. LetValueCommit Sapling andNoteCommit Sapling be as specified in §4.1.8 ‘Commitment’ on p.32. LetKA Sapling be as specified in §4.1.5 ‘Key Agreement’ on p.28. LetDiversifyHash Sapling be as specified in §4.1.1 ‘Hash Functions’ on p.26. LetToScalar Sapling be as specified in §4.2.2 ‘Sapling Key Components’ on p.38. Letrepr J and𝑟 J be as defined in §5.4.9.3 ‘Jubjub’ on p.105. Let ovk be a Saplingoutgoing viewing keythat is intended to be able to decrypt this payment. This may be one of: •theoutgoing viewing keyfor the address (or one of the addresses) from which the payment was sent; •theoutgoing viewing keyfor all payments associated with an “account”, to be defined in [ZIP-32]; •⊥, if the sender should not be able to decrypt the payment once it has deleted its own copy. Note:Choosing ovk=⊥ is useful if the sender prefers to obtain forward secrecy of the payment information with respect to compromise of its own secrets. Let leadByte be thenote plaintext lead byte, chosen according to §3.2.1 ‘Note Plaintexts and Memo Fields’ on p. 16 withpool=SaplingPool. 47 For eachOutput description, the sender selects a value v {0..MAX_MONEY} and a destination Saplingshielded payment address(d,pk d), and then performs the following steps: Check that pkd is of type KASapling.PublicPrimeOrder, i.e. itMUSTbe a validctEdwards curvepoint on theJubjub curve(as defined in §5.4.9.3 ‘Jubjub’ on p.105),[𝑟 J]pk d =𝒪 J, andpk d̸=𝒪 J. Calculateg d =DiversifyHash Sapling(d)and check thatg d̸=⊥. Choose a uniformly randomcommitment trapdoorrcv← R ValueCommitSapling.GenTrapdoor(). IfleadByte= 0x01: Choose a uniformly randomephemeral private keyesk← R KASapling.Private∖{0}. Choose a uniformly randomcommitment trapdoorrcm← R NoteCommit.GenTrapdoor(). Setrseed:=I2LEOSP 256(rcm). else: Choose uniformly randomrseed←R BY Y[32]. Derivercm=ToScalar Sapling(︀PRFexpandrseed ([4]))︀. Deriveesk=ToScalar Sapling(︀PRFexpandrseed ([5]))︀. Letcv=ValueCommit Saplingrcv (v). Letcm=NoteCommit Saplingrcm (reprJ(gd),repr J(pkd),v). Letnp= (leadByte,d,v,rseed,memo). Encrypt np to the recipientdiversified transmission key pkd withdiversified base gd, and to theoutgoing viewing key ovk, giving thetransmitted note ciphertext (epk,C enc,C out). This procedure is described in §4.20.1 ‘Encryption (Sapling and Orchard)’ on p.70; it also uses cv and cmu to deriveock, and takeseskas input. Generate a proof𝜋 ZKOutput for theOutput statementin §4.18.3 ‘Output Statement (Sapling)’ on p.65. Return(cv,cm,epk,C enc,C out, 𝜋ZKOutput). In order to minimize information leakage, the senderSHOULDrandomize the order ofOutput descriptionsin a transaction. Other considerations relating to information leakage from the structure oftransactionsare beyond the scope of this specification. The encodedtransactionis submitted to thepeer-to-peer network. 4.7.3 Sending Notes (Orchard) #orchardsend In order to send Orchard-pool shieldedvalue, the sender constructs atransactionwith one or moreAction descriptions. This section describes how to produce the output-related fields of anAction description. LetValueCommit Orchard andNoteCommit Orchard be as specified in §4.1.8 ‘Commitment’ on p.32. LetPRF expand be as specified in §4.1.2 ‘Pseudo Random Functions’ on p.26. LetKA Orchard be as specified in §4.1.5 ‘Key Agreement’ on p.28. LetDiversifyHash Orchard be as specified in §4.1.1 ‘Hash Functions’ on p.26. LetToScalar Orchard andToBase Orchard be as specified in §4.2.3 ‘Orchard Key Components’ on p.40. Letrepr P,𝑟 P, and thePallas curvebe as defined in §5.4.9.6 ‘Pallas and Vesta’ on p.108. LetExtract⊥P be as defined in §5.4.9.7 ‘Coordinate Extractor for Pallas’ on p.109. LetI2LEOSPbe as defined in §5.1 ‘Integers, Bit Sequences, and Endianness’ on p.76. Let ovk be an Orchardoutgoing viewing keythat is intended to be able to decrypt this payment. The considerations for choosingoutgoing viewing keysare as described for Saplingin §4.7.2 ‘Sending Notes (Sapling)’ on p.47. Let leadByte be thenote plaintext lead byte, chosen according to §3.2.1 ‘Note Plaintexts and Memo Fields’ on p. 16 withpool∈{OrchardPool}. 48 For eachAction description, the sender selects a value v {0..MAX_MONEY} and a destination Orchardshielded payment address(d,pk d), and performs the following steps: Check thatpk d is of typeKA Orchard.PublicPrimeOrder. Calculateg d =DiversifyHash Orchard(d). Choose a uniformly randomcommitment trapdoorrcv← R ValueCommitOrchard.GenTrapdoor(). Choose uniformly randomrseed←R BY Y[32]. Letρ=nf old from the sameAction description, and letρ =I2LEOSP 256(ρ). Deriveesk=ToScalar Orchard(︀PRFexpandrseed ([4]||ρ ))︀. Ifesk= 0 (mod𝑟 P), repeat the above steps using a differentrseed. Deriveψ=ToBase Orchard(︀PRFexpandrseed ([9]||ρ ))︀. Derivercm=ToScalar Orchard(︀PRFexpandrseed ([5]||ρ ))︀. Let cvnet be thevalue commitmentto the value of the inputnoteminus the value v of the outputnotefor this Action transfer, usingrcv, as described in §4.14 ‘Balance and Binding Signature (Orchard)’ on p.57. Letcm 𝑥 =Extract⊥P(︀NoteCommitOrchardrcm (reprP(gd),repr P(pkd),v,ρ,ψ) )︀. Ifcm 𝑥 =⊥, repeat the above steps using a differentrseed. Letnp= (leadByte,d,v,rseed,memo). Encrypt np to the recipientdiversified transmission key pkd withdiversified base gd, and to theoutgoing viewing key ovk, giving thetransmitted note ciphertext (epk,C enc,C out). This procedure is described in §4.20.1 ‘Encryption (Sapling and Orchard)’ on p.70; it usescv net andcm 𝑥 to deriveock, and takeseskas input. Fill in the spending side of theAction transfer( §4.15 ‘Spend Authorization Signature (Sapling and Orchard)’ on p.59), and generate a proof𝜋for theAction statementin §4.18.4 ‘Action Statement (Orchard)’ on p.66. Return(cv,cm 𝑥,epk,C enc,C out, 𝜋). If no real Orchard-pool noteis being spent in the sameAction transfer, the senderSHOULDcreate adummy noteto spend as described in §4.8.3 ‘Dummy Notes (Orchard)’ on p. 51, and use thatdummy note’snullifieras the ρ value. In order to minimize information leakage, the senderSHOULDrandomize the order ofAction descriptionsin a transaction. Other considerations relating to information leakage from the structure oftransactionsare beyond the scope of this specification. The encodedtransactionis submitted to thepeer-to-peer network. Note:The domain separators [4] and [5] used in the input to PRFexpandrseed are swapped for Orchardrelative to Sapling. This was due to an oversight and there is no good reason for it. 4.8 Dummy Notes #dummynotes 4.8.1 Dummy Notes (Sprout) #sproutdummynotes The fields in aJoinSplit descriptionallow for Nold inputnotes, and Nnew outputnotes. In practice, we may wish to encode aJoinSplit transferwith fewer input or outputnotes. This is achieved usingdummy notes. Letℓ ask andℓ SproutPRF be as defined in §5.3 ‘Constants’ on p.77. LetPRF nfSprout be as defined in §4.1.2 ‘Pseudo Random Functions’ on p.26. LetNoteCommit Sprout be as defined in §4.1.8 ‘Commitment’ on p.32. 49 AdummySprout-poolinputnote, with index𝑖in theJoinSplit description, is constructed as follows: •Generate a new uniformly randomspending keya oldsk,𝑖←R B[ℓask] and derive itspaying keya oldpk,𝑖. •Setv old𝑖 = 0. •Choose uniformly randomρ old𝑖 ←R B[ℓSproutPRF ] andrcm old𝑖 ←R NoteCommitSprout.GenTrapdoor(). •Computenf old𝑖 =PRF nfSproutaoldsk,𝑖 (ρold𝑖 ). • Let path𝑖 be adummy Merkle pathfor theauxiliary inputto theJoinSplit statement(this will not be checked). •When generating theJoinSplit proof, setenforceMerklePath 𝑖 to0. Adummy Sprout-pool outputnoteis constructed as normal but with zero value, and sent to a randomshielded payment address. 4.8.2 Dummy Notes (Sapling) #saplingdummynotes In Saplingthere is no need to usedummy notessimply in order to fill otherwise unused inputs as in the case of a JoinSplit description; nevertheless it may be useful for privacy to obscure the number of realshielded inputsfrom Sapling-poolnotes. Letℓ sk be as defined in §5.3 ‘Constants’ on p.77. LetValueCommit Sapling andNoteCommit Sapling be as defined in §4.1.8 ‘Commitment’ on p.32. LetDiversifyHash Sapling be as specified in §4.1.1 ‘Hash Functions’ on p.26. LetToScalar Sapling be as specified in §4.2.2 ‘Sapling Key Components’ on p.38. Letrepr J and𝑟 J be as defined in §5.4.9.3 ‘Jubjub’ on p.105. LetPRF nfSapling be as defined in §4.1.2 ‘Pseudo Random Functions’ on p.26. LetNoteCommit Sapling be as defined in §4.1.8 ‘Commitment’ on p.32. ASpend descriptionfor adummy Sapling-pool inputnotewithnote plaintext lead byte 0x02 is constructed as follows: •Choose uniformly randomsk← R B[ℓsk]. • Generate the ak and nk components of afull viewing keyand adiversified payment address (d,pk d) for sk, as described in §4.2.2 ‘Sapling Key Components’ on p.38. •Letv= 0andpos= 0. •Choose uniformly randomrcv← R ValueCommitSapling.GenTrapdoor(). •Choose uniformly randomrseed← R BY Y[32]. •Derivercm=ToScalar Sapling(︀PRFexpandrseed ([4]))︀. •Letcv=ValueCommit Saplingrcv (v). •Letcm=NoteCommit Saplingrcm (︀reprJ(gd),repr J(pkd),v )︀. •Letρ⋆=repr J (︀ MixingPedersenHash(cm,pos) )︀ . •Letnk⋆=repr J(nk). •Letnf=PRF nfSaplingnk⋆ (ρ⋆). • Construct adummy Merkle path path for use in theauxiliary inputto theSpend statement(this will not be checked, becausev= 0). As in Sprout, adummy Sapling-pool outputnoteis constructed as normal but with zero value, and sent to a random shielded payment address. 50 4.8.3 Dummy Notes (Orchard) #orcharddummynotes As for Sapling, it may be useful for privacy to obscure the number of realshielded inputsfromOrchard-poolnotes. Letℓ sk be as defined in §5.3 ‘Constants’ on p.77. LetValueCommit Orchard andNoteCommit Orchard be as defined in §4.1.8 ‘Commitment’ on p.32. LetDiversifyHash Orchard be as specified in §4.1.1 ‘Hash Functions’ on p.26. LetToScalar Orchard andToBase Orchard be as specified in §4.2.3 ‘Orchard Key Components’ on p.40. Letrepr P and𝑟 P be as defined in §5.4.9.6 ‘Pallas and Vesta’ on p.108. LetDeriveNullifierbe as defined in §4.16 ‘Computingρvalues and Nullifiers’ on p.60. LetNoteCommit Orchard be as defined in §4.1.8 ‘Commitment’ on p.32. LetI2LEOSPbe as defined in §5.1 ‘Integers, Bit Sequences, and Endianness’ on p.76. Let leadByte be thenote plaintext lead byte, chosen according to §3.2.1 ‘Note Plaintexts and Memo Fields’ on p. 16 withpool=OrchardPool. The spend-related fields of anAction descriptionfor adummy Orchard-pool inputnoteare constructed as follows: •Choose uniformly randomsk← R B[ℓsk]. • Generate afull viewing key (ak,nk,rivk) and adiversified payment address (d,pk d) for sk as described in §4.2.3 ‘Orchard Key Components’ on p.40. •Letv= 0. •Choose uniformly randomrseed← R BY Y[32]. •Choose uniformly randomρ P←R P. •Letρ=Extract P(ρP)andρ =I2LEOSP 256(ρ). •Deriveψ=ToBase Orchard(︀PRFexpandrseed ([9]||ρ ))︀. •Derivercm=ToScalar Orchard(︀PRFexpandrseed ([5]||ρ ))︀. •Letcm=NoteCommit Orchardrcm (︀reprP(gd),repr P(pkd),v,ρ,ψ )︀. •Ifcm=⊥, repeat the above steps using a differentrseed. •Letnf=DeriveNullifier nk(ρ,ψ,cm). • Construct adummy Merkle path path for use in theauxiliary inputto theAction statement(this will not be checked, becausev= 0). As in Sproutand Sapling, adummy Orchard-pool outputnoteis constructed as normal but with zero value, and sent to a randomshielded payment address. Note:The domain separators [4] and [5] used in the input to PRFexpandrseed are swapped for Orchardrelative to Sapling. This was due to an oversight and there is no good reason for it. 51 4.9 Merkle Path Validity #merklepath Let MerkleDepth be MerkleDepthSprout for the Sprout-pool note commitment tree, or MerkleDepthSapling for the Sapling- pool note commitment tree, or MerkleDepthOrchard for the Orchard-pool note commitment tree. These constants are defined in §5.3 ‘Constants’ on p.77. Similarly, let MerkleCRH be MerkleCRHSprout for Sprout, or MerkleCRHSapling for Sapling, or MerkleCRHOrchard for Orchard. The discussion below applies independently to theSprout-pool and Sapling-pool and Orchard-pool note commitment trees. Eachnodein theincremental Merkle treeis associated with ahash value, which is abit sequence. Thelayernumberedℎ, counting fromlayer0at theroot, has2 ℎ nodeswithindices0to2 ℎ−1inclusive. LetM ℎ𝑖 be thehash valueassociated with thenodeatindex𝑖inlayerℎ. Thenodesatlayer MerkleDepth are calledleaf nodes. When anote commitmentis added to the tree, it occupies theleaf node hash valueM MerkleDepth𝑖 for the next available𝑖. As-yet unusedleaf nodesare associated with a distinguishedhash value UncommittedSprout or UncommittedSapling or UncommittedOrchard. It is assumed to be infeasible to find a preimagenote n such that NoteCommitmentSprout(n) = UncommittedSprout. (No similar assumption is needed for Saplingor Orchardbecause we use a representation for UncommittedSapling that cannot occur as an output ofNoteCommitment Sapling, and similarly for Orchard.) Thenodesatlayers 0 to MerkleDepth−1 inclusive are calledinternal nodes, and are associated with MerkleCRH outputs.Internal nodesare computed from their children in the nextlayeras follows: for 0≤ℎ <MerkleDepth and 0≤𝑖 <2 ℎ, Mℎ𝑖 :=MerkleCRH(ℎ,M ℎ+12𝑖 ,M ℎ+12𝑖+1). AMerkle pathfromleaf nodeM MerkleDepth𝑖 in theincremental Merkle treeis the sequence [ [Mℎsibling(ℎ,𝑖) forℎfromMerkleDepthdown to1 ] ], where sibling(ℎ, 𝑖) :=floor (︂ 𝑖 2MerkleDepth−ℎ )︂ ⊕1 Given such aMerkle path, it is possible to verify thatleaf nodeM MerkleDepth𝑖 is in a tree with a givenrootrt=M 00. Notes: • For Sapling, Merklehash valuesare specified to be encoded asbit sequences, but theroot rtSaplingPool is encoded for theprimary inputof aSpend proofas an element ofF 𝑞J, as specified in §A.4 ‘The Sapling Spend circuit’ on p. 224. TheSpend circuitallows inputs to MerkleCRHSapling at eachnodeto benon-canonicallyencoded, as specified in §A.3.4 ‘Merkle path check’ on p.220. • For Orchard, Merklehash valueshave type {0.. 𝑞P−1} as defined in §5.4.9.7 ‘Coordinate Extractor for Pallas’ on p. 109. Similarly to Sapling, theAction circuitallows inputs to MerkleCRHOrchard at eachnodeto benon- canonicallyencoded. • TheAction circuitis permitted to be implemented in such a way that theMerkle pathvalidity check can pass if anyhash valueon the path, including theroot, is 0. This can only happen if SinsemillaHash returned ⊥ for that hash, because 0 is not theaffine-short-Weierstrass 𝑥-coordinate of any point on thePallas curve (as shown in a note at §5.4.9.7 ‘Coordinate Extractor for Pallas’ on p. 109), and SinsemillaHashToPoint cannot return𝒪P. Allowing the validity check to pass in that case models the fact that incomplete addition is used to implement Sinsemilla in the circuit. As proven in Theorem 5.4.4 on p. 87, a⊥ output from SinsemillaHash yields a nontrivialdiscrete logarithmrelation. Since we assume finding such a relation to be infeasible, we can argue that it is safe to allow an adversary to create a proof that passes the Merkle validity check in such a case. 52 4.10 SIGHASH Transaction Hashing #sighash BitcoinandZcashuse signatures and/or non-interactive proofs associated withtransactioninputs to authorize spending. Because these signatures or proofs could otherwise be replayed in a differenttransaction, it is necessary to “bind” them to thetransactionfor which they are intended. This is done by hashing information about the transactionand (where applicable) the specific input, to give aSIGHASH transaction hashwhich is then used for the Spend authorization. The means of authorization differs betweentransparent inputs, inputs to SproutJoinSplit transfers, and SaplingSpend transfersor OrchardAction transfers, but for a giventransaction versionthe same SIGHASH transaction hashalgorithm is used. In the case ofZcash, the BCTV14 and Groth16 and Halo 2 proving systems used are malleable, meaning that there is the potential for an adversary who does not know all of theauxiliary inputsto a proof, to malleate it in order to create a new proof involving relatedauxiliary inputs [DSDCOPS2001]. This can be understood as similar to a malleability attack on an encryption scheme, in which an adversary can malleate a ciphertext in order to create an encryption of a related plaintext, without knowing the original plaintext.Zcashhas been designed to mitigate malleability attacks, as described in §4.11 ‘Non-malleability (Sprout)’ on p. 54, §4.13 ‘Balance and Binding Signature (Sapling)’ on p. 55, and §4.15 ‘Spend Authorization Signature (Sapling and Orchard)’ on p.59. To provide additional flexibility when combining spend authorizations from different sources,Bitcoindefines sev- eralSIGHASH typesthat cover various parts of a transaction [Bitcoin-SigHash]. One of these types is SIGHASH_ALL, which is used forZcash-specific signatures, i.e.JoinSplit signatures,spend authorization signatures,Sapling binding signatures, andOrchard binding signatures. In these cases theSIGHASH transaction hashis not associated with a transparent input, and so the input to hashing excludes all of the scriptSig fields in
프로젝트로 돌아가기