6

I've noticed a discrepancy between the gas cost to deploy our contracts locally and on mainnet. I would have guessed that they should cost exactly the same.

Does anyone know why this happens?

JohnAllen
  • 1,318
  • 1
  • 13
  • 29
  • 3
    In the past forks have altered the price of some opcodes, if your private blockchain didn't enable the it might be using the old prices. Another reason can be if your contract make calls to other contracts. And obviously contracts compiled with different versions of solidity compiler might generate different code. – Ismael Mar 31 '18 at 17:55
  • Check here - possible duplicate https://ethereum.stackexchange.com/questions/45923/will-same-contract-consume-different-gas-in-different-network – Madan Apr 18 '18 at 07:18

1 Answers1

1

As highlighted here, there are 3 Main Factors:

  1. Variable State (unbounded iteration leaves room for uncertainty)
  2. Compiler Version (different compilers will produce different bytecode)
  3. Gas Cost (same protocol version cannot be guaranteed between networks)
Vignesh Karthikeyan
  • 1,950
  • 1
  • 12
  • 40