VRF Verification Library for WASM contracts
A minimal, optimized VRF proof verification library specifically designed for smart contracts on WASM-based platforms like NEAR, CosmWasm, 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, CosmWasm, 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
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
[]
= { = "0.4.3", = ["near"] }
use ;
Generic WASM (without platform-specific features)
[]
= { = "0.4.3", = false }
API Reference
Core Verification Functions
All verification functions are in the near_vrf_verifier module:
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.
Error Types
Build Configuration
Features
| Feature | Description | Dependencies Added |
|---|---|---|
default |
No platform features | Base crypto only |
near |
NEAR smart contract support | near-sdk, bincode |
cosmwasm |
CosmWasm support | bincode |
Conditional Compilation Examples
# Build without any platform features (smallest)
# Build for NEAR smart contracts
# Build for CosmWasm
# Test all configurations
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;
use cosmwasm_std;
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
- ✅ CosmWasm (Cosmos SDK)
- ✅ 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
Example: NEAR VRF Oracle
use ;
use VrfVerifier;
License
Apache-2.0