Crates.io | libecvrf |
lib.rs | libecvrf |
version | 1.1.2 |
source | src |
created_at | 2023-02-25 07:08:40.467776 |
updated_at | 2023-09-01 09:18:30.410159 |
description | A ECVRF that's friendly with EVM, based on curve secp256k1 and keccak256 |
homepage | |
repository | https://github.com/orochi-network/orochimaru/ |
max_upload_size | |
id | 794224 |
size | 49,624 |
A library from Orand @ Orochi Network
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.
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.
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);
}
This project licensed under the Apache License, Version 2.0.
build with ❤️ and 🦀