| Crates.io | vrf-contract-verifier |
| lib.rs | vrf-contract-verifier |
| version | 0.8.2 |
| created_at | 2025-06-19 03:21:31.323521+00 |
| updated_at | 2025-06-21 11:12:55.814231+00 |
| description | Minimal VRF proof verification for smart contracts |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1717771 |
| size | 98,475 |
A minimal, optimized VRF proof verification library specifically designed for smart contracts on WASM-based platforms like NEAR, and others.
[dependencies]
vrf-contract-verifier = "0.8"
For NEAR smart contracts with enhanced features:
[dependencies]
vrf-contract-verifier = { version = "0.8", features = ["near"] }
To use both libraries together, you must enable the browser feature in vrf-wasm for your tests and the near feature for contract builds.
For cargo test:
# In your dev-dependencies
vrf-wasm = { version = "0.7", features = ["browser"] }
For NEAR contract builds:
# In your dependencies
vrf-wasm = { version = "0.7", default-features = false, features = ["near"] }
vrf-contract-verifier = { version = "0.7", features = ["near"] }
This setup ensures your tests use the browser-compatible RNG while your contract uses the NEAR-specific RNG.
use vrf_contract_verifier::{verify_vrf, VerificationError};
// Verify a VRF proof (80 bytes: gamma(32) + challenge(16) + scalar(32))
let result = verify_vrf(proof_bytes, public_key_bytes, input_bytes);
match result {
Ok(vrf_output) => {
// VRF proof is valid, use the 64-byte output
println!("VRF output: {:?}", vrf_output);
}
Err(VerificationError::InvalidProof) => {
// Invalid proof
}
Err(e) => {
// Other verification errors
}
}
use vrf_contract_verifier::{verify_vrf_bool, verify_vrf};
#[near_bindgen]
impl MyContract {
// Simple boolean verification
pub fn verify_randomness(&self, proof: Vec<u8>, pk: Vec<u8>, seed: Vec<u8>) -> bool {
verify_vrf_bool(proof, pk, seed)
}
// Full verification with VRF output
pub fn verify_and_get_output(&self, proof: Vec<u8>, pk: Vec<u8>, seed: Vec<u8>) -> Option<Vec<u8>> {
match verify_vrf(proof, pk, seed) {
Ok(output) => Some(output.to_vec()),
Err(_) => None,
}
}
}
verify_vrf(proof_bytes, public_key_bytes, input) -> Result<VrfOutput, VerificationError>Complete VRF verification returning the 64-byte VRF output on success.
verify_vrf_fixed(proof_array, public_key_array, input) -> Result<VrfOutput, VerificationError>Type-safe version using fixed-size arrays instead of Vec.
verify_vrf_bool(proof_bytes, public_key_bytes, input) -> boolSimple boolean verification for contract usage.
# Build without any platform features (smallest)
cargo build --target wasm32-unknown-unknown --release
# Build for NEAR contracts specifically
cargo build --target wasm32-unknown-unknown --features near --release
# Test all configurations
cargo test # Basic features
cargo test --features near # With NEAR features
vrf-wasm and vrf-contract-verifier in the same project, ensure consistent feature flagsnear feature enables NEAR-specific optimizations but requires NEAR runtime for executionThe crate uses conditional compilation to minimize dependencies:
// NEAR-specific serialization only when needed
#[cfg_attr(feature = "near", near_sdk::near(serializers = [borsh, json]))]
pub struct VrfProof { ... }
// Platform-specific dependencies only when features are enabled
#[cfg(feature = "near")]
use near_sdk;
Compatible with Sui VRF implementation:
sui_vrfThis library only performs verification - does not generate keys or proofs in contracts
Verify proofs were generated with proper randomness
Consider replay attack protection in contract logic
Apache-2.0