Announcing our Verifiable Random Function (VRF) Rust library

A fast and extensible Verifiable Random Function (VRF) library, which currently supports some of the most widely used elliptic cipher suites.

Mario Cao
Mario Cao
Jun 3 · 2 min read

Recently Gorka Irazoqui Apecechea and me proudly published a VRF crate as an open source project under the MIT license.

The library is a fast, flexible and general-purpose Verifiable Random Function (VRF) library written in Rust, which follows the IETF standard draft written by Sharon Goldberg, Moni Naor, Dimitris Papadopoulos, Leonid Reyzin, and Jan Včelák.

Introducing the library

  • RFC6979 for the nonce generation functionCurrently the supported cipher suites use the SHA256 hashing algorithm and the following elliptic curves: secp256k1, secp256r1 and sect163k1.

The library was written with the idea of being extensible so that additional cipher suites and algorithms can easily be added by implementing the trait VRF.

  • RFC6979 for the nonce generation functionCurrently the supported cipher suites use the SHA256 hashing algorithm and the following elliptic curves: secp256k1, secp256r1 and sect163k1.
use vrf::openssl::{CipherSuite, ECVRF};
use vrf::VRF;
fn main() {
// Initialization of VRF context by providing a curve
let mut vrf = ECVRF::from_suite(CipherSuite::SECP256K1_SHA256_TAI).unwrap();
// Inputs: Secret Key, Public Key (derived) & Message
let secret_key =
hex::decode("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721").unwrap();
let public_key = vrf.derive_public_key(&secret_key).unwrap();
let message: &[u8] = b"sample";

// VRF proof and hash output
let pi = vrf.prove(&secret_key, &message).unwrap();
let hash = vrf.proof_to_hash(&pi).unwrap();
// VRF proof verification (returns VRF hash output)
let beta = vrf.verify(&public_key, &pi, &message);
}

A complete example can be found in examples/basic.rs

What is a VRF?

A VRF is a cryptographic primitive that provides a pseudo-random function along with a publicly verifiable proof of its outputs’ correctness. Additionally, the VRF hash output is deterministic, in the sense that it always produces the same output given the same pair of inputs. VRF were firstly introduced by Micali, Rabin and Vadhan in 1999.

It can be better understood as the public-key version of a keyed cryptographic hash. Only the holder of the VRF secret key is able to compute a valid hash (i.e. pseudo-random value), while anyone with the public can verify its correctness.

Why VRFs?

VRFs are widely used in various cryptographic schemes, protocols and systems. Similarly to Algorand, the Witnet network protocol uses VRFs to conduct secret cryptographic sortitions which are used for the leader and committee selections as part of the underlying consensus protocol. Cryptographic sortition allows Witnet blockchain to be secure while being efficient and scalable.


Contribute with us!

Please take a look to our GitHub repository and feel free to report issues, propose changes and contribute to the code.

The Witnet Foundation Blog

A P2P protocol that connects smart contracts to the real world #DontTrustTheMessenger

Thanks to Gorka Irazoqui Apecechea.

Mario Cao

Written by

Mario Cao

The Witnet Foundation Blog

A P2P protocol that connects smart contracts to the real world #DontTrustTheMessenger