privacy-scaling-explorations / zk-kit.solidity

A monorepo of reusable contracts for zero-knowledge technologies.
MIT License
10 stars 2 forks source link

Error invoking poseidon #38

Open chancehudson opened 2 weeks ago

chancehudson commented 2 weeks ago

Describe the bug Bug was originally reported in discord. Relevant text below

Hey folks, I'm playing with the LeanIMT. Having an issue with `InternalLeanIMT._insert()`.
It seems to work as expected on the first insertion, but fails with `Error: Transaction reverted without a reason string` on any subsequent insertions.
I'm sure there is something simple I've neglected, but whatever it is is not obvious to me.
Here's [the code I'm playing with](<https://github.com/gnosisguild/enclave/commit/456ff18fb1728bc4dbb33a05a3db6f759be95078>).
`yarn`
`yarn run`

Line `248` in `Enclave.sol` and line `988` in `Enclave.spec.ts`.
looks like it's failing here https://github.com/privacy-scaling-explorations/zk-kit.solidity/blob/main/packages/lean-imt/contracts/InternalLeanIMT.sol#L67 🤔

To Reproduce Unclear

Screenshots

Technologies (please complete the following information):

Additional context

chancehudson commented 2 weeks ago

Attempting to reproduce the issue here but have not been successful. I'd guess the bug is somewhere in the zk-kit stack. It may be related to the hardhat version, that's the only way i've seen the error.

Hardhat versions before 2.14.0 will error when building poseidon for solidity >= 0.8.20

auryn-macmillan commented 2 weeks ago

Ran your repo in a codespace but pointed it at hardhat network rather than sepolia, got this error.

$ yarn test
yarn run v1.22.22
$ hardhat test ./test/a.test.js

  asfas
0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
    1) should execute

  0 passing (798ms)
  1 failing

  1) asfas
       should execute:
     Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="test()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.7.0)
      at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:269:28)
      at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:281:20)
      at Interface.decodeFunctionResult (node_modules/@ethersproject/abi/src.ts/interface.ts:427:23)
      at Contract.<anonymous> (node_modules/@ethersproject/contracts/src.ts/index.ts:400:44)
      at step (node_modules/@ethersproject/contracts/lib/index.js:48:23)
      at Object.next (node_modules/@ethersproject/contracts/lib/index.js:29:53)
      at fulfilled (node_modules/@ethersproject/contracts/lib/index.js:20:58)

So perhaps it's an issue with hardhat network?

auryn-macmillan commented 2 weeks ago

I was able to get my original code working with hardhat network by adding an override to the compiler settings and deploying the contract, rather than relying on the deterministically deployed contracts.

    overrides: {
      "node_modules/poseidon-solidity/PoseidonT3.sol": {
        settings: {
          optimizer: {
            enabled: true,
            runs: 2 ** 32 - 1,
          },
        },
      },
    },