poseidon-goldilocks-lite
v0.2.3
Published
A zero dependency suite of poseidon goldilocks hash functions compatible with plonky2.
Downloads
2
Readme
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-lite';
const c = twoToOne([1337n, 123456n, 100n, 15n], [1n, 2n, 3n, 4n]);
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-lite';
const result = hashPad([1n, 2n, 3n, 1337n, 9999n, 123n]);
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.