Skip to content

A demonstration of hashing a Poseidon2 merkle tree in parallel using a WebGPU compute shader

License

Notifications You must be signed in to change notification settings

QEDProtocol/poseidon2-webgpu-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Poseidon2 WebGPU Demo

A browser benchmark which compares the performance of hashing a poseidon2-goldilocks merkle tree on CPU using the poseidon2 npm package vs. our experimental WebGPU poseidon2 compute shader.

Demo Link - Requires the latest version of Chrome or a browser that supports WebGPU

Open Benchmark Demo

Setup

pnpm i
pnpm start

(you can use your favorite node package manager if you do not have pnpm installed)

Note: This benchmark only works on browsers which have support for WebGPU

Benchmark Results on Chrome / 2021 Apple M1 Max (MacBook Pro)

Merkle Tree Height Total Time CPU (ms) Total Time WebGPU (ms) WebGPU Performace Gain
8 (256 Leaves) 15.09 ms 32.07 ms 2.1x Slower than CPU
12 (4096 Leaves) 216.1 ms 40.8 ms 5.3x Faster than CPU
16 (65536 Leaves) 3606.4 ms 177.2 ms 20.35x Faster than CPU
20 (1048676 Leaves) 58219.7 ms 2119.3 ms 27.47x Faster than CPU

Info/Tips

  • Our WebGPU compute shader can be found in src/webgpu/poseidon2-goldilocks.wgsl.
  • Right now there are limitations on how much memory can be allocated to WebGPU compute workgroups, so staying in the range of 1-22 height merkle trees is recommended (if you want larger, you can just create several job instances and then connect them with another small merkle tree on top)
  • For tree heights greater than 20, CPU is so slow that the benchmark often freezes, but you can still benchmark WebGPU at these heights if you check the "Disable CPU" option

Credits

Made with ❤️ by QED Team

Special thanks to Recmo for his uint128 implementation of Goldilocks multiplication for WGSL

License

MIT License

Copyright (c) 2023 Zero Knowledge Labs Limited

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A demonstration of hashing a Poseidon2 merkle tree in parallel using a WebGPU compute shader

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published