Add zkVM (RISC-V) cross-compilation target#2090
Open
goodlyrottenapple wants to merge 2 commits intomainfrom
Open
Add zkVM (RISC-V) cross-compilation target#2090goodlyrottenapple wants to merge 2 commits intomainfrom
goodlyrottenapple wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a standalone zkVM (bare-metal RISC-V) build target to produce libmonad-zkvm.a, enabling the Monad EVM interpreter/runtime to run inside planned ZisK/SP1 zkVM backends.
Changes:
- Introduces a new
category/zkvm/CMake project, RISC-V toolchain file, and anewlibsubmodule forsetjmp/longjmpsupport. - Adds zkVM-specific libc/libstdc++ stubs plus backend-abstracted
aligned_allocandexitinterfaces. - Refactors compilation/common flags into
cmake/compile_options.cmakeand addsMONAD_ZKVMguards across runtime/interpreter to avoid x86/ASM dependencies.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| third_party/newlib-cygwin | Adds newlib-cygwin submodule commit for RISC-V setjmp.S. |
| .gitmodules | Registers third_party/newlib-cygwin submodule. |
| cmake/compile_options.cmake | Extracts shared compile options; adds zkVM-specific flags/defs. |
| CMakeLists.txt | Reuses extracted compile_options.cmake. |
| category/zkvm/CMakeLists.txt | New standalone build that assembles VM object libs + zkVM stubs into libmonad-zkvm.a. |
| category/core/toolchains/riscv64-elf-toolchain.cmake | Adds bare-metal RISC-V toolchain configuration. |
| category/zkvm/include/category/zkvm/allocator.hpp | Backend-abstracted aligned allocator interface. |
| category/zkvm/include/category/zkvm/exit.hpp | Backend-abstracted exit syscall interface. |
| category/zkvm/src/libc.cpp | Minimal malloc/calloc/free stubs for bare-metal. |
| category/zkvm/src/libstdcxx.cpp | Minimal operator new/delete + std::terminate for bare-metal. |
| category/zkvm/include/category/core/runtime/uint256.hpp | intx-backed uint256_t wrapper to replace x86-specific implementation. |
| category/core/runtime/non_temporal_memory.hpp | Uses memcpy/memset under zkVM; AVX2 streams otherwise. |
| category/vm/runtime/CMakeLists.txt | Skips ASM sources/language when building for zkVM. |
| category/vm/runtime/types.hpp | Switches exit_stack_ptr type under zkVM to std::jmp_buf*. |
| category/vm/runtime/exit.cpp | Uses setjmp/longjmp-based exit under zkVM; preserves ASM exit for host. |
| category/vm/runtime/context.cpp | Uses zkVM allocator instead of std::aligned_alloc under zkVM. |
| category/vm/runtime/cached_allocator.hpp | Avoids destructor/atexit under zkVM; uses zkVM allocator. |
| category/vm/runtime/allocator.hpp | Removes thread_local cache under zkVM. |
| category/vm/runtime/allocator.cpp | Defines non-thread_local cache list under zkVM. |
| category/vm/runtime/transmute.hpp | Disables AVX2 bounded-load path under zkVM. |
| category/vm/runtime/math.hpp | Replaces ASM mul with intx multiplication under zkVM. |
| category/vm/interpreter/CMakeLists.txt | Skips ASM entry trampoline + utils library on zkVM. |
| category/vm/interpreter/execute.cpp | Bypasses trampoline and installs setjmp exit handler under zkVM. |
| category/vm/interpreter/instruction_table.hpp | Routes MUL to runtime::mul; avoids AVX conversion on SWAP under zkVM. |
| category/vm/interpreter/push.hpp | Includes <immintrin.h> only when __AVX2__ is defined. |
| category/vm/interpreter/debug.hpp | Compiles out tracing dependencies/output under zkVM. |
| category/vm/core/assert.cpp | Adds zkVM assertion handlers that exit instead of relying on libc/abort. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
49bba82 to
7757d7c
Compare
9580867 to
3c55712
Compare
590cefb to
87f7b22
Compare
Add a standalone CMake project (category/zkvm/) that builds libmonad-zkvm.a for bare-metal RISC-V targets (ZisK and SP1 zkVM backends). This allows the Monad EVM interpreter to run inside zkVMs. Key changes: - RISC-V toolchain file (rv64ima, lp64, medany, -nostdlib++) - intx-backed uint256 wrapper replacing AVX2 implementation - zkVM-abstracted allocator (zkvm_aligned_alloc) and exit (zkvm_exit) interfaces with ZisK/SP1 backends - Conditional compilation guards (#ifdef MONAD_ZKVM) for bare-metal compatibility across interpreter, runtime, and core components - Shared compile_options.cmake extracted from root CMakeLists.txt - Bare-metal stubs: libc (malloc/calloc/free), libstdc++ (operator new/delete, std::terminate), and assert handlers - nix derivation for a custom riscv64 compiler with newlib version of libc Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
87f7b22 to
63bde47
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a standalone CMake project (
category/zkvm) that buildslibmonad-zkvm.afor bare-metal RISC-V targets (planned ZisK and SP1 zkVM backends). This allows the Monad EVM interpreter to run inside zkVMs.Key changes:
category/zkvmcode targeting RISC-VCo-authored with Claude