Skip to content

openvm: improve runtime#639

Merged
gballet merged 4 commits intoblockblaz:mainfrom
tellabg:add-openvm
Mar 7, 2026
Merged

openvm: improve runtime#639
gballet merged 4 commits intoblockblaz:mainfrom
tellabg:add-openvm

Conversation

@gballet
Copy link
Copy Markdown
Contributor

@gballet gballet commented Mar 7, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 7, 2026 17:03
- Update inline asm clobber syntax from legacy string format to
  new struct format (.{ .memory = true })
- Fix alignedAlloc alignment parameter type (comptime_int -> Alignment enum)
Copy link
Copy Markdown
Contributor

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

This PR updates the OpenVM zkVM runtime wiring to better match the project’s RISC-V runtime layout and introduces a new OpenVM-specific input path using OpenVM “hint” instructions, while also enabling OpenVM as a built zkVM runtime target in the build.

Changes:

  • Refactors the OpenVM linker script to a more complete RISC-V layout (sections, gp, bss symbols, discards).
  • Reworks OpenVM runtime input handling to read a length prefix and then pull word-aligned input via new hint syscalls.
  • Adds openvm to the zkvm_targets list so its runtime ELF is built alongside the other zkVM targets.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
pkgs/state-transition-runtime/src/openvm/openvm.ld Replaces the simplistic memory/sections layout with a full RISC-V style linker script.
pkgs/state-transition-runtime/src/openvm/lib.zig Adjusts heap range and replaces the input reader with hint-based, word-aligned input loading.
pkgs/state-transition-runtime/src/openvm/io.zig Replaces byte-at-a-time printing/input reading with hint-based I/O syscalls.
build.zig Adds OpenVM to the set of zkVM runtime targets built by default.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1 to 2
const std = @import("std");

Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

const std = @import("std"); is now unused in this file, which will fail compilation under Zig's unused-declaration checks. Remove the import or use it.

Suggested change
const std = @import("std");

Copilot uses AI. Check for mistakes.
:
: [char] "r" (@as(usize, c)),
: [ptr] "r" (str.ptr),
[len] "{x11}" (str.len),
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

print_str passes a pointer to memory into inline asm but does not include a .memory clobber. If callers build/modify the buffer right before printing (e.g. formatted logs), the compiler may reorder memory operations around the asm. Add a memory clobber to ensure the printed bytes reflect prior writes.

Suggested change
[len] "{x11}" (str.len),
[len] "{x11}" (str.len),
: .{ .memory = true }

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +34
const input_len: usize = @intCast(len_buf);

const word_count: u32 = @intCast((input_len + 3) / 4);
const buf = allocator.alignedAlloc(u8, .@"4", word_count * 4) catch @panic("could not allocate space for input");

pub fn free_input(allocator: std.mem.Allocator, input: []const u8) void {
allocator.free(input);
io.hint_buffer_u32(buf.ptr, word_count);

return buf[0..input_len];
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

input_len is derived from an external hint (io.hint_store_u32) and then used in (input_len + 3) / 4 to compute word_count without any upper bound check, which can overflow usize on RV32 for very large lengths and cause word_count * 4 to be smaller than input_len. In that case allocator.alignedAlloc reserves fewer bytes than are exposed via the returned slice buf[0..input_len], so callers of get_input can perform out-of-bounds reads/writes on the heap, potentially corrupting adjacent data or leaking sensitive state. Add explicit limits and overflow checks on input_len (e.g. ensuring input_len <= max_allowed && input_len + 3 does not overflow and that buf.len >= input_len) before allocating and constructing the returned slice.

Copilot uses AI. Check for mistakes.
tellabg added 2 commits March 7, 2026 18:54
- Remove dotnet, Android SDK, CodeQL, and Docker images on Ubuntu runners
  to reclaim ~30GB of disk space before building
- Force rocksdb dependency to .ReleaseFast regardless of project optimize
  level, reducing debug info size significantly
- Fixes CI out-of-disk-space errors during rocksdb compilation
Copilot AI review requested due to automatic review settings March 7, 2026 21:38
Copy link
Copy Markdown
Contributor

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.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@gballet gballet merged commit 6bce5db into blockblaz:main Mar 7, 2026
10 checks passed
gballet added a commit that referenced this pull request Mar 8, 2026
* add some fixes

* openvm: fix zig 0.15.2 compatibility

- Update inline asm clobber syntax from legacy string format to
  new struct format (.{ .memory = true })
- Fix alignedAlloc alignment parameter type (comptime_int -> Alignment enum)

* openvm/io: remove unused std import (Zig 0.15 compat)

* ci: free disk space on runners + force rocksdb ReleaseFast

- Remove dotnet, Android SDK, CodeQL, and Docker images on Ubuntu runners
  to reclaim ~30GB of disk space before building
- Force rocksdb dependency to .ReleaseFast regardless of project optimize
  level, reducing debug info size significantly
- Fixes CI out-of-disk-space errors during rocksdb compilation

---------

Co-authored-by: tellabg <249254436+tellabg@users.noreply.github.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.

3 participants