MCPcopy Index your code
hub / github.com/dusk-network/Poseidon252

github.com/dusk-network/Poseidon252 @v0.43.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.43.0 ↗ · + Follow
105 symbols 198 edges 18 files 35 documented · 33%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Build Status Repository Documentation

Dusk-Poseidon

Reference implementation for the Poseidon Hashing algorithm.

Reference: Starkad and Poseidon: New Hash Functions for Zero Knowledge Proof Systems

This repository has been created so there's a unique library that holds the tools & functions required to perform Poseidon Hashes on field elements of the bls12-381 elliptic curve.

The hash uses the Hades design for its inner permutation and the SAFE framework for contstructing the sponge.

The library provides the two hashing techniques of Poseidon: - The 'normal' hashing functionalities operating on BlsScalar. - The 'gadget' hashing functionalities that build a circuit which outputs the hash.

Features

Select exactly one BLS backend feature when depending on this crate:

  • bls-backend-dusk forwards the pure Rust Dusk backend.
  • bls-backend-blst forwards the blst backend.

The backend features are mutually exclusive and are not enabled by default. The zk feature enables the dusk-plonk gadgets, and encryption enables the SAFE encryption helpers.

Example

use rand::rngs::StdRng;
use rand::SeedableRng;

use dusk_poseidon::{Domain, Hash};
use dusk_curves::bls12_381::BlsScalar;
use ff::Field;

// generate random input
let mut rng = StdRng::seed_from_u64(0xbeef);
let mut input = [BlsScalar::zero(); 42];
for scalar in input.iter_mut() {
    *scalar = BlsScalar::random(&mut rng);
}

// digest the input all at once
let hash = Hash::digest(Domain::Other, &input);

// update the input gradually
let mut hasher = Hash::new(Domain::Other);
hasher.update(&input[..3]);
hasher.update(&input[3..]);
assert_eq!(hash, hasher.finalize());

// create a hash used for merkle tree hashing with arity = 4
let merkle_hash = Hash::digest(Domain::Merkle4, &input[..4]);

// which is different when another domain is used
assert_ne!(merkle_hash, Hash::digest(Domain::Other, &input[..4]));

Benchmarks

There are benchmarks for hashing, encrypting and decrypting in their native form, operating on Scalar, and for a zero-knowledge circuit proof generation and verification.

To run all benchmarks on your machine, run

cargo bench --features=zk,encryption,bls-backend-blst

in the repository.

Licensing

This code is licensed under Mozilla Public License Version 2.0 (MPL-2.0). Please see LICENSE for further info.

About

Implementation designed by the dusk team.

Contributing

  • If you want to contribute to this repository/project please, check CONTRIBUTING.md
  • If you want to report a bug or request a new feature addition, please open an issue on this repository.

Extension points exported contracts — how you extend this code

Hades (Interface)
Defines the Hades252 permutation algorithm. This permutation is a 3-step process that: - Applies half of the `FULL_ROUN [2 …
src/hades/permutation.rs

Core symbols most depended-on inside this repo

compile_and_verify
called by 9
tests/hash.rs
public_inputs
called by 9
tests/hash.rs
encrypt
called by 8
src/encryption.rs
u64_from_buffer
called by 8
src/hades.rs
setup
called by 8
src/hades/permutation/gadget.rs
update
called by 5
src/hash.rs
finalize
called by 4
src/hash.rs
permute
called by 4
src/hades/permutation/gadget.rs

Shape

Method 57
Function 32
Class 13
Enum 2
Interface 1

Languages

Rust100%

Modules by API surface

src/hades/permutation/gadget.rs17 symbols
tests/hash.rs11 symbols
src/hash.rs11 symbols
src/hades/permutation/scalar.rs11 symbols
tests/encryption_gadget.rs9 symbols
src/hash/gadget.rs8 symbols
src/hades.rs8 symbols
tests/encryption.rs5 symbols
benches/encrypt.rs5 symbols
benches/decrypt.rs5 symbols
src/hades/permutation.rs4 symbols
benches/hash.rs4 symbols

For agents

$ claude mcp add Poseidon252 \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page