-
Notifications
You must be signed in to change notification settings - Fork 3.9k
op-program: Introduce basic infrastructure for fault proof program #5297
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 @@ | ||
| bin |
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 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2023 Optimism | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
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,27 @@ | ||
| GITCOMMIT := $(shell git rev-parse HEAD) | ||
| GITDATE := $(shell git show -s --format='%ct') | ||
| VERSION := v0.0.0 | ||
|
|
||
| LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT) | ||
| LDFLAGSSTRING +=-X main.GitDate=$(GITDATE) | ||
| LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/op-program/version.Version=$(VERSION) | ||
| LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/op-program/version.Meta=$(VERSION_META) | ||
| LDFLAGS := -ldflags "$(LDFLAGSSTRING)" | ||
|
|
||
| op-program: | ||
| env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/op-program ./cmd/main.go | ||
|
|
||
| clean: | ||
| rm -rf bin | ||
|
|
||
| test: | ||
| go test -v ./... | ||
|
|
||
| lint: | ||
| golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint -e "errors.As" -e "errors.Is" | ||
|
|
||
| .PHONY: \ | ||
| op-program \ | ||
| clean \ | ||
| test \ | ||
| lint |
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,43 @@ | ||
| # op-program | ||
|
|
||
| Implements a fault proof program that runs through the rollup state-transition to verify an L2 output from L1 inputs. | ||
| This verifiable output can then resolve a disputed output on L1. | ||
|
|
||
| The program is designed such that it can be run in a deterministic way such that two invocations with the same input | ||
| data wil result in not only the same output, but the same program execution trace. This allows it to be run in an | ||
| on-chain VM as part of the dispute resolution process. | ||
|
|
||
| ## Compiling | ||
|
|
||
| To build op-program, from within the `op-program` directory run: | ||
|
|
||
| ```shell | ||
| make op-program | ||
| ``` | ||
|
|
||
| This resulting executable will be in `./bin/op-program` | ||
|
|
||
| ## Testing | ||
|
|
||
| To run op-program unit tests, from within the `op-program` directory run: | ||
|
|
||
| ```shell | ||
| make test | ||
| ``` | ||
|
|
||
| ## Lint | ||
|
|
||
| To run the linter, from within the `op-program` directory run: | ||
| ```shell | ||
| make lint | ||
| ``` | ||
|
|
||
| This requires having `golangci-lint` installed. | ||
|
|
||
| ## Running | ||
|
|
||
| From within the `op-program` directory, options can be reviewed with: | ||
|
|
||
| ```shell | ||
| ./bin/op-program --help | ||
| ``` |
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,90 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-node/chaincfg" | ||
| "github.com/ethereum-optimism/optimism/op-program/config" | ||
| "github.com/ethereum-optimism/optimism/op-program/flags" | ||
| "github.com/ethereum-optimism/optimism/op-program/version" | ||
| oplog "github.com/ethereum-optimism/optimism/op-service/log" | ||
| "github.com/ethereum/go-ethereum/log" | ||
| "github.com/urfave/cli" | ||
| ) | ||
|
|
||
| var ( | ||
| GitCommit = "" | ||
| GitDate = "" | ||
| ) | ||
|
|
||
| // VersionWithMeta holds the textual version string including the metadata. | ||
| var VersionWithMeta = func() string { | ||
| v := version.Version | ||
| if GitCommit != "" { | ||
| v += "-" + GitCommit[:8] | ||
| } | ||
| if GitDate != "" { | ||
| v += "-" + GitDate | ||
| } | ||
| if version.Meta != "" { | ||
| v += "-" + version.Meta | ||
| } | ||
| return v | ||
| }() | ||
|
|
||
| func main() { | ||
| args := os.Args | ||
| err := run(args, FaultProofProgram) | ||
| if err != nil { | ||
| log.Crit("Application failed", "message", err) | ||
| } | ||
| } | ||
|
|
||
| type ConfigAction func(log log.Logger, config *config.Config) error | ||
|
|
||
| // run parses the supplied args to create a config.Config instance, sets up logging | ||
| // then calls the supplied ConfigAction. | ||
| // This allows testing the translation from CLI arguments to Config | ||
| func run(args []string, action ConfigAction) error { | ||
| // Set up logger with a default INFO level in case we fail to parse flags, | ||
| // otherwise the final critical log won't show what the parsing error was. | ||
| oplog.SetupDefaults() | ||
|
|
||
| app := cli.NewApp() | ||
| app.Version = VersionWithMeta | ||
| app.Flags = flags.Flags | ||
| app.Name = "op-program" | ||
| app.Usage = "Optimism Fault Proof Program" | ||
| app.Description = "The Optimism Fault Proof Program fault proof program that runs through the rollup state-transition to verify an L2 output from L1 inputs." | ||
| app.Action = func(ctx *cli.Context) error { | ||
| logger, err := setupLogging(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| logger.Info("Starting fault proof program", "version", VersionWithMeta) | ||
|
|
||
| cfg, err := config.NewConfigFromCLI(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return action(logger, cfg) | ||
| } | ||
|
|
||
| return app.Run(args) | ||
| } | ||
|
|
||
| func setupLogging(ctx *cli.Context) (log.Logger, error) { | ||
| logCfg := oplog.ReadCLIConfig(ctx) | ||
| if err := logCfg.Check(); err != nil { | ||
| return nil, fmt.Errorf("log config error: %w", err) | ||
| } | ||
| logger := oplog.NewLogger(logCfg) | ||
| return logger, nil | ||
| } | ||
|
|
||
| // FaultProofProgram is the programmatic entry-point for the fault proof program | ||
| func FaultProofProgram(log log.Logger, cfg *config.Config) error { | ||
trianglesphere marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cfg.Rollup.LogDescription(log, chaincfg.L2ChainIDToNetworkName) | ||
| return nil | ||
| } | ||
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,125 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-node/chaincfg" | ||
| "github.com/ethereum-optimism/optimism/op-program/config" | ||
| "github.com/ethereum/go-ethereum/log" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestLogLevel(t *testing.T) { | ||
| t.Run("RejectInvalid", func(t *testing.T) { | ||
| verifyArgsInvalid(t, "unknown level: foo", addRequiredArgs("--log.level=foo")) | ||
| }) | ||
|
|
||
| for _, lvl := range []string{"trace", "debug", "info", "error", "crit"} { | ||
| lvl := lvl | ||
| t.Run("AcceptValid_"+lvl, func(t *testing.T) { | ||
| logger, _, err := runWithArgs(addRequiredArgs("--log.level", lvl)) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, logger) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestDefaultCLIOptionsMatchDefaultConfig(t *testing.T) { | ||
| cfg := configForArgs(t, addRequiredArgs()) | ||
| require.Equal(t, config.NewConfig(&chaincfg.Goerli), cfg) | ||
| } | ||
|
|
||
| func TestNetwork(t *testing.T) { | ||
| t.Run("Unknown", func(t *testing.T) { | ||
| verifyArgsInvalid(t, "invalid network bar", replaceRequiredArg("--network", "bar")) | ||
| }) | ||
|
|
||
| t.Run("Required", func(t *testing.T) { | ||
| verifyArgsInvalid(t, "flag rollup.config or network is required", addRequiredArgsExcept("--network")) | ||
| }) | ||
|
|
||
| t.Run("DisallowNetworkAndRollupConfig", func(t *testing.T) { | ||
| verifyArgsInvalid(t, "cannot specify both rollup.config and network", addRequiredArgs("--rollup.config=foo")) | ||
| }) | ||
|
|
||
| t.Run("RollupConfig", func(t *testing.T) { | ||
| dir := t.TempDir() | ||
| configJson, err := json.Marshal(chaincfg.Goerli) | ||
| require.NoError(t, err) | ||
| configFile := dir + "/config.json" | ||
| err = os.WriteFile(configFile, configJson, os.ModePerm) | ||
| require.NoError(t, err) | ||
|
|
||
| cfg := configForArgs(t, addRequiredArgsExcept("--network", "--rollup.config", configFile)) | ||
| require.Equal(t, chaincfg.Goerli, *cfg.Rollup) | ||
| }) | ||
|
|
||
| for name, cfg := range chaincfg.NetworksByName { | ||
| name := name | ||
| expected := cfg | ||
| t.Run("Network_"+name, func(t *testing.T) { | ||
| cfg := configForArgs(t, replaceRequiredArg("--network", name)) | ||
| require.Equal(t, expected, *cfg.Rollup) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func verifyArgsInvalid(t *testing.T, messageContains string, cliArgs []string) { | ||
| _, _, err := runWithArgs(cliArgs) | ||
| require.ErrorContains(t, err, messageContains) | ||
| } | ||
|
|
||
| func configForArgs(t *testing.T, cliArgs []string) *config.Config { | ||
| _, cfg, err := runWithArgs(cliArgs) | ||
| require.NoError(t, err) | ||
| return cfg | ||
| } | ||
|
|
||
| func runWithArgs(cliArgs []string) (log.Logger, *config.Config, error) { | ||
| var cfg *config.Config | ||
| var logger log.Logger | ||
| fullArgs := append([]string{"op-program"}, cliArgs...) | ||
| err := run(fullArgs, func(log log.Logger, config *config.Config) error { | ||
| logger = log | ||
| cfg = config | ||
| return nil | ||
| }) | ||
| return logger, cfg, err | ||
| } | ||
|
|
||
| func addRequiredArgs(args ...string) []string { | ||
| req := requiredArgs() | ||
| combined := toArgList(req) | ||
| return append(combined, args...) | ||
| } | ||
|
|
||
| func addRequiredArgsExcept(name string, optionalArgs ...string) []string { | ||
| req := requiredArgs() | ||
| delete(req, name) | ||
| return append(toArgList(req), optionalArgs...) | ||
| } | ||
|
|
||
| func replaceRequiredArg(name string, value string) []string { | ||
| req := requiredArgs() | ||
| req[name] = value | ||
| return toArgList(req) | ||
| } | ||
|
|
||
| // requiredArgs returns map of argument names to values which are the minimal arguments required | ||
| // to create a valid Config | ||
| func requiredArgs() map[string]string { | ||
| return map[string]string{ | ||
| "--network": "goerli", | ||
| } | ||
| } | ||
|
|
||
| func toArgList(req map[string]string) []string { | ||
| var combined []string | ||
| for name, value := range req { | ||
| combined = append(combined, name) | ||
| combined = append(combined, value) | ||
| } | ||
| return combined | ||
| } |
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.