ethereum-optimism / optimism

Optimism is Ethereum, scaled.
https://optimism.io
MIT License
5.65k stars 3.28k forks source link

cannon: Multi VM executor #12072

Closed Inphi closed 1 month ago

Inphi commented 1 month ago

image

Multicannon is a cannon wrapper that can be used to load and run Cannon states using a variety of Cannon FPVM implementations. This solves the issue of supporting older versions of the Cannon FPVM STF, without introducing branching logic into the STF. See https://github.com/ethereum-optimism/design-docs/pull/88 for more details on the rationale.

Multicannon mimics the same CLI as regular cannon, and in a couple subcommands, requires an additional --version flag to be specified where it cannot autodetect the VM implementation to use. The --version flag is used to locate the appropriate cannon FPVM program to use.

The run subcommand autodetects the appropriate VM implementation to use by inspecting the input state file. The StateVersion in the state file indicates the Cannon VM implementation to use.

Multicannon also supports a new list subcommand that displays the embedded cannon VMs and their versions.

Annoyances

An embedded cannon binary must exist for every version supported by multicannon. This is wasteful in the case of single-threaded and multi-threaded VMs as a single cannon VM implementation supports both using the --type flag.

Adding additional Cannon VMs

Easiest way to do this is using the op-stack-go Dockerfile. Whenever the Cannon VM STF is altered, a new StateVersion must be created. A Github tag can then be created for the change. This tag can be referenced when building the op-stack-go docker image to build an older version of cannon into the cannon/multicannon/embeds directory. When multicannon is built, it becomes aware of all cannon VM binaries found in the embeds directory.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 31.75182% with 187 lines in your changes missing coverage. Please review.

Project coverage is 68.14%. Comparing base (9178d5f) to head (77d6d37). Report is 15 commits behind head on develop.

Files with missing lines Patch % Lines
cannon/multicannon/exec.go 0.00% 51 Missing :warning:
cannon/multicannon/list.go 0.00% 36 Missing :warning:
cannon/multicannon/main.go 0.00% 21 Missing :warning:
cannon/multicannon/run.go 0.00% 16 Missing :warning:
cannon/multicannon/load_elf.go 0.00% 15 Missing :warning:
cannon/multicannon/witness.go 0.00% 15 Missing :warning:
cannon/multicannon/util.go 45.45% 10 Missing and 2 partials :warning:
cannon/mipsevm/versions/state.go 37.50% 10 Missing :warning:
cannon/cmd/load_elf.go 69.23% 8 Missing :warning:
cannon/mipsevm/versions/detect.go 85.71% 2 Missing and 1 partial :warning:

:exclamation: There is a different number of reports uploaded between BASE (9178d5f) and HEAD (77d6d37). Click for more details.

HEAD has 1 upload less than BASE | Flag | BASE (9178d5f) | HEAD (77d6d37) | |------|------|------| |cannon-go-tests|2|1|
Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #12072 +/- ## ============================================ - Coverage 79.10% 68.14% -10.97% ============================================ Files 41 54 +13 Lines 3437 4119 +682 ============================================ + Hits 2719 2807 +88 - Misses 548 1134 +586 - Partials 170 178 +8 ``` | [Flag](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism) | Coverage Δ | | |---|---|---| | [cannon-go-tests](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism) | `68.14% <31.75%> (-10.97%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files with missing lines](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism) | Coverage Δ | | |---|---|---| | [cannon/cmd/run.go](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072?src=pr&el=tree&filepath=cannon%2Fcmd%2Frun.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism#diff-Y2Fubm9uL2NtZC9ydW4uZ28=) | `7.84% <100.00%> (ø)` | | | [cannon/cmd/witness.go](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072?src=pr&el=tree&filepath=cannon%2Fcmd%2Fwitness.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism#diff-Y2Fubm9uL2NtZC93aXRuZXNzLmdv) | `44.00% <100.00%> (ø)` | | | [cannon/mipsevm/versions/detect.go](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072?src=pr&el=tree&filepath=cannon%2Fmipsevm%2Fversions%2Fdetect.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism#diff-Y2Fubm9uL21pcHNldm0vdmVyc2lvbnMvZGV0ZWN0Lmdv) | `85.71% <85.71%> (ø)` | | | [cannon/cmd/load\_elf.go](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072?src=pr&el=tree&filepath=cannon%2Fcmd%2Fload_elf.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism#diff-Y2Fubm9uL2NtZC9sb2FkX2VsZi5nbw==) | `26.38% <69.23%> (ø)` | | | [cannon/mipsevm/versions/state.go](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072?src=pr&el=tree&filepath=cannon%2Fmipsevm%2Fversions%2Fstate.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism#diff-Y2Fubm9uL21pcHNldm0vdmVyc2lvbnMvc3RhdGUuZ28=) | `59.72% <37.50%> (-6.35%)` | :arrow_down: | | [cannon/multicannon/util.go](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072?src=pr&el=tree&filepath=cannon%2Fmulticannon%2Futil.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism#diff-Y2Fubm9uL211bHRpY2Fubm9uL3V0aWwuZ28=) | `45.45% <45.45%> (ø)` | | | [cannon/multicannon/load\_elf.go](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072?src=pr&el=tree&filepath=cannon%2Fmulticannon%2Fload_elf.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism#diff-Y2Fubm9uL211bHRpY2Fubm9uL2xvYWRfZWxmLmdv) | `0.00% <0.00%> (ø)` | | | [cannon/multicannon/witness.go](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072?src=pr&el=tree&filepath=cannon%2Fmulticannon%2Fwitness.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism#diff-Y2Fubm9uL211bHRpY2Fubm9uL3dpdG5lc3MuZ28=) | `0.00% <0.00%> (ø)` | | | [cannon/multicannon/run.go](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072?src=pr&el=tree&filepath=cannon%2Fmulticannon%2Frun.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism#diff-Y2Fubm9uL211bHRpY2Fubm9uL3J1bi5nbw==) | `0.00% <0.00%> (ø)` | | | [cannon/multicannon/main.go](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072?src=pr&el=tree&filepath=cannon%2Fmulticannon%2Fmain.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism#diff-Y2Fubm9uL211bHRpY2Fubm9uL21haW4uZ28=) | `0.00% <0.00%> (ø)` | | | ... and [2 more](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism) | | ... and [3 files with indirect coverage changes](https://app.codecov.io/gh/ethereum-optimism/optimism/pull/12072/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum-optimism)
semgrep-app[bot] commented 1 month ago

Semgrep found 1 sol-style-return-arg-fmt finding:

Named return arguments to functions must be appended with an underscore (_)

Ignore this finding from sol-style-return-arg-fmt.

semgrep-app[bot] commented 1 month ago

Semgrep found 2 sol-style-input-arg-fmt findings:

Inputs to functions must be prepended with an underscore (_)

Ignore this finding from sol-style-input-arg-fmt.

Inphi commented 1 month ago

Merging as soon as CI passes.