Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

truffle migrate requires infinite gas #960

Closed
jerryji opened this issue Nov 11, 2018 · 5 comments
Closed

truffle migrate requires infinite gas #960

jerryji opened this issue Nov 11, 2018 · 5 comments

Comments

@jerryji
Copy link

jerryji commented Nov 11, 2018

The attached contract package can not be deployed due to (seemingly infinity) high gas required. However, commenting out any trivial function makes it deployable at 6.6M gas. So the deployment gas used seems to jump at a certain point.

Expected Behavior

Well, the contract should be deployable

Current Behavior

"truffle migrate --reset" fails with the following error --

...
 Linking
   -------
   * Contract: EthWallData <--> Library: ExtlibAddressBalance (at address: 0xaEF6C2FDC4393C2FaEc0893E4251B6244AFa286a)

   Replacing 'EthWallData'
   -----------------------
Error:  *** Deployment Failed ***

"EthWallData" ran out of gas (using a value you set in your network config or deployment parameters.)
   * Block limit:  8500000
   * Gas sent:     8000000

    at /usr/lib/node_modules/truffle/build/webpack:/packages/truffle-deployer/src/deployment.js:361:1
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

comment out any function, such as getMsgSenderBalance() at line 73 and run "truffle migrate --reset" and it will succeed --

...
   Linking
   -------
   * Contract: EthWallData <--> Library: ExtlibAddressBalance (at address: 0x4A70028aD4A26A60ef72Cb84fCcD633D88239542)

   Replacing 'EthWallData'
   -----------------------
   > transaction hash:    0x51525c722724a85996ae0310f5ac30806ef2f76c67fbe02a0c1a93a17fc40b91
   > Blocks: 0            Seconds: 0
   > contract address:    0xAA07CdC7a3aD056789F99ddF6598c2e3fCEf5eFC
   > account:             0x89aA09dF70B5Aac2d12f4824d9FFdB6Bb3840413
   > balance:             100.071337416
   > gas used:            6627035
   > gas price:           1 gwei
   > value sent:          0 ETH
   > total cost:          0.006627035 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:         0.007700991 ETH

Possible Solution

I have no clue yet

Steps to Reproduce (for bugs)

ethwalldata.zip

  1. unzip the attachment, run "truffle migrate --reset" inside and see the deployment fail
  2. comment out any trivial function, e.g., getMsgSenderBalance() at line 73 and run "truffle migrate --reset" and verify that the main contract (EthWallData) is deployed with 6.6M gas
  3. In step 1., raise gas limit in truffle-config.js and Ganache won't help, e.g., I've tried 50M to no avail
  4. Why does the deployment gas jump?

Context

Not able to deploy contracts

Your Environment

  • Version used: Ganache v1.2.2; Ganache CLI v6.1.8 (ganache-core: 2.2.1) exhibits the same behavior
  • Environment name and version (e.g. PHP 5.4 on nginx 1.9.1): Truffle v5.0.0-beta.1; solc 0.4.25; gas configuration in truffle-config.js
  • Server type and version: Intel i7-7500
  • Operating System and version: Ubuntu 18.04 (64-bit)
  • Link to your project: N.A. yet
@jerryji jerryji changed the title truffle migrate gas usage is not linear truffle migrate requires infinite gas Nov 11, 2018
@mikeseese
Copy link
Contributor

mikeseese commented Nov 12, 2018

Off the top of my head, I believe you're hitting the max contract bytecode size. EIP-170 started a limit of 0x6000 bytes for contracts. Not sure why the EIP states that it should be an OOG error instead of more useful error like "contract too big" haha.

Perhaps turning on the optimizer in your Truffle config will help; here's an example: https://truffleframework.com/docs/truffle/reference/configuration#solc

EDIT: I'm just now seeing you have the optimizer enabled with 1000 runs. I take that all back haha. I'll try to reproduce this on Tuesday. Thanks for the bug report!

@jerryji
Copy link
Author

jerryji commented Nov 12, 2018

Thanks @seesemichaelj , this seems plausible. However, other than stripping my contract down, which is already barely naked at the moment, what other options do I have for a storage contract?

At the same time, I'll see if I can nudge the Ethereum core dev team to agree to raise the size limit to bring it more closely inline with the 8M gas limit.

@mikeseese
Copy link
Contributor

@jerryji There was much deliberation about the size for the EIP (conversation here: ethereum/EIPs#170) back in August 2017; I doubt it's changing anytime soon, but feel free to try!

The limit isn't a limit of how much storage you can use, it's about the size of the deployable bytecode. In the build/contracts/*.json file there is a property called bytecode. It's the length of that string divided by 2 (two hex characters make a byte).

Here's your current number of bytes per contract:

$ grep \"bytecode\" build/contracts/* | awk '{print $1 " " length($3)/2}'
build/contracts/EthWallData.json: 24969.5
build/contracts/ExtlibAddressBalance.json: 3896.5
build/contracts/LibAddressBool.json: 122.5
build/contracts/LibKeyValue.json: 122.5
build/contracts/LibSafeMath.json: 122.5
build/contracts/Migrations.json: 858.5
build/contracts/OwnablePlusContract.json: 6273.5
build/contracts/Util.json: 84.5

You can see here in EthWallData.json that you are just barely over the 24576 limit; removing even the smallest functions will put you under the limit.

However, it turns out your truffle-config.js was not quite right. optimizer is a child of solc, not a child of solc.settings. So it should be:

    solc: {
        version: "0.4.25",
        optimizer: {
            enabled: true,
            runs: 1000
        },
    }

Your new bytecodes after the change (make sure you add the --all flag in truffle compile to compile everything all over) show you under the limit:

$ grep \"bytecode\" build/contracts/* | awk '{print $1 " " length($3)/2}'
build/contracts/EthWallData.json: 15213.5
build/contracts/ExtlibAddressBalance.json: 2019.5
build/contracts/LibAddressBool.json: 122.5
build/contracts/LibKeyValue.json: 122.5
build/contracts/LibSafeMath.json: 122.5
build/contracts/Migrations.json: 624.5
build/contracts/OwnablePlusContract.json: 3449.5
build/contracts/Util.json: 84.5

Give that a shot and let me know if it works or not!

@jerryji
Copy link
Author

jerryji commented Nov 12, 2018

@seesemichaelj you are the hero! The optimizer correction saved my life.

On a side note, I didn't try to invent the syntax, it was copied from the truffle v5.0.0-beta.0 release page https://github.com/trufflesuite/truffle/releases/tag/v5.0.0-beta.0 --

compilers: {
  solc: {
    settings: {
      optimizer: {
        enabled: true, // Default: false
        runs: 1000     // Default: 200
      },
      evmVersion: "homestead"  // Default: "byzantium"
    }
  }
}

Do you think I should file a bug report with truffle?

Thanks again.

@jerryji jerryji closed this as completed Nov 12, 2018
@mikeseese
Copy link
Contributor

If you're sure you're using Truffle v5 (do a truffle version to verify), then yes, a bug report on the truffle repo should be made. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants