From d2480b8a2776bdae9024688f6e67e6a1c084183a Mon Sep 17 00:00:00 2001 From: Minhyuk Kim Date: Wed, 2 Oct 2024 13:25:34 -0600 Subject: [PATCH] Use op-service/serialize --- go.mod | 6 ++-- go.sum | 4 +-- op-e2e/e2eutils/disputegame/helper.go | 2 +- rvgo/cmd/load_elf.go | 2 +- rvgo/cmd/run.go | 2 +- rvgo/cmd/witness.go | 40 +++++++++++++++++++-------- rvgo/fast/state.go | 3 +- 7 files changed, 37 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index adc4607..052c2e9 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,7 @@ go 1.21 toolchain go1.21.1 replace github.com/ethereum/go-ethereum v1.14.8 => github.com/ethereum-optimism/op-geth v1.101408.0-rc.4.0.20240827042333-110c433a2469 - -replace github.com/ethereum-optimism/optimism v1.9.2 => github.com/testinprod-io/optimism v0.0.0-20241001233047-6a2de66c6e6d +replace github.com/ethereum-optimism/optimism v1.9.2 => github.com/testinprod-io/optimism v0.0.0-20241002192014-a9e250e1feac require ( github.com/ethereum-optimism/optimism v1.9.2 @@ -78,7 +77,6 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect - github.com/google/go-cmp v0.6.0 // indirect github.com/google/gopacket v1.1.19 // indirect github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect github.com/google/uuid v1.6.0 // indirect @@ -151,7 +149,6 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/onsi/ginkgo/v2 v2.20.0 // indirect - github.com/onsi/gomega v1.34.1 // indirect github.com/opencontainers/runtime-spec v1.2.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect @@ -219,5 +216,6 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.3.0 // indirect + lukechampine.com/uint128 v1.3.0 // indirect rsc.io/tmplfunc v0.0.3 // indirect ) diff --git a/go.sum b/go.sum index 2ed4cf4..dc4859b 100644 --- a/go.sum +++ b/go.sum @@ -714,8 +714,6 @@ github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45 github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI= github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= -github.com/testinprod-io/optimism v0.0.0-20241001233047-6a2de66c6e6d h1:5tOocZ84k0E6C7G53eXgkrydFW59zA4Z3w5jCFghXzY= -github.com/testinprod-io/optimism v0.0.0-20241001233047-6a2de66c6e6d/go.mod h1:fLtZa7iBSxRebPnKNMkwsOy8VTjOvp7XLuD+bGvvNc8= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= @@ -1024,6 +1022,8 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= lukechampine.com/blake3 v1.3.0 h1:sJ3XhFINmHSrYCgl958hscfIa3bw8x4DqMP3u1YvoYE= lukechampine.com/blake3 v1.3.0/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= +lukechampine.com/uint128 v1.3.0 h1:cDdUVfRwDUDovz610ABgFD17nXD4/uDgVHl2sC3+sbo= +lukechampine.com/uint128 v1.3.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk= rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck= diff --git a/op-e2e/e2eutils/disputegame/helper.go b/op-e2e/e2eutils/disputegame/helper.go index b3ad749..3126855 100644 --- a/op-e2e/e2eutils/disputegame/helper.go +++ b/op-e2e/e2eutils/disputegame/helper.go @@ -95,7 +95,7 @@ func (h *AsteriscFactoryHelper) StartOutputAsteriscGame(ctx context.Context, l2N return &OutputAsteriscGameHelper{ OutputCannonGameHelper: op_e2e_disputegame.OutputCannonGameHelper{ - OutputGameHelper: *op_e2e_disputegame.NewOutputGameHelper(h.T, h.Require, h.Client, h.Opts, h.PrivKey, game, h.FactoryAddr, createdEvent.DisputeProxy, provider, h.System), + OutputGameHelper: *op_e2e_disputegame.NewOutputGameHelper(h.T, h.Require, h.Client, h.Opts, h.PrivKey, game, h.FactoryAddr, createdEvent.DisputeProxy, provider, h.System, h.AllocType), }, } } diff --git a/rvgo/cmd/load_elf.go b/rvgo/cmd/load_elf.go index 1c4410d..3341b55 100644 --- a/rvgo/cmd/load_elf.go +++ b/rvgo/cmd/load_elf.go @@ -5,9 +5,9 @@ import ( "fmt" cannon "github.com/ethereum-optimism/optimism/cannon/cmd" - "github.com/ethereum-optimism/optimism/cannon/serialize" "github.com/ethereum-optimism/optimism/op-service/ioutil" "github.com/ethereum-optimism/optimism/op-service/jsonutil" + "github.com/ethereum-optimism/optimism/op-service/serialize" "github.com/urfave/cli/v2" "github.com/ethereum-optimism/asterisc/rvgo/fast" diff --git a/rvgo/cmd/run.go b/rvgo/cmd/run.go index 75f668c..0bd70e0 100644 --- a/rvgo/cmd/run.go +++ b/rvgo/cmd/run.go @@ -14,10 +14,10 @@ import ( "github.com/ethereum-optimism/asterisc/rvgo/fast" cannon "github.com/ethereum-optimism/optimism/cannon/cmd" - "github.com/ethereum-optimism/optimism/cannon/serialize" preimage "github.com/ethereum-optimism/optimism/op-preimage" "github.com/ethereum-optimism/optimism/op-service/ioutil" "github.com/ethereum-optimism/optimism/op-service/jsonutil" + "github.com/ethereum-optimism/optimism/op-service/serialize" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" diff --git a/rvgo/cmd/witness.go b/rvgo/cmd/witness.go index c5dd621..71ef91a 100644 --- a/rvgo/cmd/witness.go +++ b/rvgo/cmd/witness.go @@ -2,6 +2,9 @@ package cmd import ( "fmt" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "os" "github.com/urfave/cli/v2" @@ -12,37 +15,52 @@ import ( ) type WitnessOutput struct { - Witness []byte `json:"witness"` - StateHash [32]byte `json:"stateHash"` + Witness hexutil.Bytes `json:"witness"` + StateHash common.Hash `json:"stateHash"` + Step uint64 `json:"step"` + Exited bool `json:"exited"` + ExitCode uint8 `json:"exitCode"` + PC uint64 `json:"pc"` } func Witness(ctx *cli.Context) error { input := ctx.Path(cannon.WitnessInputFlag.Name) - output := ctx.Path(cannon.WitnessOutputFlag.Name) + witnessOutput := ctx.Path(cannon.WitnessOutputFlag.Name) state, err := fast.LoadVMStateFromFile(input) if err != nil { return fmt.Errorf("invalid input state (%v): %w", input, err) } + witness := state.EncodeWitness() stateHash, err := witness.StateHash() if err != nil { - return fmt.Errorf("failed to compute witness hash: %w", err) + return fmt.Errorf("invalid Witness (%v): %w", witness, err) + } + + if witnessOutput != "" { + if err := os.WriteFile(witnessOutput, witness, OutFilePerm); err != nil { + return fmt.Errorf("writing output to %v: %w", witnessOutput, err) + } } - witnessOutput := &WitnessOutput{ - Witness: witness, + output := &WitnessOutput{ + Witness: []byte(witness), StateHash: stateHash, + Step: state.GetStep(), + Exited: state.Exited, + ExitCode: state.ExitCode, + PC: state.PC, } - if err := jsonutil.WriteJSON(witnessOutput, ioutil.ToStdOutOrFileOrNoop(output, OutFilePerm)); err != nil { - return fmt.Errorf("failed to write witness output %w", err) + + if err := jsonutil.WriteJSON(output, ioutil.ToStdOut()); err != nil { + return fmt.Errorf("failed to write response: %w", err) } - fmt.Println(stateHash.Hex()) return nil } var WitnessCommand = &cli.Command{ Name: "witness", - Usage: "Convert an Asterisc JSON state into a binary witness", - Description: "Convert an Asterisc JSON state into a binary witness. The statehash is written to stdout", + Usage: "Convert an Asterisc JSON/binary state into a binary witness", + Description: "Convert an Asterisc JSON/binary state into a binary witness. Basic Data about the state is printed to stdout in JSON format", Action: Witness, Flags: []cli.Flag{ cannon.WitnessInputFlag, diff --git a/rvgo/fast/state.go b/rvgo/fast/state.go index 8226c64..3f970e3 100644 --- a/rvgo/fast/state.go +++ b/rvgo/fast/state.go @@ -6,8 +6,7 @@ import ( "io" "github.com/ethereum-optimism/optimism/op-service/jsonutil" - - "github.com/ethereum-optimism/optimism/cannon/serialize" + "github.com/ethereum-optimism/optimism/op-service/serialize" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil"