Crates.io | ephemeral-vrf-sdk |
lib.rs | ephemeral-vrf-sdk |
version | |
source | src |
created_at | 2025-03-26 22:50:40.336799+00 |
updated_at | 2025-04-03 11:42:25.291298+00 |
description | Ephemeral Vrf Integration SDK |
homepage | https://www.magicblock.xyz/ |
repository | https://github.com/magicblock-labs/ephemeral-vrf |
max_upload_size | |
id | 1607259 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
EphemeralVrf is a Verifiable Random Function (VRF) implementation for Solana that provides secure, verifiable randomness for decentralized applications. It uses a network of oracles to generate and verify random values on-chain.
EphemeralVrf enables dApps to request unpredictable, tamper-resistant random values that can be verified by anyone.
The implementation follows RFC 9381, utilizing Curve25519's Ristretto group for elliptic curve operations and Schnorr-like signatures for proof verification.
Consts
– Program constants.Error
– Custom program errors.Instruction
– Declared instructions.SDK
– Custom program events.State
– Program state definitions.DelegateOracleQueue
– Delegate an Oracle queue to the delegation program.RequestRandomness
– Request a new random value.ProvideRandomness
– Provide randomness for a request.Initialize
– Initialize the program state.ModifyOracle
– Add or modify oracle information.InitializeOracleQueue
– Initialize a new oracle queue.Oracle
– Oracle data structure.Oracles
– Collection of oracles.Queue
– Oracle queue for randomness requests.A Verifiable Random Function (VRF) is a cryptographic primitive that maps inputs to verifiable pseudorandom outputs. The key properties of a VRF are:
Uniqueness: For a given input and private key, there is exactly one valid output.
Verifiability: Anyone with the public key can verify that an output was correctly computed from the input without learning the private key.
Pseudorandomness: The output appears random to anyone who doesn't know the private key.
In EphemeralVrf, oracles use VRFs to generate random values that can be verified on-chain, ensuring that the randomness is both unpredictable and tamper-resistant.
This repository contains an implementation of a Verifiable Random Function (VRF) based on Curve25519 elliptic curve cryptography, using HKDF (HMAC-based Key Derivation Function) for key derivation and SHA-512 as the hash function. The VRF is designed to allow a party to prove that they know a random value derived from a secret key, with the proof being verifiable by any third party.
Curve25519: The cryptographic foundation of the VRF, offering a secure elliptic curve with efficient computation and strong security guarantees.
SHA-512: A strong hash function used throughout the protocol, including in the key derivation and challenge generation.
HKDF: A key derivation function that is based on HMAC and used for securely generating secret keys from initial entropy sources.
Schnorr-like Signature Scheme: Used for generating and verifying the VRF proof, ensuring that the output is verifiably bound to the input and secret key.
The VRF implementation follows the structure laid out in RFC 9381, consisting of the following steps:
Key Generation: A key pair is derived from a given keypair using HKDF to generate a secret key (sk
) and a corresponding public key (pk
), which is a scalar multiple of the base point on Curve25519.
VRF Computation:
hash_to_point
function.sk
) with the hashed point.k
) is derived, and commitments are computed for both the base point and the hashed point.s
) is computed using the standard Schnorr signature response formula.VRF Proof Verification:
s * G == commitment_base + c * pk
s * h == commitment_hash + c * output
The security of the VRF relies on the hardness of the Discrete Logarithm Problem (DLP) in elliptic curve cryptography. The implementation ensures that:
The code is not audited and should not be used in production environments without thorough testing and security analysis.
Compile your program:
cargo build-sbf
Run unit and integration tests:
cargo test-sbf --features test-sbf
Run the oracle service:
RUST_LOG=info cargo run --bin vrf-oracle
CLI for managing oracles. See all available commands with:
cargo run --bin vrf-cli -- --help
See the integration tests for example usage of the program.