zeropx-poseidon2-goldilocks
Pure-Python Poseidon2 permutation and hash over the Goldilocks field
(p = 2^64 - 2^32 + 1). Byte-for-byte compatible with the
qp-poseidon-core
reference used by Plonky2
and the Quantus Substrate runtime.
Zero runtime dependencies. Python 3.10+, standard library only.
What is this for
- ZK-circuit debugging. You have a Rust prover emitting Poseidon2 hashes and you want to sanity-check a witness or a public input in Python without pulling a Rust toolchain.
- Audit cross-check. Someone hands you a Poseidon2 digest allegedly computed by Plonky2 — you can verify it here without trusting their build.
- Teaching / reproducing. The Poseidon2 paper spec (eprint 2023/323)
maps to concrete code in
permutation.py, next to the round-count and matrix definitions from the same paper. - Small tools that need Poseidon2 without a heavyweight FFI stack.
Not a production prover backend. Pure Python is 100x-1000x slower than an optimised Rust/C implementation. Use it to verify someone else's output, not to prove your own.
Install
pip install zeropx-poseidon2-goldilocks
(Python import module: poseidon2_goldilocks)
Use
from poseidon2_goldilocks import (
permute, hash_no_pad, hash_bytes,
GOLDILOCKS_PRIME, SPONGE_WIDTH, POSEIDON2_OUTPUT,
)
# 12-element field state -> 12-element field state
out = permute([0] * SPONGE_WIDTH)
# Variable-length field-element input -> 4-element digest
digest = hash_no_pad([1, 2, 3, 4, 5])
# Arbitrary bytes -> 32-byte digest (8 bytes/felt, little-endian).
# This is the same composition Quantus uses for header preimages.
d32 = hash_bytes(b"hello world")
Binary Merkle tree (v0.2+)
from poseidon2_goldilocks import (
hash_no_pad, merkle_root, merkle_proof, verify_merkle_proof,
)
# Each leaf is a 4-element digest — hash your data first
leaves = [tuple(hash_no_pad([i])) for i in range(5)]
root = merkle_root(leaves)
# Produce and verify an inclusion proof for leaf index 2
proof = merkle_proof(leaves, 2)
assert verify_merkle_proof(root, leaves[2], proof, 2)
# Tamper detection: a proof for index 2 will not verify at index 3
assert not verify_merkle_proof(root, leaves[2], proof, 3)
Trees are padded to the next power of two with EMPTY_DIGEST (all
zeros). A proof is a list of (sibling_digest, "L"|"R") pairs. The
verifier cross-checks each L/R label against the corresponding
bit of the leaf index, so a proof cannot be replayed at the wrong
position even if it accidentally hashes to the same root.
Compatibility
This package produces identical output to qp-poseidon-core v3.1.0
for its default configuration (width=12, rate=8, capacity=4, S-box
d=7, RF=8, RP=22). The round constants and matrix-diagonal values are
copied verbatim from that reference (originally generated by
qp-poseidon-constants from seed 0x3141592653589793).
Test vectors from the reference implementation's own test suite are
in tests/test_permutation.py — the P3_ZERO_RESULT and
P3_SEQ_RESULT constants are the expected output of
permute([0]*12) and permute([0,1,2,...,11]) respectively.
Non-canonical input caveat
hash_bytes reads its input 8 bytes per field element as
little-endian u64. If any of those chunks decode to a value ≥
GOLDILOCKS_PRIME, it will be silently reduced. This matches the
reference bytes_to_digest, but it means the bytes→hash mapping is
not injective at the field boundary. Guards at higher layers (e.g.
BytesDigest::try_from in qp-wormhole-inputs) reject non-canonical
input before calling this. If you need injectivity, do the same
check yourself.
Related packages
- qp-poseidon-core — the Rust reference this package tracks.
- poseidon-hash —
reference implementation of the original Poseidon (not Poseidon2)
by Ingonyama. Requires
galoisandnumpy. Different algorithm, different constants. - Poseidon Cryptanalysis Initiative —
Ethereum Foundation bounty program (2024-2026) targeting round-reduced
Poseidon and Poseidon2 instances, including this exact
Poseidon-64 over Goldilocks (d=7, t=8)family.
Author & Provenance
Sole Author: Dr. Vander Geraldo Rodrigues da Cunha Júnior (vgrcjr@gmail.com).
Technical & AI-Assisted Provenance Disclosure: Auxiliary computational/LLM tooling was used strictly for boilerplate and test-harness scaffolding under 1:1 human architectural design, code review, deterministic reference-vector verification (qp-poseidon-core / Plonky2), and sole human authorship. Zero runtime third-party or AI dependencies.
License
MIT.
Metadata
Release files for zeropx-poseidon2-goldilocks 0.2.0
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 |
|---|---|---|---|---|
| zeropx_poseidon2_goldilocks-0.2.0.tar.gz | 17.4 kB | Without provenance | Details for zeropx_poseidon2_goldilocks-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zeropx_poseidon2_goldilocks-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for zeropx_poseidon2_goldilocks-0.2.0-py3-none-any.whl |
Total release size: 33.7 kB
Release files / zeropx_poseidon2_goldilocks-0.2.0.tar.gz
| Download URL | zeropx_poseidon2_goldilocks-0.2.0.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6483625a38e64352f4fd8e7c6d7b7ef4450adcbae15db0a4eafec221806a9eb
|
|
BLAKE2b-256 checksum How to use checksums |
fd47d6df522caf74e75a1e39f15f0467b16926b8111d6e04fbf8bca804007ba6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / zeropx_poseidon2_goldilocks-0.2.0-py3-none-any.whl
| Download URL | zeropx_poseidon2_goldilocks-0.2.0-py3-none-any.whl |
|---|---|
| Size | 16.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
41c0961f42e4e2e345d41d32f74aa7a0edf8ea3f6d56bec9171a074ef9f4c6c5
|
|
BLAKE2b-256 checksum How to use checksums |
fe84af102f5eb989ecd364e00d321febedafa10e9444d770108eeaf3a14d22e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for zeropx-poseidon2-goldilocks 0.2.0
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.