-
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
19
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.
+755
−3
Open
feat: zk go deployer #20219
Changes from 13 commits
Commits
Show all changes
19 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 a0f08ea
feat: merge with develop
ashitakah 833eeef
feat: merge with develop
ashitakah 027fae4
fix: comments and merge
ashitakah 991e973
fix: comments and merge
ashitakah 3f89c65
fix: lint
ashitakah fdc342b
fix: comments
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package zk | ||
|
|
||
| import ( | ||
| gameTypes "github.com/ethereum-optimism/optimism/op-challenger/game/types" | ||
| "github.com/ethereum-optimism/optimism/op-core/devfeatures" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/devtest" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/presets" | ||
| "github.com/ethereum-optimism/optimism/op-devstack/sysgo" | ||
| ) | ||
|
|
||
| func zkOpts() []presets.Option { | ||
| return []presets.Option{ | ||
| presets.WithGameTypeAdded(gameTypes.ZKDisputeGameType), | ||
| presets.WithDeployerOptions(sysgo.WithDevFeatureEnabled(devfeatures.ZKDisputeGameFlag)), | ||
| presets.WithDeployerOptions(sysgo.WithJovianAtGenesis), | ||
| } | ||
| } | ||
|
|
||
| func newSystem(t devtest.T) *presets.Minimal { | ||
| return presets.NewMinimal(t, zkOpts()...) | ||
| } |
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,23 @@ | ||
| package zk | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-devstack/devtest" | ||
| ) | ||
|
|
||
| // TestSmoke verifies that op-deployer correctly deploys and registers the ZK | ||
| // dispute game when ZKDisputeGameFlag is enabled. | ||
| func TestSmoke(gt *testing.T) { | ||
| t := devtest.ParallelT(gt) | ||
| sys := newSystem(t) | ||
| require := t.Require() | ||
|
|
||
| zk := sys.DisputeGameFactory().ZKGameImpl() | ||
|
|
||
| require.NotEmpty(zk.Address, "ZK dispute game impl must be registered in DisputeGameFactory") | ||
| require.NotZero(zk.Args.MaxChallengeDuration, "maxChallengeDuration must be set") | ||
| require.NotZero(zk.Args.MaxProveDuration, "maxProveDuration must be set") | ||
| require.Positive(zk.Args.ChallengerBond.Sign(), "challengerBond must be non-zero") | ||
| require.Equal(sys.L2Chain.ChainID().ToBig(), zk.Args.L2ChainID, "l2ChainId must match deployed chain") | ||
| } |
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
185 changes: 185 additions & 0 deletions
185
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,185 @@ | ||
| 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") | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be wrong?
ZK_ARGS_LENGTHis 172 but this encodes 160 bytes (32*5 bytes)? Am I missing something?optimism/packages/contracts-bedrock/src/dispute/lib/LibGameArgs.sol
Line 97 in 08f91c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dug into this further, it is wrong, and it's not just a length mismatch. Walked through the full call chain and wrote a repro.
zkGameArgEncoder(dispute_games.go:265) is a w3 ABI tuple encoder, producing 5 × 32 = 160 bytes with per-field left-padding. The bytes flow throughSetDisputeGameImpl.s.sol:75intofactory.setImplementation(gameType, impl, gameArgs)(DisputeGameFactory.sol:315-316), which stores them verbatim and appends them to every clone as CWIA immutable data (:210).ZKDisputeGame.sol:181-217reads the packed layout at fixed byte offsets, and sinceLibGameArgs.sol:116reverts withInvalidGameArgsLengthon anything other than 172 bytes, any clone instantiated against this impl reverts on creation. Not silently broken, actively unusable.The same tuple encoder works fine in
upgrade/embedded/upgrade.gobecause OPCM re-abi.decodes and re-packs it on-chain viaOPContractsManagerUtils.makeGameArgs(:455-467). The deployer path skips that step. The Cannon peer atdispute_games.go:189usesgameargs.PackPermissionless(), which is the precedent to follow.Also noticed the blob is missing three fields entirely:
anchorStateRegistry,weth, andl2ChainId. Even if we switched to packed encoding without fixing that, we'd still be short, and those need to come fromthisState.OpChainContractsandthisIntent.ID.Wrote a quick repro: https://gist.github.com/wwared/75bf76f775a44410ade3fac80ce402d9
It encodes a known config via
zkGameArgEncoder, strips the selector the same waydispute_games.go:157does, and compares against the reference 172-byte packed layout. A PASS onTestZKGameArgs_DeployerEncoderProducesWrongLayoutmeans the args are encoded incorrectly: each assertion pins one fact about the broken state (len == 160, verifier reads back as0x000…0001111…1111from the ABI pad, etc.). Once the fix lands the assertions flip, and at that point this should be replaced with a golden-byte positive-path test.On why we didn't catch it earlier: the unit tests in
dispute_games_test.goare all negative paths (…_ZeroImpl,…_NilParams,…_WrongDisputeGameType,…_NilChallengerBond,…_ZeroChallengerBond), which return before the encoder runs, so nothing inspects its output.TestEncodedUpgradeInputV2_GameArgsEncodingdoes pin the 160-byte ABI form byte-for-byte, but only for the upgrade path where OPCM re-packs. And the new smoke test inop-acceptance-tests/tests/proofs/zk/smoke_test.goroutes throughdelegateCallWithSetCodeon the OPCM impl (insysgo/add_game_type.go), which is the upgrade path again. The newDeployAdditionalDisputeGamesZK branch has no coverage.Fix-wise: swap the tuple encoder for a packed encoder matching
OPContractsManagerUtils.makeGameArgsforZK_DISPUTE_GAME(172 bytes, appending ASR/WETH/chainID), following the Cannongameargs.PackPermissionless()pattern. Add a golden-byte positive-path test. And ideally a test that actually exercises the deployer path rather than only the upgrade flow.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: it's entirely possible Claude got some stuff wrong in the above comment, but at the very least it does seem like the game args on the ZKDisputeGame.sol contract are different from the ones in this PR (missing the last three):
optimism/packages/contracts-bedrock/src/dispute/zk/ZKDisputeGame.sol
Line 288 in 13fd70f
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You were right, fixed everything you flagged.
Swapped the w3 ABI tuple encoder for a proper ZKGameArgs.Pack() in the gameargs package (same pattern as PackPermissionless() for Cannon), now produces the correct 172 packed bytes. Also added the three missing fields (anchorStateRegistry, weth, l2ChainId) from thisState.OpChainContracts and thisIntent.ID, plus a test pinning every offset.
The end-to-end acceptance test for the deployer path is a follow-up, agreed it's missing but I will leave it as a separate issue.