-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat: zk go deployer #20219
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
ashitakah
wants to merge
13
commits into
ethereum-optimism:develop
Choose a base branch
from
defi-wonderland:feat/zk-go-deployer
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
feat: zk go deployer #20219
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
65bf9ee
feat: merge with dev
ashitakah c92df45
feat: merge with dev
ashitakah b23bd24
Merge branch 'develop' of github.com:defi-wonderland/optimism into de…
ashitakah b72f9a0
fix: merge with dev
ashitakah bcd3405
Merge branch 'develop' of github.com:defi-wonderland/optimism into de…
ashitakah ede7c85
fix: merge with dev
ashitakah b91f370
Merge branch 'develop' of github.com:defi-wonderland/optimism into de…
ashitakah 5e18971
Merge branch 'develop' of github.com:defi-wonderland/optimism into de…
ashitakah 326f7e4
feat: op deployer zk
ashitakah 3ad0694
feat: op deployer zk
ashitakah 473eaf8
fix: lint
ashitakah 8736fc7
feat: acceptance tests and fix
ashitakah d95d853
fix: lint
ashitakah 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
245 changes: 245 additions & 0 deletions
245
op-deployer/pkg/deployer/pipeline/dispute_games_test.go
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,245 @@ | ||
| package pipeline | ||
|
|
||
| import ( | ||
| "log/slog" | ||
| "math/big" | ||
| "testing" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-chain-ops/addresses" | ||
| "github.com/ethereum-optimism/optimism/op-core/devfeatures" | ||
| "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/state" | ||
| "github.com/ethereum-optimism/optimism/op-service/testlog" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/common/hexutil" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestShouldDeployAdditionalDisputeGames(t *testing.T) { | ||
| dummyGame := state.AdditionalDisputeGame{VMType: state.VMTypeCannon} | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| intent *state.ChainIntent | ||
| st *state.ChainState | ||
| expected bool | ||
| }{ | ||
| { | ||
| name: "no_games_in_intent", | ||
| intent: &state.ChainIntent{}, | ||
| st: &state.ChainState{}, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "games_in_intent_empty_state", | ||
| intent: &state.ChainIntent{AdditionalDisputeGames: []state.AdditionalDisputeGame{dummyGame}}, | ||
| st: &state.ChainState{}, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "games_in_intent_already_deployed", | ||
| intent: &state.ChainIntent{AdditionalDisputeGames: []state.AdditionalDisputeGame{dummyGame}}, | ||
| st: &state.ChainState{ | ||
| AdditionalDisputeGames: []state.AdditionalDisputeGameState{ | ||
| {GameType: 1, VMType: state.VMTypeCannon}, | ||
| }, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "zk_game_in_intent_empty_state", | ||
| intent: &state.ChainIntent{AdditionalDisputeGames: []state.AdditionalDisputeGame{{VMType: state.VMTypeZK}}}, | ||
| st: &state.ChainState{}, | ||
| expected: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := shouldDeployAdditionalDisputeGames(tt.intent, tt.st) | ||
| require.Equal(t, tt.expected, got) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestDeployDisputeGame_ZK_ZeroImpl(t *testing.T) { | ||
| lgr := testlog.Logger(t, slog.LevelInfo) | ||
|
|
||
| env := &Env{Logger: lgr} | ||
| st := &state.State{ | ||
| ImplementationsDeployment: &addresses.ImplementationsContracts{ | ||
| ZkDisputeGameImpl: common.Address{}, // zero — flag was not active | ||
| }, | ||
| } | ||
| game := state.AdditionalDisputeGame{ | ||
| VMType: state.VMTypeZK, | ||
| ZKDisputeGame: &state.ZKDisputeGameParams{ | ||
| Verifier: common.HexToAddress("0x1111111111111111111111111111111111111111"), | ||
| AbsolutePrestate: common.HexToHash("0xdeadbeef"), | ||
| ChallengerBond: (*hexutil.Big)(big.NewInt(1e18)), | ||
| }, | ||
| } | ||
|
|
||
| err := deployDisputeGame(env, st, &state.ChainIntent{}, &state.ChainState{}, game) | ||
| require.ErrorContains(t, err, "ZkDisputeGameImpl is not deployed") | ||
| } | ||
|
|
||
| func TestDeployDisputeGame_ZK_NilParams(t *testing.T) { | ||
| lgr := testlog.Logger(t, slog.LevelInfo) | ||
|
|
||
| env := &Env{Logger: lgr} | ||
| st := &state.State{ | ||
| ImplementationsDeployment: &addresses.ImplementationsContracts{ | ||
| ZkDisputeGameImpl: common.HexToAddress("0x2222222222222222222222222222222222222222"), | ||
| }, | ||
| } | ||
| game := state.AdditionalDisputeGame{ | ||
| VMType: state.VMTypeZK, | ||
| ZKDisputeGame: nil, // params not set | ||
| } | ||
|
|
||
| err := deployDisputeGame(env, st, &state.ChainIntent{}, &state.ChainState{}, game) | ||
| require.ErrorContains(t, err, "ZKDisputeGame params must be set") | ||
| } | ||
|
|
||
| func TestDeployDisputeGame_ZK_WrongDisputeGameType(t *testing.T) { | ||
| lgr := testlog.Logger(t, slog.LevelInfo) | ||
|
|
||
| env := &Env{Logger: lgr} | ||
| st := &state.State{ | ||
| ImplementationsDeployment: &addresses.ImplementationsContracts{ | ||
| ZkDisputeGameImpl: common.HexToAddress("0x2222222222222222222222222222222222222222"), | ||
| }, | ||
| } | ||
| game := state.AdditionalDisputeGame{ | ||
| VMType: state.VMTypeZK, | ||
| ZKDisputeGame: &state.ZKDisputeGameParams{}, | ||
| ChainProofParams: state.ChainProofParams{DisputeGameType: 0}, // wrong — must be GameTypeZKDisputeGame (10) | ||
| } | ||
|
|
||
| err := deployDisputeGame(env, st, &state.ChainIntent{}, &state.ChainState{}, game) | ||
| require.ErrorContains(t, err, "DisputeGameType must be") | ||
| } | ||
|
|
||
| func TestDeployDisputeGame_ZK_NilChallengerBond(t *testing.T) { | ||
| lgr := testlog.Logger(t, slog.LevelInfo) | ||
|
|
||
| env := &Env{Logger: lgr} | ||
| st := &state.State{ | ||
| ImplementationsDeployment: &addresses.ImplementationsContracts{ | ||
| ZkDisputeGameImpl: common.HexToAddress("0x2222222222222222222222222222222222222222"), | ||
| }, | ||
| } | ||
| game := state.AdditionalDisputeGame{ | ||
| VMType: state.VMTypeZK, | ||
| ZKDisputeGame: &state.ZKDisputeGameParams{ | ||
| ChallengerBond: nil, | ||
| }, | ||
| ChainProofParams: state.ChainProofParams{DisputeGameType: 10}, | ||
| } | ||
|
|
||
| err := deployDisputeGame(env, st, &state.ChainIntent{}, &state.ChainState{}, game) | ||
| require.ErrorContains(t, err, "ChallengerBond must be set") | ||
| } | ||
|
|
||
| func TestDeployDisputeGame_ZK_ZeroChallengerBond(t *testing.T) { | ||
| lgr := testlog.Logger(t, slog.LevelInfo) | ||
|
|
||
| env := &Env{Logger: lgr} | ||
| st := &state.State{ | ||
| ImplementationsDeployment: &addresses.ImplementationsContracts{ | ||
| ZkDisputeGameImpl: common.HexToAddress("0x2222222222222222222222222222222222222222"), | ||
| }, | ||
| } | ||
| game := state.AdditionalDisputeGame{ | ||
| VMType: state.VMTypeZK, | ||
| ZKDisputeGame: &state.ZKDisputeGameParams{ | ||
| ChallengerBond: (*hexutil.Big)(big.NewInt(0)), | ||
| }, | ||
| ChainProofParams: state.ChainProofParams{DisputeGameType: 10}, | ||
| } | ||
|
|
||
| err := deployDisputeGame(env, st, &state.ChainIntent{}, &state.ChainState{}, game) | ||
| require.ErrorContains(t, err, "ChallengerBond must be set") | ||
| } | ||
|
|
||
| func TestDeployDisputeGame_UnsupportedVMType(t *testing.T) { | ||
| lgr := testlog.Logger(t, slog.LevelInfo) | ||
|
|
||
| env := &Env{Logger: lgr} | ||
| st := &state.State{ | ||
| ImplementationsDeployment: &addresses.ImplementationsContracts{}, | ||
| } | ||
| game := state.AdditionalDisputeGame{ | ||
| VMType: state.VMType("UNSUPPORTED"), | ||
| } | ||
|
|
||
| err := deployDisputeGame(env, st, &state.ChainIntent{}, &state.ChainState{}, game) | ||
| require.ErrorContains(t, err, "unsupported VM type") | ||
| } | ||
|
|
||
| // TestZKDisputeGameFlag validates that devfeatures.ZKDisputeGameFlag matches the expected value. | ||
| func TestZKDisputeGameFlag(t *testing.T) { | ||
| expected := common.HexToHash("0x0000000000000000000000000000000000000000000000000000000001000000") | ||
| require.Equal(t, expected, devfeatures.ZKDisputeGameFlag, | ||
| "devfeatures.ZKDisputeGameFlag must match the expected value") | ||
| } | ||
|
|
||
| // TestZKDevFlagAutoEnable validates that DeployImplementations auto-enables | ||
| // the ZK dev flag when a chain has VMTypeZK in AdditionalDisputeGames. | ||
| func TestZKDevFlagAutoEnable(t *testing.T) { | ||
| chainID := common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000001") | ||
|
|
||
| intentWithZK := &state.Intent{ | ||
| GlobalDeployOverrides: map[string]any{}, | ||
| Chains: []*state.ChainIntent{ | ||
| { | ||
| ID: chainID, | ||
| AdditionalDisputeGames: []state.AdditionalDisputeGame{ | ||
| {VMType: state.VMTypeZK}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| intentWithoutZK := &state.Intent{ | ||
| GlobalDeployOverrides: map[string]any{}, | ||
| Chains: []*state.ChainIntent{ | ||
| { | ||
| ID: chainID, | ||
| AdditionalDisputeGames: []state.AdditionalDisputeGame{}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| t.Run("zk_game_enables_flag", func(t *testing.T) { | ||
| bitmap := computeDevFeatureBitmap(intentWithZK) | ||
| // ZK flag bit (0x01000000) should be set | ||
| require.NotEqual(t, common.Hash{}, bitmap) | ||
| for i := range devfeatures.ZKDisputeGameFlag { | ||
| require.Equal(t, devfeatures.ZKDisputeGameFlag[i], bitmap[i]&devfeatures.ZKDisputeGameFlag[i], | ||
| "ZK dev flag bit %d should be set in bitmap", i) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("no_zk_game_does_not_enable_flag", func(t *testing.T) { | ||
| bitmap := computeDevFeatureBitmap(intentWithoutZK) | ||
| require.Equal(t, common.Hash{}, bitmap) | ||
| }) | ||
| } | ||
|
|
||
| // computeDevFeatureBitmap extracts the ZK flag auto-enable logic from DeployImplementations for testing. | ||
| func computeDevFeatureBitmap(intent *state.Intent) common.Hash { | ||
| var bitmap common.Hash | ||
| outer: | ||
| for _, chain := range intent.Chains { | ||
| for _, game := range chain.AdditionalDisputeGames { | ||
| if game.VMType == state.VMTypeZK { | ||
| for i := range bitmap { | ||
| bitmap[i] |= devfeatures.ZKDisputeGameFlag[i] | ||
| } | ||
| break outer | ||
| } | ||
| } | ||
| } | ||
| return bitmap | ||
| } |
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.