From a6cca6da51f0c763ce481f18b33dbc923a3320ec Mon Sep 17 00:00:00 2001 From: mbaxter Date: Fri, 3 Jan 2025 16:33:00 -0500 Subject: [PATCH 1/5] cannon: Add new state version and start migrating --- cannon/cmd/load_elf.go | 2 +- cannon/mipsevm/versions/detect.go | 2 +- cannon/mipsevm/versions/detect_test.go | 2 +- cannon/mipsevm/versions/state.go | 12 +++++++++--- cannon/mipsevm/versions/state64_test.go | 8 ++++---- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cannon/cmd/load_elf.go b/cannon/cmd/load_elf.go index c76ebbe8f7cb..53760b5ab0fe 100644 --- a/cannon/cmd/load_elf.go +++ b/cannon/cmd/load_elf.go @@ -80,7 +80,7 @@ func LoadELF(ctx *cli.Context) error { } return program.PatchStack(state) } - case versions.VersionMultiThreaded, versions.VersionMultiThreaded64: + case versions.VersionMultiThreaded, versions.VersionMultiThreaded64_v2: createInitialState = func(f *elf.File) (mipsevm.FPVMState, error) { return program.LoadELF(f, multithreaded.CreateInitialState) } diff --git a/cannon/mipsevm/versions/detect.go b/cannon/mipsevm/versions/detect.go index 4513eddf837a..0b14569c3049 100644 --- a/cannon/mipsevm/versions/detect.go +++ b/cannon/mipsevm/versions/detect.go @@ -27,7 +27,7 @@ func DetectVersion(path string) (StateVersion, error) { } switch ver { - case VersionSingleThreaded, VersionMultiThreaded, VersionSingleThreaded2, VersionMultiThreaded64: + case VersionSingleThreaded, VersionMultiThreaded, VersionSingleThreaded2, VersionMultiThreaded64, VersionMultiThreaded64_v2: return ver, nil default: return 0, fmt.Errorf("%w: %d", ErrUnknownVersion, ver) diff --git a/cannon/mipsevm/versions/detect_test.go b/cannon/mipsevm/versions/detect_test.go index bd1acd115eaf..045237a6462e 100644 --- a/cannon/mipsevm/versions/detect_test.go +++ b/cannon/mipsevm/versions/detect_test.go @@ -66,7 +66,7 @@ func TestDetectVersion_singleThreadedBinary(t *testing.T) { func TestDetectVersion_multiThreadedBinary(t *testing.T) { targetVersion := VersionMultiThreaded if !arch.IsMips32 { - targetVersion = VersionMultiThreaded64 + targetVersion = VersionMultiThreaded64_v2 } state, err := NewFromState(multithreaded.CreateEmptyState()) diff --git a/cannon/mipsevm/versions/state.go b/cannon/mipsevm/versions/state.go index eee0c00d2b12..67352dd905b2 100644 --- a/cannon/mipsevm/versions/state.go +++ b/cannon/mipsevm/versions/state.go @@ -22,7 +22,9 @@ const ( VersionMultiThreaded // VersionSingleThreaded2 is based on VersionSingleThreaded with the addition of support for fcntl(F_GETFD) syscall VersionSingleThreaded2 + // VersionMultiThreaded64 is the original 64-bit MTCannon implementation (pre-audit), tagged at cannon/v1.2.0 VersionMultiThreaded64 + VersionMultiThreaded64_v2 ) var ( @@ -31,7 +33,7 @@ var ( ErrUnsupportedMipsArch = errors.New("mips architecture is not supported") ) -var StateVersionTypes = []StateVersion{VersionSingleThreaded, VersionMultiThreaded, VersionSingleThreaded2, VersionMultiThreaded64} +var StateVersionTypes = []StateVersion{VersionSingleThreaded, VersionMultiThreaded, VersionSingleThreaded2, VersionMultiThreaded64, VersionMultiThreaded64_v2} func LoadStateFromFile(path string) (*VersionedState, error) { if !serialize.IsBinaryFile(path) { @@ -63,7 +65,7 @@ func NewFromState(state mipsevm.FPVMState) (*VersionedState, error) { }, nil } else { return &VersionedState{ - Version: VersionMultiThreaded64, + Version: VersionMultiThreaded64_v2, FPVMState: state, }, nil } @@ -114,7 +116,7 @@ func (s *VersionedState) Deserialize(in io.Reader) error { } s.FPVMState = state return nil - case VersionMultiThreaded64: + case VersionMultiThreaded64_v2: if arch.IsMips32 { return ErrUnsupportedMipsArch } @@ -151,6 +153,8 @@ func (s StateVersion) String() string { return "singlethreaded-2" case VersionMultiThreaded64: return "multithreaded64" + case VersionMultiThreaded64_v2: + return "multithreaded64-2" default: return "unknown" } @@ -166,6 +170,8 @@ func ParseStateVersion(ver string) (StateVersion, error) { return VersionSingleThreaded2, nil case "multithreaded64": return VersionMultiThreaded64, nil + case "multithreaded64-2": + return VersionMultiThreaded64_v2, nil default: return StateVersion(0), errors.New("unknown state version") } diff --git a/cannon/mipsevm/versions/state64_test.go b/cannon/mipsevm/versions/state64_test.go index ddffd7e618a5..a7dfc34fcac6 100644 --- a/cannon/mipsevm/versions/state64_test.go +++ b/cannon/mipsevm/versions/state64_test.go @@ -15,16 +15,16 @@ import ( ) func TestNewFromState(t *testing.T) { - t.Run("multithreaded64", func(t *testing.T) { + t.Run("multithreaded64-2", func(t *testing.T) { actual, err := NewFromState(multithreaded.CreateEmptyState()) require.NoError(t, err) require.IsType(t, &multithreaded.State{}, actual.FPVMState) - require.Equal(t, VersionMultiThreaded64, actual.Version) + require.Equal(t, VersionMultiThreaded64_v2, actual.Version) }) } func TestLoadStateFromFile(t *testing.T) { - t.Run("Multithreaded64FromBinary", func(t *testing.T) { + t.Run("Multithreaded64_v2_FromBinary", func(t *testing.T) { expected, err := NewFromState(multithreaded.CreateEmptyState()) require.NoError(t, err) @@ -40,7 +40,7 @@ func TestVersionsOtherThanZeroDoNotSupportJSON(t *testing.T) { version StateVersion createState func() mipsevm.FPVMState }{ - {VersionMultiThreaded64, func() mipsevm.FPVMState { return multithreaded.CreateEmptyState() }}, + {VersionMultiThreaded64_v2, func() mipsevm.FPVMState { return multithreaded.CreateEmptyState() }}, } for _, test := range tests { test := test From 29384f3c13c43b430263cee93d801cbd1a05fd8b Mon Sep 17 00:00:00 2001 From: mbaxter Date: Fri, 3 Jan 2025 16:48:00 -0500 Subject: [PATCH 2/5] cannon: Add new test state for version 4 --- cannon/mipsevm/versions/testdata/states/4.bin.gz | Bin 0 -> 44 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 cannon/mipsevm/versions/testdata/states/4.bin.gz diff --git a/cannon/mipsevm/versions/testdata/states/4.bin.gz b/cannon/mipsevm/versions/testdata/states/4.bin.gz new file mode 100644 index 0000000000000000000000000000000000000000..a0c27eebaaec6a4afc55aade06c97ca2adf0c1d7 GIT binary patch literal 44 vcmb2|=3oGW|4E4pWPk9p8rUgI^}2G3Ie3fnRWbl2|NsAdJZ$xTMg|4|^WF@E literal 0 HcmV?d00001 From 8844f034c696f40b545f40e047a323cef9aa55f5 Mon Sep 17 00:00:00 2001 From: mbaxter Date: Fri, 3 Jan 2025 16:54:50 -0500 Subject: [PATCH 3/5] cannon: Update cannon commands to use new state version --- Makefile | 4 ++-- op-program/Dockerfile.repro | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 15212d696e48..aedc300e22ad 100644 --- a/Makefile +++ b/Makefile @@ -148,8 +148,8 @@ cannon-prestate: op-program cannon ## Generates prestate using cannon and op-pro mv op-program/bin/0.json op-program/bin/prestate-proof.json .PHONY: cannon-prestate -cannon-prestate-mt: op-program cannon ## Generates prestate using cannon and op-program in the multithreaded64 cannon format - ./cannon/bin/cannon load-elf --type multithreaded64 --path op-program/bin/op-program-client64.elf --out op-program/bin/prestate-mt.bin.gz --meta op-program/bin/meta-mt.json +cannon-prestate-mt: op-program cannon ## Generates prestate using cannon and op-program in the multithreaded64-2 cannon format + ./cannon/bin/cannon load-elf --type multithreaded64-2 --path op-program/bin/op-program-client64.elf --out op-program/bin/prestate-mt.bin.gz --meta op-program/bin/meta-mt.json ./cannon/bin/cannon run --proof-at '=0' --stop-at '=1' --input op-program/bin/prestate-mt.bin.gz --meta op-program/bin/meta-mt.json --proof-fmt 'op-program/bin/%d-mt.json' --output "" mv op-program/bin/0-mt.json op-program/bin/prestate-proof-mt.json .PHONY: cannon-prestate-mt diff --git a/op-program/Dockerfile.repro b/op-program/Dockerfile.repro index 60eba7accab6..4cc6de02c95f 100644 --- a/op-program/Dockerfile.repro +++ b/op-program/Dockerfile.repro @@ -35,7 +35,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build cd op-program && make op-pro # Run the op-program-client.elf binary directly through cannon's load-elf subcommand. RUN /app/cannon/bin/cannon load-elf --type singlethreaded-2 --path /app/op-program/bin/op-program-client.elf --out /app/op-program/bin/prestate.bin.gz --meta "/app/op-program/bin/meta.json" RUN /app/cannon/bin/cannon load-elf --type multithreaded --path /app/op-program/bin/op-program-client.elf --out /app/op-program/bin/prestate-mt.bin.gz --meta "/app/op-program/bin/meta-mt.json" -RUN /app/cannon/bin/cannon load-elf --type multithreaded64 --path /app/op-program/bin/op-program-client64.elf --out /app/op-program/bin/prestate-mt64.bin.gz --meta "/app/op-program/bin/meta-mt64.json" +RUN /app/cannon/bin/cannon load-elf --type multithreaded64-2 --path /app/op-program/bin/op-program-client64.elf --out /app/op-program/bin/prestate-mt64.bin.gz --meta "/app/op-program/bin/meta-mt64.json" # Generate the prestate proof containing the absolute pre-state hash. RUN /app/cannon/bin/cannon run --proof-at '=0' --stop-at '=1' --input /app/op-program/bin/prestate.bin.gz --meta "" --proof-fmt '/app/op-program/bin/%d.json' --output "" From d0844457c50127e3484f4def5b4ccfb8f3dcf696 Mon Sep 17 00:00:00 2001 From: mbaxter Date: Fri, 3 Jan 2025 19:24:36 -0500 Subject: [PATCH 4/5] cannon: Update cannon embeds command --- cannon/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cannon/Makefile b/cannon/Makefile index 6156cd68d64e..ff83b9e96af1 100644 --- a/cannon/Makefile +++ b/cannon/Makefile @@ -36,8 +36,8 @@ cannon-embeds: cannon32-impl cannon64-impl @cp bin/cannon32-impl ./multicannon/embeds/cannon-2 # multithreaded @cp bin/cannon32-impl ./multicannon/embeds/cannon-1 - # 64-bit multithreaded - @cp bin/cannon64-impl ./multicannon/embeds/cannon-3 + # 64-bit multithreaded v2 + @cp bin/cannon64-impl ./multicannon/embeds/cannon-4 cannon: cannon-embeds env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/cannon ./multicannon/ From 197b20ddc29a54a44f87551ef830de41ce58c701 Mon Sep 17 00:00:00 2001 From: mbaxter Date: Fri, 3 Jan 2025 19:25:18 -0500 Subject: [PATCH 5/5] cannon: Update Dockerfile to include cannon version 3 binary --- ops/docker/op-stack-go/Dockerfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ops/docker/op-stack-go/Dockerfile b/ops/docker/op-stack-go/Dockerfile index b6fb3f45c90b..a74163b83144 100644 --- a/ops/docker/op-stack-go/Dockerfile +++ b/ops/docker/op-stack-go/Dockerfile @@ -63,11 +63,15 @@ ARG TARGETARCH # The "id" defaults to the value of "target", the cache will thus be reused during this build. # "sharing" defaults to "shared", the cache will thus be available to other concurrent docker builds. -FROM --platform=$BUILDPLATFORM us-docker.pkg.dev/oplabs-tools-artifacts/images/cannon:v1.0.0 AS cannon-builder-0 +FROM --platform=$BUILDPLATFORM us-docker.pkg.dev/oplabs-tools-artifacts/images/cannon:v1.0.0 AS cannon-builder-v1-0-0 +FROM --platform=$BUILDPLATFORM us-docker.pkg.dev/oplabs-tools-artifacts/images/cannon:v1.2.0 AS cannon-builder-v1-2-0 FROM --platform=$BUILDPLATFORM builder AS cannon-builder ARG CANNON_VERSION=v0.0.0 -COPY --from=cannon-builder-0 /usr/local/bin/cannon ./cannon/multicannon/embeds/cannon-0 +# Copy cannon binaries from previous versions +COPY --from=cannon-builder-v1-0-0 /usr/local/bin/cannon ./cannon/multicannon/embeds/cannon-0 +COPY --from=cannon-builder-v1-2-0 /usr/local/bin/cannon-3 ./cannon/multicannon/embeds/cannon-3 +# Build current binaries RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build cd cannon && make cannon \ GOOS=$TARGETOS GOARCH=$TARGETARCH GITCOMMIT=$GIT_COMMIT GITDATE=$GIT_DATE VERSION="$CANNON_VERSION"