-
Couldn't load subscription status.
- Fork 2
Description
This is a rough plan for the direction of the repo.
Goals
- Expose the risc0
rust-toolchainas a package derivation. - Provide a
buildRisc0Packagebuilder, similar tobuildRustPackage, but also builds the guest circuit. - Provide a
buildRisc0Proofbuilder or similar that takes a circuit and any necessary inputs, and produces a succinct proof. - Include a working, simple-as-possible, demo example that builds and verifies a proof #2
risc0 rust-toolchain
There are two paths here:
- Wrap the binaries similar to rust-overlay.
- Compile from scratch.
Path 1: Wrapping Binaries
This approach will be faster to build (as we just fetch binaries), but provides less flexibility around patching behaviour. It'll likely require some serious hacks.
- Follow the rust-overlay approach of exposing a
rust-binpackage collection.- This is currently implemented, only for the latest
1.85.0release. - This just gets all of the tools running, but there is still runtime behaviour that needs solving.
- This is currently implemented, only for the latest
- Solve Ideas for getting the
rust-toolchain-binbuilds working #4 using something likebuildFHSUserEnvto wrap the binary with a temporary environment that places the risc0 rust-toolchain under the~/.rustupdirectory via symlink. NOTE: This may not be necessary in the future as it looks like newer versions ofrzupmay accept env vars. - Continue from there, patching further as necessary...
Path 2: Compile Components
This approach requires building all the toolchain components from scratch, but provides more flexibility by allowing for patching certain behaviour (e.g. inserting env vars that can be used to override paths, disabling fetching in favour of providing prefetched paths, etc). This would also allow for building the master version of the toolchain without having to wait months for new releases (e.g. risc0's latest released version is 1.85, which is a couple months old).
- Create a package derivation (i.e. under
pkgs/) for each of the rust-toolchain components.- feat: (WIP) Rudimentary, WIP attempt at building risc0's fork of rustc #5 is a very rough beginning at getting
rustcbuilding by overriding the nixpkgsrustcpackage derivation.
- feat: (WIP) Rudimentary, WIP attempt at building risc0's fork of rustc #5 is a very rough beginning at getting
- Bring all of the components together under one
risc0-rust-toolchainderivation using thesymlinkJoinnixpkgs builder to mirror the rustup toolchain structure:$ tree -L 3 result result ├── bin │ ├── cargo │ ├── cargo-clippy │ ├── cargo-fmt │ ├── clippy-driver │ ├── rustc │ ├── rustdoc │ └── rustfmt └── lib ├── librustc_driver-7e9901864e0059da.so └── rustlib ├── riscv32im-risc0-zkvm-elf └── x86_64-unknown-linux-gnu - Patch the source as necessary to override paths/fetching.
- Setup a binary cache.
cachixprovides free caches, but have a 5GB limit. Could likely fit the latest couple of versions at least.- The magic nix cache seems to be running again, but this isn't accessible outside of the CI environment. We'd likely want something devs can add as a substituter to DL the binaries locally more quickly.
buildRisc0Package, buildRisc0Proof
These can be thought of as small wrappers around stdenv.mkDerivation or buildRustPackage that make any necessary tweaks necessary for buidling risc0 circuits in particular.
Building the guest
The tricky part here will be that technically the guest has a different architecture (riscv32im-risc0-zkvm-elf) from the host, so it will either:
- Require adding a new target to
pkgsCrossand usingpkgs.pkgsCross.riscv32im-rics0-zkvm.buildRustPackageto cross-compile the guest or - Use
mkDerivationinstead ofbuildRustPackageand manually build the package using a custom cargo command that specifies the correct target.
Building the proof
For groth16, but trickiest part by far will be fetching and running the docker image in the nix sandbox... at least until there's some native way to build and run it.
It might be possible to do this by implementing a custom docker image "fetcher" (similar to fetchFromGitHub etc, but fetches and hashes the docker image)... It looks like some folks have had mixed success by adding special privileges for the docker daemon? 🥴
Stretch Goals
- Expose each released semver version of the
rust-toolchainunder a separate package group (similar torust-overlay), with alatestshorthand for latest release.