1. 引言
Geometry团队近日发布了一个bounty(1500美金)项目:
希望借助WebGPU技术,实现在客户端的ZKP证明。
现有的一些WebGPU基础算法库有:
- https://github.com/geometryresearch/wgsl-poseidon(Rust+TypeScript+WGSL):基于BN254 Scalar域以WGSL实现了Poseidon哈希函数,可在浏览器内和命令行运行。
- https://github.com/sampritipanda/msm-webgpu(WGSL+HTML+Python):实现了Vesta域的基于Pippenger算法MSM,以及其他一些关键椭圆曲线运算函数。【注意wgsl不支持u64运算,实现的是基于u32数组的modular运算。基于u32数组的modular运算也可参看https://github.com/filecoin-project/ec-gpu/中的
FIELD_LIMB_BITS == 32
场景。】 - https://github.com/voidash/webgpu-examples(Rust+WGSL):实现了BLS12-381有限域运算。
本次bounty项目重点关注但不限于以下维度:
- 1)高层算法:
- Multi-scalar multiplication(MSM)
- 快速傅里叶变换(FFT)
- 2)高效椭圆曲线运算:
- 如曲线加法、指数幂运算等。
- 3)高效有限域运算:
- 如Poseidon哈希函数中高频使用的 x 5 m o d p x^5\mod p x5modp运算,或MiMC7哈希函数中高频使用的 x 7 m o d p x^7\mod p x7modp运算。
- 4)任意常用哈希函数:
- 如Poseidon 2、Reinforced Concrete、Tip5 或 MiMC等。
Rust提供了wgpu
库,可实现CLI方式来运行WGSL代码。
2. 何为WebGPU?
WebGPU详细背景知识见:
3. wgsl-poseidon示例
https://github.com/geometryresearch/wgsl-poseidon(Rust+TypeScript+WGSL):基于BN254 Scalar域以WGSL实现了Poseidon哈希函数,可在浏览器内和命令行运行。
命令行运行:
running 1 test
Computing 16384 Poseidon hashes in Rust / WebGPU
CPU took 3388ms
AdapterInfo { name: "NVIDIA GeForce RTX 2060", vendor: 4318, device: 7944, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "516.94", backend: Vulkan }
GPU took 28ms
test poseidon::test_poseidon ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 3 filtered out; finished in 15.27s
浏览器内运行:
Computing 16384 Poseidon hashes in the browser / WebGPU
CPU took 829 ms
GPU took 49 ms
https://github.com/geometryresearch/wgsl-poseidon中关键参数为:
- 输入长度(即rate)为 1
- Poseidon inner state长度为 t = 2 t = 2 t=2,即对应capacity为1。
- R f = 8 R_f=8 Rf=8
- R p = 56 R_p=56 Rp=56
参考资料
[1] Geometry团队2023年7月博客 Geometry Bounty: WebGPU for ZK Proving