Rust-backed Python library for generating timelock-encrypted weight commitments for Bittensor's commit-reveal mechanism using drand randomness.
Archived. The repository is read-only: no more fixes or releases will come.
pip install bittensor-drandbittensor-drand
Drand timelock encryption for Bittensor commit-reveal weights and general-purpose commitments. Rust core with Python bindings via PyO3.
What's new in 2.0
get_encrypted_commitis replaced byget_encrypted_commit_v2. The old modulo-based epoch math ((block + netuid + 1) / (tempo + 1)) is gone. The chain now uses a stateful epoch counter (SubnetEpochIndex), owner-triggered pending epochs, and configurable tempo. The new function simulates the chain'sblock_steppipeline to predict the exact reveal block.- Breaking change:
get_encrypted_commit_v2requires epoch schedule state instead oftempo + current_block + netuid. The SDK (bittensor>=11.0.0) provides this viasubtensor.get_epoch_schedule_state(netuid). - Added
encrypt_mlkem768andmlkem_kdf_idfor ML-KEM-768 + XChaCha20Poly1305 encryption.
Quick start
from bittensor_drand import get_encrypted_commit_v2
Installation
pip install bittensor-drand
For development (build from source):
git clone https://github.com/opentensor/bittensor-drand.git
cd bittensor-drand
python3 -m venv venv
. venv/bin/activate
pip install maturin bittensor
maturin develop
Usage: commit-reveal weights
Using the SDK (recommended)
The Bittensor SDK handles all the epoch state plumbing internally. You just call set_weights:
import bittensor as bt
sub = bt.Subtensor("local") # or "finney" for mainnet
wallet = bt.Wallet()
result, message = sub.set_weights(
wallet=wallet,
netuid=1,
uids=[0, 1, 2],
weights=[0.5, 0.3, 0.2],
wait_for_inclusion=True,
wait_for_finalization=True,
)
print(f"Success: {result}, message: {message}")
Using bittensor_drand directly
If you need lower-level control (custom clients, miners, tooling):
import bittensor as bt
from bittensor_drand import get_encrypted_commit_v2
sub = bt.Subtensor("local")
netuid = 1
current_block = sub.get_current_block()
# Fetch epoch schedule state from chain
schedule = sub.get_epoch_schedule_state(netuid, block=current_block)
reveal_period = sub.get_subnet_reveal_period_epochs(netuid=netuid)
uids = [1, 3]
weights = [100, 200] # u16 values after convert_weights_and_uids_for_emit
version_key = 843000
wallet = bt.Wallet()
commit_bytes, reveal_round = get_encrypted_commit_v2(
uids=uids,
weights=weights,
version_key=version_key,
last_epoch_block=schedule.last_epoch_block,
pending_epoch_at=schedule.pending_epoch_at,
subnet_epoch_index=schedule.subnet_epoch_index,
tempo=schedule.tempo,
blocks_since_last_step=schedule.blocks_since_last_step,
current_block=current_block,
subnet_reveal_period_epochs=reveal_period,
block_time=12.0,
hotkey=wallet.hotkey.public_key,
)
print(f"Encrypted commit: {len(commit_bytes)} bytes, reveal round: {reveal_round}")