Chia Proof of Space (chiapos)

2.0.12 · active · verified Thu Apr 16

chiapos is the official Python wrapper for the Chia Network's proof-of-space (PoS) C++ library. It provides core functionalities for creating plot files and verifying proofs of space, serving as a foundational component for the Chia blockchain. Currently at version 2.0.12, the library typically sees regular minor updates, often aligning with the broader Chia blockchain development cycle, focusing on performance, security, and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Verifier` class and call its `validate_proof` method using placeholder data. Note that actual plotting and proof generation are resource-intensive operations and are not included in this simple example. The `DiskProver` class is used to interact with existing plot files for generating proofs.

import hashlib
from chiapos import Verifier
import os

# Note: Generating an actual plot and proof is extremely resource-intensive
# and time-consuming. This example uses placeholder values to demonstrate
# the Verifier API, not a successful real-world verification.

# 1. Initialize the Verifier
verifier = Verifier()

# 2. Prepare dummy data for verification
# In a real scenario, these would come from the blockchain or a prover
plot_id_hex = "0x" + hashlib.sha256(b"my_plot_id_seed").hexdigest()
challenge_hash_hex = "0x" + hashlib.sha256(b"my_challenge_seed").hexdigest()
proof_bytes = b'\x00' * 64 # A dummy 64-byte proof (actual proofs are complex)

# Convert hex strings to bytes as required by the Verifier
plot_id = bytes.fromhex(plot_id_hex[2:])
challenge_hash = bytes.fromhex(challenge_hash_hex[2:])

print(f"Using Plot ID: {plot_id.hex()}")
print(f"Using Challenge Hash: {challenge_hash.hex()}")

# 3. Attempt to validate a proof with dummy data
# This demonstrates the API call. With dummy data, it will likely return None
# or raise an error, which is expected.
try:
    # `k_size` typically 32 for mainnet plots
    quality_string = verifier.validate_proof(plot_id, 32, challenge_hash, proof_bytes)
    if quality_string:
        print(f"Proof validation returned quality: {quality_string.hex()}")
    else:
        print("Proof validation returned None (expected with dummy data).")
except Exception as e:
    print(f"Proof validation failed with an error (expected with dummy data): {e}")

print("\nFurther usage of DiskProver and create_plot_disk requires actual plot files and significant resources.")

view raw JSON →