以太坊matter-labs bellman代码解析

1. 引言

前序博客有:

以太坊matter-labs bellman代码仓库为:

  • https://github.com/matter-labs/bellman

ZCash开发的https://github.com/zkcrypto/bellman 主要针对的是BLS12-381曲线,以太坊matter-labs在该基础上,对以太坊中所使用的BN256曲线进行了优化,并在crates.io中发布为了bellman_ce

目前以太坊matter-labs bellman中提供了2个稳定可用于生产的features,且相应的API会保持不变。这两都是基于Groth16 proof system implementation实现的:

  • multicore:默认启用。用于在PC上运行,且环境支持包含threading的full std
  • singlecore:主要用于WASM系统,其中non-compatible external crates已移除,以及所有的多线程实现也已移除。

为了实现对WASM的兼容,在实现GM17和SONIC方案时,也需要做相应的考虑。

主要依赖有:

  • pairing_ce:在Zcash https://github.com/zkcrypto/pairing 中仅支持BLS12-381曲线,matter-labs在此基础上,增加了BN256曲线支持。详细见https://github.com/matter-labs/pairing/tree/master/src/bn256 文件。
  • cfg-if:宏定义,用于if-else chain大量 #[cfg] 配置来定义参数。
cfg_if::cfg_if! {
    if #[cfg(unix)] {
        fn foo() { /* unix specific functionality */ }
    } else if #[cfg(target_pointer_width = "32")] {
        fn foo() { /* non-unix, 32-bit functionality */ }
    } else {
        fn foo() { /* fallback implementation */ }
    }
}

fn main() {
    foo();
}
  • byteorder:用于encode或decode number为big-endian或little-endian order。
  • futures:为Rust异步编程库。
  • num_cpus:用于获取机器CPU的数量。
  • crossbeam:并发编程工具
  • prefetch:提供了 a type-safe wrapper around LLVM’s prefetch intrinsic。
declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>)

prefetch主要用来实现内存数据的预抓取处理。一般CPU内部都会提供几级高速缓存,在高速缓存中进行数据存取要比在内存中速度快。因此为了提升性能,可以预先将某个内存地址中的数据读取或写入到高速缓存中去,这样当真实需要对内存地址进行存取时实际上是在高速缓存中进行。而prefetch函数就是用来将某个内存中的数据预先加载或写入到高速缓存中去。

  • web-sys:提供了raw wasm-bindgen imports for all of the Web’s APIs,包括:window.fetch、Node.prototype.appendChild、WebGL、WebAudio等等。
  • tiny-keccak:实现了Keccak派生函数,如sha3等。
  • blake2-rfc:为基于RFC7693 实现的BLAKE2 hash函数。

参考资料

[1] Edcon2019_material
[2] EDCON Workshop record (youtube): Intro to bellman: Practical zkSNARKs constructing for Ethereum
[3] LLVM编译器中的内置(built-in)函数
[4] LLVM Language Reference Manual

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值