vrf_fun-0.12.0 has been yanked.
vrf_fun
Verifiable Random Function (VRF) implementation for secp256k1.
Use
[]
= "0.12"
= "0.12"
= "0.10"
Overview
This crate provides RFC 9381 compliant VRF implementations for secp256k1, supporting both:
- TAI (Try-And-Increment) hash-to-curve method
- RFC 9380 hash-to-curve method
Features
- RFC 9381 compliant VRF implementation
- Support for both TAI and RFC 9380 hash-to-curve methods
- Simple VRF variant for when spec compliance is not required
- Generic over hash functions (SHA-256, etc.)
- Deterministic proofs
- Suite strings:
0xFEfor TAI,0xFFfor RFC SSWU
- Suite strings:
Usage
High-Level API
RFC 9381 with TAI (Try-And-Increment)
use ;
use rfc9381;
// Generate a keypair
let keypair = new;
// Create a VRF proof
let alpha = b"test message";
let proof = ;
// Verify the proof
let verified = .expect;
// Get the VRF output
let beta = verified.;
RFC 9381 with RFC 9380 Hash-to-Curve
use rfc9381;
// Same keypair and message
let proof = ;
// Verify with the RFC 9380 verifier
let verified = .expect;
let beta = verified.;
Low-Level API
For more control over the hash-to-curve process:
use ;
use ;
// Create VRF instance
let vrf = default;
// Hash to curve yourself
let h = ;
// Generate proof
let proof = vrf.prove;
// Verify
let verified = vrf.verify
.expect;
Implementation Details
Challenge Generation
The challenge is computed as:
c = Hash(suite_string || 0x02 || Y || H || Gamma || U || V || 0x00)
Where:
suite_string:0xFEfor TAI,0xFFfor RFC 9380Yis the public keyHis the hash-to-curve of the inputGammais the VRF output point (x*H)UandVare the DLEQ proof commitments
The hash output is truncated to 16 bytes for secp256k1.
VRF Output
The VRF output beta is computed as:
beta = Hash(suite_string || 0x03 || Gamma || 0x00)
Important Notes
- The TAI and RFC 9380 variants use different suite strings (0xFE and 0xFF)
- Proofs generated with one method cannot be verified with the other
- The same input will produce different outputs with different hash-to-curve methods
- This implementation includes the public key in the challenge (unlike draft-05)
Generic Hash Support
The implementation is generic over the hash function, constrained by secp256kfun::hash::Hash32. This allows using different SHA256 implementations or other 32-byte output hash functions.