Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cannon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ifeq ($(shell uname),Darwin)
FUZZLDFLAGS := -ldflags=-extldflags=-Wl,-ld_classic
endif

.DEFAULT_GOAL := cannon

cannon-impl:
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/cannon-impl .

Expand Down
30 changes: 24 additions & 6 deletions cannon/cmd/witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"os"

factory "github.com/ethereum-optimism/optimism/cannon/mipsevm/versions"
"github.com/ethereum-optimism/optimism/op-service/ioutil"
"github.com/ethereum-optimism/optimism/op-service/jsonutil"
"github.com/ethereum/go-ethereum/common"
"github.com/urfave/cli/v2"
)

Expand All @@ -22,28 +25,43 @@ var (
}
)

type response struct {
WitnessHash common.Hash `json:"witnessHash"`
Step uint64 `json:"step"`
Exited bool `json:"exited"`
ExitCode uint8 `json:"exitCode"`
}

func Witness(ctx *cli.Context) error {
input := ctx.Path(WitnessInputFlag.Name)
output := ctx.Path(WitnessOutputFlag.Name)
witnessOutput := ctx.Path(WitnessOutputFlag.Name)
state, err := factory.LoadStateFromFile(input)
if err != nil {
return fmt.Errorf("invalid input state (%v): %w", input, err)
}
witness, h := state.EncodeWitness()
if output != "" {
if err := os.WriteFile(output, witness, 0755); err != nil {
return fmt.Errorf("writing output to %v: %w", output, err)
if witnessOutput != "" {
if err := os.WriteFile(witnessOutput, witness, 0755); err != nil {
return fmt.Errorf("writing output to %v: %w", witnessOutput, err)
}
}
fmt.Println(h.Hex())
output := response{
WitnessHash: h,
Step: state.GetStep(),
Exited: state.GetExited(),
ExitCode: state.GetExitCode(),
}
if err := jsonutil.WriteJSON(output, ioutil.ToStdOut()); err != nil {
return fmt.Errorf("failed to write response: %w", err)
}
return nil
}

func CreateWitnessCommand(action cli.ActionFunc) *cli.Command {
return &cli.Command{
Name: "witness",
Usage: "Convert a Cannon JSON state into a binary witness",
Description: "Convert a Cannon JSON state into a binary witness. The hash of the witness is written to stdout",
Description: "Convert a Cannon JSON state into a binary witness. Basic data about the state is printed to stdout in JSON format.",
Action: action,
Flags: []cli.Flag{
WitnessInputFlag,
Expand Down
2 changes: 1 addition & 1 deletion cannon/multicannon/witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Witness(ctx *cli.Context) error {
var WitnessCommand = &cli.Command{
Name: "witness",
Usage: "Convert a Cannon JSON state into a binary witness",
Description: "Convert a Cannon JSON state into a binary witness. The hash of the witness is written to stdout",
Description: "Convert a Cannon JSON state into a binary witness. Basic data about the state is printed to stdout in JSON format.",
Action: Witness,
SkipFlagParsing: true,
}