Fast Python bindings for the Baby JubJub elliptic curve (Research Prototype)
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file babyjubjub_py-0.1.1.tar.gz.
File metadata
- Download URL: babyjubjub_py-0.1.1.tar.gz
- Upload date:
- Size: 23.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c6fb09825f1a6f5e853ae0678dca92d5c7ecdb04f3fa7bd40f00043d20534d1
|
|
| MD5 |
6577166cf420702db2ba6a396f305b63
|
|
| BLAKE2b-256 |
c74f8838710fa91d2da1419e525e47860f421dd46e49c9a8a4557ac800f5c781
|
File details
Details for the file babyjubjub_py-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: babyjubjub_py-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 370.3 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0310e5d009b102bfee085fbcee8fef02384d723f3c5e65169136f2e2acecfc0e
|
|
| MD5 |
088e77d1b53c706332bbce3c3563e17a
|
|
| BLAKE2b-256 |
cb56699cf85ce824b10b12308edf607a8e651d00ec52f55bd1beab9059a3b225
|