npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

poseidon-solidity

v0.0.5

Published

Poseidon hash function implemented in Solidity

Downloads

4,502

Readme

poseidon-solidity CircleCI

Poseidon implementation in Solidity over alt_bn128 (aka BN254).

This implementation has not been audited.

Benchmark

T2 hash
  - poseidon-solidity: 13,488 gas
  - circomlibjs: 19,395 gas
  - address: 0x22233340039aAB0C858bc6086f508d9A4f2fA4db

T3 hash
  - poseidon-solidity: 21,124 gas
  - circomlibjs: 32,173 gas
  - address: 0x3333333C0A88F9BE4fd23ed0536F9B6c427e3B93

T4 hash
  - poseidon-solidity: 37,617 gas
  - circomlibjs: 48,267 gas
  - address: 0x4443338EF595F44e0121df4C21102677B142ECF0

T5 hash
  - poseidon-solidity: 54,326 gas
  - circomlibjs: 73,307 gas
  - address: 0x555333f3f677Ca3930Bf7c56ffc75144c51D9767

T6 hash
  - poseidon-solidity: 74,039 gas
  - circomlibjs: 100,197 gas
  - address: 0x666333F371685334CdD69bdDdaFBABc87CE7c7Db

# ---

Deploy cost (T3)
  - poseidon-solidity: 5,129,638 gas
  - circomlibjs: 2,156,516 gas

Use

npm i poseidon-solidity
import "poseidon-solidity/PoseidonT3.sol";

contract Example {

  function combine(uint input0, uint input1) public {
    uint out = PoseidonT3.hash([input0, input1]);
  }

}

Deploy

This package includes config info for deploying with a deterministic proxy. The proxy itself is deployed using Nick's method with a pre-signed transaction from a keyless address. The poseidon contracts are deployed through this proxy to get the same address in any evm.

To deploy in a hardhat/ethers type environment:

const { proxy, PoseidonT3 } = require('poseidon-solidity')

const [sender] = await ethers.getSigners()

// First check if the proxy exists
if (await ethers.provider.getCode(proxy.address) === '0x') {
  // fund the keyless account
  await sender.sendTransaction({
    to: proxy.from,
    value: proxy.gas,
  })

  // then send the presigned transaction deploying the proxy
  await ethers.provider.sendTransaction(proxy.tx)
}

// Then deploy the hasher, if needed
if (await ethers.provider.getCode(PoseidonT3.address) === '0x') {
  await send.sendTransaction({
    to: proxy.address,
    data: PoseidonT3.data
  })
}

console.log(`PoseidonT3 deployed to: ${PoseidonT3.address}`)

Testing

npm install
npm test