Chia VDF Verification Library

1.1.14 · active · verified Thu Apr 16

chiavdf is a Python library that provides bindings for a C++ implementation of Verifiable Delay Functions (VDFs), primarily used within the Chia blockchain ecosystem. It allows for the creation of discriminants and verification of Wesolowski proofs. The library is actively maintained with frequent updates, often including improvements to the underlying C++ components and build processes. Current version is 1.1.14.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use `chiavdf` to create a discriminant and verify a Wesolowski proof. Note that the `x_value` and `proof_bytes` in this example are placeholders and will likely not result in a valid proof. You should replace them with actual data from a VDF prover for successful verification.

import chiavdf
import hashlib

# Example input data (replace with actual challenge, x, and proof from your VDF)
# For a real VDF proof, challenge_hash, x_value, and proof_bytes would be specific outputs
# from a VDF prover.
challenge_seed = b"my_unique_vdf_challenge_seed_001"
challenge_hash = hashlib.sha256(challenge_seed).digest()
form_size = 512 # Standard form size for Chia
num_iterations = 1_000_000 # Number of iterations the VDF ran for
n_wesolowski = 600 # Wesolowski proof parameter

# Dummy x and proof bytes for demonstration. These values will likely result in 'False'
# or an error if not actual valid proof components.
x_value = b"\x01" * 64 # Placeholder for a 64-byte value
proof_bytes = b"\x02" * 128 # Placeholder for a 128-byte proof

try:
    # Create the discriminant based on the challenge hash
    discriminant = chiavdf.create_discriminant(challenge_hash, form_size)

    # Verify the Wesolowski proof
    # In a real scenario, x_value and proof_bytes must correspond to a valid VDF computation
    is_valid = chiavdf.verify_wesolowski(
        challenge_hash,
        form_size,
        discriminant,
        x_value,
        proof_bytes,
        num_iterations,
        n_wesolowski,
        1, # num_threads (can be increased for faster verification on multi-core CPUs)
        True, # check_input
    )
    print(f"VDF Wesolowski proof verification result: {is_valid}")

except ValueError as e:
    print(f"Input Error during VDF verification: {e}")
except Exception as e:
    print(f"An unexpected error occurred during VDF verification: {e}")

view raw JSON →