trufflesuite / ganache-cli-archive

Fast Ethereum RPC client for testing and development. See https://github.com/trufflesuite/ganache for current development.
https://www.trufflesuite.com/ganache
MIT License
3.36k stars 695 forks source link

Ganache Crashes on estimateGas #834

Closed rayyan808 closed 3 years ago

rayyan808 commented 3 years ago

Expected Behavior

Ganache should deploy the contract, but during deployment it calls upon estimateGas which causes an assertion failure. This failure has something todo with handling BN's (BigNumbers). At first I presumed it was my contract gas overflowing, but the same instance of the contract deploys on Remix-IDE. The deployment on truffle side fails once the Ganache-CLI disconnects after throwing an error.

Current Behavior

eth_estimateGas
Error: Assertion failed
    at assert (/usr/lib/node_modules/ganache-cli/node_modules/bn.js/lib/bn.js:6:21)
    at BN._initNumber (/usr/lib/node_modules/ganache-cli/node_modules/bn.js/lib/bn.js:128:7)
    at BN.init [as _init] (/usr/lib/node_modules/ganache-cli/node_modules/bn.js/lib/bn.js:78:19)
    at new BN (/usr/lib/node_modules/ganache-cli/node_modules/bn.js/lib/bn.js:39:12)
    at /usr/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:55:2090655
    at e.exports (/usr/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:55:2090698)
    at /usr/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:55:2088020
    at e.exports (/usr/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:55:2090110)

Steps to Reproduce (for bugs)

To reproduce, you could simply clone my repo: https://github.com/rayyan808/bsc-project.git

There you may extract Election.sol and it's dependencies: MiMC.sol, utility.sol and verifier.sol

Context

Without this, my entire project and 2 months work is void because I cannot demo this app over REMIX-IDE. My application is a real life example of utilizing zk-SNARKs and researching into modern hashing techniques to be able to conduct a voting procedure completely on-chain. My react application needs to interact with a proper blockchain through web3.

Your Environment

rayyan808 commented 3 years ago

For anyone who may encounter this issue, check that your truffle-config has a valid gas value. My gas value was a very large number, which caused Ganache to crash as it isn't meant to handle BNs in gas values (that's my guess anyway). Reducing the gas size fixed this error.