Skip to content

feat: add encrypt_at_round() for direct Drand round encryption#56

Merged
basfroman merged 4 commits intoopentensor:stagingfrom
ShubhamChndrvnshi:main
Nov 12, 2025
Merged

feat: add encrypt_at_round() for direct Drand round encryption#56
basfroman merged 4 commits intoopentensor:stagingfrom
ShubhamChndrvnshi:main

Conversation

@ShubhamChndrvnshi
Copy link
Contributor

@ShubhamChndrvnshi ShubhamChndrvnshi commented Nov 5, 2025

Summary

  • What: Add encrypt_at_round(data: bytes, reveal_round: int) to timelock-encrypt data for a specific Drand reveal round. Expose the function to Python and extend tests.
  • Why: Allows callers to target an exact Drand round instead of deriving it from block timing, simplifying integrations and deterministic tests.
  • How: Bind a new Rust function that encrypts using a provided round, return encoded payload plus the same round; export wrapper in Python package.

Changes

  • Rust/FFI:
    • Add encrypt_at_round to src/python_bindings.rs using drand::encrypt_and_compress and drand::UserData { encrypted_data, reveal_round }.encode().
    • Register the function in the Python module init.
  • Python bindings:
    • Export _encrypt_at_round from native module and provide a typed wrapper encrypt_at_round(data: bytes, reveal_round: int) -> tuple[bytes, int] in bittensor_drand/__init__.py.
  • Tests:
    • Extend tests/test_all_functions.py with test_encrypt_at_round_and_decrypt covering past and future round behavior.

Diff Summary

  • Files changed vs upstream main:
    • bittensor_drand/__init__.py (+17)
    • src/python_bindings.rs (+38)
    • tests/test_all_functions.py (+28 −1)

Technical Details

  • The new binding directly accepts a reveal_round: u64 and produces an encoded payload that includes both the ciphertext and the round metadata.
  • Python wrapper mirrors the existing API style and returns (encrypted_bytes, reveal_round).
  • Tests assert immediate decryptability for past rounds and graceful non-decryption for future rounds when no_errors=True.

Compatibility

  • No breaking changes; existing APIs (encrypt, decrypt, get_encrypted_commit, get_encrypted_commitment) remain unchanged.
  • Works with current crate and PyO3 versions declared in Cargo.toml and Python versions in pyproject.toml.

Testing

  • Added unit tests in tests/test_all_functions.py.
  • Local verification: maturin develop followed by running the test suite.

Documentation

  • Python docstring added for encrypt_at_round in __init__.py.
  • README usage can optionally include a short example for encrypt_at_round.

Checklist

  • Tests pass locally
  • Docs/README updated if needed
  • Backward compatibility confirmed
  • CI/build (maturin/wheels) verified

Related

  • Upstream repository: opentensor/bittensor-drand (link)

@ShubhamChndrvnshi ShubhamChndrvnshi changed the base branch from main to staging November 6, 2025 05:59
@thewhaleking
Copy link
Contributor

Looks fine to me, but I want @basfroman to have a look.

@ShubhamChndrvnshi
Copy link
Contributor Author

Looks fine to me, but I want @basfroman to have a look.

Thanks for the review! Happy to make any changes if @basfroman has feedback.

@basfroman
Copy link
Contributor

Looks fine to me, but I want @basfroman to have a look.

Thanks for the review! Happy to make any changes if @basfroman has feedback.

Hey @ShubhamChndrvnshi LGTM. But I updated staging after your PR. Please pull the changes and I run the workflows again.
Thank your for contribution!

@ShubhamChndrvnshi
Copy link
Contributor Author

@basfroman
Done! I've merged the changes from upstream staging. Ready for review and workflow runs. Thanks!

@basfroman basfroman merged commit aad02ed into opentensor:staging Nov 12, 2025
38 checks passed
This was referenced Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants