您当前的位置: 首页 > 

mutourend

暂无认证

  • 2浏览

    0关注

    661博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

appliedzkp的zkevm(2)Bus mapping

mutourend 发布时间:2021-08-11 18:41:26 ,浏览量:2

1. 引言

state proof和EVM proof之间需要通信,需借助某种accumulator来实现。 若使用Merkle tree的话,需为每个opcode额外增加1000个constraints。 因此,zkevm中选用了bus mapping ——》a plookup key value mapping。

为VM构建snark的难点之一是:需要能随时读随机值或随机opcode。因此,为了解决该问题,需要使用key-value mappings。key value mappings为basically random linear combination of all elements。

2. plookup key-value mappings

在plookup中,可按如下方式构建key-value mappings:

def build_mapping():
    keys = [1,3,5]
    values = [2,4,6]
 
    randomness = hash(keys, values)
    
    mappings = []

    for key , value in zip(keys,values):
        mappings.append(key + randomness*value)
    return(mappings)

相应的open cost为3个plookups:

def open_mapping(mappings, keys, values):
    randomness = hash(keys,values)
    index = 1
    # Prover can chose any mapping, key , value
    mapping = plookup(mappings)
    key = plookup(keys)
    value = plookup(values)
    # But it has to satisfy this check
    require(mappings[index] == key[index] + randomness*value[index])
    # with overwhelming probablitiy will not find an invalid mapping.
3. Bus mapping
bus_mapping[global_counter] = {
    type_flag = ["stack", "memory", "storage"], 
    rw_flag,
    key, 
    value, 
    index: opcode,
    call_id: call_id,
    prog_counter: prog_counter
}

该bus mapping为Prover的witness。在EVM proof中,需确保Prover不会包含额外的变量。为此,需限制L1 EVM中的degree,同时在EVM proof中对每个单独的element进行检查。

对该bus mapping的commitment值为state proof和EVM proof的public input。

会将state proof中variables的commitments发送给evm proof。

bus mapping更低的degree意味着可同时verify更多的op。目前有四种设计方案,具体采用哪种会根据实际实现的evm circuit进行优化。【同时,下述方案中的compress可去除,因为 halo2 中已做了相应实现。】

3.1 bus mapping方案一

为evm circuit引入2个bus mapping entry:

  • DUP2.READ
  • DUP2.WRITE

在这里插入图片描述

3.2 bus mapping方案二

在方案一的基础上,额外引入了witness comp,使得只需要一个bus mapping entry。 由于无法对图中绿色box进行partial lookup,因此DUP2.WRITE无法保证DUP2.READ存在。 在这里插入图片描述

3.3 bus mapping方案三

在方案二的基础上增加了 inner bus mapping来支持partial bus mapping lookup。 在DUP2.WRITE row,若其lookup发现黄色box存在,则同时lookup绿色box,lookup方式为: 蓝 色 b o x + ( 黄 色 b o x − g c ⋅ r ) ⋅ r 3 蓝色box + (黄色box - gc \cdot r)\cdot r^3 蓝色box+(黄色box−gc⋅r)⋅r3。 在这里插入图片描述

3.4 bus mapping方案四

在方案三的基础上,去掉comp witness。因为可要求DUP2.WRITE知道其write操作。所以第一个lookup对应为 ( g c , k e y + 2 , v a l , R E A D ) (gc, key+2, val, READ) (gc,key+2,val,READ),第二个lookup同方案三。 在这里插入图片描述

参考资料

[1] https://hackmd.io/HfCsKWfWRT-B_k5j3LjIVw [2] https://hackmd.io/AmhZ2ryITxicmhYFyQ0DEw

关注
打赏
1664532908
查看更多评论
立即登录/注册

微信扫码登录

0.0385s