Registry / aws / bittensor-drand

bittensor-drand

JSON →
library1.3.0pypypi✓ verified 82d ago

bittensor-drand is a Python library that provides functionality for interacting with the Drand (distributed randomness) mechanism within the Bittensor ecosystem. It facilitates secure, verifiable randomness for applications like commit-reveal schemes and timelock encryption of weights on the Subtensor blockchain. The library is currently at version 1.3.0 and receives regular updates to support new cryptographic features and Bittensor protocol changes.

pip install bittensor-drand
INSTALL
IMPORT
SIG · BITTENSOR-DRAND
B
bittensor-drand
awspythonv1.3.0
Install
1.6s avg
Import
11ms
Disk
21MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 1.6s
py 3.11
✕ build_error
✓ 1.53s
py 3.12
✕ build_error
✓ 1.68s
py 3.13
✕ build_error
✓ 1.63s
py 3.9
✕ build_error
✕ build_error
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_encrypted_commit
from bittensor_drand import get_encrypted_commit_v2
from bittensor_drand import get_encrypted_commit

This quickstart demonstrates how to generate an encrypted commit for Bittensor weights and perform MLKEM768 encryption using the bittensor-drand library. It includes mocking necessary Bittensor network parameters for a runnable example, though in a real application, these would be fetched from a live or local Subtensor instance. A local Subtensor node with commit-reveal v3 (CRv3) and Drand support is required for actual testing.

import numpy as np import bittensor_drand as drand_lib import bittensor as bt from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit import os # NOTE: This quickstart assumes a local Bittensor Subtensor node is running. # For full functionality, you need a running Subtensor instance and a configured wallet. # Example: subtensor = bt.subtensor(network="local", chain_endpoint="ws://127.0.0.1:9944") # Mock data for demonstration purposes uids = np.array([1, 3], dtype=np.int64) weights = np.array([0.3, 0.7], dtype=np.float32) version_key = 843000 # Example version key netuid = 1 # Example network ID # In a real scenario, you would fetch these from a live or local subtensor instance # For local testing, ensure your local subtensor is configured with CRv3 and Drand. # tempo = subtensor.get_subnet_hyperparameters(netuid).tempo # current_block = subtensor.get_current_block() # subnet_reveal_period_epochs = subtensor.get_subnet_reveal_period_epochs(netuid=netuid) tempo = 10 # Mock tempo current_block = 100 # Mock current block subnet_reveal_period_epochs = 20 # Mock reveal period # Ensure weights are correctly formatted for emit uids, weights = convert_weights_and_uids_for_emit(uids, weights) try: encrypted_commit = drand_lib.get_encrypted_commit( uids=uids, weights=weights, version_key=version_key, tempo=tempo, current_block=current_block, netuid=netuid, subnet_reveal_period_epochs=subnet_reveal_period_epochs ) print(f"Successfully generated encrypted commit: {encrypted_commit[:60]}...") # Example of MLKEM768 encryption (requires a target Drand round) drand_round = 123456 # A specific Drand round to encrypt for encryption_data = b"My secret message for Drand round!" encrypted_mlkem_payload = drand_lib.encrypt_mlkem768(drand_round, encryption_data) print(f"MLKEM768 encrypted payload: {encrypted_mlkem_payload[:60]}...") except Exception as e: print(f"An error occurred: {e}") print("Please ensure you have a local Bittensor Subtensor node running with CRv3 support ") print("and that bittensor is installed (pip install bittensor).")
Debug
Known issues
breakingThe package was renamed from `bittensor-commit-reveal` to `bittensor-drand` in version 0.5.0. Users upgrading from `0.4.x` or earlier must update their import statements and package name.
fix
Uninstall `bittensor-commit-reveal` and install `bittensor-drand`. Update all `import bittensor_commit_reveal` statements to `import bittensor_drand`.
affects: <0.5.0
breakingIn v1.0.0, the `hotkey` parameter was added to the `WeightsTlockPayload` structure. Integrations that directly construct or interact with this payload might need to be updated.
fix
Review any direct usage of `WeightsTlockPayload` and ensure the `hotkey` parameter is correctly provided.
affects: <1.0.0
gotchaThe `bittensor-drand` library heavily relies on the functionality provided by the Subtensor blockchain (Bittensor's L1). Runtime upgrades on Subtensor can introduce breaking API changes related to Drand pulse writes, commit-reveal mechanisms, and other core features. Compatibility with specific Subtensor runtime versions is crucial.
fix
Always consult the official Bittensor documentation and release notes for both `bittensor-drand` and `Subtensor` to ensure compatibility between library versions and the target Subtensor network (mainnet, testnet, or local). Monitor Subtensor runtime version updates.
affects: All versions
gotchaFor local development and building from source, the Rust toolchain and `maturin` (Rust-based Python binding tool) are required to compile the underlying Rust components.
fix
Ensure Rust and `maturin` (`pip install maturin`) are installed and configured in your development environment if building from source or contributing.
affects: All versions (for development/source installs)
Upgrade
Version history
1.3.0latest on PyPI · released Feb 19, 2026
Audit
Dependencies
bittensorrequiredCore interaction with the Bittensor network and Subtensor blockchain.
numpyrequiredUsed for array manipulation in weight handling.
maturinoptionalRequired for building the Rust-backed Python package from source during development.
Agent activity
63 hits · last 30 days
node
54
OpenAI (training)
1
Resources