4

When executing a function through the browser compiler, the compiler shows the gas costs, for example:

Transaction cost: 30754 gas.
Execution cost: 9290 gas.

Are these costs actually identical to the transaction costs on the homestead blockchain (assuming the transaction only executes the given function)? Is it safe to assume that if a certain function is optimized there, it will also be optimized on the live blockchain and vice versa?

3

Optimisation is a compiler feature. So a contract compiled with the same compiler on Browser Solidity (Javascript Solc) or on the command-line (C++ Solc I reckon), provided it has the same "optimise" flag, will yield the same bytecode.

It is the bytecode that runs when you call a function that will determine the gas cost of the call.

So, unless a hard-fork changes the gas cost of individual opcodes, you are in control of the gas it costs a function.

  • Yeah, that makes sense, but the question is - when the browser compiler executes a function, does it compute cost per opcode exactly like miners do? – nergall Jan 23 '17 at 18:05
  • It does calculate it correctly, but you have to be careful if your contract relies on things like timestamp, block number, blockhash, etc. because the browser will not use realistic values for those. – Tjaden Hess Jan 23 '17 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.