The OPCODE GASLIMIT gets the block's gas limit. Could in-line assembly,

    uint gasLimit;

    assembly {
        gasLimit := gaslimit
    }

fetch the gas limit ?

contract B {

function getGasLimit() returns (uint) {
    uint gasLimit;

    assembly {
        gasLimit := gaslimit
    }
    return gasLimit;

}

}

Using https://ethereum.github.io/browser-solidity/, with a gaslimit set to 3000000, getGasLimit() returns 6000000.

Why does it return twice the gas limit ?

enter image description here

  • After a little testing, I think this may actually be a bug with browser solidity setting the gas limit to twice the requested amount. Try it in, testrpc or on the real chain, it works for me – Tjaden Hess Jan 9 '17 at 22:49
  • That was my guess too. Tested it on Ropsten test net, seems to work there, imgur.com/a/pkcoC – diablo Jan 9 '17 at 22:55
  • Not a bug, actually, just bad design. Looking at the code, it seems that the "gas limit" is actually the gas limit for each transaction, not the block gas limit. The browser VM automatically sets the block gas limit to twice the transaction gas. You can see this if you just look at the msg.gas for the transactions being sent. It will be what you put in the gas limit field (minus a bit) – Tjaden Hess Jan 9 '17 at 22:57
  • I submitted an issue/PR github.com/ethereum/browser-solidity/issues/370 – Tjaden Hess Jan 9 '17 at 23:08
  • Please post your answer @TjadenHess. – eth Jan 12 '17 at 4:19

This confusion was due to ambiguity in the term "gas limit," which in browser solidity meant per transaction gas, but OP assumed meant the block gas limit. The confusion was compounded by the fact that the block gas limit in the browser VM defaults to twice the transaction gas limit.

I submitted a PR, which was merged, and now the label says "Transaction gas limit" which should hopefully be clearer

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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