Integration of Arkworks cryptographic primitives as Substrate host functions, demonstrating efficient elliptic curve operations within the Polkadot/Substrate ecosystem.
This project serves two primary purposes:
-
On-chain Arkworks Demonstration: Shows practical integration of cryptographic operations from the Arkworks ecosystem into Substrate based runtimes through custom pallets and host functions.
-
Arkworks-extensions Backend: Demonstrates how Polkadot SDK host calls can serve as the computational backend for arkworks-extensions, offloading expensive elliptic curve operations from Wasm to native host execution for significant performance improvements.
Provides cryptographic operations on the Ed-on-BLS12-381-Bandersnatch curve with two curve representations:
Short Weierstrass (SW) Curve Operations:
ed_on_bls12_381_bandersnatch_msm_sw- Multi-Scalar Multiplicationed_on_bls12_381_bandersnatch_mul_projective_sw- Projective scalar multiplicationed_on_bls12_381_bandersnatch_mul_affine_sw- Affine scalar multiplication
Twisted Edwards (TE) Curve Operations:
ed_on_bls12_381_bandersnatch_msm_te- Multi-Scalar Multiplicationed_on_bls12_381_bandersnatch_mul_projective_te- Projective scalar multiplicationed_on_bls12_381_bandersnatch_mul_affine_te- Affine scalar multiplication
Each operation supports both native Arkworks and Substrate-optimized implementations
via the optimized parameter.
Implements Verifiable Random Function verification operations using the Bandersnatch suite:
IETF VRF:
ietf_verify- Verify RFC-compliant VRF proof
Ring-based VRF:
ring_reset- Initialize ring verifier key builderpush_members/push_member_buffered- Add ring membersring_commit- Finalize ring and build verifier keyring_verify- Verify ring-based VRF proof
Configuration options:
- Configurable ring sizes (2^11 with
small-ringfeature; 2^16 default) - Pregenerated Universal Reference String (URS) (from zcash ceremony)
This project demonstrates how Polkadot SDK host calls can act as a performance-critical backend for the arkworks-extensions library. The integration works as follows:
- Wasm Runtime: Runtime code uses arkworks-extensions API for elliptic curve operations
- Host Call Backend: Expensive operations are dispatched to native host functions
(
sp-crypto-ecpolkadot-sdk crate) - Performance Gain: Native execution avoids Wasm overhead for computationally intensive cryptographic primitives (MSM, scalar multiplication, etc.)
polkadot-ark-hostcalls/
├── pallets/
│ ├── hostcalls/ # Arkworks cryptographic hostcalls pallet
│ └── vrf/ # VRF verification pallet
├── runtime/ # Substrate based runtime
├── node/ # Substrate based node
├── benchmark.sh # Benchmark execution script
cargo run --release -- --devcargo run -- --dev --tmpThe project includes comprehensive benchmarking infrastructure
Examples:
# Benchmark all extrinsics from ark_hostcalls pallet
./benchmark.sh pallet_ark_hostcalls all
# Benchmark substrate based (optimized) VRF verification from ark_vrf pallet
./benchmark.sh pallet_ark_vrf sub_ring_vrf_verify
# Benchmark all extrinsics from ark_vrf pallet
./benchmark.sh pallet_ark_vrf allBenchmark results are shown in the terminal and stored in the results/ directory.
std- Standard library supportruntime-benchmarks- Enable benchmark implementationssmall-ring- Reduced ring sizes for testing (2^11 instead of 2^16)