-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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: 64-bit Refactor #12029
cannon: 64-bit Refactor #12029
Conversation
Semgrep found 13
Prefer |
Very cool idea. I think it's worth having a wrapper of some form so that op-challenger can just invoke |
65cc296
to
25886a3
Compare
Refactor Cannon codebase to support both 32-bit and 64-bit MIPS emulation while reusing code as much as possible.
25886a3
to
dfa61bb
Compare
Semgrep found 2 require() must include a reason string Ignore this finding from sol-style-require-reason.Semgrep found 12
_args parameter should be wrapped with DeployUtils.encodeConstructor Ignore this finding from sol-safety-deployutils-args. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good. Awesome job!
Approving as this looks good per the original 64-bit changes I made in #11388. Probably good to get eyes from @mbaxter + @ajsutton as well before merging + moving forward with the 64-bit smart contract from #11404.
P.S. - there's also some 64-bit ASM tests from #11388 we can use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM generally. I assume at some point we'll have 64bit MIPS reference tests we can pull in to verify each instruction is implemented correctly. That's quite hard to review manually.
Otherwise mostly just ensuring we have issues referenced for the TODOs (I'd just point them all to the 64-bit support tracker issue and not try to log individual issues for everything necessarily). And we'll have to sort out some conflicts with the getfd support but I don't think that will be a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks really good!
Would definitely be nice to get the additional differential tests in for extra confidence that none of the 32-bit behavior has changed. I did end up kind skimming over some of the new 64-bit ops - might try to spend some more time looking through those later.
Semgrep found 8
No Semgrep found 3
Detected non-static command inside Command. Audit the input to 'exec.Command'. If unverified user data can reach this call site, this is a code injection vulnerability. A malicious actor can inject a malicious script to execute arbitrary code. Ignore this finding from dangerous-exec-command. |
@mbaxter I've kicked off the cannon-stf-verify job to assert that this change doesn't break the VM STF. It uses this PR and cannon/v1.1.0-alpha.1 to compute the post-exit state of the |
* cannon: 64-bit Refactor Refactor Cannon codebase to support both 32-bit and 64-bit MIPS emulation while reusing code as much as possible. * fix 64-bit test compilation errors * review comments * more review comments * fcntl syscall err for 64-bit * simplify pad check * cannon: sc must store lsb 32 on 64-bits * lint * fix sc 64-bit logic * add TODO state test
Overview
This is a refactor of Cannon to support both 32-bit and 64-bit MIPS emulation while reusing code as much as possible.
A lot of the implementation was guided by the initial efforts in #11388 and @GrapeBaBa for anton-rs/cannon-rs#36.
The refactor prioritizes readability and avoids duplicating code to ensure that the 32-bit behavior is not altered. This is achieved by partitioning 64-bit and 32-bit logic using go build tags. The
cannon32
andcannon64
build tags are used to implement architecture specific functionality. Most MIPS emulation logic can be factorized into common constructs with minimal loss in readability. For example,exec.SignExtend
can be implemented across all VMs with the following:Where
arch
is a new cannon package that abstracts away the specifics of either MIPS32 or MIPS64.One advantage of this approach is that MT-Cannon can be gradually ported over to MIPS64 without breaking the altering the existing code structure. Similarly, the single-threaded Cannon VM can be ported over to MIPS64 (though this isn't desired). This unlocks parallel development of 32 and 64 bit VMs.
This refactor does not affect the MIPS solidity contracts. The goal is to retain readability such that the refactored Go implementations can still be easily compared with the solidity counterparts. Introducing a 64-bit MIPS VM in Solidity will be done later.
Concerns
The downside of this approach is that both 32-bit and 64-bit VMs can no longer exist in the same Cannon binary. This breaks other packages, including the op-challenger, that rely on cannon packages for state decoding. Deployment of the op-challenger is further complicated as two VM binaries are needed for both single-threaded MIPS32 and MT-MIPS64 emulation. Fortunately this issue can be solved using multicannon which lets us select either 32-bit or 64-bit VM implementations depending on the CLI inputs.
Testing Plan
Note that the MIPS64 implementation is not complete. The primary goal of this PR is to ensure that the MIPS32 VM behaviors are not altered. Comprehensive MIPS64 testing will be added later.