Skip to content

malda-protocol/risc0pkgs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

142 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

risc0pkgs - Nixified RISC Zero Packages

⚠️ This repository is no longer maintained by the core team. Community contributions are welcome.

risc0pkgs contains risc0 related packages like r0vm and risc0's rustc fork packaged with Nix. The following section describes how to set up a risc0 project from scratch.

Context in Malda Sequencer

This is a generic Nix helper for RISC Zero projects, providing deterministic builds of zkVM guests. Within the Malda ecosystem, it served as an extra build dependency for the ZkCoprocessor — specifically for deterministic builds of the zkVM guest program. The ZkCoprocessor can be built without it, but the resulting image ID will differ from the canonical one. This repository is kept separate because it is not Malda-specific and can be used with any RISC Zero project.

Getting Started

It's recommended to get started by initializing your project using the default template:

mkdir risc0-workspace
cd risc0-workspace

nix flake init -t github:malda-protocol/risc0pkgs

git init
git add -A

nix build .

If you want to integrate risc0 into your existing flake, see ./templates/default/flake.nix.

Development Shell

To get dropped into a development shell with all the required tooling, run:

nix develop

Troubleshooting

Rust compiler version mismatch

If you get errors about different Rust compilers being used (e.g. "found crate compiled by an incompatible version of rustc"), the ~/.risc0/settings.toml file may be pointing to a stale or mismatched toolchain version.

Check the current default:

cat ~/.risc0/settings.toml

List installed toolchains:

ls ~/.risc0/toolchains/

Make sure settings.toml references a version that matches one of the installed toolchains. If not, either update the version in settings.toml or re-enter nix develop to reconfigure it.

"RISC Zero zkVM feature bigint2 is not available"

If your guest code depends on risc0-bigint2, you need to set the RISC0_FEATURE_bigint2 environment variable. Add it to both your buildRisc0Guest derivation and your devShells.default:

# In buildRisc0Guest:
RISC0_FEATURE_bigint2 = "";

# In devShells.default mkShell:
RISC0_FEATURE_bigint2 = "";

Building from source on platforms without prebuilts

Prebuilt binaries are available for x86_64-linux and aarch64-darwin. On other platforms (e.g. aarch64-linux, x86_64-darwin), the Rust toolchain is compiled from source, which can take 1+ hours on the first build. Subsequent builds will use the cached result from the Nix store.

The from-source build requires nixpkgs with Rust >= 1.92, as this is the first version where RISC Zero toolchain changes are upstream and no patches are needed. Make sure your flake.lock pins a sufficiently recent nixpkgs revision.


Experiments

At https://github.com/malda-protocol/risc0pkgs/commit/f1c8522a786fea9c3adae826a886a3a1fbf73d11 we were using combined vendor for Risc0 guest and host. Overall it works great, unless host methods is a workspace member and root's Cargo.lock introduces too many conflicting dependencies. Especially guest patches could easilly collide with host dependencies, and fixing that was not possible using single vendor directory.

At branch feature/experimental-vendor-split we have experimental work on having two vendor directories, but it does not seem to be a good solution. Update: probably it just requires cherry-picking 'submodule clone fix', same as the master branch - see commit ceb955bc0aa50a6dc6eec78f74492c293f9c0c4f.

Currently we use a dedicated Risc0 guest build, and Risc0 host build. Quite a lot of shenanigans are used to mimic Risc0 build process... over time we will see if this is a good and maintainable approach.

License

This project is licensed under the MIT License.

About

Nixified RISC Zero.

Resources

License

Stars

Watchers

Forks

Contributors