{"id":46004868,"url":"https://github.com/opentensor/bittensor-drand","last_synced_at":"2026-02-28T23:01:57.529Z","repository":{"id":266338433,"uuid":"894773912","full_name":"opentensor/bittensor-drand","owner":"opentensor","description":null,"archived":false,"fork":false,"pushed_at":"2026-02-19T20:50:20.000Z","size":436,"stargazers_count":6,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-19T21:37:36.787Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opentensor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.MD","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-11-27T00:54:50.000Z","updated_at":"2026-02-19T20:47:11.000Z","dependencies_parsed_at":"2025-01-08T18:47:11.046Z","dependency_job_id":"e8c65567-b738-468a-9ede-cbef4d5db584","html_url":"https://github.com/opentensor/bittensor-drand","commit_stats":null,"previous_names":["opentensor/bittensor-commit-reveal","opentensor/bittensor-drand"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/opentensor/bittensor-drand","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentensor%2Fbittensor-drand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentensor%2Fbittensor-drand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentensor%2Fbittensor-drand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentensor%2Fbittensor-drand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opentensor","download_url":"https://codeload.github.com/opentensor/bittensor-drand/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentensor%2Fbittensor-drand/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29954583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T22:53:01.873Z","status":"ssl_error","status_checked_at":"2026-02-28T22:52:50.699Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-02-28T23:01:54.547Z","updated_at":"2026-02-28T23:01:57.514Z","avatar_url":"https://github.com/opentensor.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Usage\r\nPython package `bittensor_drand` has one function.\r\n\r\n```python\r\nfrom bittensor_drand import get_encrypted_commit\r\n```\r\n\r\nTo test the function in your terminal:\r\n1. Spin up a local subtensor branch which includes CR3\r\n2. Create a subnet with netuid 1 (or replace the netuid with the one you create)\r\n```bash\r\nmkdir test\r\ncd test\r\npython3 -m venv venv\r\n. venv/bin/activate\r\npip install maturin bittensor ipython\r\ncd ..\r\n\r\nmaturin develop\r\nipython\r\n\r\n```\r\n\r\nthen copy-past to ipython\r\n```python\r\nimport numpy as np\r\nimport bittensor_drand as crv3\r\nfrom bittensor.utils.weight_utils import convert_weights_and_uids_for_emit\r\nimport bittensor as bt\r\n\r\nuids = [1, 3]\r\nweights = [0.3, 0.7]\r\nversion_key = 843000\r\nnetuid = 1\r\n\r\nsubtensor = bt.Subtensor(\"local\")\r\n\r\nsubnet_reveal_period_epochs = subtensor.get_subnet_reveal_period_epochs(\r\n        netuid=netuid\r\n    )\r\ntempo = subtensor.get_subnet_hyperparameters(netuid).tempo\r\ncurrent_block = subtensor.get_current_block()\r\n\r\nif isinstance(uids, list):\r\n    uids = np.array(uids, dtype=np.int64)\r\nif isinstance(weights, list):\r\n    weights = np.array(weights, dtype=np.float32)\r\n\r\nuids, weights = convert_weights_and_uids_for_emit(uids, weights)\r\n\r\nprint(crv3.get_encrypted_commit(uids, weights, version_key, tempo, current_block, netuid, subnet_reveal_period_epochs))\r\n```\r\nexpected result\r\n```python\r\n(b'\\xb9\\x96\\xe4\\xd1\\xfd\\xabm\\x8cc\\xeb\\xe3W\\r\\xc7J\\xb4\\xea\\xa9\\xd5u}OG~\\xae\\xcc\\x9a@\\xdf\\xee\\x16\\xa9\\x0c\\x8d7\\xd6\\xea_c\\xc2\u003c\\xcb\\xa6\\xbe^K\\x97|\\x16\\xc6|;\\xb5Z\\x97\\xc9\\xb4\\x8em\\xf1hv\\x16\\xcf\\xea\\x1e7\\xbe-Z\\xe7e\\x1f$\\n\\xf8\\x08\\xcb\\x18.\\x94V\\xa3\\xd7\\xcd\\xc9\\x04F::\\t)Z\\xc6\\xbey \\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xaaN\\xe8\\xe97\\x8f\\x99\\xbb\"\\xdf\\xad\\xf6\\\\#%\\xca:\\xc2\\xce\\xf9\\x96\\x9d\\x8f\\x9d\\xa2\\xad\\xfd\\xc73j\\x16\\xda \\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x84*\\xb0\\rw\\xad\\xdc\\x02o\\xf7i)\\xbb^\\x99e\\xe2\\\\\\xee\\x02NR+-Q\\xcd \\xf7\\x02\\x83\\xffV\u003e\\x00\\x00\\x00\\x00\\x00\\x00\\x00\"\\x00\\x00\\x00\\x00\\x00\\x00\\x00*\\x13wXb\\x93\\xc5\"F\\x17F\\x05\\xcd\\x15\\xb0=\\xe2d\\xfco3\\x16\\xfd\\xe9\\xc6\\xbc\\xd1\\xb3Y\\x97\\xf9\\xb9!\\x01\\x0c\\x00\\x00\\x00\\x00\\x00\\x00\\x00X\\xa2\\x8c\\x18Wkq\\xe5\\xe6\\x1c2\\x86\\x08\\x00\\x00\\x00\\x00\\x00\\x00\\x00AES_GCM_', 13300875)\r\n```\r\n\r\nTo test this in a local subnet:\r\n1. Spin up a local node based on the subtensor branch `spiigot/add-pallet-drand` using command `./scripts/localnet.sh False`\r\n2. Create a subnet\r\n3. Change the following hyperparameters:\r\n    - `commit_reveal_weights_enabled` -\u003e `True`\r\n    - `tempo` -\u003e 10 (keep in mind that you need to provide this as `tempo` argument to `get_encrypted_commit` function. Use polkadot website for this action.)\r\n    - `weights_rate_limit` -\u003e 0 (Reduces the limit when you can set weights.)\r\n4. Register 1 or more wallets to the subnet\r\n5. Create and activate python virtual environment (`python3 -m venv venv \u0026\u0026 . venv/bin/activate`)\r\n6. Checkout bittensor `feat/roman/cr-v-3` branch.\r\n7. Install bittensor `pip install -e .`\r\n8. Cd to directory you cloned `https://github.com/opentensor/bittensor-commit-reveal/tree/staging` (FFI for CRv3).\r\n9. Install the `maturin` python package and build/install `bittensor-commit-reveal` package to your env using the command `pip install maturin \u0026\u0026 maturin develop`\r\n10. Run the following script within your python environment:\r\n```python\r\nimport requests\r\nimport time\r\n\r\nfrom bittensor import Subtensor, logging, Wallet\r\n\r\nDRAND_API_BASE_URL_Q = \"https://api.drand.sh/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971\"\r\n\r\nlogging.set_info()\r\n\r\n\r\ndef get_drand_info(uri):\r\n    \"\"\"Fetch Drand network information.\"\"\"\r\n    url = f\"{uri}/info\"\r\n    response = requests.get(url)\r\n    response.raise_for_status()\r\n    return response.json()\r\n\r\n\r\ndef get_current_round(info):\r\n    \"\"\"Calculate the current round based on genesis_time and period.\"\"\"\r\n    current_time = int(time.time())\r\n    genesis_time = info[\"genesis_time\"]\r\n    period = info[\"period\"]\r\n    return (current_time - genesis_time) // period + 1\r\n\r\n\r\ndef main():\r\n    sub = Subtensor(\"local\")\r\n\r\n    uids = [0]\r\n    weights = [0.7]\r\n\r\n    wallet = Wallet()  # corresponds the subnet owner wallet\r\n\r\n    result, message = sub.set_weights(\r\n        wallet=wallet,\r\n        netuid=1,\r\n        uids=uids,\r\n        weights=weights,\r\n        wait_for_inclusion=True,\r\n        wait_for_finalization=True,\r\n    )\r\n    logging.info(f\"\u003e\u003e\u003e Success, [blue]{result}[/blue], message: [magenta]{message}[/magenta]\")\r\n\r\n    reveal_round = int(message.split(\":\")[-1])\r\n    # Fetch Drand network info\r\n    for uri in [DRAND_API_BASE_URL_Q]:\r\n        print(f\"Fetching info from {uri}...\")\r\n        info = get_drand_info(uri)\r\n        print(\"Info:\", info)\r\n\r\n        while True:\r\n            time.sleep(info[\"period\"])\r\n            current_round = get_current_round(info)\r\n            logging.console.info(f\"Current round: [yellow]{current_round}[/yellow]\")\r\n            if current_round == reveal_round:\r\n                logging.console.warning(f\"\u003e\u003e\u003e It's time to reveal the target round: [blue]{reveal_round}[/blue]\")\r\n\r\n                break\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    main()\r\n```\r\n11. Wait until your target_round comes.\r\n\r\n12. Check your weights with the following code:\r\n\r\n```python\r\nimport bittensor as bt\r\n\r\nsub = bt.Subtensor(network=\"local\")\r\n\r\nnetuid = 1  # your created subnet's netuid\r\n\r\nprint(sub.weights(netuid=netuid))\r\n```\r\n13. You can now see the same weights which you committed earlier","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentensor%2Fbittensor-drand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopentensor%2Fbittensor-drand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentensor%2Fbittensor-drand/lists"}