Halo2学习笔记——基本概念(1)

1. 引言

Halo2 book 为 ZCash实现的halo2方案。

相关术语定义遵循 ZKProof Community Reference

本博客重点关注Halo2中各个基本概念的定义。

2. Proof system定义

任何proof system的目的都是能证明有趣的数学或密码学statements。

通常,需要基于public inputs,证明Prover确实知道某些private inputs,使得该statements成立。

使用relation R \mathcal{R} R ,其指定了public和private inputs的哪些组合是有效的。

为了区分不同的relation R \mathcal{R} R 及其实现,定义了circuit。

针对特定proof system定义的circuit language可表述为arithmetization。
arithmetization将使用polynomial constraints on variables over a field来定义circuit。

为了创建a proof of a statement,Prover需知道the private inputs以及相应的中间值,中间值也称为advice values。private inputs 和advice values都将用于circuit中。

假设我们可根据private和public inputs高效计算出advice values。特定的advice values将取决于实现circuit的方式,而不仅仅取决于high-level statement。

private inputs和advice values都统称为witness。

假设为了证明知道a preimage x x x of a hash function H H H for a digest y y y

  • private input:preimage x x x
  • public input:digest y y y
  • relation: { ( x , y ) : H ( x ) = y } \{(x,y): H(x)=y\} {(x,y):H(x)=y}
  • 对于某一特定的public input Y Y Y,其statement可为: { ( x ) : H ( x ) = Y } \{(x):H(x)=Y\} {(x):H(x)=Y}
  • advice values:为在hash function circuit实现过程中的所有中间值。
  • witness:为private input x x x和所有advice values。

Non-interactive Argument是指:Prover create a proof for a given statement and witness。
所谓proof是指:用于convince a Verifier that there exists a witness for which the statement holds的data。
所谓soundness是指:the security property that such proofs cannot falsely convince a Verifier。

Non-interactive Argument of Knowledge (NARK) 在Non-interactive Argument的基础上进一步:convince the Verifier that the Prover knew a witness for which the statement holds。对应的security property称为knowledge soundness,即意味着soundness。

事实上,在密码学协议中,knowledge soundness比 soundness 更实用:如,在某协议中,若感兴趣Alice是否hold a secret key,即意味着,需Alice证明其know the key,而不仅仅是存在该key。

knowledge soundness可表述为:
存在an extractor,其可observe precisely how the proof is generated, 从而必须能compute the witness。

可能会有如下缺陷:

  • 1)malleability:即根据已有proof,在不知道witness的前提下,修改出的不同proof仍能证明相同或相关的statement。
  • 2)replay:若Alice给了一个由别人生成的proof,不应判定为Alice知道相应的key。

若proof中不会泄露任何关于witness(除了知道该witness确实存在且仅Prover知道)的信息,则可称该proof system为zero knowledge的。
若proof的size很短(即为circuit size的polylog),则可称该proof system为succinct的。
succinct NARK称为SNARK(Succinct Non-interactive Argument of Knowledge)。

根据以上SNARK定义可知,SNARK不要求verification time为circuit size的polylog。有些论文会以“efficient”术语来表示SNARK的verification time为ploylog of circuit size。但是在Halo2中,将避免使用该术语,因为会与支持amortized或recursive verification SNARK 混淆。

zk-SNARK是指:zero-knowledge SNARK。

3. PLONKish Arithmetization

Halo2中的arithmetization采用的是PLONK,或更准确地说是基于扩展的UltraPLONK。
UltraPLONK支持 custom gates和lookup argument,此处成为其为PLONKish。

PLONKish circuit由一系列矩阵值表示,其中的rows, columns和cells与传统的矩阵定义是一致的。

PLONKish circuit取决于a configuration:

  • 1)有限域 F \mathbb{F} F,对于特定的statement和witness,矩阵中的cell values为有限域值。
  • 2)fixed columns是指fixed by the circuit;advice columns对应witness values;instance columns正常用于public inputs(技术上来说,可用于表示Prover与Verifier之间共享的任意elements)。columns的subset可参加equality constraints。
  • 3)需定义a polynomial degree bound。对于a sequence of polynomial constraints,multivariate polynomials over F \mathbb{F} F 必须在每行都evaluate to zero。polynomial constraint中的variables可指向当前行中特定列的一个cell,或者指向a given column of another row relative to this one (with wrap-around, 即taken modulo n n n)。每个polynomial的maximum degree由其polynomial degree bound定义。
  • 4)会根据tuples of input expressions (which are multivariate polynomials as above) and table columns来构建a sequence lookup arguments。
  • 5)定义矩阵的行数 n n n n n n必须对应the size of a multiplicative subgroup of F × \mathbb{F}^{\times} F×,通常为a power of two。
  • 6)equality constraints用于表示:two given cells must have equal values。
  • 7)定义the values of the fixed columns at each row。
  • 8)可通过fixed columons中定义的selectors来控制polynomial constraints的开关。如,a constraint q i ⋅ p ( ⋯   ) = 0 q_i\cdot p(\cdots)=0 qip()=0可通过设置 q i = 0 q_i=0 qi=0来关闭特定行 i i i的约束。有时,会将由a set of selector columns控制的a set of constraints定义为gate。通常,standard gate支持generic operations like field multiplication and division,而custom gates支持更特殊的操作。

根据circuit description,可生成a proving key和a verification key,分别用于prove和verify环节。

4. Chips

第2和第3节都是low-level description of a circuit。实际实现时,为了auditability, efficiency, modularity和expressiveness,会封装higher-level API——借助Chips,内部提供pre-built implementations of particular functionality。

可具有如下功能的chips:

  • 实现了hash function的chip
  • 实现了cipher的chip
  • 实现了scalar multiplication的chip
  • 实现了pairing的chip

在UPA中,可基于具有field multiplication和filed addition的standard gates实现任意的逻辑。但是,借助custom gate效率可能会更优。

在Halo2中,chips “know” how to use particular sets of custom gates。从而实现了抽象层,隔离了直接使用custom gates的复杂性。

有时,会同时实现high-level circuit和chips,这样便于理解、审计、维护以及复用。

UPA中的gates通过relative references指向cells,即指向the cell in a given column 并 指向 the row at a given offset relative to the one in which the gate’s selector is set。若offset 为非零值,则可称为offset reference(即offset reference 为 relative reference的子集)。

与relative reference对应的是absolute reference,absolute reference用于equality constraints,可point to any cell。

offset reference的主要目的是减少configuration中的column的数量,从而进一步减少proof size。若没有offset reference,需要有单独的一列来hold each value referred to by a custom gate,同时需要使用equality constraints来copy values from other cells of the circuit into that column。使用offset reference,不仅需要更少的columns,而且不再需要equality constraints来支持这些 columns,从而提升了效率。

在R1CS中,circuit中包含了a “sea of gates” with no semantically significant ordering。因为有 offset references,UPA circuit中的rows是有顺序的,便于在gadget level层构建circuit时,无需直接处理relative references或gate layout。

可将circuit切分为regions,在每个region都包含了a disjoint subset of cells,且relative references only ever point within a region。
chip实现的一部分职责是保证gates that make offset references are laid out in the correct positions in a region。

根据多个regions及其shapes,可使用不同的floor planner来决定各个region的位置。有一个default floor planner实现了通用算法,但是你可根据需要编写自己的floor planner。

floor planning会在matrix中留下空白,因为the gate in a given row did not use all available columns。这些空白可填充对位置无要求的gates,如gates that do not require offset references。

Chips也可以定义lookup tables,若有more than one table is defined for the same lookup argument,可使用tag column来表明which table is used on each row。同时,也可以实现lookup in the union of several tables(limited by the polynomial degree bound)。

为何combine多个chips的functionality,可将其组合为a tree。The top-level chip定义了a set of fixed, advice, and instance columns,然后明确规定了how they should be distributed between lower-level chips。

最简单的情况是,每个lower-level chips将使用columns disjoint from the other chips。但是,也允许在chips之间共享a column。对advice columns数量的优化尤其重要,因为这将影响proof size。

经过优化后的最终结果为a UPA configuration。circuit implementation将parameterized on a chip,且可use any features of the supported lower-level chips via the top-level chip。

希望,经验不足的用户可找到现有的chip来满足其希望的操作,或者仅需要对现有的chip做一点小小的改动。而专业的用户完全可控制进行circuit优化。

5. Gadgets

当实现circuit时,可直接使用所选择的chips的features。但是,通常会借助gadgets。这种间接方法很有用,因为出于效率和UPA施加的限制,芯片接口通常依赖于low-level实现细节。gadget接口可以提供一个更方便、更稳定的API,它可以从无关的细节中抽象出来。

比如,以SHA-256 hash函数为例,支持SHA-256的chip 节点需依赖内部设计的hash函数,如message schedule和 compression function之间的隔离。而相应的gadget接口,可提供更方便更熟悉的update/finalize API,也可以hash函数中不需要chip支持的部分,如padding。这类似于CPU上cryptographic primitives的加速指令通常通过软件库而不是直接访问的方式。

同时,Gadgets可为circuit编程提供更高level的模块化和可复用抽象,类似于使用libsnark库bellman库
除了有抽象函数,还有抽象类型,如elliptic curve points或integers of specific sizes。

参考资料

[1] Halo2 book

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值