Baby JubJub Python Bindings
Fast Python bindings for the Baby JubJub elliptic curve, powered by Rust.
Research Prototype Warning
This library is a research prototype and should NOT be used in production systems.
- The
hash_to_pointimplementation is NOT cryptographically secure - It uses a simple hash-to-scalar-to-point method that introduces bias
- Proper hash-to-curve methods (RFC 9380) are not implemented
- This library is intended for research and experimentation only
- No security audits have been performed
Overview
This library provides Python bindings to the babyjubjub-rs Rust library, offering high-performance elliptic curve operations for the Baby JubJub curve.
Baby JubJub is a twisted Edwards curve embedded in the BN254 scalar field, designed for efficient use in zero-knowledge proof systems like Circom, zkSync, and Tornado Cash.
Features
- Fast: Native Rust implementation provides 100x speedup over pure Python
- Complete API: Point addition, scalar multiplication, compression, hashing
- Thread-safe: GIL is released during expensive operations for true parallelism
- Well-tested: Comprehensive test suite with 26+ tests
- Cross-platform: Supports Linux, macOS, and Windows (Python 3.10+)
- Easy to use: Simple Python API with no Rust knowledge required
Performance
Individual operations are highly optimized:
Point addition: 1.85 µs
Scalar multiplication: 3.38 µs
Compression: 0.67 µs
Uncompressed serialize: 0.07 µs
Uncompressed deserialize: 0.15 µs
The library includes both compressed (32-byte) and uncompressed (64-byte) serialization. Uncompressed serialization is significantly faster for multiprocessing scenarios where points need frequent serialization.
Installation
pip install babyjubjub-py
From source
# Clone the repository
cd /path/to/babyjubjub-py
# Install maturin
pip install maturin
# Build and install
maturin develop --release
Quick Start
import babyjubjub_py as bjj
# Get the generator point
G = bjj.ECPoint.generator()
# Scalar multiplication
P = bjj.ECPoint.from_scalar("123")
# Point addition
Q = bjj.ECPoint.from_scalar("456")
R = P.add(Q)
# Hash to curve point
H = bjj.ECPoint.hash_to_point(b"Hello, World!")
# Compression
compressed = P.to_bytes()
P_restored = bjj.ECPoint.from_bytes(compressed)
API Reference
ECPoint class
Constructors
ECPoint(x_hex: str, y_hex: str)- Create from coordinatesECPoint.generator()- Get the base point (B8)ECPoint.infinity()- Get the identity pointECPoint.from_scalar(scalar: str)- Create asscalar * GECPoint.from_bytes(bytes: list[int])- Decompress from 32 bytesECPoint.hash_to_point(data: bytes)- Hash arbitrary data to a point
Methods
add(other: ECPoint) -> ECPoint- Point additionneg() -> ECPoint- Point negationsub(other: ECPoint) -> ECPoint- Point subtractionscalar_mult(scalar: str) -> ECPoint- Scalar multiplicationis_infinity() -> bool- Check if identityx_hex() -> str- Get x coordinate as hex stringy_hex() -> str- Get y coordinate as hex stringto_bytes() -> list[int]- Compress to 32 bytes
Module Constants
__version__- Library versionCURVE_NAME- "Baby JubJub"CURVE_ORDER- Order of the curve subgroup
Baby JubJub Curve Details
- Curve equation: ax² + y² = 1 + dx²y² (twisted Edwards)
- Base field: BN254 scalar field (254-bit prime)
- Order: 21888242871839275222246405745257275088614511777268538073601725287587578984328
- Cofactor: 8
Use Cases
- Zero-knowledge proofs: Circom, zkSync, Aztec
- EdDSA signatures: Privacy-preserving signatures
- Commitment schemes: Pedersen commitments
- Threshold cryptography: Distributed key generation
- Cryptographic protocols: Any application requiring Baby JubJub curve operations
Development
Requirements
- Rust 1.56+ (install via rustup)
- Python 3.8+
- Maturin
Building
# Development build (fast iteration)
maturin develop
# Release build (optimized)
maturin build --release
# Run tests
python test_basic.py
Project Structure
babyjubjub-py/
├── Cargo.toml # Rust dependencies
├── pyproject.toml # Python packaging
├── src/
│ └── lib.rs # PyO3 bindings
├── test_basic.py # Python tests
└── README.md
Example Usage in Applications
The library can be integrated into cryptographic applications requiring Baby JubJub operations:
from babyjubjub_py import ECPoint
# Use in your cryptographic protocol
def my_protocol(data):
# Hash input to curve point
point = ECPoint.hash_to_point(data)
# Perform operations
secret = "123456789"
commitment = point.scalar_mult(secret)
return commitment
License
Apache-2.0 (same as babyjubjub-rs)
Credits
- Built on babyjubjub-rs by arnaucube
- Uses PyO3 for Python bindings
Alternatives
- Pure Python: pybabyjubjub - slower but no dependencies
- Full Rust: Use babyjubjub-rs directly
Troubleshooting
Import Error
ImportError: cannot import name 'ECPoint' from 'babyjubjub_py'
Solution: Rebuild the library with maturin develop --release
Performance Issues
If operations are slow:
- Ensure you built with
--releaseflag - Check Python version (3.10+ recommended)
- Verify Rust is using the release profile
Installation Errors
If pip install fails:
- Install Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - Install Python dev headers:
sudo apt-get install python3-dev - Install build tools:
sudo apt-get install build-essential
Contributing
Contributions welcome! Please feel free to:
- Report bugs
- Suggest features
- Submit pull requests
- Improve documentation
Support
For issues or questions:
- Open an issue on GitHub
- Check the babyjubjub-rs documentation
- Review the PyO3 user guide
Status: Research Prototype / Beta
Version: 0.1.1
Warning: Not for production use. See security warning at top of README.
Metadata
Release files for babyjubjub-py 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| babyjubjub_py-0.1.1.tar.gz | 23.7 kB | Without provenance | Details for babyjubjub_py-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| babyjubjub_py-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl | CPython 3.10 | CPython 3.10 | Linux glibc 2.34+ x86-64 | Details for babyjubjub_py-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl |
Total release size: 394.1 kB
Release files / babyjubjub_py-0.1.1.tar.gz
| Download URL | babyjubjub_py-0.1.1.tar.gz |
|---|---|
| Size | 23.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4c6fb09825f1a6f5e853ae0678dca92d5c7ecdb04f3fa7bd40f00043d20534d1
|
|
BLAKE2b-256 checksum How to use checksums |
c74f8838710fa91d2da1419e525e47860f421dd46e49c9a8a4557ac800f5c781
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.0
|
Release files / babyjubjub_py-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl
| Download URL | babyjubjub_py-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 370.3 kB |
| Tags | CPython 3.10 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
0310e5d009b102bfee085fbcee8fef02384d723f3c5e65169136f2e2acecfc0e
|
|
BLAKE2b-256 checksum How to use checksums |
cb56699cf85ce824b10b12308edf607a8e651d00ec52f55bd1beab9059a3b225
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.0
|
Security for babyjubjub-py 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.