Skip to content

0-knight/poseidon

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

poseidon

poseidon is built to be used in SNARK and non native recursion friendly transcript for appliedzkp/halo2.

Poseidon hash function implmenetation is in line with the reference and the test vectors. It also uses optimized constants and sparse MDS matrices to reduce number of multiplications. For now constants are calculated in construction time they are planned to be hardcoded once transcript design matures. Currently only supports variable length hashing with $\alpha = 5$ sbox. Some parts of Poseidon implementation are adapted or ported from:

Example usage

// Initialize a mutable hasher with constant capacity parameters 
// and number of rounds arguments. This will also generate matrices 
// and constants according to the specification
let mut hasher = Poseidon::<Fr, T, RATE>::new(number_of_full_rounds, number_of_half_rounds);

// In sake of the example we generate some dummy scalar inputs
let inputs = (0..number_of_inputs_0)
    .map(|_| Fr::random(&mut rng))
    .collect::<Vec<Fr>>();

// Feed inputs to the Absorption line
hasher.update(&inputs[..]);

// Yield your challange with squeeze function
let challenge_alpha = hasher.squeeze();

// Then again ...
let inputs = (0..number_of_inputs_1)
    .map(|_| Fr::random(&mut rng))
    .collect::<Vec<Fr>>();
hasher.update(&inputs[..]);
let challenge_beta = hasher.squeeze();

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%