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

core, params, beacon/engine: implement EIP 4788 BeaconRoot #27849

Merged
merged 14 commits into from
Aug 22, 2023

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Aug 3, 2023

EIP 4788 : Beacon block root in the EVM


This is a version-2 of EPI-4788, main difference being that the contract is an actual contract rather than a precompile, as in #27289.

cc @ralexstokes

MariusVanDerWijden and others added 5 commits August 4, 2023 17:33
consensus/misc: add eip4788

consensus/misc: header

core/vm: allow for stateful precompiles

core/vm: implement 4788 as a stateful precompile

core, consensus/misc: update to new 4788 spec

core: fix rebase

core/vm: add activator

core/vm: reduce interface, increase testability, remove opcode

params: introduce params.BeaconRootStorageAddress

happy lint, happy life

core: make sure to only apply beaconroot after cancun!

params, consensus: fix review comments
consensus/misc: set beaconroot precompile non-zero nonce (poc)
@holiman holiman added the cancun label Aug 7, 2023
@holiman holiman marked this pull request as ready for review August 7, 2023 11:14
@holiman holiman changed the title [WIP] Eip 4788 v2 implement EIP 4788: BeaconRoot Aug 7, 2023
// we can use the header.BaseFee and set that instead.
msg := &Message{
From: params.SystemAddress,
GasLimit: 100_000,
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to use gas limit of 30_000_000 to be in line with the Gnosis Chain spec for system transactions.

@@ -66,6 +66,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
blockNumber = block.Number()
allLogs []*types.Log
gp = new(GasPool).AddGas(block.GasLimit())
beaconRoot *common.Hash
Copy link
Member

Choose a reason for hiding this comment

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

Is this just a placeholder until we later activate this by checking block.BeaconRoot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, yeah we should remove this and use block.BeaconRoot instead. Looks very odd like that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yeah that change is probably in the follow-up PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, #27872 is the follow-up, but it still doesn't fill this placeholder :/

Copy link
Member

Choose a reason for hiding this comment

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

Yeah no worries, I have these changes in the devnet-8 branch. I'm not sure the best way to be tracking this for everyone as it pretty out-of-sync with master.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lightclient thanks for adding your updates, I have also pushed some changes now -- primarily, hooking it into evm t8n so I could actually test it and see it working in practice.
PTAL

core/types/block.go Outdated Show resolved Hide resolved
core/state_processor.go Outdated Show resolved Hide resolved
@@ -292,6 +292,14 @@ func Transition(ctx *cli.Context) error {
prestate.Env.Difficulty = calcDifficulty(chainConfig, env.Number, env.Timestamp,
env.ParentTimestamp, env.ParentDifficulty, env.ParentUncleHash)
}
if chainConfig.IsCancun(big.NewInt(int64(prestate.Env.Number)), prestate.Env.Timestamp) {
Copy link
Member

Choose a reason for hiding this comment

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

big.NewInt(int64(prestate.Env.Number)

seems like this is used a lot, might be nice to assign above ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Myeah, a couple, but I don't think it's worth it. Might do a bigger refactor later IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean, some uses refer to big.NewInt(int64(prestate.Env.Number)), some refer to int64(prestate.Env.Number), and some refer to prestate.Env.Number

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did the bigger refactor, ptal!

return NewError(ErrorConfig, errors.New("post-cancun env requires parentBeaconBlockRoot to be set"))
}
} else {
env.ParentBeaconBlockRoot = nil // un-set it if it has been set too early
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be an error if beacon root is requested before the fork?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could but in go-ethereum, due to how the json parser works, we typically ignore extraneous json-fields. I think the engine-api is the sole exception where we explicitly check for, and error on, fields that we do not expect.

For t8n, I'd prefer to keep the older behaviour

cmd/evm/testdata/29/readme.md Outdated Show resolved Hide resolved
consensus/beacon/consensus.go Show resolved Hide resolved
core/state_processor.go Outdated Show resolved Hide resolved
params/protocol_params.go Outdated Show resolved Hide resolved
Copy link
Member

@lightclient lightclient left a comment

Choose a reason for hiding this comment

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

LGTM

@holiman holiman added this to the 1.13.0 milestone Aug 22, 2023
@holiman holiman changed the title implement EIP 4788: BeaconRoot core, params, beacon/engine: implement EIP 4788 BeaconRoot Aug 22, 2023
@holiman holiman merged commit b8d38e7 into ethereum:master Aug 22, 2023
yperbasis added a commit to erigontech/erigon that referenced this pull request Aug 24, 2023
See ethereum/EIPs#7456 &
ethereum/go-ethereum#27849. Also set the gas
limit for system calls to 30M (previously 2^64-1), which is in line with
the [Gnosis
spec](https://github.com/gnosischain/specs/blob/master/execution/withdrawals.md#specification),
but should be doubled checked for Gnosis Chain.
AskAlexSharov pushed a commit to erigontech/erigon that referenced this pull request Sep 6, 2023
See ethereum/EIPs#7456 &
ethereum/go-ethereum#27849. Also set the gas
limit for system calls to 30M (previously 2^64-1), which is in line with
the [Gnosis
spec](https://github.com/gnosischain/specs/blob/master/execution/withdrawals.md#specification),
but should be doubled checked for Gnosis Chain.
@holiman holiman deleted the eip-4788-v2 branch October 11, 2023 07:27
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
…27849)

This change implements "EIP 4788 : Beacon block root in the EVM". It implements version-2 of EPI-4788, main difference being that the contract is an actual contract rather than a precompile, as in ethereum#27289.
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
sduchesneau pushed a commit to streamingfast/go-ethereum that referenced this pull request Feb 26, 2024
 Conflicts:
  cmd/evm/internal/t8ntool/transition.go
Callsite for IsShanghai moved to a different function, moved our
modification there.

 Additions:
  go-ethereum/cmd/evm/testdata/29/exp.json
Added Arbitrum field to expected receipt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants