| Crates.io | atlas-poseidon |
| lib.rs | atlas-poseidon |
| version | 0.1.1 |
| created_at | 2025-11-25 06:18:33.287921+00 |
| updated_at | 2025-11-29 14:26:41.034115+00 |
| description | Atlas Poseidon hashing |
| homepage | https://atlaschain.io |
| repository | https://github.com/atlas-chain/atlas-poseidon |
| max_upload_size | |
| id | 1949252 |
| size | 66,965 |
Atlas Poseidon hashing library for zero-knowledge proof systems and blockchain applications.
This crate provides an implementation of the Poseidon hash function, optimized for use in zero-knowledge proof systems. Poseidon is a cryptographic hash function designed specifically for efficient use in zkSNARKs and other advanced cryptographic protocols.
no_std environmentsAdd this to your Cargo.toml:
[dependencies]
atlas-poseidon = "0.1.0"
For unstable API usage (required from v4.0.0 onward):
[dependencies]
atlas-poseidon = { version = "0.1.0", features = ["atlas-unstable-api"] }
Hash a single 32-byte input:
use atlas_poseidon::{hash, Parameters, Endianness};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let input = [1u8; 32];
let hash_result = hash(
Parameters::Bn254X5,
Endianness::BigEndian,
&input
)?;
println!("Hash: {:?}", hash_result.to_bytes());
Ok(())
}
Hash multiple inputs together:
use atlas_poseidon::{hashv, Parameters, Endianness};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let input1 = [1u8; 32];
let input2 = [2u8; 32];
let hash_result = hashv(
Parameters::Bn254X5,
Endianness::BigEndian,
&[&input1, &input2]
)?;
println!("Hash: {:?}", hash_result.to_bytes());
Ok(())
}
The library supports both big-endian and little-endian byte ordering:
use atlas_poseidon::{hash, Parameters, Endianness};
let input = [1u8; 32];
// Big-endian
let hash_be = hash(Parameters::Bn254X5, Endianness::BigEndian, &input)?;
// Little-endian
let hash_le = hash(Parameters::Bn254X5, Endianness::LittleEndian, &input)?;
hash(parameters, endianness, data) - Hash a single inputhashv(parameters, endianness, inputs) - Hash multiple inputsParameters::Bn254X5 - BN254 curve with x^5 S-box (currently the only supported parameter)Endianness::BigEndian - Big-endian byte orderingEndianness::LittleEndian - Little-endian byte orderingThe library provides detailed error types through PoseidonSyscallError:
InvalidNumberOfInputs - Maximum of 12 inputs allowedInvalidInputLength - Input length must match the prime field modulus (32 bytes)InputLargerThanModulus - Input value exceeds the prime field modulusThis crate works on both standard platforms and the Atlas Chain:
light-poseidon and ark-bn254 libraries for computationFor compatibility with older code, a legacy API is available in the legacy module. See the documentation for details.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.