Zcash 백서

Zcash

원문

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

s: •Theprimary inputsare encoded as the following sequence of typeF 𝑞P [9]:[︀ rtOrchardPool (mod𝑞 P), 𝑥(︀cvnet)︀, 𝑦(︀cvnet)︀,nf old (mod𝑞 P), 𝑥(rk), 𝑦(rk),cm 𝑥 (mod𝑞 P),enableSpends(mod𝑞 P), enableOutputs(mod𝑞 P) ]︀ . (Recall from §2 ‘Notation’ on p.11 that “(mod𝑞 P)” interprets an integer as anF 𝑞P element.) • Primaryandauxiliary inputsMUSTbe constrained to have the types specified. In particular, goldd , pkoldd , gnewd , pknewd , and akP cannot be𝒪P. The ValueCommitOrchard.Output and SpendAuthSigOrchard.Public types represent Pallas curvepoints, i.e.P. • The case rk=𝒪 P will not occur, due to the consensus rule in §4.6 ‘Action Descriptions’ on p. 44 that rk MUST NOTbe the identity point. • The scalar multiplication used in ValueCommitOrchard must operate correctly on the range{−264 + 1..2 64−1} , which is different to the range{−2 63 ..2 63−1}ofv OrchardPoolBalance. • In the Merkle path validity check, eachlayerdoes not check that its inputbit sequenceis a canonical encoding (in{0.. 𝑞P−1}) of the integer from the previouslayer. • As specified in §4.9 ‘Merkle Path Validity’ on p. 52, the validity check is permitted to be implemented in such a way that it can pass if any MerkleCRHOrchard hash on theMerkle pathoutputs 0. This allows nondeterministic, incomplete addition to be used in the circuit forSinsemillaHash. •It is not checked thatrcv< 𝑟 P or thatrcm old < 𝑟P or thatrcm new < 𝑟P. •SpendAuthSig Orchard.RandomizePublic(𝛼,ak P) =ak P +[𝛼]𝒢 Orchard. (𝒢Orchard is as defined in §5.4.7.1 ‘Spend Authorization Signature (Sapling and Orchard)’ on p.98.) 67 • The validity of g⋆d and pk⋆d are not checked in this circuit. Also, rtOrchardPool and cm𝑥 are not checked to be Pallasaffine-short-Weierstrass𝑥-coordinates or0. • When a value given as a field element in theAction circuitis used as a scalar for scalar multiplication, it involves witnessing the scalar as a sequence of bits or window indices, typically for a total of255 bits (except in the case of multiplying by the value difference vold−v new). This raises the possibility that the witnessed 255-bit representation may match the original field element modulo 𝑞P, but not modulo 𝑟P. Unless it can be proven to result in an equivalent statement, the decomposition of each scalar valueMUSTbe canonical. The cases in which not checking canonicity results in an equivalent statement are those where the state- ment only requires to prove knowledge of the scalar, without using it elsewhere — i.e. the multiplica- tions by rcmold or rcmnew in NoteCommitOrchard, by rcv in ValueCommitOrchard, by rivk in Commitivk, and by 𝛼 in SpendAuthSigOrchard.RandomizePublic. In particular, the representation of (PRFnfOrchardnk (ρ) +ψ) mod𝑞 P that is used for the scalar multiplication in DeriveNullifier MUSTbe checked to be canonical in order to avoid a potentialdouble-spendvulnerability, and similarly for the representation ofivkin[ivk]g oldd . Non-normative notes: • The procedure in §4.2.3 ‘Orchard Key Components’ on p. 40 will always produce aspend authorization address keythat effectively has the compressed 𝑦-coordinate, ˜𝑦, set to 0. TheAction statement, on the other hand, allows the prover to witness akP with ˜𝑦set to 0 or 1. This is harmless because if the prover and signer(s) of thespend authorization signaturecollectively know rsk and 𝛼, we can conclude that they collectively knowaskup to sign, which is sufficient for spend authorization. • There is intentionally no equivalent to the Ephemeral public key integrity check from the SaplingOutput statement. It is unnecessary for the sender of an Orchard-pool noteto prove knowledge of esk, because the potential attack this originally addressed for Saplingis prevented by checks added atCanopyactivation in [ZIP-212]. These checks are required after the end of the ZIP 212 grace period, which precedes NU5 activation. • If NoteCommitOrchard returns⊥ for the old or newnote, then the correspondingnote commitment integrity check is satisfied. Similarly, ifCommitivk returns⊥, then thediversified address integritycheck is satisfied. This models the fact that the implemented circuit uses incomplete point addition to computeSinsemillaHashToPoint. If an exceptional case were to occur, the prover could arbitrarily choose the intermediate𝜆 value in an addition, which must be assumed to allow them to control the output. (The formal output of SinsemillaHashToPoint is⊥ in such a case, while the output computed by the circuit would be nondeterministic.) But as proven in Theorem 5.4.4 on p. 87, these exceptional cases allow immediately finding a nontrivialdiscrete logarithm relation. If theDiscrete Logarithm Problemis hard on thePallas curve, then finding such a case is infeasible. 4.19 In-band secret distribution (Sprout) #sproutinband In Sprout, the secrets that need to be transmitted to a recipient of funds in order for them to later spend, arev, ρ, andrcm. Amemo field( §3.2.1 ‘Note Plaintexts and Memo Fields’ on p.16) is also transmitted. To transmit these secrets securely to a recipient without requiring anout-of-bandcommunication channel, the transmission key pkenc is used to encrypt them. The recipient’s possession of the associatedincoming viewing key ivkis used to reconstruct the originalnoteandmemo field. A singleephemeral public keyis shared between encryptions of the Nnew shielded outputsin aJoinSplit description. All of the resulting ciphertexts are combined to form atransmitted notes ciphertext. For both encryption and decryption, •letSymbe the scheme instantiated in §5.4.3 ‘Symmetric Encryption’ on p.91; •letKDF Sprout be theKey Derivation Functioninstantiated in §5.4.5.2 ‘Sprout Key Derivation’ on p.92; •letKA Sprout be thekey agreement schemeinstantiated in §5.4.5.1 ‘Sprout Key Agreement’ on p.91; •leth Sig be the value computed for thisJoinSplit descriptionin §4.3 ‘JoinSplit Descriptions’ on p.41. 68 4.19.1 Encryption (Sprout) #sproutencrypt LetKA Sprout be thekey agreement schemeinstantiated in §5.4.5.1 ‘Sprout Key Agreement’ on p.91. Letpk enc,1..Nnew be thetransmission keysfor the intended recipient addresses of each newnote. Letnp 1..Nnew beSprout-poolnote plaintextsdefined in §3.2.1 ‘Note Plaintexts and Memo Fields’ on p.16. Then to encrypt: •Generate a newKA Sprout (public, private) key pair(epk,esk). •For𝑖∈{1..N new}, –LetP enc𝑖 BY Y[585] be theraw encodingofnp 𝑖. –LetsharedSecret 𝑖 =KA Sprout.Agree(esk,pk enc,𝑖). –LetK enc𝑖 =KDF Sprout(𝑖,h Sig,sharedSecret 𝑖,epk,pk enc,𝑖). –LetC enc𝑖 =Sym.Encrypt Kenc𝑖 (Penc𝑖 ). The resultingtransmitted notes ciphertextis(epk,C enc1..Nnew). Note:It is technically possible to replace Cenc𝑖 for a givennotewith a random (and undecryptable) dummy ciphertext, relying instead onout-of-bandtransmission of thenoteto the recipient. In this case the ephemeral key MUSTstill be generated as a randompublic key(rather than a randombit sequence) to ensure indistinguishability from otherJoinSplit descriptions. This mode of operation raises further security considerations, for example of how to validate aSprout-poolnotereceivedout-of-band, which are not addressed in this document. 4.19.2 Decryption (Sprout) #sproutdecrypt Let ivk= (a pk,sk enc) be the recipient’sincoming viewing key, and let pkenc be the correspondingtransmission key derived fromsk enc as specified in §4.2.1 ‘Sprout Key Components’ on p.38. Letcm 1..Nnew be thenote commitmentsof each output coin. Then for each𝑖∈{1..N new}, the recipient will attempt to decrypt that ciphertext component(epk,C enc𝑖 )as follows: letsharedSecret 𝑖 =KA Sprout.Agree(skenc,epk) letK enc𝑖 =KDF Sprout(𝑖,h Sig,sharedSecret 𝑖,epk,pk enc) letP enc𝑖 =Sym.Decrypt Kenc𝑖 (Cenc𝑖 ) ifP enc𝑖 =⊥, return⊥ returnExtractNote Sprout(Penc𝑖 ,cm 𝑖,a pk). ExtractNoteSprout(Penc𝑖 BY Y[585],cm 𝑖 BY Y[32],a pk B[ℓSproutPRF ])is defined as follows: extract np𝑖 = (leadByte 𝑖 BY Y,v 𝑖 {0..2 ℓvalue−1},ρ 𝑖 B[ℓSproutPRF ],rcm 𝑖 NoteCommitSprout.Trapdoor,memo 𝑖 BY Y[512]) fromP enc𝑖 letn 𝑖 = (apk,v 𝑖,ρ 𝑖,rcm 𝑖) ifleadByte 𝑖̸= 0x00 orNoteCommitment Sprout(n𝑖)̸=cm 𝑖, return⊥ return(n 𝑖,memo 𝑖). 69 Notes: • The decryption algorithm corresponds to step 3 (b) i. and ii. (first bullet point) of the Receive algorithm shown in [BCGGMTV2014, Figure 2]. • To test whether anoteis unspent in a particularblock chainalso requires thespending key ask; the coin is unspent if and only ifnf=PRF nfSproutask (ρ)is not in thenullifier setfor thatblock chain. • Anotecan change from being unspent to spent as a node’s view of thebest valid block chainis extended by newtransactions. Also,block chain reorganizationscan cause a node to switch to a differentbest valid block chainthat does not contain thetransactionin which anotewas output. See §8.7 ‘In-band secret distribution’ on p. 153 for further discussion of the security and engineering rationale behind this encryption scheme. 4.20 In-band secret distribution (SaplingandOrchard) #saplingandorchardinband In Saplingand Orchard, the secrets that need to be transmitted to a recipient of anoteso that they can later spend it, ared,v, andrcmorrseed. Amemo field( §3.2.1 ‘Note Plaintexts and Memo Fields’ on p.16) is also transmitted. To transmit these secrets securely to a recipient without requiring anout-of-bandcommunication channel, the diversified transmission key pkd is used to encrypt them. The recipient’s possession of the associated KASapling or KAOrchard private keyivkis used to reconstruct the originalnoteandmemo field. Unlike in Sprout, eachSapling-poolorOrchard-pooloutputnoteis encrypted by a freshephemeral public key. For both encryption and decryption, •letℓ ovk be as defined in §5.3 ‘Constants’ on p.77; •letSymbe the encryption scheme instantiated in §5.4.3 ‘Symmetric Encryption’ on p.91; • let KA be thekey agreement scheme KASapling or KAOrchard instantiated in §5.4.5.3 ‘Sapling Key Agreement’ on p.92 or §5.4.5.5 ‘Orchard Key Agreement’ on p.93; • let KDF be theKey Derivation Function KDFSapling or KDFOrchardinstantiated in §5.4.5.4 ‘Sapling Key Derivation’ on p.92 or §5.4.5.6 ‘Orchard Key Derivation’ on p.93; • let G, ℓG, and reprG be instantiated as J, ℓJ, and reprJ defined in §5.4.9.3 ‘Jubjub’ on p. 105, or P, ℓP, and reprP defined in §5.4.9.6 ‘Pallas and Vesta’ on p.108; • let ExtractG(𝑟) be ExtractJ(𝑟) as defined in §5.4.9.4 ‘Coordinate Extractor for Jubjub’ on p. 107 or ExtractP as defined in §5.4.9.7 ‘Coordinate Extractor for Pallas’ on p.109; •letPRF ock bePRF ockSapling orPRF ockOrchard instantiated in §5.4.2 ‘Pseudo Random Functions’ on p.89; • let DiversifyHash be DiversifyHashSapling in §5.4.1.6 ‘DiversifyHashSapling andDiversifyHash Orchard Hash Functions’ on p.81, orDiversifyHash Orchard in the same section; • let NoteCommitmentbe NoteCommitmentSapling or NoteCommitmentOrcharddefined in §3.2.2 ‘Note Commitments’ on p.17; • let ToScalarbe ToScalarSapling defined in §4.2.2 ‘Sapling Key Components’ on p. 38 or ToScalarOrchard defined in §4.2.3 ‘Orchard Key Components’ on p.40; •LEBS2OSP , LEOS2IP, I2LEBSP, and I2LEOSP are defined in §5.1 ‘Integers, Bit Sequences, and Endianness’ on p.76. 4.20.1 Encryption (SaplingandOrchard) #saplingandorchardencrypt Let pkd KA.PublicPrimeOrder be thediversified transmission keyfor the intended recipient address of a new Sapling-pool or Orchard-pool note, and let gd KA.PublicPrimeOrder be the correspondingdiversified basecomputed asDiversifyHash(d). Since Saplingnoteencryption is used only in the context of §4.7.2 ‘Sending Notes (Sapling)’ on p. 47, and similarly Orchardnoteencryption is used only in the context of §4.7.3 ‘Sending Notes (Orchard)’ on p. 48, we may assume thatg d has already been calculated and is not⊥. Also, theephemeral private keyeskhas been chosen. 70 Let ovk BY Y[ℓovk/8]∪{⊥} be as described in §4.7.2 on p. 47 or §4.7.3 on p. 48, i.e. theoutgoing viewing keyof the shielded payment addressfrom which thenoteis being spent, or anoutgoing viewing keyassociated with a [ZIP-32] account, or⊥. Let np= (leadByte,d,v,rseed,memo) be the Saplingor Orchardnote plaintext. np is encoded as defined in §5.5 ‘Encodings of Note Plaintexts and Memo Fields’ on p.115. Let cv be thevalue commitmentfor theOutput descriptionorAction description(for Orchard, this also depends on the value of thenotebeing spent), and let cm be thenote commitment. These are needed to derive theoutgoing cipher keyockin order to produce theoutgoing ciphertextC out. Then to encrypt: letP enc be theraw encodingofnp letepk=KA.DerivePublic(esk,g d) let ephemeralKey =LEBS2OSP ℓG (︀ reprG(epk) )︀ letsharedSecret=KA.Agree(esk,pk d) letK enc =KDF(sharedSecret, ephemeralKey) letC enc =Sym.Encrypt Kenc(Penc) ifovk=⊥: choose randomock←R Sym.Kandop← R BY Y[(ℓG+256)/8] else: let cv =LEBS2OSP ℓG (︀ reprG(cv) )︀ let cm* =LEBS2OSP 256 (︀ ExtractG(𝑟)(cm) )︀ letock=PRF ockovk(cv, cm*, ephemeralKey) letop=LEBS2OSP ℓG+256 (︀ reprG(pkd)||I2LEBSP 256(esk) )︀ letC out =Sym.Encrypt ock(op) The resultingtransmitted note ciphertextis( ephemeralKey,C enc,C out). Note:It is technically possible to replace Cenc for a givennotewith a random (and undecryptable) dummy ciphertext, relying instead onout-of-bandtransmission of thenoteto the recipient. In this case the ephemeral key MUSTstill be generated as a randompublic key(rather than a randombit sequence) to ensure indistinguishability from otherOutput descriptions. This mode of operation raises further security considerations, for example of how to validate aSapling-poolorOrchard-poolnotereceivedout-of-band, which are not addressed in this document. 4.20.2 Decryption using an Incoming Viewing Key (SaplingandOrchard) #decryptivk Let ivk {1..2 ℓSaplingivk −1} (in Sapling) or{1.. 𝑞P−1} (in Orchard) be the recipient’s KASapling or KAOrchard private key, as specified in §4.2.2 ‘Sapling Key Components’ on p.38 or in §4.2.3 ‘Orchard Key Components’ on p.40. Let (ephemeralKey,C enc,C out) be thetransmitted note ciphertextfrom theOutput description. Let cm* be the cmu or cmx field of theOutput descriptionorAction descriptionrespectively. (This encodes theaffine-ctEdwards 𝑢-coordinate oraffine-short-Weierstrass𝑥-coordinate of thenote commitment, i.e.Extract G(𝑟)(cm).) LetpoolandallowedLeadBytesbe as defined in §3.2.1 ‘Note Plaintexts and Memo Fields’ on p.16. Let height be theblock heightof theblockcontaining thistransaction, and let txVersion be thetransaction version number. 71 The recipient will attempt to decrypt the ephemeralKey andC enc components of thetransmitted note ciphertext: letepk=abst G(ephemeralKey). ifepk=⊥, return⊥ letsharedSecret=KA.Agree(ivk,epk) letK enc =KDF(sharedSecret, ephemeralKey) letP enc =Sym.Decrypt Kenc(Cenc). ifP enc =⊥, return⊥ extractnp= (leadByte BY Y,d B[ℓd],v {0..2 ℓvalue−1},rseed BY Y[32],memo BY Y[512])fromP enc ifleadByte̸∈allowedLeadBytes pool(height,txVersion), return⊥ forpool=SaplingPool, letpre_rcm= [4]andpre_esk= [5] for pool=OrchardPool , let ρ =I2LEOSP 256 (︀ nfold from the sameAction description )︀, pre_rcm= [5]||ρ , and pre_esk= [4]||ρ letrcm= {︃ LEOS2IP256(rseed),ifleadByte= 0x01 ToScalar (︀ PRFexpandrseed (pre_rcm))︀,otherwise ifrcm≥𝑟 G, return⊥ letg d =DiversifyHash(d). if (forpool=SaplingPool)g d =⊥, return⊥ [Canopyonward] ifleadByte̸= 0x01: esk=ToScalar (︀ PRFexpandrseed (pre_esk))︀ ifrepr G (︀ KA.DerivePublic(esk,g d) )︀ ̸= ephemeralKey, return⊥ letpk d =KA.DerivePublic(ivk,g d) forpool=SaplingPool, letn= (d,pk d,v,rcm) forpool=OrchardPool, letn= (d,pk d,v,ρ,ψ,rcm)whereψ=ToBase Orchard(︀PRFexpandrseed ([9]||ρ ))︀ letcm′* =NoteCommitment(n). if (forpool=OrchardPool)cm ′* =⊥, return⊥ ifI2LEOSP 256 (︀ ExtractG(𝑟)(cm′*))︀̸= cm*, return⊥ return(n,memo). Notes: •g d has already been computed when applyingNoteCommitment, and need not be computed again. • For Sapling, as explained in the note in §5.4.9.3 ‘Jubjub’ on p. 105, abstJ acceptsnon-canonicalcompressed encodings ofJubjub curvepoints. Therefore, an implementationMUSTuse the original ephemeralKey field as encoded in thetransactionas input to KDFSapling, and (ifCanopyis active and leadByte̸= 0x01) in the comparison against reprG (︀ KA.DerivePublic(esk,g d) )︀ . For consistency this is also what is specified for Orchard. • Normally onlytransmitted note ciphertextsoftransactionsinblocksneed to be decrypted. In that case, any received Sapling-pool noteis necessarily apositioned note, so its ρ value can immediately be calculated per §4.16 ‘Computingρvalues and Nullifiers’ on p. 60. To test whether a Sapling-pool or Orchard-pool note is unspent in a particularblock chainalso requires thenullifier deriving key nk; the coin is unspent if and only if thenullifiercomputed as in §4.16 on p.60 is not in thenullifier setfor thatblock chain. • Anotecan change from being unspent to spent as a node’s view of thebest valid block chainis extended by newtransactions. Also,block chain reorganizationscan cause a node to switch to a differentbest valid block chainthat does not contain thetransactionin which anotewas output. • A clientMAYattempt to decrypt atransmitted note ciphertextof atransactionin themempool, using the nextblock heightfor height. However, in that case itMUST NOTassume that thetransactionwill be mined andMUSTtreat the decrypted information as provisional, and private. • [ NU5 onward] It is a consensus rule (in §4.6 ‘Action Descriptions’ on p. 44) that eachAction descriptionfield MUSTbe a valid encoding of its declared type, which in the case of ephemeralKey is KAOrchard.Public (i.e. P*), and thereforeepkcannot be𝒪 P. • [ 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. 72 4.20.3 Decryption using an Outgoing Viewing Key (SaplingandOrchard) #decryptovk Let ovk BY Y[ℓovk/8] be theoutgoing viewing key, as specified in §4.2.2 ‘Sapling Key Components’ on p. 38 or §4.2.3 ‘Orchard Key Components’ on p. 40, that is to be used for decryption. (If ovk=⊥ was used for encryption, the payment is not decryptable by this method.) Let the constantsCanopyActivationHeightandZIP212GracePeriodbe as defined in §5.3 ‘Constants’ on p.77. Let height be theblock heightof theblockcontaining thistransaction, and let txVersion be thetransaction version number. Let( ephemeralKey,C enc,C out)be thetransmitted note ciphertext. For a Saplingtransmitted note ciphertext, let cv and cm* be the cv and cmu fields of theOutput description. For an Orchardtransmitted note ciphertext, let cv and cm* be the cv and cmx fields of theAction description. Theoutgoing viewing keyholder will attempt to decrypt thetransmitted note ciphertextas follows: letock=PRF ockovk(cv, cm*, ephemeralKey) letop=Sym.Decrypt ock(Cout). ifop=⊥, return⊥ extract(pk⋆ d B[ℓG],esk BY Y[32])fromop letesk=LEOS2IP 256 (︀ esk )︀ andpk d =abst G(pk⋆d) ifesk≥𝑟 G orpk d =⊥, return⊥ ifrepr P (︀ pkd )︀ ̸=pk⋆ d, return⊥ letsharedSecret=KA.Agree(esk,pk d) letK enc =KDF(sharedSecret, ephemeralKey) letP enc =Sym.Decrypt Kenc(Cenc). ifP enc =⊥, return⊥ extractnp= (leadByte BY Y,d B[ℓd],v {0..2 ℓvalue−1},rseed BY Y[32],memo BY Y[512])fromP enc ifleadByte̸∈allowedLeadBytes pool(height,txVersion), return⊥ forpool=SaplingPool, letpre_rcm= [4]andpre_esk= [5] for pool=OrchardPool , let ρ =I2LEOSP 256 (︀ nfold from the sameAction description )︀, pre_rcm= [5]||ρ , and pre_esk= [4]||ρ [Canopyonward] ifleadByte̸= 0x01 andToScalar (︀ PRFexpandrseed (pre_esk))︀̸=esk, return⊥ letrcm= {︃ LEOS2IP256(rseed),ifleadByte= 0x01 ToScalar (︀ PRFexpandrseed (pre_rcm))︀,otherwise ifrcm≥𝑟 G, return⊥ letg d =DiversifyHash(d). if (forpool=SaplingPool)g d =⊥orpk d̸∈J (𝑟)* (see note below), return⊥ forpool=SaplingPool, letn= (d,pk d,v,rcm) forpool=OrchardPool, letn= (d,pk d,v,ρ,ψ,rcm)whereψ=ToBase Orchard(︀PRFexpandrseed ([9]||ρ ))︀ letcm′* =NoteCommitment(n). if (forpool=OrchardPool)cm ′* =⊥, return⊥ ifI2LEOSP 256 (︀ ExtractG(𝑟)(cm′*))︀̸= cm*, return⊥ ifrepr G (︀ KA.DerivePublic(esk,g d) )︀ ̸= ephemeralKey, return⊥ return(n,memo). 73 Notes: •g d has already been computed when applyingNoteCommitment, and need not be
프로젝트로 돌아가기