#vrf #randomness #ecvrf #random #public-key

no-std libecvrf

A ECVRF that's friendly with EVM, based on curve secp256k1 and keccak256

4 releases (stable)

new 1.2.1-beta.0 Nov 25, 2024
1.1.2 Sep 1, 2023
1.0.1 Feb 25, 2023

#1782 in Cryptography

Download history 27/week @ 2024-09-23

204 downloads per month

Apache-2.0

29KB
619 lines

Libecvrf

A library from Orand @ Orochi Network

Overview

In cryptography, a verifiable random function (VRF) is a public key version of a pseudorandom function. It produces a pseudorandom output and a proof certifying that the output is computed correctly.

A VRF includes a pair of keys, named public and secret keys. The secret key, along with the input is used by the holder to compute the value of a VRF and its proof, while the public key is used by anyone to verify the correctness of the computation.

The issue with traditional pseudorandom functions is that their output cannot be verified without the knowledge of the seed. Thus a malicious adversary can choose an output that benefits him and claim that it is the output of the function. VRF solves this by introducing a public key and a proof that can be verified publicly while the owner can keep secret key to produce numbers indistinguishable from randomly chosen ones.

VRF has applications in various aspects. Among them, in internet security, it is used to provide privacy against offline enumeration (e.g. dictionary attacks) on data stored in a hash-based data structure irtf-vrf15. VRF is also used in lottery systems MR02 and E-cashes BCKL09.

Features

This library is a part of Orand a Decentralized RNG (or Public Randomness Beacon). This crate provide two main features, ordinary ECVRF describe in irtf-vrf15 and EVM friendly ECVRF that compatible with Chaink VRF's verifier in Solidity.

Usage

use libecvrf::{
    extends::ScalarExtend,
    secp256k1::{curve::Scalar, SecretKey},
    util::thread_rng,
    ECVRF,
};

fn main() {
    let secret_key = SecretKey::random(&mut thread_rng());
    let ecvrf = ECVRF::new(secret_key);
    let alpha = Scalar::randomize();

    let proof = ecvrf.prove(&alpha);
    println!("result: {:#?}", proof);

    println!("{:?}", ecvrf.verify(&alpha, &proof));

    let smart_contract_proof = ecvrf.prove_contract(&alpha);

    println!("result: {:#?}", smart_contract_proof);
}

License

This project licensed under the Apache License, Version 2.0.

build with ❤️ and 🦀

Dependencies

~1–1.3MB
~27K SLoC