VRF Verification Library for WASM contracts
A minimal, optimized VRF proof verification library specifically designed for smart contracts on WASM-based platforms like NEAR, and others.
Features
- Minimal Dependencies: Only essential crypto libraries, no RNG or signing
- No-std Compatible: Works in constrained smart contract environments
- Multi-Platform: NEAR, and generic WASM support
- Size Optimized: ~10KB compiled size vs 100KB+ for full libraries
- Conditional Compilation: Only include platform-specific code when needed
- Battle Tested: Uses proven verification logic from FastCrypto
Installation
Generic WASM Contracts (Default)
[]
= "0.8"
NEAR Smart Contracts
For NEAR smart contracts with enhanced features:
[]
= { = "0.8", = ["near"] }
Using with VRF-WASM for Proof Generation
To use both libraries together, you must enable the browser feature in vrf-wasm for your tests and the near feature for contract builds.
For cargo test:
# In your dev-dependencies
= { = "0.7", = ["browser"] }
For NEAR contract builds:
# In your dependencies
= { = "0.7", = false, = ["near"] }
= { = "0.7", = ["near"] }
This setup ensures your tests use the browser-compatible RNG while your contract uses the NEAR-specific RNG.
Quick Start
Basic Usage (Generic WASM)
use ;
// Verify a VRF proof (80 bytes: gamma(32) + challenge(16) + scalar(32))
let result = verify_vrf;
match result
NEAR Smart Contract
use ;
API Reference
Core Verification Functions
verify_vrf(proof_bytes, public_key_bytes, input) -> Result<VrfOutput, VerificationError>
Complete VRF verification returning the 64-byte VRF output on success.
verify_vrf_fixed(proof_array, public_key_array, input) -> Result<VrfOutput, VerificationError>
Type-safe version using fixed-size arrays instead of Vec.
verify_vrf_bool(proof_bytes, public_key_bytes, input) -> bool
Simple boolean verification for contract usage.
Build Examples
# Build without any platform features (smallest)
# Build for NEAR contracts specifically
# Test all configurations
Important Notes
- Feature Compatibility: When using both
vrf-wasmandvrf-contract-verifierin the same project, ensure consistent feature flags - NEAR Runtime: The
nearfeature enables NEAR-specific optimizations but requires NEAR runtime for execution - Cross-Verification: Both libraries use identical cryptographic implementations for compatibility
Platform-Specific Build Optimization
The crate uses conditional compilation to minimize dependencies:
// NEAR-specific serialization only when needed
// Platform-specific dependencies only when features are enabled
use near_sdk;
Compatibility
VRF Suite
Compatible with Sui VRF implementation:
- Suite string:
sui_vrf - Curve: Ristretto255
- Hash: SHA-512
- Challenge length: 16 bytes
- Output length: 64 bytes
Smart Contract Platforms
- ✅ NEAR Protocol
- ✅ Generic WASM contracts
Security Notes
- This library only performs verification - does not generate keys or proofs in contracts
- Verify proofs were generated with proper randomness
- Consider replay attack protection in contract logic
License
Apache-2.0