Skip to content

Poseidon Hash for Goldilocks Field with Expanded Functionality

License

Notifications You must be signed in to change notification settings

OpenAssetStandards/poseidon-goldilocks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues


poseidon-goldilocks

A full suite of Poseidon Goldilocks hash functions that are one-to-one compatible with those used in plonky2, along with commonly used functions for creating and verifying merkle proofs compatible with plonky2.

Credit to the original Mir team for creating plonky2. Constants for poseidon goldilocks were generated using hadeshash.

Usage:

Two to One (Hash two 4-element-wide values)

import {twoToOne} from 'poseidon-goldilocks';
const c = twoToOne([1337n, 123456n, 100n, 15n], [1n, 2n, 3n, 4n]);
Plonky2 Equivalent

type F = GoldilocksField;
let a = HashOut { elements: [
  F::from_noncanonical_u64(1337),
  F::from_noncanonical_u64(123456),
  F::from_noncanonical_u64(100),
  F::from_noncanonical_u64(15),
] };
let b = HashOut { elements: [
  F::from_noncanonical_u64(1),
  F::from_noncanonical_u64(2),
  F::from_noncanonical_u64(3),
  F::from_noncanonical_u64(4),
] };
let c = PoseidonHash::two_to_one(a, b);

Sponge Hash with Pad (Hash n elements with padding)

import {hashPad} from 'poseidon-goldilocks';
const result = hashPad([1n, 2n, 3n, 1337n, 9999n, 123n]);
Plonky2 Equivalent

type F = GoldilocksField;
let result = PoseidonHash::hash_pad(&[
  F::from_noncanonical_u64(1),
  F::from_noncanonical_u64(2),
  F::from_noncanonical_u64(3),
  F::from_noncanonical_u64(1337),
  F::from_noncanonical_u64(9999),
  F::from_noncanonical_u64(123),
]);

Todo

  • Complete rest of documentation

License

MIT License

Copyright (c) 2023 Zero Knowledge Labs Limited

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Poseidon Hash for Goldilocks Field with Expanded Functionality

Resources

License

Stars

Watchers

Forks

Packages

No packages published