Skip to content

Add zkVM (RISC-V) cross-compilation target#2090

Open
goodlyrottenapple wants to merge 2 commits intomainfrom
zkvm-cross-compilation
Open

Add zkVM (RISC-V) cross-compilation target#2090
goodlyrottenapple wants to merge 2 commits intomainfrom
zkvm-cross-compilation

Conversation

@goodlyrottenapple
Copy link
Contributor

@goodlyrottenapple goodlyrottenapple commented Feb 20, 2026

Add a standalone CMake project (category/zkvm) that builds libmonad-zkvm.a for bare-metal RISC-V targets (planned 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 planned 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
  • CI build of category/zkvm code targeting RISC-V

Co-authored with Claude

Copilot AI review requested due to automatic review settings February 20, 2026 10:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 a newlib submodule for setjmp/longjmp support.
  • Adds zkVM-specific libc/libstdc++ stubs plus backend-abstracted aligned_alloc and exit interfaces.
  • Refactors compilation/common flags into cmake/compile_options.cmake and adds MONAD_ZKVM guards 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.

@goodlyrottenapple goodlyrottenapple force-pushed the zkvm-cross-compilation branch 11 times, most recently from 49bba82 to 7757d7c Compare February 24, 2026 11:16
@goodlyrottenapple goodlyrottenapple force-pushed the zkvm-cross-compilation branch 11 times, most recently from 9580867 to 3c55712 Compare March 3, 2026 13:47
@goodlyrottenapple goodlyrottenapple force-pushed the zkvm-cross-compilation branch 3 times, most recently from 590cefb to 87f7b22 Compare March 19, 2026 10:01
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>
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.

2 participants