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: Finish emulating rest of 64-bit instructions #12483

Merged
merged 10 commits into from
Oct 23, 2024
Merged

Conversation

Inphi
Copy link
Contributor

@Inphi Inphi commented Oct 16, 2024

This completes 64-bit instruction execution (except lld/scd which is handled separately).

Testing

  • Differential tests for non-trivial 32-bit instructions asserting backwards compatibility.
  • Added new tests for 64-bit instructions (except lld/scd).
  • Fuzz tests for dmult

These tests are only run on by the 64-bit VM. So they do not run on CI, except for the dmult fuzz test which is executed by the fuzz-golang job.

Meta

Fixes #12243 and #12248.

@Inphi Inphi force-pushed the inphi/cannon64-insn branch from 6a90eda to 551622c Compare October 16, 2024 14:12
Copy link
Contributor

semgrep-app bot commented Oct 16, 2024

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

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

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

Semgrep found 1 golang_fmt_errorf_no_params finding:

  • op-supervisor/supervisor/backend/db/db_test.go

No fmt.Errorf invocations without fmt arguments allowed

Ignore this finding from golang_fmt_errorf_no_params.

Semgrep found 1 math-random-used finding:

  • op-supervisor/supervisor/backend/source/head_monitor_test.go

Do not use math/rand. Use crypto/rand instead.

Ignore this finding from math-random-used.

Semgrep found 1 marshal-json-pointer-receiver finding:

  • op-supervisor/supervisor/backend/db/heads/types.go

MarshalJSON with a pointer receiver has surprising results: golang/go#22967

Ignore this finding from marshal-json-pointer-receiver.

Semgrep found 1 err-nil-check finding:

superfluous nil err check before return

Ignore this finding from err-nil-check.

@Inphi Inphi requested a review from mbaxter October 16, 2024 14:12
@Inphi Inphi marked this pull request as ready for review October 16, 2024 14:12
@Inphi Inphi force-pushed the inphi/cannon64-insn branch from 551622c to b749c7f Compare October 16, 2024 14:21
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 19.81132% with 85 lines in your changes missing coverage. Please review.

Project coverage is 63.79%. Comparing base (f6ca236) to head (8fb303e).
Report is 30 commits behind head on develop.

Files with missing lines Patch % Lines
cannon/mipsevm/exec/mips_instructions.go 19.81% 79 Missing and 6 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #12483      +/-   ##
===========================================
- Coverage    64.86%   63.79%   -1.08%     
===========================================
  Files           54       54              
  Lines         4460     4538      +78     
===========================================
+ Hits          2893     2895       +2     
- Misses        1391     1461      +70     
- Partials       176      182       +6     
Flag Coverage Δ
cannon-go-tests 63.79% <19.81%> (-1.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cannon/mipsevm/exec/mips_instructions.go 64.89% <19.81%> (-9.30%) ⬇️

Copy link
Contributor

@mbaxter mbaxter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Left a number of nits + a few questions.

go.mod Show resolved Hide resolved
cannon/mipsevm/exec/mips_instructions.go Show resolved Hide resolved
cannon/mipsevm/exec/mips_instructions.go Outdated Show resolved Hide resolved
cannon/mipsevm/tests/evm_common64_test.go Outdated Show resolved Hide resolved
cannon/mipsevm/tests/evm_common64_test.go Outdated Show resolved Hide resolved
cannon/mipsevm/tests/evm_common64_test.go Show resolved Hide resolved
cannon/mipsevm/tests/evm_common64_test.go Show resolved Hide resolved
cannon/mipsevm/tests/fuzz_evm_common64_test.go Outdated Show resolved Hide resolved
cannon/mipsevm/tests/fuzz_evm_common64_test.go Outdated Show resolved Hide resolved
cannon/mipsevm/tests/evm_common64_test.go Show resolved Hide resolved
Copy link
Contributor

semgrep-app bot commented Oct 22, 2024

Semgrep found 1 sol-style-require-reason finding:

  • packages/contracts-bedrock/src/L2/SuperchainWETH.sol

require() must include a reason string

Ignore this finding from sol-style-require-reason.

Semgrep found 1 sol-style-notice-over-dev-natspec finding:

  • packages/contracts-bedrock/src/cannon/interfaces/IPreimageOracle.sol

Prefer @notice over @dev in natspec comments

Ignore this finding from sol-style-notice-over-dev-natspec.

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

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

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

Semgrep found 8 golang_fmt_errorf_no_params findings:

No fmt.Errorf invocations without fmt arguments allowed

Ignore this finding from golang_fmt_errorf_no_params.

@Inphi
Copy link
Contributor Author

Inphi commented Oct 22, 2024

@mbaxter I fixed a bug in dmult. And I've removed the dmult fuzz tests in favor of more static tests. I couldn't figure out a way to reimplement dmult correctly using the Go std library. At least not without copying the implementation used by mipsevm, which defeats the purpose of the fuzz test.

I have verified the expected dmult behavior using user-mode qemu like I mentioned earlier. All static test cases were written based off the results of qemu-mips. Please let me know if there are any more interesting cases you'd like me to add.

Copy link
Contributor

@mbaxter mbaxter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - just a few last questions on dmult and div/divu divide by zero

cannon/mipsevm/exec/mips_instructions.go Outdated Show resolved Hide resolved
cannon/mipsevm/exec/mips_instructions.go Show resolved Hide resolved
cannon/mipsevm/tests/evm_common64_test.go Show resolved Hide resolved
cannon/mipsevm/tests/evm_common64_test.go Show resolved Hide resolved
Copy link
Contributor

semgrep-app bot commented Oct 23, 2024

Semgrep found 1 no-direct-write-to-responsewriter finding:

  • op-challenger/game/fault/trace/prestates/multi_test.go

Detected directly writing or similar in 'http.ResponseWriter.write()'. This bypasses HTML escaping that prevents cross-site scripting vulnerabilities. Instead, use the 'html/template' package and render data using 'template.Execute()'.

Ignore this finding from no-direct-write-to-responsewriter.

Semgrep found 1 no-direct-write-to-responsewriter-taint finding:

  • op-challenger/game/fault/trace/prestates/multi_test.go

Untrusted input could be used to tamper with a web page rendering, which can lead to a Cross-site scripting (XSS) vulnerability. XSS vulnerabilities occur when untrusted input executes malicious JavaScript code, leading to issues such as account compromise and sensitive information leakage. To prevent this vulnerability, validate the user input, perform contextual output encoding or sanitize the input. For more information, see: Go XSS prevention.

View Dataflow Graph
flowchart LR
    classDef invis fill:white, stroke: none
    classDef default fill:#e7f5ff, color:#1c7fd6, stroke: none

    subgraph File0["<b>op-challenger/game/fault/trace/prestates/multi_test.go</b>"]
        direction LR
        %% Source

        subgraph Source
            direction LR

            v0["<a href=https://github.com/ethereum-optimism/optimism/blob/498a36def44ac54d68189319fff89cc45994414b/op-challenger/game/fault/trace/prestates/multi_test.go#L194 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 194] r.URL</a>"]
        end
        %% Intermediate

        %% Sink

        subgraph Sink
            direction LR

            v1["<a href=https://github.com/ethereum-optimism/optimism/blob/498a36def44ac54d68189319fff89cc45994414b/op-challenger/game/fault/trace/prestates/multi_test.go#L194 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 194] w.Write([]byte(r.URL.Path))</a>"]
        end
    end
    %% Class Assignment
    Source:::invis
    Sink:::invis

    File0:::invis

    %% Connections

    Source --> Sink

Loading
Ignore this finding from no-direct-write-to-responsewriter-taint.

@Inphi Inphi enabled auto-merge October 23, 2024 21:00
@Inphi Inphi added this pull request to the merge queue Oct 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 23, 2024
@mslipper mslipper added this pull request to the merge queue Oct 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 23, 2024
@Inphi Inphi enabled auto-merge October 23, 2024 22:09
Copy link
Contributor

coderabbitai bot commented Oct 23, 2024


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

semgrep-app bot commented Oct 23, 2024

Semgrep found 1 ban_non_wraparound_modifiers finding:

  • packages/contracts-bedrock/src/L2/SuperchainERC20.sol

Modifiers that don't do something before and after execution are banned.

Ignore this finding from ban_non_wraparound_modifiers.

@Inphi Inphi added this pull request to the merge queue Oct 23, 2024
Merged via the queue into develop with commit 93ca294 Oct 23, 2024
48 checks passed
@Inphi Inphi deleted the inphi/cannon64-insn branch October 23, 2024 22:25
samlaf pushed a commit to samlaf/optimism that referenced this pull request Nov 10, 2024
…sm#12483)

* cannon: Finish emulating rest of 64-bit instructions

This fixes the 64-bit stubs for various instructions (except lld/scd).

* review comments; fix dmult

* add todo

* test div by zero

* add a couple more dmultu tests

* remove dead code

* cannon: Fix remaining mips64 emulation bugs

* fix 64-bit Makefile build script; review comments

* fix build script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

64-bit arithmetic instructions
2 participants