Skip to content

Commit

Permalink
feat: Add derivation for risc0-groth16-prover binaries (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
eureka-cpu authored Oct 23, 2024
1 parent 2aa22aa commit 9dcccba
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
with:
extra-conf: |
extra-substituters = https://bonsol.cachix.org
extra-trusted-public-keys = bonsol.cachix.org-1:yz7vi1rCPW1BpqoszdJvf08HZxQ/5gPTPxft4NnT74A=
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: DeterminateSystems/flake-checker-action@main
- run: nix flake check --all-systems -L
Expand All @@ -32,6 +36,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
with:
extra-conf: |
extra-substituters = https://bonsol.cachix.org
extra-trusted-public-keys = bonsol.cachix.org-1:yz7vi1rCPW1BpqoszdJvf08HZxQ/5gPTPxft4NnT74A=
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: nix develop

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

### Fixed
* `risc0-groth16-prover` binaries (rapidsnark & stark-verify) are available to the nix store, partially unblocking NixOS support.

## [0.2.1] - 2024-10-13

### Changed
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/contributing/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ that avoids unecessary downloading, rebuilding and patching. With one command yo

The following link will install nix with the above features and include the bonsol binary cache as a trusted substitutor. Without the substitutor many dependencies will build from source, which could take a the first time they are built!
```bash
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install --extra-conf "extra-substitutors = https://bonsol.cachix.org" --extra-conf "extra-trusted-public-keys = bonsol.cachix.org-1:yz7vi1rCPW1BpqoszdJvf08HZxQ/5gPTPxft4NnT74A="
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install --extra-conf "extra-substituters = https://bonsol.cachix.org" --extra-conf "extra-trusted-public-keys = bonsol.cachix.org-1:yz7vi1rCPW1BpqoszdJvf08HZxQ/5gPTPxft4NnT74A="
```

- `docker` ([see why](https://nixos.wiki/wiki/Docker#Running_the_docker_daemon_from_nix-the-package-manager_-_not_NixOS))
Expand Down
7 changes: 7 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@
r0vm = pkgs.callPackage ./nixos/pkgs/risc0/r0vm {
inherit risc0CircuitRecursionPatch;
};
risc0-groth16-prover = pkgs.callPackage ./nixos/pkgs/risc0/groth16-prover {
imageDigest = "sha256:5a862bac2c5c070ec50ff615572a05d870c1372818cf0f5d8bb9effc101590c8";
sha256 = "sha256-SV8nUjtq6TheYW+vQltyApOa7/gxnBrWx4Y6fQ71LFg=";
finalImageTag = "v2024-05-17.1";
};
solana-platform-tools = pkgs.callPackage ./nixos/pkgs/solana/platform-tools { };
solana-cli = pkgs.callPackage ./nixos/pkgs/solana { inherit solana-platform-tools; };
in
Expand Down Expand Up @@ -263,6 +268,7 @@

cargo-risczero
r0vm
risc0-groth16-prover
solana-cli
solana-platform-tools;

Expand Down Expand Up @@ -345,6 +351,7 @@
run-node
r0vm
cargo-risczero
risc0-groth16-prover
solana-cli
];

Expand Down
79 changes: 79 additions & 0 deletions nixos/pkgs/risc0/groth16-prover/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{ lib
, dockerTools
, stdenv
, autoPatchelfHook
, libclang
, libsodium
, gmp
, fetchurl

, imageDigest
, sha256
, finalImageTag
}:

let
owner = "risczero";
pname = "risc0-groth16-prover";
imageName = "${owner}/${pname}";
# Pulls the image from docker hub and builds the layered image
# producing a tarball.
src = dockerTools.exportImage {
name = imageName;
fromImage = dockerTools.pullImage {
inherit
imageName
imageDigest
sha256
finalImageTag;
};
diskSize = 10240; # 10G is necessary to build the layered image.
};
in
stdenv.mkDerivation {
inherit pname src;
version = finalImageTag;

nativeBuildInputs = [ autoPatchelfHook ];

buildInputs = [
libclang
# This just overrides the version of libsodium from the current one
# available in nixpkgs to use the version required by the version
# of rapidsnark.
(libsodium.overrideAttrs (old: rec {
version = "1.0.18";
src = fetchurl {
url = "https://download.libsodium.org/libsodium/releases/libsodium-${version}.tar.gz";
hash = "sha256-b1BEkLNCpPikxKAvybhmy++GItXfTlRStGvhIeRmNsE=";
};
}))
gmp
];

# Unpack the layered image into the source directory.
unpackPhase = ''
tar -xf $src
'';

# Create the output directory where the prover is expected to be by bonsol binaries
# and copy the files from the prover image into it.
buildPhase = ''
mkdir -p $out/stark
cp app/stark_verify $out/stark/
cp app/stark_verify.dat $out/stark/
cp app/stark_verify_final.zkey $out/stark/
cp usr/local/sbin/rapidsnark $out/stark/
'';

meta = with lib; {
description = ''
Utilities for performing a "stark2snark" workflow, useful for transforming a RISC Zero
STARK proof into a Groth16 SNARK proof which is suitable for publishing on-chain.
'';
homepage = "https://hub.docker.com/r/risczero/risc0-groth16-prover";
license = licenses.asl20;
maintainers = with maintainers; [ eureka-cpu ];
platforms = platforms.linux;
};
}
2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ packages:
- "vkey"
- "docs"
- "examples/bonsol-pow-example"

2 changes: 1 addition & 1 deletion setup.dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax = docker/dockerfile:1.2
FROM scratch as chef
FROM scratch as chef
WORKDIR /app
COPY --from=risczero/risc0-groth16-prover:v2024-05-17.1 /app/stark_verify /stark/stark_verify
COPY --from=risczero/risc0-groth16-prover:v2024-05-17.1 /app/stark_verify.dat /stark/stark_verify.dat
Expand Down

0 comments on commit 9dcccba

Please sign in to comment.