https://github.com/psyprotocol/poseidon-goldilocks
Poseidon Hash for Goldilocks Field with Expanded Functionality
https://github.com/psyprotocol/poseidon-goldilocks
Last synced: 9 months ago
JSON representation
Poseidon Hash for Goldilocks Field with Expanded Functionality
- Host: GitHub
- URL: https://github.com/psyprotocol/poseidon-goldilocks
- Owner: PsyProtocol
- License: mit
- Created: 2023-03-12T00:42:50.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-18T14:50:53.000Z (about 3 years ago)
- Last Synced: 2025-05-20T21:04:29.949Z (about 1 year ago)
- Language: TypeScript
- Size: 393 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
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](https://extgit.iaik.tugraz.at/krypto/hadeshash).
# Usage:
### Two to One (Hash two 4-element-wide values)
```javascript
import {twoToOne} from 'poseidon-goldilocks';
const c = twoToOne([1337n, 123456n, 100n, 15n], [1n, 2n, 3n, 4n]);
```
Plonky2 Equivalent
```rust
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)
```javascript
import {hashPad} from 'poseidon-goldilocks';
const result = hashPad([1n, 2n, 3n, 1337n, 9999n, 123n]);
```
Plonky2 Equivalent
```rust
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.
[contributors-shield]: https://img.shields.io/github/contributors/OpenAssetStandards/poseidon-goldilocks.svg?style=for-the-badge
[contributors-url]: https://github.com/OpenAssetStandards/poseidon-goldilocks/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/OpenAssetStandards/poseidon-goldilocks.svg?style=for-the-badge
[forks-url]: https://github.com/OpenAssetStandards/poseidon-goldilocks/network/members
[stars-shield]: https://img.shields.io/github/stars/OpenAssetStandards/poseidon-goldilocks.svg?style=for-the-badge
[stars-url]: https://github.com/OpenAssetStandards/poseidon-goldilocks/stargazers
[issues-shield]: https://img.shields.io/github/issues/OpenAssetStandards/poseidon-goldilocks.svg?style=for-the-badge
[issues-url]: https://github.com/OpenAssetStandards/poseidon-goldilocks/issues