iden3 / circomlibjs

Javascript library to work with circomlib circuits
75 stars 58 forks source link

Why there is no Poseidon contract generator for arbitrary number of hash inputs? #15

Open AndriianChestnykh opened 2 years ago

AndriianChestnykh commented 2 years ago

Why there is no Poseidon contract generator for arbitrary number of has inputs? It can be only fixed and in 1..8 range.

export function createCode(nInputs) {

    if (( nInputs<1) || (nInputs>8)) throw new Error("Invalid number of inputs. Must be 1<=nInputs<=8");
...

As far as I remember, there some old contract generator version had this functionality. Although, the code was located in the iden3/circomlib repo at that time

eigmax commented 2 years ago

It's depends on how large the MDS is. you can check out this linearhash (https://github.com/0xPolygonHermez/pil-stark/blob/main/circuits.gl/linearhash.circom) to support arbitrary size of inputs.

AndriianChestnykh commented 2 years ago

@eigmax, yes, it looks like the Poseidon itself depends on MDS constant values (so, the old contract generator couldn't even work properly with arbitrary input size, I guess). Thanks for pointing out the LinearHash function. It may be of help as a workaround.

ilya-korotya commented 1 year ago

Hi @eigmax. I have the same issue. I want to generate Ethereum Smart Contract that can support 16 inputs for Poseidon hash. Could I create a larger MDS that will support 16 inputs? I don't want to use any loops to manage 16 inputs (since loops are increasing gas consumption). For example, golang implementation of Poseidon hash supports 16 inputs from the box. https://github.com/iden3/go-iden3-crypto/blob/master/poseidon/poseidon_test.go#L14

eigmax commented 1 year ago

@ilya-korotya sure, use Cauchy matrix mentioned in Poseidon's paper, and check out how neptune generates here: https://github.com/filecoin-project/neptune/blob/master/src/mds.rs#L21

ilya-korotya commented 1 year ago

@eigmax thanks a lot. It will be helpful.