-
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
18
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 all commits
Commits
Show all changes
18 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
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
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,77 @@ | ||
| package forks | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestNext(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| fork Name | ||
| expected Name | ||
| }{ | ||
| {"first fork", Bedrock, Regolith}, | ||
| {"middle fork", Ecotone, Fjord}, | ||
| {"second-to-last", Karst, Interop}, | ||
| {"last fork returns None", Interop, None}, | ||
| {"unknown fork returns None", Name("unknown"), None}, | ||
| } | ||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| require.Equal(t, tc.expected, Next(tc.fork)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestPrev(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| fork Name | ||
| expected Name | ||
| }{ | ||
| {"first fork returns None", Bedrock, None}, | ||
| {"second fork", Regolith, Bedrock}, | ||
| {"middle fork", Fjord, Ecotone}, | ||
| {"last fork", Interop, Karst}, | ||
| {"unknown fork returns None", Name("unknown"), None}, | ||
| } | ||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| require.Equal(t, tc.expected, Prev(tc.fork)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestNextPrevInverse(t *testing.T) { | ||
| // For every mainline fork that is not the first, Prev(Next(prev)) == prev, | ||
| // and for every fork that is not the last, Next(Prev(next)) == next. | ||
| // This guards against the two maps drifting out of sync. | ||
| for i, f := range All { | ||
| if i < len(All)-1 { | ||
| require.Equal(t, f, Prev(Next(f)), "Prev(Next(%s)) must equal %s", f, f) | ||
| } | ||
| if i > 0 { | ||
| require.Equal(t, f, Next(Prev(f)), "Next(Prev(%s)) must equal %s", f, f) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestFrom(t *testing.T) { | ||
| t.Run("from first returns all", func(t *testing.T) { | ||
| require.Equal(t, All, From(Bedrock)) | ||
| }) | ||
| t.Run("from middle returns tail", func(t *testing.T) { | ||
| got := From(Ecotone) | ||
| require.Equal(t, Ecotone, got[0]) | ||
| require.Equal(t, All[len(All)-1], got[len(got)-1]) | ||
| require.Len(t, got, len(All)-4) // Bedrock, Regolith, Canyon, Delta excluded | ||
| }) | ||
| t.Run("from last returns single", func(t *testing.T) { | ||
| require.Equal(t, []Name{Interop}, From(Interop)) | ||
| }) | ||
| t.Run("unknown fork panics", func(t *testing.T) { | ||
| require.Panics(t, func() { From(Name("unknown")) }) | ||
| }) | ||
| } |
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,178 @@ | ||
| 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-optimism/optimism/op-node/rollup/derive" | ||
| "github.com/ethereum-optimism/optimism/op-service/bigs" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "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, every upgrade tx executes successfully, and the fault-proof program | ||
| // can prove the result. | ||
| // | ||
| // 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. | ||
| // | ||
| // Fork-specific state assertions (e.g. Karst's proxy implementation swap) are | ||
| // dispatched via the switch in [testActivationBlockNUTBundle]. Future forks | ||
| // with their own post-activation invariants register a case there. | ||
| func TestActivationBlockNUTBundle(gt *testing.T) { | ||
| matrix := helpers.NewMatrix[forks.Name]() | ||
|
|
||
| for _, fork := range forks.From(forks.Karst) { | ||
| _, _, err := derive.UpgradeTransactions(fork) | ||
| require.NoError(gt, err, "fork %s from Karst onward must have a NUT bundle", fork) | ||
|
|
||
| preFork := forks.Prev(fork) | ||
| require.NotEqual(gt, forks.None, preFork, "fork %s has no preceding fork in forks.All", fork) | ||
| 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() | ||
| require.True(t, | ||
| env.Sd.RollupCfg.IsActivationBlockForFork(actHeader.Time, fork), | ||
| "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.
|
||
|
|
||
| // Fork-specific post-activation assertions. Future forks register cases here. | ||
| switch fork { | ||
| case forks.Karst: | ||
| assertKarstActivation(t, env, actHeader) | ||
| } | ||
|
|
||
| // Advance the safe head across the activation boundary so the fault-proof | ||
| // program verifies a non-trivial span including the upgrade block. No new | ||
| // L2 blocks are produced past the activation block, so the safe head should | ||
| // land exactly on it. | ||
| env.BatchMineAndSync(t) | ||
| l2SafeHead := env.Sequencer.L2Safe() | ||
| require.Equal(t, bigs.Uint64Strict(actHeader.Number), l2SafeHead.Number, | ||
| "safe head must be exactly the %s activation block", fork) | ||
|
|
||
| env.RunFaultProofProgram(t, l2SafeHead.Number, testCfg.CheckResult, testCfg.InputParams...) | ||
| } | ||
|
|
||
| // assertKarstActivation verifies Karst-specific state changes: representative | ||
| // predeploy proxies' EIP-1967 implementation slots must change across the | ||
| // activation block and the new implementations must have code. This is a | ||
| // smoke test that the bundle's upgrade transactions actually rewrote proxy | ||
| // implementation pointers, not a check of what the new implementations do. | ||
| func assertKarstActivation(t actionsHelpers.StatefulTesting, env *helpers.L2FaultProofEnv, actHeader *types.Header) { | ||
| ethCl := env.Engine.EthClient() | ||
| postBlock := actHeader.Number | ||
| preBlock := new(big.Int).Sub(postBlock, big.NewInt(1)) | ||
|
|
||
| // 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) | ||
|
|
||
| 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) | ||
| } | ||
| } | ||
|
|
||
| // 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
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.