Skip to content
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

cannon: Add mtcannon64 state versioning #13582

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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cannon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion cannon/cmd/load_elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion cannon/mipsevm/versions/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cannon/mipsevm/versions/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
12 changes: 9 additions & 3 deletions cannon/mipsevm/versions/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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) {
Expand Down Expand Up @@ -63,7 +65,7 @@ func NewFromState(state mipsevm.FPVMState) (*VersionedState, error) {
}, nil
} else {
return &VersionedState{
Version: VersionMultiThreaded64,
Version: VersionMultiThreaded64_v2,
FPVMState: state,
}, nil
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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"
}
Expand All @@ -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")
}
Expand Down
8 changes: 4 additions & 4 deletions cannon/mipsevm/versions/state64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
Binary file added cannon/mipsevm/versions/testdata/states/4.bin.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion op-program/Dockerfile.repro
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
8 changes: 6 additions & 2 deletions ops/docker/op-stack-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down