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

Rebase Merge spec with London #2533

Merged
merged 7 commits into from
Aug 10, 2021
Merged

Conversation

mkalinin
Copy link
Contributor

The following changes are introduced by this PR:

  • add base_fee_per_gas to ExecutionPayload and ExecutionPayloadHeader
  • add base_fee_per_gas verification to process_execution_payload function
  • add gas_limit verification to process_execution_payload function
  • fix tests accordingly

The source of above changes is https://eips.ethereum.org/EIPS/eip-1559 and its code snippets.

@mkalinin mkalinin requested review from hwwhww and protolambda July 26, 2021 13:56
@hwwhww hwwhww added the Bellatrix CL+EL Merge label Jul 27, 2021
Copy link
Contributor

@hwwhww hwwhww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side notes: there are now two gas systems: one is execution layer and one in sharding. #2486 addresses it by replacing samples with gas. If #2486 doesn't get merged, we should address it in a separate PR.

specs/merge/beacon-chain.md Outdated Show resolved Hide resolved
specs/merge/beacon-chain.md Outdated Show resolved Hide resolved
specs/merge/beacon-chain.md Outdated Show resolved Hide resolved
specs/merge/beacon-chain.md Outdated Show resolved Hide resolved
specs/merge/beacon-chain.md Outdated Show resolved Hide resolved
gas_used_delta = parent_gas_target - parent_gas_used
base_fee_per_gas_delta = \
parent_base_fee_per_gas * gas_used_delta // parent_gas_target // BASE_FEE_MAX_CHANGE_DENOMINATOR
return max(parent_base_fee_per_gas - base_fee_per_gas_delta, 0)
Copy link
Contributor

@hwwhww hwwhww Jul 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

underflow protection

I don't see the EIP-1559 code have such underflow protection so I checked the math. I think it is not required:

Since gas_used_delta = parent_gas_target - parent_gas_used
parent_gas_target >= gas_used_delta ---- (1)

Now look at expected_base_fee_per_gas:
expected_base_fee_per_gas
= parent_base_fee_per_gas - base_fee_per_gas_delta
= parent_base_fee_per_gas - (parent_base_fee_per_gas * gas_used_delta // parent_gas_target // BASE_FEE_MAX_CHANGE_DENOMINATOR) ---- (2)

Apply (1) to (2), we can get parent_base_fee_per_gas - base_fee_per_gas_delta >= 0.
Or more precisely, expected_base_fee_per_gas is greater than or equal to ~parent_base_fee_per_gas * 7/8.


But both Geth and Nethermind do have such underflow protection.


For eth2 spec, I'm not sure...

  • To make the spec clear -> maybe remove the unnecessary protection
  • To align with Eth1 and minimize risks -> maybe keep it

Any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I'd remove max with a corresponding comment that it never underflows. It would make sense to leave this sanity check would this arithmetics be a subject to change to avoid potential underflow that could appear in the future. Even if BASE_FEE_MAX_CHANGE_DENOMINATOR = 1 (which should never be the case) we got 0 in the "worst" case and never a < 0 value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check is removed and the comment is added

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that the unnecessary max was removed 2 days ago: ethereum/EIPs#3640 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol 😂

Copy link
Contributor

@hwwhww hwwhww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@djrtwo djrtwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

We need to revive the conversation about if/how empty slots should affect base fee

options:

  1. you only consider the capacity and usage of the chain created (similar to the sequential block-by-block alg used on pow mainnet)
  2. consider a skip slot as an empty payload and thus adjusting basefee downward to account for what was "unused" capacity

We can revive this convo on discord and/or the next merge call

specs/merge/beacon-chain.md Outdated Show resolved Hide resolved
specs/merge/beacon-chain.md Show resolved Hide resolved
specs/merge/beacon-chain.md Show resolved Hide resolved
@mkalinin
Copy link
Contributor Author

nice!

We need to revive the conversation about if/how empty slots should affect base fee

options:

  1. you only consider the capacity and usage of the chain created (similar to the sequential block-by-block alg used on pow mainnet)
  2. consider a skip slot as an empty payload and thus adjusting basefee downward to account for what was "unused" capacity

We can revive this convo on discord and/or the next merge call

Good point! If we decide that an empty slot is treated as an empty execution payload which it certainly is up to some extent, then how do you think base_fee_per_gas check should be implemented by execution client? Should the consensus client share the information about a number of skipped slots or should this check be removed from execution client and validated only by beacon chain state transition?

@mkalinin
Copy link
Contributor Author

options:

  1. you only consider the capacity and usage of the chain created (similar to the sequential block-by-block alg used on pow mainnet)
  2. consider a skip slot as an empty payload and thus adjusting basefee downward to account for what was "unused" capacity

Option 3 would be to do nothing (take option 1) at the merge and consider basefee computation re-adjustment in the fork after the merge.

@djrtwo
Copy link
Contributor

djrtwo commented Aug 10, 2021

I made an issue to track the base_fee / empty-slot convo
#2545

Copy link
Contributor

@djrtwo djrtwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

@djrtwo djrtwo merged commit c404cd1 into ethereum:dev Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bellatrix CL+EL Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants