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

Implement EIP4788: Beacon block root in EVM #2810

Merged
merged 15 commits into from
Jul 10, 2023
Merged

Conversation

jochem-brouwer
Copy link
Member

@jochem-brouwer jochem-brouwer commented Jun 22, 2023

Implements https://eips.ethereum.org/EIPS/eip-4788

WIP

Note: keep eyes on ethereum/EIPs#7178

From the EIP (specifically ethereum/EIPs#7178:)

When verifying a block, execution clients MUST ensure the root value in the block header matches the one provided by the consensus client.

This will need a PR on the CL side for the execution API, so will not implement here

@codecov
Copy link

codecov bot commented Jun 22, 2023

Codecov Report

Merging #2810 (ea1d15f) into master (0747b4c) will increase coverage by 0.42%.
The diff coverage is 100.00%.

❗ Current head ea1d15f differs from pull request most recent head 8917fcc. Consider uploading reports for the commit 8917fcc to get more accurate results

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
vm 77.80% <100.00%> (+0.42%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@jochem-brouwer
Copy link
Member Author

Referenced PR is merged. This is ready for review.

@jochem-brouwer jochem-brouwer marked this pull request as ready for review July 9, 2023 10:37
@jochem-brouwer
Copy link
Member Author

Am on mobile, cannot see if this can be merged without conflicts. (how do I see this on mobile?)

@holgerd77
Copy link
Member

Yes, no, so this needs a branch update.

@holgerd77
Copy link
Member

Have also dropped a short question on the readiness-state of the EIP on https://discord.com/channels/595666850260713488/856943705209569291/1127869874354524240.

@@ -935,6 +936,7 @@ export class EVM {
common: this.common,
_EVM: this,
_debug: this.DEBUG ? debugPrecompiles : undefined,
stateManager: this.stateManager,
Copy link
Contributor

Choose a reason for hiding this comment

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

super 👍

Copy link
Member

Choose a reason for hiding this comment

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

Out of interest because I'm totally not getting the whole picture: what's the "super" part here? 😋 What does this do/change?

Copy link
Member

Choose a reason for hiding this comment

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

Update: just only getting this now, is this whole thing a precompile and not an opcode??

}
}
const timestampExtended = timestampIndex + historicalRootsLength
const returnData = setLengthLeft(
Copy link
Contributor

Choose a reason for hiding this comment

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

does the output of getContractStorage needs setLengthLeft?

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this writes to CALLs out memory, so we need to write 32 bytes. This is not explicit in getContractStorage;

    const value = await trie.get(key)
    if (!this._storageCacheSettings.deactivate) {
      this._storageCache?.put(address, key, value ?? hexToBytes('0x80'))
    }
    const decoded = RLP.decode(value ?? new Uint8Array(0)) as Uint8Array
    return decoded
    ```

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh makes sense, thank you!

Copy link
Contributor

@g11tech g11tech left a comment

Choose a reason for hiding this comment

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

filed name change is requested to be consistent with eip and specs

Co-authored-by: g11tech <gajinder@g11.in>
Copy link
Contributor

@g11tech g11tech left a comment

Choose a reason for hiding this comment

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

lgtm 🚀

@g11tech g11tech merged commit b3cb348 into master Jul 10, 2023
@holgerd77 holgerd77 deleted the eip4788-beaconroot branch July 11, 2023 07:38
"comment": "Beacon block root in the EVM",
"url": "https://eips.ethereum.org/EIPS/eip-4788",
"status": "Draft",
"minimumHardfork": "cancun",
Copy link
Member

Choose a reason for hiding this comment

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

I know it's somewhat counter intuitive and I wonder if we ever "get this in" reliably 😋, but the minimum HF here is not the inclusion HF but St least one lower (do here Shanghai would be a good choice), otherwise this can't be used in a Shanghai+EIP way.

So this is to read: the state of the network where all preconditions are fulfilled so that this EIP can be activated.

Copy link
Member

Choose a reason for hiding this comment

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

So just to re-iterate on this and make this very concrete: this is the situation which breaks otherwise (and currently does) if the minimum HF is set to Cancun here:

➜  vm git:(master) ts-node
> import { Chain, Common, Hardfork } from '@ethereumjs/common'
undefined
> let c = new Common({ chain: Chain.Mainnet, eips: [ 4788 ] })
/ethereumjs-monorepo/packages/common/dist/cjs/common.js:361
                throw new Error(`${eip} cannot be activated on hardfork ${this.hardfork()}, minimumHardfork: ${minHF}`);
                ^

Uncaught Error: 4788 cannot be activated on hardfork shanghai, minimumHardfork: false
    at Common.setEIPs (/ethereumjs-monorepo/packages/common/src/common.ts:455:15)
    at new Common (/ethereumjs-monorepo/packages/common/src/common.ts:241:12)
    at /ethereumjs-monorepo/packages/vm/<repl>.ts:2:9
    at Script.runInThisContext (node:vm:129:12)
    at runInContext (/node/v18.14.2/lib/node_modules/ts-node/src/repl.ts:673:19)
    at Object.execCommand (/node/v18.14.2/lib/node_modules/ts-node/src/repl.ts:639:28)
    at /node/v18.14.2/lib/node_modules/ts-node/src/repl.ts:661:47
    at Array.reduce (<anonymous>)
    at appendCompileAndEvalInput (/node/v18.14.2/lib/node_modules/ts-node/src/repl.ts:661:23)
    at evalCodeInternal (/node/v18.14.2/lib/node_modules/ts-node/src/repl.ts:222:12)
>

Copy link
Member

Choose a reason for hiding this comment

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

Not sure, since this is such a re-occuring place for stumbling over it might be really worth to rename to something like the following? 🤔

minimumHardforkForIsolatedEIP

Even if the name is a bit bulky.

Copy link
Member

Choose a reason for hiding this comment

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

Will take over this discussion to the chat for a quick exchange.

Copy link
Member Author

Choose a reason for hiding this comment

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

For EL it should be Merge (instead of Shanghai), I agree here though we should review whatever the lowest hardfork should be (I should have set this to Merge)

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.

3 participants