Truffle Ganache – Out-of-Gas During Deployment

ganacheout-of-gastruffle

I have a bunch of contracts which deploy just fine.

Deployment of one of the contracts, XBRNetwork takes exactly 5418911 gas – no problems with that.

However, once I add another trivial (public) function to the contract, deployment during CI run for the PR fails:

   Replacing 'XBRNetwork'
   ----------------------

Error:  *** Deployment Failed ***

"XBRNetwork" ran out of gas (using a value you set in your network config or deployment parameters.)
   * Block limit:  0x989680
   * Gas sent:     10000000

    at /home/oberstet/scm/crossbario/xbr-protocol/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:364:1
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.1.11 (core: 5.1.11)
Node v10.16.0
Makefile:110: recipe for target 'deploy' failed
make: *** [deploy] Error 1

I have set:

What other option do I need? How would I change the PR to get rid of the "out of gas" issue?


Do test, start ganache:

docker-compose up --force-recreate ganache

and deploy

truffle migrate --reset --network ganache

UPDATE (solution)

The real reason (see the answer) is: apparently, there is a 24kB size restriction on the deployed bytecode (besides the gas limits).

I have added this helper to our CI:

https://github.com/crossbario/xbr-protocol/blob/6f7384c51d52c4d88bfa88314841baf63fc0b7cf/check-abi-files.py

Result:

WORKS:

(cpy381_3) oberstet@intel-nuci7:~/scm/crossbario/xbr-protocol$ python check-abi-files.py 
..
ABI file "abi/XBRNetwork.json           " bytecode= 25547  bytes, deployedBytecode= 23998  bytes 
..

FAILS:

(cpy381_3) oberstet@intel-nuci7:~/scm/crossbario/xbr-protocol$ python check-abi-files.py 
..
ABI file "abi/XBRNetwork.json           " bytecode= 26344  bytes, deployedBytecode= 24795  bytes   WARNING - maximum deployed contract size of 24kB exceeded
..

And the actual solution consequently: refactoring the contract code into a library. Can be done .. np .. now that I know this hidden limit;)

Best Answer

I took the liberty of checking the size of your contract's byte-code in your GitHub repository.

It turns out to be 51708 hexadecimal characters, which means ‭25854‬ bytes when deployed.

Ethereum has a contract code-size limit of 24KB, i.e., ‭24576‬ bytes.

If you contract's code-size exceeds this limit, then your contract deployment will fail.

Related Topic