Skip to content

Commit

Permalink
remove gas validations from CL
Browse files Browse the repository at this point in the history
  • Loading branch information
djrtwo committed Nov 1, 2021
1 parent 77fe450 commit 52a97ab
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 181 deletions.
27 changes: 1 addition & 26 deletions specs/merge/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
- [`execute_payload`](#execute_payload)
- [Block processing](#block-processing)
- [Execution payload](#execution-payload)
- [`is_valid_gas_limit`](#is_valid_gas_limit)
- [`process_execution_payload`](#process_execution_payload)
- [Epoch processing](#epoch-processing)
- [Slashings](#slashings)
Expand Down Expand Up @@ -347,39 +346,15 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None:

#### Execution payload

##### `is_valid_gas_limit`

```python
def is_valid_gas_limit(payload: ExecutionPayload, parent: ExecutionPayloadHeader) -> bool:
parent_gas_limit = parent.gas_limit

# Check if the payload used too much gas
if payload.gas_used > payload.gas_limit:
return False

# Check if the payload changed the gas limit too much
if payload.gas_limit >= parent_gas_limit + parent_gas_limit // GAS_LIMIT_DENOMINATOR:
return False
if payload.gas_limit <= parent_gas_limit - parent_gas_limit // GAS_LIMIT_DENOMINATOR:
return False

# Check if the gas limit is at least the minimum gas limit
if payload.gas_limit < MIN_GAS_LIMIT:
return False

return True
```

##### `process_execution_payload`

```python
def process_execution_payload(state: BeaconState, payload: ExecutionPayload, execution_engine: ExecutionEngine) -> None:
# Verify consistency of the parent hash, block number, base fee per gas and gas limit
# Verify consistency of the parent hash and block number
# with respect to the previous execution payload header
if is_merge_complete(state):
assert payload.parent_hash == state.latest_execution_payload_header.block_hash
assert payload.block_number == state.latest_execution_payload_header.block_number + uint64(1)
assert is_valid_gas_limit(payload, state.latest_execution_payload_header)
# Verify random
assert payload.random == get_randao_mix(state, get_current_epoch(state))
# Verify timestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from eth2spec.utils.ssz.ssz_typing import uint64
from eth2spec.test.helpers.execution_payload import (
build_empty_execution_payload,
get_execution_payload_header,
Expand Down Expand Up @@ -228,157 +227,3 @@ def test_bad_timestamp_regular_payload(spec, state):
execution_payload.timestamp = execution_payload.timestamp + 1

yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)


@with_merge_and_later
@spec_state_test
def test_gaslimit_zero_first_payload(spec, state):
# pre-state
state = build_state_with_incomplete_transition(spec, state)
next_slot(spec, state)

# execution payload
execution_payload = build_empty_execution_payload(spec, state)
execution_payload.gas_limit = uint64(0)

yield from run_execution_payload_processing(spec, state, execution_payload)


@with_merge_and_later
@spec_state_test
def test_gaslimit_max_first_payload(spec, state):
# pre-state
state = build_state_with_incomplete_transition(spec, state)
next_slot(spec, state)

# execution payload
execution_payload = build_empty_execution_payload(spec, state)
execution_payload.gas_limit = uint64(2**64 - 1)

yield from run_execution_payload_processing(spec, state, execution_payload)


@with_merge_and_later
@spec_state_test
def test_gaslimit_upper_plus_regular_payload(spec, state):
# pre-state
state = build_state_with_complete_transition(spec, state)
next_slot(spec, state)

# execution payload
execution_payload = build_empty_execution_payload(spec, state)
execution_payload.gas_limit = (
execution_payload.gas_limit +
execution_payload.gas_limit // spec.GAS_LIMIT_DENOMINATOR
)

yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)


@with_merge_and_later
@spec_state_test
def test_gaslimit_upper_regular_payload(spec, state):
# pre-state
state = build_state_with_complete_transition(spec, state)
next_slot(spec, state)

# execution payload
execution_payload = build_empty_execution_payload(spec, state)
execution_payload.gas_limit = (
execution_payload.gas_limit +
execution_payload.gas_limit // spec.GAS_LIMIT_DENOMINATOR - uint64(1)
)

yield from run_execution_payload_processing(spec, state, execution_payload)


@with_merge_and_later
@spec_state_test
def test_gaslimit_lower_minus_regular_payload(spec, state):
# pre-state
state = build_state_with_complete_transition(spec, state)
next_slot(spec, state)

# execution payload
execution_payload = build_empty_execution_payload(spec, state)
execution_payload.gas_limit = (
execution_payload.gas_limit -
execution_payload.gas_limit // spec.GAS_LIMIT_DENOMINATOR
)

yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)


@with_merge_and_later
@spec_state_test
def test_gaslimit_lower_regular_payload(spec, state):
# pre-state
state = build_state_with_complete_transition(spec, state)
next_slot(spec, state)

# execution payload
execution_payload = build_empty_execution_payload(spec, state)
execution_payload.gas_limit = (
execution_payload.gas_limit -
execution_payload.gas_limit // spec.GAS_LIMIT_DENOMINATOR + uint64(1)
)

yield from run_execution_payload_processing(spec, state, execution_payload)


@with_merge_and_later
@spec_state_test
def test_gaslimit_minimum_regular_payload(spec, state):
# pre-state
state = build_state_with_complete_transition(spec, state)
next_slot(spec, state)
state.latest_execution_payload_header.gas_limit = spec.MIN_GAS_LIMIT

# execution payload
execution_payload = build_empty_execution_payload(spec, state)
execution_payload.gas_limit = execution_payload.gas_limit

yield from run_execution_payload_processing(spec, state, execution_payload)


@with_merge_and_later
@spec_state_test
def test_gaslimit_minimum_minus_regular_payload(spec, state):
# pre-state
state = build_state_with_complete_transition(spec, state)
next_slot(spec, state)
state.latest_execution_payload_header.gas_limit = spec.MIN_GAS_LIMIT

# execution payload
execution_payload = build_empty_execution_payload(spec, state)
execution_payload.gas_limit = execution_payload.gas_limit - uint64(1)

yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)


@with_merge_and_later
@spec_state_test
def test_gasused_gaslimit_regular_payload(spec, state):
# pre-state
state = build_state_with_complete_transition(spec, state)
next_slot(spec, state)

# execution payload
execution_payload = build_empty_execution_payload(spec, state)
execution_payload.gas_used = execution_payload.gas_limit

yield from run_execution_payload_processing(spec, state, execution_payload)


@with_merge_and_later
@spec_state_test
def test_gasused_gaslimit_plus_regular_payload(spec, state):
# pre-state
state = build_state_with_complete_transition(spec, state)
next_slot(spec, state)

# execution payload
execution_payload = build_empty_execution_payload(spec, state)
execution_payload.gas_used = execution_payload.gas_limit + uint64(1)

yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)

0 comments on commit 52a97ab

Please sign in to comment.