https://github.com/yuriko627/poseidon-sol
Poseidon Hash Function implementation in Solidity
https://github.com/yuriko627/poseidon-sol
hashfunction solidity zkp
Last synced: 4 months ago
JSON representation
Poseidon Hash Function implementation in Solidity
- Host: GitHub
- URL: https://github.com/yuriko627/poseidon-sol
- Owner: yuriko627
- License: apache-2.0
- Created: 2023-02-13T01:26:05.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-27T23:16:51.000Z (over 2 years ago)
- Last Synced: 2025-06-22T17:05:18.645Z (12 months ago)
- Topics: hashfunction, solidity, zkp
- Language: Solidity
- Homepage:
- Size: 1.96 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# poseidon-sol
## Overview
Poseidon Hash Function implementation in Solidity


[](https://github.com/yuriko627/poseidon-sol/actions?query=workflow%3A%22Build+Status%2)
[](https://codecov.io/gh/yuriko627/poseidon-sol)
[](https://www.npmjs.com/package/poseidon-sol)
[](https://poseidon-sol.readthedocs.io/en/latest/?badge=latest)
## Description
Currently, the most widely-used Poseidon hash function for EVM is implemented in JS, and it is performant but it could be more unreadable. Also, if you write a smart contract in Solidity, it has to link the bytecode or call an external contract address for hash functions, which is inconvenient.
In the future, Poseidon hash might be implemented as a precompile contract in the Ethereum protocol (https://eips.ethereum.org/EIPS/eip-5988), so that people can call it with cheap gas. However, I think it would still be valuable to have a Poseidon Solidity implementation as a baseline for the performance benchmark.
## Installation
make sure that your noder version is >= 16.
`npm install poseidon-sol`
## Usage
put the 2 elements that you want to hash into the array:
`poseidon.hash([0, 0])`
## Contribution
make sure to run the test and lint before making a PR.
### How to run a test
1. `npm install`
2. `npx hardhat test`
you can see the test coverage by the following command:
`npx hardhat coverage`
### How to lint
1. `npm install`
2. `npx solhint contracts/Poseidon.sol`
### Other commands
- `npx hardhat compile`: compile the contract