Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower maximum transaction gas limit #92

Closed
chfast opened this issue Apr 13, 2016 · 21 comments · Fixed by #2179
Closed

Lower maximum transaction gas limit #92

chfast opened this issue Apr 13, 2016 · 21 comments · Fixed by #2179

Comments

@chfast
Copy link
Member

chfast commented Apr 13, 2016

Overwiew

Maximum allowed transaction gas limit is 263 - 1.

Specification

Any transaction with the gas limit greater than 263 - 1 should be ignored by a client.

Motivation

Designing Ethereum VM for unrealistic case where amount of gas is greater than 264 is a waste of time.

Allowing the gas counter to fit regular CPU register on 64-bit targets is a big performance win. One more bit is reserved to allow faster overflow detection.

@axic
Copy link
Member

axic commented Apr 13, 2016

Any transaction with the gas limit greater than 2^63 - 1 should be ignored by a client.

Do you mean it should:

  • take it as 2^63
  • or reject the transaction?

@chfast
Copy link
Member Author

chfast commented Apr 13, 2016

It should reject the transaction. The first option is not possible in my opinion.

@obscuren
Copy link
Contributor

I had been toying with a similar idea and have been playing with an inplementation in the past.

I'll try to dig it up or reimplement (shouldn't be too difficult) and see if I can get some benchmarks done :-)

@chriseth
Copy link
Contributor

An option would be to modify the block gas adjustment scheme to not only have a "min gas" but also a "max gas".

@gcolvin
Copy link
Contributor

gcolvin commented Apr 13, 2016

I am already changing the interpreter to throw an OutOfGas exception if the gas limit , the memory limit, or the calculations are >=263. This of course violates the spec, but saves a lot of calculation. It is also a practical impossibility to get anywhere near those limits in the real world. Unfortunately, my code fails tests that push the inputs past those limits anyway. The spec should put hard limits on gas and memory -- they can always be changed later as hardware advances. I agree that 263 -1 is a good limit so far as being practically impossible to approach and fast to compute.

@wanderer
Copy link
Member

wanderer commented Apr 14, 2016

we could add a few more caps as well

  • balances cap to 128 integer
  • gasPrice cap to 64 bits integer
  • gas cap to 64 bits integer

@wanderer wanderer added the ERC label Apr 14, 2016
@wanderer wanderer changed the title ERC: Lower maximum transaction gas limit Lower maximum transaction gas limit Apr 14, 2016
@chfast
Copy link
Member Author

chfast commented Apr 14, 2016

I think codesize and calldatasize can be implementation defined. I'm using size_t in JIT and nobody cares.

@larspensjo
Copy link

Using "implementation defined" can in theory lead to consensus failure? If so, there should never be any limitations that are implementation defined?

@chfast
Copy link
Member Author

chfast commented Apr 18, 2016

@larspensjo no. E.g. minimum gas price is user / implementation defined. Transactions with the gas price lower that the minimum are rejected / not mined.

@larspensjo
Copy link

I see, thanks!

@gcolvin
Copy link
Contributor

gcolvin commented Apr 29, 2016

The program counter is another one. Just noticed this in the Go code

        // For optimisation reason we're using uint64 as the program counter.
        // It's theoretically possible to go above 2^64. The YP defines the PC to be uint256. Pratically much less so feasible.
        pc = uint64(0) // program counter

And the C++ interpreter is using a uint64_t as well. Not much sense using a counter for more memory than you can physically address. I'm not sure if testing catches this.

@gcolvin
Copy link
Contributor

gcolvin commented May 13, 2016

2^256-1 =
115,792,089,237,316,195,423,570,985,008,687,907,853,269,984,665,640,564,039,457,584,007,913,129,
639,935
This is 78 digits. Estimates of the numbers of atoms in the visible universe run from 10^70 to 10^80.

@chfast
Copy link
Member Author

chfast commented May 25, 2016

@wanderer, I used following caps in EVMJIT successfully:

  • block number: 64 bits,
  • timestamp: 64 bits,
  • gas price: 64 bits (more/less successfully).

I think there are some test cases that use gas price bigger than 64 bits. I can give up this one as gas price seems not to be on critical path (rarely used in contracts).

Never considered using 128-bit integers, wanted to keep the type set small.

How can we formalize the above?

konradkonrad added a commit to ethereum/pyethereum that referenced this issue Jul 8, 2016
konradkonrad added a commit to ethereum/pyethereum that referenced this issue Jul 8, 2016
@axic
Copy link
Member

axic commented Jul 19, 2016

The EVM2.0 design sets out the following limits:

Further more we define the following caps on the environmental variables

codesize is capped to a 64 bit integer
calldata size is capped to 64 bits
balances are repesented as a 128 bit little endian unsigned integer
gasPrice is repesented as a 64 bit little endian unsigned integer
gas is repesented as a 64 bit little endian unsigned integer

@gcolvin IIRC if codesize is limited to 64bit, that would put the pc under the same limit

@SergioDemianLerner
Copy link
Contributor

SergioDemianLerner commented Sep 16, 2016

In RSK (a.k.a Rootstock) we've defined the limit to be about 2^62. The reason is that it is much more efficient to compute several additions to the gas counter and then to check for int64 oveflow than to check for int64 overflow after each, when each added value is known to be well below 2^20.
Using this and other optimizations our EVM-compatible VM is 5.8 times faster than get/eth for simple arithmetic computations in loops.

@bobsummerwill
Copy link

Thanks for sharing that, @SergioDemianLerner. Much appreciated!

@chfast
Copy link
Member Author

chfast commented Sep 26, 2016

@SergioDemianLerner Can you explain why do you need 2 additional bits to do it instead of one?

@SergioDemianLerner
Copy link
Contributor

There is no need for 2 bits. We use Java that has signed 64-bit integers, so by limiting ourselves to 62 bits we can be sure all operations remain positive, even when they overflow. But we could also check for negative values. For a platform that has 64-bit unsigned arithmetic, limiting the gas to 2^63-1 would be the same.

@chfast
Copy link
Member Author

chfast commented Sep 28, 2016

I think we use signed int64 and check for negatives (however it is not full C++ compliant). Thanks for sharing that.

@chfast
Copy link
Member Author

chfast commented Mar 3, 2017

This was somehow agreed on, by limiting block's max gas limit to 2^63-1. But I'm not sure there is any official EIP expressing that.

@axic
Copy link
Member

axic commented Jul 6, 2019

This is now covered by https://eips.ethereum.org/EIPS/eip-1985. I propose to close this issue, @chfast.

@axic axic added type: Core and removed type: ERC labels Jul 6, 2019
@chfast chfast closed this as completed Jul 7, 2019
@ethereum ethereum deleted a comment Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.