5

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

diablo
  • 51
  • 1
  • 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 09 '17 at 22:49
  • That was my guess too. Tested it on Ropsten test net, seems to work there, http://imgur.com/a/pkcoC – diablo Jan 09 '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 09 '17 at 22:57
  • I submitted an issue/PR https://github.com/ethereum/browser-solidity/issues/370 – Tjaden Hess Jan 09 '17 at 23:08
  • Please post your answer @TjadenHess. – eth Jan 12 '17 at 04:19

1 Answers1

2

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

Tjaden Hess
  • 37,046
  • 10
  • 91
  • 118