{"id":7078,"library":"chiavdf","title":"Chia VDF Verification Library","description":"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.","status":"active","version":"1.1.14","language":"en","source_language":"en","source_url":"https://github.com/Chia-Network/chiavdf","tags":["chia","vdf","cryptography","blockchain","proof-of-space","verification"],"install":[{"cmd":"pip install chiavdf","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"verify_wesolowski","correct":"from chiavdf import verify_wesolowski"},{"symbol":"verify_vdf","correct":"from chiavdf import verify_vdf"},{"symbol":"create_discriminant","correct":"from chiavdf import create_discriminant"}],"quickstart":{"code":"import chiavdf\nimport hashlib\n\n# Example input data (replace with actual challenge, x, and proof from your VDF)\n# For a real VDF proof, challenge_hash, x_value, and proof_bytes would be specific outputs\n# from a VDF prover.\nchallenge_seed = b\"my_unique_vdf_challenge_seed_001\"\nchallenge_hash = hashlib.sha256(challenge_seed).digest()\nform_size = 512 # Standard form size for Chia\nnum_iterations = 1_000_000 # Number of iterations the VDF ran for\nn_wesolowski = 600 # Wesolowski proof parameter\n\n# Dummy x and proof bytes for demonstration. These values will likely result in 'False'\n# or an error if not actual valid proof components.\nx_value = b\"\\x01\" * 64 # Placeholder for a 64-byte value\nproof_bytes = b\"\\x02\" * 128 # Placeholder for a 128-byte proof\n\ntry:\n    # Create the discriminant based on the challenge hash\n    discriminant = chiavdf.create_discriminant(challenge_hash, form_size)\n\n    # Verify the Wesolowski proof\n    # In a real scenario, x_value and proof_bytes must correspond to a valid VDF computation\n    is_valid = chiavdf.verify_wesolowski(\n        challenge_hash,\n        form_size,\n        discriminant,\n        x_value,\n        proof_bytes,\n        num_iterations,\n        n_wesolowski,\n        1, # num_threads (can be increased for faster verification on multi-core CPUs)\n        True, # check_input\n    )\n    print(f\"VDF Wesolowski proof verification result: {is_valid}\")\n\nexcept ValueError as e:\n    print(f\"Input Error during VDF verification: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred during VDF verification: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"If compiling from source, ensure your build scripts or CMake configurations are updated to remove references to `-lboost_system` or `boost_system` during linking. For most users, `pip install` provides pre-compiled wheels, avoiding this issue.","message":"When compiling `chiavdf` from source (not installing via `pip install` which uses pre-built wheels), the underlying Boost library linkage changed significantly in versions 1.1.12 and 1.1.13. The `boost_system` library was removed from Boost distributions.","severity":"breaking","affected_versions":">=1.1.12"},{"fix":"Ensure your Python environment is running Python 3.9 or a newer version (e.g., Python 3.10, 3.11, 3.12, 3.14 are supported in latest versions). Upgrade your Python installation if necessary.","message":"The `chiavdf` library requires Python 3.9 or newer. Installing with older Python versions will fail or result in compatibility issues.","severity":"gotcha","affected_versions":"All (explicitly stated as >=3.9 in PyPI since recent versions)"},{"fix":"Experiment with the `num_threads` parameter based on your CPU's core count. Typically, setting it to the number of physical cores or slightly less than logical cores provides a good balance. For most verification tasks, 1 thread is sufficient unless benchmarking.","message":"VDF verification is a computationally intensive process. The `num_threads` parameter in `verify_wesolowski` and `verify_vdf` can significantly impact performance. Setting it too high or too low might not yield optimal results.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install chiavdf`","cause":"The 'chiavdf' library is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'chiavdf'"},{"fix":"Check the exact function names from the official documentation or the `__init__.pyi` file. Common functions are `verify_wesolowski`, `verify_vdf`, and `create_discriminant`.","cause":"You are attempting to call a function or access an attribute that does not exist or has been misspelled within the `chiavdf` module.","error":"AttributeError: module 'chiavdf' has no attribute 'verify_proof'"},{"fix":"Ensure all binary data inputs are properly encoded as `bytes`. For example, use `my_string.encode('utf-8')` or prefix string literals with `b` (e.g., `b'some_data'`).","cause":"Input parameters like `challenge_hash`, `x_value`, and `proof_bytes` are expected to be byte strings (e.g., `b'...'`), but a regular string was provided.","error":"TypeError: argument 'challenge_hash' must be bytes, not str"}]}