Skip to content

Add support for risc0#25

Merged
g11tech merged 13 commits intomainfrom
add-risc0
May 26, 2025
Merged

Add support for risc0#25
g11tech merged 13 commits intomainfrom
add-risc0

Conversation

@gballet
Copy link
Copy Markdown
Contributor

@gballet gballet commented May 20, 2025

Adds support for proving on risc0.

@gballet gballet requested review from Copilot and g11tech May 20, 2025 19:13
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 adds support for the risc0 backend by introducing related syscall enums, host functions, build scripts, and CLI integration. Key changes include new risc0 syscall and assembly files, updated host FFI and Cargo configuration for risc0, and adjustments to the build pipeline for post-processing the risc0 executable.

Reviewed Changes

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

Show a summary per file
File Description
pkgs/state-transition-runtime/src/risc0/syscalls.zig Added syscall, halt_reason, and keccak_mode enums for risc0.
pkgs/state-transition-runtime/src/risc0/start.s Introduced a new startup assembly file for risc0.
pkgs/state-transition-runtime/src/risc0/risc0.ld Provides the linker script for risc0.
pkgs/state-transition-runtime/src/risc0/lib.zig Added host functions using inline assembly to trigger risc0 syscalls.
pkgs/state-transition-runtime/src/risc0/io.zig Introduced IO syscall wrappers corresponding to risc0.
pkgs/state-transition-runtime/src/risc0/host/src/lib.rs New risc0 host functions to perform prove and verify operations.
pkgs/state-transition-runtime/src/risc0/host/Cargo.toml Updated Cargo configuration for risc0 host integration.
pkgs/state-transition-runtime/src/main.zig Adjusted memory allocation and configuration for risc0 runtime.
pkgs/state-proving-manager/src/manager.zig Extended the state transition opts union to support risc0.
pkgs/cli/src/main.zig Updated CLI to select risc0 instead of powdr backend.
build/risc0.zig Added a build script to postprocess the risc0 executable.
build.zig Adjusted build logic to incorporate risc0 target and postbuild steps.

Comment on lines +6 to +11
pub fn halt(status: u32) noreturn {
sys_halt(&empty_digest, status);
}

const empty_digest = [_]u32{ 0x5c176f83, 0x53f3c062, 0x42651683, 0x340b8b7e, 0x19d2d1f6, 0xae4d7602, 0xb8c606b4, 0xb075b53d };

Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

Consider moving the declaration of 'empty_digest' before its usage in the 'halt' function to improve readability and avoid potential confusion.

Suggested change
pub fn halt(status: u32) noreturn {
sys_halt(&empty_digest, status);
}
const empty_digest = [_]u32{ 0x5c176f83, 0x53f3c062, 0x42651683, 0x340b8b7e, 0x19d2d1f6, 0xae4d7602, 0xb8c606b4, 0xb075b53d };
const empty_digest = [_]u32{ 0x5c176f83, 0x53f3c062, 0x42651683, 0x340b8b7e, 0x19d2d1f6, 0xae4d7602, 0xb8c606b4, 0xb075b53d };
pub fn halt(status: u32) noreturn {
sys_halt(&empty_digest, status);
}

Copilot uses AI. Check for mistakes.
@gballet gballet force-pushed the add-risc0 branch 2 times, most recently from d864b67 to d7f1656 Compare May 22, 2025 14:18
@gballet
Copy link
Copy Markdown
Contributor Author

gballet commented May 23, 2025

Housekeeping tasks:

  • fix the commitments so that the program does more than committing to an empty hash
  • Use the mock prover so that it is possible to check the hash results, and thus let the test pass
  • Fix the powdr build, or at the very least disable it until it works
  • Update the documentation on how to run it
  • Add something to CI
  • check build mode for binary -> it's .ReleaseFast, good.

Some of these will be done in subsequent PRs.

gballet added 11 commits May 25, 2025 20:13
Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Runtime is probably still borked, but messages + panics are working

Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
gballet added 2 commits May 25, 2025 21:05
Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>

pub fn verify_transition(stf_proof: types.BeamSTFProof, state_root: types.Bytes32, block_root: types.Bytes32, opts: StateTransitionOpts) !void {
_ = stf_proof;
_ = state_root;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(pre) stateroot and blockroot are stil unused to verify transition it seems

try sftFactory.apply_transition(allocator, &beam_state, block);

// verify the block
try stateProvingManager.verify_transition(proof, [_]u8{0} ** 32, [_]u8{0} ** 32, options);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

conceptually proof needs to be validated against pre state root and block root, since those are still being ignored in verify transition i can do a followup PR to change mock chain to add prestateroots (block roots are already there) so that it becomes handy over here

Copy link
Copy Markdown
Member

@g11tech g11tech left a comment

Choose a reason for hiding this comment

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

lgtm, further verification changes can followup on another PR

@g11tech g11tech merged commit fbe9960 into main May 26, 2025
4 checks passed
@g11tech g11tech deleted the add-risc0 branch June 10, 2025 21:17
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