-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat(kona): execute NUT bundles at Karst fork activation #20157
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
Open
maurelian
wants to merge
21
commits into
develop
Choose a base branch
from
feat-kona-nut-execution
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
bdba171
feat(kona): execute NUT bundles at Karst fork activation
df9aabf
test(op-e2e): add generic NUT bundle activation block action test
42545f5
fix(kona): mirror NUT bundles into kona-hardforks crate
e3dc8f0
Revert "fix(kona): mirror NUT bundles into kona-hardforks crate"
815bf97
build(docker): pass NUT bundles as named context to kona images
38f54db
test(op-e2e): tighten NUT bundle activation test coverage
e6c3c0b
refactor(kona-hardforks): extract impl_hardfork_from_bundle macro
0fd7ad6
refactor(kona-hardforks): make build.rs testable with shared codegen
0e3aad4
test(op-e2e): add karst_fork_test with pre/post impl slot assertion
a89baf9
refactor(op-core/forks): add Prev() sibling to Next()
026b01c
test(op-e2e): run fault-proof program and fold karst assertions in
34aea3e
test(op-e2e): tighten activation-block checks
977bd37
test(op-core/forks): add unit tests for Next, Prev, From
4c507a8
perf(kona-hardforks): cache NUT bundle in OnceCell
2d6126a
style(kona-hardforks): apply nightly rustfmt and clippy fixes
42445e9
build(docker): mount NUT bundles into kona-cannon-prestate build
d37ab99
fix: address nightly rustfmt and go-lint findings
1a1b24f
fix(kona-hardforks): use OnceBox to avoid critical-section dep on no_std
6789edd
build(kona): mount op-core/nuts/bundles in build-cannon-client recipe
e390086
test(op-e2e): tombstone forks-without-NUT-bundle exception list
c4d3154
chore(kona-hardforks): propagate std feature to new dependencies
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package proofs | ||
|
|
||
| import ( | ||
| "context" | ||
| "math/big" | ||
| "testing" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-chain-ops/genesis" | ||
| "github.com/ethereum-optimism/optimism/op-core/forks" | ||
| "github.com/ethereum-optimism/optimism/op-core/predeploys" | ||
| actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers" | ||
| "github.com/ethereum-optimism/optimism/op-e2e/actions/proofs/helpers" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/common/hexutil" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestKarstPredeployImplementationsUpgraded verifies that Karst activation | ||
| // replaces the implementation address stored in the EIP-1967 slot of | ||
| // representative predeploy proxies. It is a smoke test that the bundle's | ||
| // upgrade transactions actually rewrote proxy implementation pointers — not | ||
| // a check of what the new implementations do (that's the job of the per- | ||
| // contract test suites). | ||
| // | ||
| // The invariant is Karst-specific: every "Deploy X Implementation" intent in | ||
| // the Karst bundle lands at a fresh address, and L2ProxyAdmin's batch upgrade | ||
| // (bundle intent 31) repoints predeploy proxies to those fresh addresses. A | ||
| // future fork that doesn't upgrade proxies wouldn't satisfy this, which is | ||
| // why the assertion lives in a Karst-specific test rather than in the generic | ||
| // NUT bundle activation test. | ||
| func TestKarstPredeployImplementationsUpgraded(gt *testing.T) { | ||
| matrix := helpers.NewMatrix[any]() | ||
| matrix.AddDefaultTestCases( | ||
| nil, | ||
| helpers.NewForkMatrix(helpers.Jovian), | ||
| testKarstPredeployImplementationsUpgraded, | ||
| ) | ||
| matrix.Run(gt) | ||
| } | ||
|
|
||
| func testKarstPredeployImplementationsUpgraded(gt *testing.T, testCfg *helpers.TestCfg[any]) { | ||
| t := actionsHelpers.NewDefaultTesting(gt) | ||
|
|
||
| offset := uint64(4) | ||
| testSetup := func(dc *genesis.DeployConfig) { | ||
| dc.L1PragueTimeOffset = ptr(hexutil.Uint64(0)) | ||
| dc.SetForkTimeOffset(forks.Karst, &offset) | ||
| } | ||
| env := helpers.NewL2FaultProofEnv(t, testCfg, helpers.NewTestParams(), helpers.NewBatcherCfg(), testSetup) | ||
|
|
||
| env.Miner.ActEmptyBlock(t) | ||
| env.Sequencer.ActL1HeadSignal(t) | ||
| for i := 0; i < int(offset); i++ { | ||
| env.Sequencer.ActL2EmptyBlock(t) | ||
| } | ||
|
|
||
| engine := env.Engine | ||
| actHeader := engine.L2Chain().CurrentHeader() | ||
| require.Equal(t, forks.Karst, | ||
| env.Sd.RollupCfg.IsActivationBlock(actHeader.Time-env.Sd.RollupCfg.BlockTime, actHeader.Time), | ||
| "expected Karst activation block at time %d", actHeader.Time) | ||
|
|
||
| postBlock := actHeader.Number | ||
| preBlock := new(big.Int).Sub(postBlock, big.NewInt(1)) | ||
|
|
||
| ethCl := engine.EthClient() | ||
|
|
||
| // Representative predeploys whose implementation Karst replaces. L1Block and | ||
| // GasPriceOracle mirror the proxies asserted by earlier fork tests (ecotone, | ||
| // isthmus); covering them keeps vocabulary consistent across fork tests. | ||
| proxies := []struct { | ||
| name string | ||
| addr common.Address | ||
| }{ | ||
| {"L1Block", predeploys.L1BlockAddr}, | ||
| {"GasPriceOracle", predeploys.GasPriceOracleAddr}, | ||
| } | ||
| for _, p := range proxies { | ||
| preImpl, err := ethCl.StorageAt(context.Background(), p.addr, genesis.ImplementationSlot, preBlock) | ||
| require.NoError(t, err, "read %s impl slot pre-activation", p.name) | ||
| postImpl, err := ethCl.StorageAt(context.Background(), p.addr, genesis.ImplementationSlot, postBlock) | ||
| require.NoError(t, err, "read %s impl slot post-activation", p.name) | ||
|
|
||
| require.NotEqualf(t, preImpl, postImpl, | ||
| "%s (%s) implementation slot must change across Karst activation", p.name, p.addr) | ||
|
|
||
| // New impl must actually be deployed — guards against an upgrade that | ||
| // repoints a proxy at an empty address. | ||
| newImplAddr := common.BytesToAddress(postImpl) | ||
| code, err := ethCl.CodeAt(context.Background(), newImplAddr, postBlock) | ||
| require.NoError(t, err, "read code at new %s impl", p.name) | ||
| require.NotEmptyf(t, code, "new %s impl %s must have code", p.name, newImplAddr) | ||
| } | ||
|
maurelian marked this conversation as resolved.
Outdated
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| package proofs | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-chain-ops/genesis" | ||
| "github.com/ethereum-optimism/optimism/op-core/forks" | ||
| actionsHelpers "github.com/ethereum-optimism/optimism/op-e2e/actions/helpers" | ||
| "github.com/ethereum-optimism/optimism/op-e2e/actions/proofs/helpers" | ||
| "github.com/ethereum-optimism/optimism/op-node/rollup/derive" | ||
| "github.com/ethereum/go-ethereum/common/hexutil" | ||
| "github.com/ethereum/go-ethereum/core/types" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestActivationBlockNUTBundle verifies that, for every fork from Karst onward, | ||
| // the fork's activation block contains exactly the bundle's deposit transactions | ||
| // in order and that every upgrade tx executes successfully. | ||
| // | ||
| // Discovery runs through [forks.From]([forks.Karst]), so any future fork is | ||
| // covered automatically — and required to have a NUT bundle registered with | ||
| // [derive.UpgradeTransactions]. The only per-fork requirement beyond that is | ||
| // that the fork immediately preceding it is registered in [helpers.Hardforks] | ||
| // — a one-line entry needed for any fork-parametrized test in this package. | ||
| func TestActivationBlockNUTBundle(gt *testing.T) { | ||
| matrix := helpers.NewMatrix[forks.Name]() | ||
|
|
||
| // Resolve Karst's index in forks.All so we can reach the immediately preceding | ||
| // fork for each entry yielded by forks.From(Karst). | ||
| karstIdx := -1 | ||
| for i, f := range forks.All { | ||
| if f == forks.Karst { | ||
| karstIdx = i | ||
| break | ||
| } | ||
| } | ||
| require.Greater(gt, karstIdx, 0, "Karst must not be first in forks.All") | ||
|
|
||
| for i, fork := range forks.From(forks.Karst) { | ||
|
maurelian marked this conversation as resolved.
Outdated
|
||
| _, _, err := derive.UpgradeTransactions(fork) | ||
| require.NoError(gt, err, "fork %s from Karst onward must have a NUT bundle", fork) | ||
|
|
||
| preFork := forks.All[karstIdx+i-1] | ||
|
maurelian marked this conversation as resolved.
Outdated
|
||
| preHelper := lookupHardforkHelper(preFork) | ||
| require.NotNil(gt, preHelper, | ||
| "no pre-fork helper registered for NUT-bundle fork %s (prior fork: %s); add %s to helpers.Hardforks", | ||
| fork, preFork, preFork) | ||
|
|
||
| matrix.AddDefaultTestCasesWithName( | ||
| string(fork), | ||
| fork, | ||
| helpers.NewForkMatrix(preHelper), | ||
| testActivationBlockNUTBundle, | ||
| ) | ||
| } | ||
|
|
||
| matrix.Run(gt) | ||
| } | ||
|
|
||
| func testActivationBlockNUTBundle(gt *testing.T, testCfg *helpers.TestCfg[forks.Name]) { | ||
| fork := testCfg.Custom | ||
| t := actionsHelpers.NewDefaultTesting(gt) | ||
|
|
||
| offset := uint64(4) | ||
| testSetup := func(dc *genesis.DeployConfig) { | ||
| dc.L1PragueTimeOffset = ptr(hexutil.Uint64(0)) | ||
| dc.SetForkTimeOffset(fork, &offset) | ||
| } | ||
| env := helpers.NewL2FaultProofEnv(t, testCfg, helpers.NewTestParams(), helpers.NewBatcherCfg(), testSetup) | ||
|
|
||
| expectedTxs, expectedGas, err := derive.UpgradeTransactions(fork) | ||
| require.NoError(t, err, "load NUT bundle for %s", fork) | ||
| require.NotEmpty(t, expectedTxs, "bundle for %s must contain at least one upgrade tx", fork) | ||
|
|
||
| env.Miner.ActEmptyBlock(t) | ||
| env.Sequencer.ActL1HeadSignal(t) | ||
| for i := 0; i < int(offset); i++ { | ||
| env.Sequencer.ActL2EmptyBlock(t) | ||
| } | ||
|
|
||
| engine := env.Engine | ||
| actHeader := engine.L2Chain().CurrentHeader() | ||
| blockTime := env.Sd.RollupCfg.BlockTime | ||
| require.Equal(t, fork, | ||
| env.Sd.RollupCfg.IsActivationBlock(actHeader.Time-blockTime, actHeader.Time), | ||
|
maurelian marked this conversation as resolved.
Outdated
|
||
| "expected activation block for %s at time %d", fork, actHeader.Time) | ||
|
|
||
| actBlock := engine.L2Chain().GetBlockByHash(actHeader.Hash()) | ||
| txs := actBlock.Transactions() | ||
| // Index 0 is the L1 info deposit; indices 1.. are the NUT upgrade deposits. | ||
| require.Len(t, txs, 1+len(expectedTxs), | ||
| "activation block should have 1 L1 info deposit + %d NUT upgrade txs", len(expectedTxs)) | ||
|
|
||
| var totalUpgradeGas uint64 | ||
| for i, rawExpected := range expectedTxs { | ||
| actualBytes, err := txs[1+i].MarshalBinary() | ||
| require.NoError(t, err) | ||
| require.Equal(t, []byte(rawExpected), actualBytes, "NUT tx %d byte mismatch", i) | ||
|
|
||
| var expected types.Transaction | ||
| require.NoError(t, expected.UnmarshalBinary(rawExpected)) | ||
| totalUpgradeGas += expected.Gas() | ||
| } | ||
| require.Equal(t, expectedGas, totalUpgradeGas, "total NUT gas must equal bundle total") | ||
|
maurelian marked this conversation as resolved.
maurelian marked this conversation as resolved.
|
||
|
|
||
| // Every tx in the activation block — the L1 info deposit and all NUT upgrade | ||
| // deposits — must execute successfully. A reverted upgrade tx would leave the | ||
| // chain in a broken fork-activation state. | ||
| receipts := engine.L2Chain().GetReceiptsByHash(actHeader.Hash()) | ||
| require.Len(t, receipts, len(txs), "receipt count must match tx count") | ||
| for i, r := range receipts { | ||
| require.Equal(t, types.ReceiptStatusSuccessful, r.Status, | ||
| "activation-block tx %d reverted", i) | ||
| } | ||
|
maurelian marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // lookupHardforkHelper resolves a fork name to its [helpers.Hardfork] entry by | ||
| // scanning [helpers.Hardforks]. Returns nil when the fork isn't registered. | ||
| func lookupHardforkHelper(name forks.Name) *helpers.Hardfork { | ||
| for _, hf := range helpers.Hardforks { | ||
| if forks.Name(hf.Name) == name { | ||
| return hf | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
maurelian marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| //! Build script for `kona-hardforks`. | ||
| //! | ||
| //! Reads NUT bundle JSON files from `op-core/nuts/bundles/` and generates Rust source | ||
| //! that constructs [`op_alloy_consensus::NutBundle`] values at runtime without serde. | ||
| //! | ||
| //! The parsing and codegen logic lives in [`build_helpers`] so it can be shared | ||
| //! with integration tests under `tests/`. | ||
|
|
||
| use std::{env, fs, path::PathBuf}; | ||
|
|
||
| use anyhow::{anyhow, Context, Result}; | ||
|
|
||
| #[path = "build_helpers.rs"] | ||
| mod build_helpers; | ||
|
|
||
| use build_helpers::{capitalize, format_bundle, parse_bundle}; | ||
|
|
||
| /// Read the bundle JSON, generate Rust source, and write it to `out_dir`. | ||
| fn generate(name: &str, json_path: &PathBuf, out_dir: &str) -> Result<()> { | ||
| let json = fs::read_to_string(json_path) | ||
| .with_context(|| format!("read {}", json_path.display()))?; | ||
| let bundle = parse_bundle(&json).with_context(|| format!("parse {}", json_path.display()))?; | ||
| let code = format_bundle(name, &capitalize(name), &bundle); | ||
| let out_path = PathBuf::from(out_dir).join(format!("{name}_nut_bundle.rs")); | ||
| fs::write(&out_path, code).with_context(|| format!("write {}", out_path.display()))?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn run() -> Result<()> { | ||
| let out_dir = env::var("OUT_DIR").context("OUT_DIR not set")?; | ||
| let manifest_dir = | ||
| PathBuf::from(env::var("CARGO_MANIFEST_DIR").context("CARGO_MANIFEST_DIR not set")?); | ||
|
|
||
| let monorepo_root = manifest_dir | ||
| .ancestors() | ||
| .find(|p| p.join("op-core").is_dir()) | ||
| .ok_or_else(|| { | ||
| anyhow!( | ||
| "could not find op-core/ in any ancestor of {}", | ||
| manifest_dir.display() | ||
| ) | ||
| })? | ||
| .to_path_buf(); | ||
|
|
||
| let karst_bundle = monorepo_root.join("op-core/nuts/bundles/karst_nut_bundle.json"); | ||
| println!("cargo::rerun-if-changed={}", karst_bundle.display()); | ||
|
|
||
| generate("karst", &karst_bundle, &out_dir).context("generate karst bundle") | ||
|
maurelian marked this conversation as resolved.
|
||
| } | ||
|
|
||
| fn main() { | ||
| if let Err(e) = run() { | ||
| panic!("{e:?}"); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.