1. 引言

本文主要关注Sapling note。

Zcash中Sapling note以n\mathbf{n}n表示,其代表a value vvv is spendable by the recipient who holds the spending key corresponding to a given shielded payment address。

1.1 相关约定

  • MAX_MONEY\text{MAX\_MONEY}MAX_MONEY:为2.1∗10152.1*10^{15}2.1∗1015 (zatoshi)
  • lPRFnfSaplingl_{PRFnfSapling}lPRFnfSapling​:为256。
  • ldl_dld​: 为88。
  • NoteCommitSaplingNoteCommit^{Sapling}NoteCommitSapling:为Windowed Pedersen commitment。
  • KASaplingKA^{Sapling}KASapling:为Sapling Key Agreement。
  • DiversifyHashSaplingDiversifyHash^{Sapling}DiversifyHashSapling:为Hash Function。
  • lvaluel_{value}lvalue​:为64。
  • lMerkleSaplingl_{Merkle}^{Sapling}lMerkleSapling​:为255。

2. Sapling note

Sapling note的组成为tuple n=(d,pkd,v,rcm)\mathbf{n}=(d, pk_d, v, rcm)n=(d,pkd​,v,rcm),其中:

  • ddd:为接收方的shielded payment address对应的diversifier值。【为88bit,B[ld]\mathbb{B}^{[l_d]}B[ld​]】
  • pkdpk_dpkd​:为接收方的shielded payment address对应的diversified transmission key。【为Jubjub point,KASapling.PublicPrimeSubgroupKA^{Sapling}.PublicPrimeSubgroupKASapling.PublicPrimeSubgroup】
  • vvv:取值范围为MAX_MONEY\text{MAX\_MONEY}MAX_MONEY,代表note中的value值,单位为zatoshi。
  • rcmrcmrcm:为random commitment trapdoor。【NoteCommitSapling.TrapdoorNoteCommit^{Sapling}.TrapdoorNoteCommitSapling.Trapdoor】

可将a Sapling note表示为 NoteSaplingNote^{Sapling}NoteSapling:
NoteSapling=B[ld]×KASapling.PublicPrimeSubgroup×MAX_MONEY×NoteCommitSapling.TrapdoorNote^{Sapling}=\mathbb{B}^{[l_d]}\times KA^{Sapling}.PublicPrimeSubgroup\times \text{MAX\_MONEY}\times NoteCommit^{Sapling}.TrapdoorNoteSapling=B[ld​]×KASapling.PublicPrimeSubgroup×MAX_MONEY×NoteCommitSapling.Trapdoor

可通过”Sending Notes“来创建新的note,当note已发送,仅对以上值的commitment会对外公开,同时增加一个叫做”note commitment tree“的data structure。而具体的value值和接收方可继续保密,当需要spend the note时,仅需在zk-SNARK proof中使用该commitment值,来验证该note确实存在于链上。

对n=(d,pkd,v,rcm)\mathbf{n}=(d, pk_d, v, rcm)n=(d,pkd​,v,rcm) Sapling note的commit计算方式为:

  • gd=DiversifyHashSapling(d)g_d=DiversifyHash^{Sapling}(d)gd​=DiversifyHashSapling(d)
  • 若gdg_dgd​为无效point,则返回⊥\perp⊥;否则返回NoteCommitrcmSapling(reprJ(gd),reprJ(pkd),v)NoteCommit_{rcm}^{Sapling}(repr_{\mathbb{J}}(g_d),repr_{\mathbb{J}}(pk_d),v)NoteCommitrcmSapling​(reprJ​(gd​),reprJ​(pkd​),v)

注意Sapling note中并不包含ρ\rhoρ元素,若已知该note在note commitment tree中的位置,可计算出相应的ρ\rhoρ值。已知note position pospospos 的Sapling note可称为 positioned note。

note的nullifier可表示为nfnfnf。
Sapling note的nullifier值可根据 ρ\rhoρ值和接收方的nullifier deriving key nknknk 计算获得。

在nullifier 的计算过程中,会用到Pseudo Random Function。

Sapling note spent的过程为:

  • 对外公开spent note对应的nullifier nfnfnf值,nfnfnf值可用于防止双花;
  • prove knowledge of (ρ,ak,nsk)(\rho, ak,nsk)(ρ,ak,nsk) in zero knowledge;
  • 额外还需要a spend authorization signature,用于证明knowledge of askaskask。

2.1 Sapling note plaintext and memo field

区块链上的transmitted notes是以密文形式存储,同时附加有该note的commitment cmcmcm值。

Sapling note plaintext可表示为np\mathbf{np}np,其组成有:
(leadByte:BY,d:B[ld],v:{0..2lvalue−1},memo:BY[512])(leadByte:\mathbb{B}^{\mathbb{Y}}, d:\mathbb{B}^{[l_d]},v:\{0..2^{l_{value}}-1\}, memo:\mathbb{B}^{\mathbb{Y}^{[512]}})(leadByte:BY,d:B[ld​],v:{0..2lvalue​−1},memo:BY[512])

其中d,vd,vd,v的含义同上,memomemomemo为与该note关联的512字节的memo field。
The usage of the memomemomemo field is by agreement between the sender and recipient of the note。

  • JoinSplit description中:采用相应的transmission keys pkenc,1..Nnewnewpk_{enc,1..N^{new}}^{new}pkenc,1..Nnewnew​ 来对note plaintext进行加密。
  • Output description中:采用diversified payment address (d,pkd)(d,pk_d)(d,pkd​) 来对note plaintext进行加密。

3. Zcash区块链

在特定时间,每一个full validator都会感知到a set of candidate blocks。这些候选区块以tree的形式存在,该tree的root根为genesis block。tree中的每个节点都通过区块头中的”hashPrevBlock“ field来指向其父节点。
tree中,由根节点到某叶子节点的路径中包含了一个或多个符合共识规则的区块,该路径称为valid block chain。

区块链中的每个区块都有相应的block height。genesis block的区块高度为0,后续区块的区块高度依次加1。

为了从整个block tree中选择best valid block chain,区块链节点会对每一个valid block chain中的work求和,并认为work值最大的路径为the best valid block chain。为了断开leaf block之间的关系,区块链节点会优先选择其先收到的区块。

所谓共识协议,是用于保证在任意区块高度,绝大多数的区块链节点都对到那高度的best valid block chain 达成共识。

3.1 Zcash区块链交易及treestate

每个区块包含1笔或多笔交易。

交易中的transparent inputs值会插入到交易对应的”transparent transaction value pool“中,而transparent outputs会将相应的值从该pool中移除。在Bitcoin中,pool中剩余的值则作为矿工的费用。同时要求pool中剩余的值必须为非负数。

Sapling中,每笔交易都有相应的initial treestates,每个treestate包含有:

  • a note commitment tree
  • a nullifier set

UTXO (Unspent Transaction Output) validate state 针对的是transaprent inputs and outputs。

note commitment tree的Merkle tree root称为anchor。根据该Merkle tree hash function的安全假设属性,anchor可唯一确定该note commitment tree的state。
由于nullifier set总是和note commitment tree同步更新,anchor也可标识所关联nullifier set的特定状态。

Sapling区块链中,treestates的链接方式为:

  • 第一个区块的input treestate为空;
  • 区块中第一笔交易的input treestate为前一区块的final treestate;
  • 同一区块中(除第一笔交易外)的每一笔交易的input treestate为前一笔交易的output treestate。
  • 区块的final treestate为其最后一笔交易的output treestate。

Sprout中的JoinSplit description存在interstitial input and output treestate,而Sapling中,不存在interstitial treestate。

JoinSplit transfer中不会用到Sapling notes。

Zcash中设计为:

  • 对于每个shielded input,有单独的Spend transfer;【交易中Spend transfer相关数据为Spend description】
  • 对于每个shielded output,有单独的Output transfer。【交易中Output transfer相关数据为Output description】

每笔交易中包含了一系列的Spend descriptions 和 一系列的Output descriptions。

  • Spend transfer
    Spend transfer 花费 note nold\mathbf{n}^{old}nold,其Spend description中包含了 a Pedersen value commitment to the value of the note。其与an instance of a Spend statement关联,会提供a zk-SNARK proof。

  • Output transfer
    Output transfer 创建 note nnew\mathbf{n}^{new}nnew,其Output description中包含了 a Pedersen value commitment to the value of the note。其与an instance of a Output statement关联,会提供a zk-SNARK proof。

3.2 Note commitment tree


note commitment tree为具有固定depth的incremental Merkle tree,其用于存储由JoinSplit transfer或Spend transfer产生的note commitments。

note commitment tree 与 Bitcoin中的unspent transaction output set (UTXO set) 的相同之处在于:

  • 都可以express the existence of value and the capability to spend it。

note commitment tree 与 Bitcoin中的unspent transaction output set (UTXO set) 的不同之处在于:

  • note commitment tree为append-only的,无法用其来防止双花。

note commitment tree的root 与 每个treestate 关联。

该incremental Merkle tree中的每个节点都与一个hash值关联,该hash值的长度为255-bit。

令root在0层,则在第hhh层,有2h2^h2h个节点,编号为0~2h−12^h-12h−1。将hhh层iii节点对应的hash值表示为MihM_i^hMih​。

所谓note position,是指:
the index of a note’s commitment at the leafmost layer。

3.3 Nullifier set

每个full validator都维护了a nullifier set logically associated with each treestate。
由于valid transaction中可包含JoinSplit transfer或Spend transfer,则相应JoinSplit description或Spend description中的nullifier值会插入到与new treestate 相关的 nullifier set中。

为了防止双花,valid block chain中的nullifier值被强制要求为唯一的。

valid block chain中,同一交易内和跨交易的nullifier值都必须为不重复的。Sprout nullifier和Sapling nullifier尽管二者具有相同的bit pattern,但是可认为二者是不相交的。

3.4 区块奖励,funding streams and founders’ reward

与Bitcoin类似,Zcash也是通过挖区块来铸币,挖区块所创造的值称为区块奖励。
与Bitcoin类似,区块矿工可获得交易费用。

区块奖励,矿工奖励,Founders’ Reward以及funding streams的计算依赖于区块高度。

3.5 coinbase transaction

区块中的第一笔交易称为coinbase transaction。
coinbase transaction会collects and spends any miner subsidy and transaction fees paid by transactions included in this block。

3.6 Zcash的主网和测试网

Zcash protocol 由Electric Coin Company和Zcash Foundation共同管理。

Zcash主网Mainnet的token为ZEC,测试网Testnet的token为TAZ。1ZEC=108zatoshi,1TAZ=108zatoshi1\ ZEC=10^8\ zatoshi,1\ TAZ=10^8\ zatoshi1 ZEC=108 zatoshi,1 TAZ=108 zatoshi

本节所有的区块hash值都以RPC byte order形式表示(为byte-reversed relative to the normal order for a SHA-256 hash)。
主网Mainnet的genesis block hash值为:00040fe8ec8471911baa1db1266ea15dd06b4a8a5c453883c000b031973dce08
测试网Testnet的genesis block hash值为:
05a60a92d99d85997cce3b87616c089f6124d7342af37106edc76126334a2c38

4. Sending notes (Sapling)

为了send Sapling shielded value,sender需在交易中构建一个或多个 Output description。

令ovkovkovk为可用于decrypt 该payment的outgoing viewing key,ovkovkovk的取值可为以下之一:

  • payment发送方(或发送方之一)的outgoing viewing key;
  • the outgoing viewing key for all payments associated with an “account”,具体见ZIP-32中定义。
  • 为⊥\perp⊥,if the sender should not be able to decrypt the payment once it has deleted its own copy。

相比于comprise of its own secrets,若sender想要具有forward secrecy of the payment information,可选择ovkovkovk为⊥\perp⊥。

sender为每个Output description选择a value v:{0..MAX_MONEY}v:\{0..\text{MAX\_MONEY}\}v:{0..MAX_MONEY} 和 a destination Sapling shielded payment address (d,pkd)(d,pk_d)(d,pkd​),然后执行以下操作:

  • 1)check pkdpk_dpkd​为KASapling.PublicPrimeSubgroupKA^{Sapling}.PublicPrimeSubgroupKASapling.PublicPrimeSubgroup类型,即pkdpk_dpkd​必须为Jubjub curve上一个有效的ctEdwards curve point,且[rJ]pkd=OJ[r_{\mathbb{J}}]pk_d=\mathcal{O}_{\mathbb{J}}[rJ​]pkd​=OJ​。

  • 2)计算gd=DiversifyHashSapling(d)g_d=DiversifyHash^{Sapling}(d)gd​=DiversifyHashSapling(d),并验证gdg_dgd​不为⊥\perp⊥。

  • 3)选择uniformly random commitment trapdoor rcv←RValueCommitSapling.GenTrapdoor()rcv\leftarrow_R ValueCommit^{Sapling}.GenTrapdoor()rcv←R​ValueCommitSapling.GenTrapdoor()

  • 4)选择uniformly random ephemeral private key esk←RKASapling.Private∖{0}esk\leftarrow_R KA^{Sapling}.Private\setminus\{0\}esk←R​KASapling.Private∖{0}

  • 5)计算cv=ValueCommitrcvSapling(v)cv=ValueCommit_{rcv}^{Sapling}(v)cv=ValueCommitrcvSapling​(v)

  • 6)计算cm=NoteCommitrcmSapling(reprJ(gd),reprJ(pkd),v)cm=NoteCommit_{rcm}^{Sapling}(repr_{\mathbb{J}}(g_d),repr_{\mathbb{J}}(pk_d),v)cm=NoteCommitrcmSapling​(reprJ​(gd​),reprJ​(pkd​),v)

  • 7)令np=(leadByte,d,v,memo)\mathbf{np}=(leadByte,d,v,memo)np=(leadByte,d,v,memo),分别用接收方的diversified transmission key pkdpk_dpkd​、outgoing viewing key ovkovkovk对np\mathbf{np}np进行加密,并用diversified base gdg_dgd​根据eskeskesk计算epkepkepk,最终输出transmitted note ciphertext (epk,Cenc,Cout)(epk, C^{enc}, C^{out})(epk,Cenc,Cout)。具体可参见”Encryption (Sapling)“ 章节内容,也可以根据cv,cmucv,cmucv,cmu来计算ockockock,然后以eskeskesk为输入进行加密。【cmucmucmu为Output description中的cmucm_ucmu​ field。】
    【 详细的加解密流程可参看博客 Zcash中的加解密机制 】

  • 8)为Output statement生成proof πZKOutput\pi_{ZKOutput}πZKOutput​。

  • 10)最终sending note流程的输出为(cv,cm,epk,Cenc,Cout,πZKOutput)(cv,cm,epk,C^{enc}, C^{out},\pi_{ZKOutput})(cv,cm,epk,Cenc,Cout,πZKOutput​)。

为了减少信息泄露,sender应随机打乱 交易中的Output descriptions的顺序。

最终,the encoded transaction会提交到peer-to-peer网络。

Sapling中没必要使用Dummy notes。

一笔交易中可以有1个或多个JoinSplit descriptions或Spend descriptions。当进入到区块链中,会将所有的候选constituent note commitments添加到note commitment tree中。所有的constituent nullifiers也会进入到关联的treestate的nullifier set中。若某nullifier在nullifier set中已存在,则该nullifier不允许添加,且可判定该交易为not valid的。

在Sapling中,每个positioned note有关联的ρ\rhoρ值,该ρ\rhoρ值可根据note commitment cmcmcm 和 note position pospospos计算出来:
ρ=MixingPedersenHash(cm,pos)\rho = MixingPedersenHash(cm,pos)ρ=MixingPedersenHash(cm,pos)

对于Sapling note,其nullifier nfnfnf 可derived as PRFnk⋆nfSapling(ρ⋆)PRF_{nk\star}^{nfSapling}(\rho\star)PRFnk⋆nfSapling​(ρ⋆),其中nk⋆nk\starnk⋆代表与note关联的nullifier deriving key,ρ⋆=reprJ(ρ)\rho\star=repr_{\mathbb{J}}(\rho)ρ⋆=reprJ​(ρ)。

Security requirement:对于每一个shielded protocol,对nullifier derivation的要求如下:

  • derived 必须由note的fields完全确定,由其position可能确定。使得其可被checked in the corresponding statement that controls spends。(即JoinSplit statement,或Spend statement)
  • 已假设ρ\rhoρ值为唯一的,则要求generate two notes with distinct note commitments but the same nullifier是不可能的。
  • 给定一组未知notes的nullifiers set,无法以多于随机的概率来将note和nullifier值关联,甚至于adversary知道相应的incoming viewing keys(而不是full viewing keys) 的情况下也无法确定相应的关联关系,甚至于其中的某些notes是由adversary创建的。

参考资料

[1] Zcash Protocol Specification

Zcash中的Notes相关推荐

  1. Zcash中的加解密机制

    1. 引言 接前序博客 Zcash中的Notes. Sapling note的组成为tuple n=(d,pkd,v,rcm)\mathbf{n}=(d, pk_d, v, rcm)n=(d,pkd​ ...

  2. Zcash中的signatures

    1. 引言 在 Zcash Protocol Specification 中,约定对signature是"validate",对zk-SNARK proof是"verif ...

  3. Zcash中的description

    1. 引言 Zcash 中支持的description类型有: JoinSplit description Spend description Output description JoinSplit ...

  4. Zcash中的keys和addresses

    1. 引言 [还有个ockockock:outgoing cipher key,用于encrypt an outgoing ciphertext.] 在Zcash协议中,用户若想接收shielded ...

  5. Zcash中的zk-SNARK statements

    1. 引言 zero-knowledge proving system为a cryptographic protocol,用于证明: a particular statement,dependent ...

  6. 在Domino上部署运行在Web浏览器中的Notes客户机

    大家好,才是真的好. 一个月没见,有没有分外想念?今年夏天是真热,好歹熬过来了,而且幼儿园陆续开学,所以我又回来了. 是真的,直接在Domino中支持运行在Web中的Notes客户机(即Nomad W ...

  7. Zcash中的hash函数

    1. 引言 Zcash中的hash函数主要有: BLAKE2 Hash Function Group Hash into Jubjub Pedersen Hash Function Mixing Pe ...

  8. ios 开发账号 退出协作_如何在iOS 10中的Notes上进行协作

    ios 开发账号 退出协作 iOS' Notes app provides a convenient way to remember the great ideas you come up with ...

  9. 端口映射/dmz主机_在DMZ中使用Notes / Domino SMTP

    端口映射/dmz主机 在本系列文章的第1部分中,我们开始了关于如何配置Lotus Notes / Domino以通过DMZ路由SMTP邮件的讨论. 我们将在第2部分中继续这个主题,详细研究如何在DMZ ...

最新文章

  1. 浅析TCP之SACK(选择性确认)
  2. 百度关闭新闻源背后的13个趋势风口
  3. Ubuntu 安装配置NFS网络文件系统服务器
  4. 文本框内容改变触发事件
  5. 【kafka】Replication factor: 1 larger than available brokers:0
  6. java正则学习笔记
  7. Kubernetes 小白学习笔记(5)--Kubernetes集群的部署service、部署deployment、自动负载均衡、自动伸缩、版本升级、版本回退
  8. storm流式处理框架
  9. 云钉一体,支撑5亿用户1900万企业背后的技术复盘
  10. 使用SecretScanner发现容器镜像和文件系统中的敏感数据
  11. 全国火车高铁站及车次数据爬虫(内含100W+数据)
  12. 台式计算机按住开关风扇才能转,台式机风扇转但不开机的解决方法
  13. Win10的Git中文文件名繁体火星文乱码问题
  14. 操作系统实验3—实现请求页式存储管理模拟程序
  15. cgb2007-京淘day05
  16. kali2022.1安装google chrome develop 专业版
  17. 华为鸿蒙魔法闪投大小屏幕互动,「老熊科普」魔法闪投,荣耀智慧屏就是你的“超级大手机”...
  18. 山东省计算机应用能力考核初级,山东省计算机应用能力考核1.doc
  19. 解决IDEA Warning: Class ‘XXX‘ not found in module ‘XXX‘
  20. Windows下strongswan-5.5.3源码安装

热门文章

  1. 7月16日周二晚上,陈勇,【敏捷网络课堂第六期】【免费】敏捷开发早期估算...
  2. VueCli脚手架的使用详解
  3. 架构师教大家如何用SpringBoot技术快速实现天气预报系统
  4. 苹果x怎么关机_苹果12怎么关机 iPhone12关机方法汇总
  5. DeepMind「通才」AI智能体Gato来了,多模态、多任务,受大语言模型启发
  6. JavaWeb学习第二十七天——项目实例
  7. 深入理解vue中的slot与slot-scope (简单易懂)
  8. 基于WEB的网上在线图书商城的设计与实现
  9. 对电脑十分有用的100招。
  10. ESM测向误差对定位误差的影响分析