pedersen-fast
Blazing fast Pedersen hash implementation for Node.JS
Exposes starknet-crypto's implementation written in Rust as WASM package.
Usage
npm i pedersen-fast
Package exposes two functions, one for calculations from HEX strings, the other from decimal strings:
import { pedersen_from_hex, pedersen_from_dec } from "pedersen-fast";
// returns a hex string starting with 0x
pedersen_from_hex(
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcde",
"0x11223344556677889900aabbccddeeff11223344556677889900aabbccddeef",
);
Current state
According to our benchmarks, the fastest implementation would be the native module (via NEON). The problem with native modules is a need to compile them on the client or precompile them before. None of these solutions is trivial, that's why we use WASM for now.
napi-rs
seems to be great at simplifying shipping native modules for nodejs. but its performance is much worse than neons. This needs further research.
Benchmarks
For 10 000
hash calculations from hex strings:
Implementation | Time | Hash/s |
---|---|---|
Starknet JS | 23,493 ms | 425.659 hash/s |
starknet_crypto (WASM) | 241 ms | 41,493.776 hash/s |
starknet_crypto (native module) | 90 ms | 111,111.111 hash/s |
Acknowledgments
Thanks goes to:
- starknet-rs team for the fastest implementation our there :)
Development
To compile every package and run benchmarks do:
./scripts/benchmark.sh
License
MIT