Skip to content

Commit 656bb07

Browse files
committed
feat: add ZK (sp1) development tools
1 parent 4cc25fb commit 656bb07

File tree

9 files changed

+190
-1
lines changed

9 files changed

+190
-1
lines changed

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [Guides](./guides/index.md)
55
- [Build Valence Contracts](./guides/build-valence-contracts.md)
66
- [Upload Contracts](./guides/upload-contracts.md)
7+
- [ZK Development](./guides/zk-development.md)
78
- [Flake Modules Reference](./reference/flake-modules/index.md)
89
- [Upload Contracts Options](./reference/flake-modules/upload-contracts.md)
910
- [Valence Contracts Options](./reference/flake-modules/valence-contracts.md)

docs/guides/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Guides
22
- [Build Valence Contracts](./build-valence-contracts.md)
33
- [Upload Contracts](./upload-contracts.md)
4+
- [ZK Development](./zk-development.md)
45

docs/guides/zk-development.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ZK Development
2+
3+
Zero.nix provides the `sp1` and `sp1-rust` packages to make it
4+
easy to setup a nix development shell with sp1 tooling.
5+
6+
To use them create a flake.nix with the following contents:
7+
```nix
8+
{{#include ../../templates/zk-development/flake.nix}}
9+
```
10+
You can also run the following command to initialize the template.
11+
```bash
12+
nix flake init -t github:timewave-computer/zero.nix#zk-dev
13+
14+
```
15+
16+
Then run `nix develop` to enter a devshell with the packages.
17+
18+

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
./packages/default.nix
2323
./tools/default.nix
2424
./docs/default.nix
25+
./templates/default.nix
2526
./flakeModules/valence-contracts.nix
2627
];
2728
};

packages/default.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{ inputs, lib, ... }:
21
{
32
imports = [
43
./valence-contracts.nix
@@ -7,6 +6,10 @@
76
packages = {
87
upload-contract = pkgs.callPackage ./upload-contract {};
98
local-ic = pkgs.callPackage ./local-ic.nix {};
9+
sp1-rust = pkgs.callPackage ./sp1-rust.nix {};
10+
sp1 = pkgs.callPackage ./sp1.nix {
11+
inherit (config.packages) sp1-rust;
12+
};
1013
};
1114
};
1215
}

packages/sp1-rust.nix

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
stdenv,
3+
autoPatchelfHook,
4+
fixDarwinDylibNames,
5+
fetchzip,
6+
zlib,
7+
...
8+
}:
9+
let
10+
fetchGitHubReleaseAsset =
11+
{
12+
owner,
13+
repo,
14+
tag,
15+
asset,
16+
hash,
17+
}:
18+
fetchzip {
19+
url = "https://github.com/${owner}/${repo}/releases/download/${tag}/${asset}";
20+
inherit hash;
21+
stripRoot = false;
22+
};
23+
24+
in
25+
stdenv.mkDerivation rec {
26+
name = "sp1-rust";
27+
version = "1.82.0";
28+
29+
nativeBuildInputs = [
30+
stdenv.cc.cc.lib
31+
zlib
32+
] ++ (if stdenv.isDarwin then [ fixDarwinDylibNames ] else [ autoPatchelfHook ]);
33+
34+
installPhase = ''
35+
runHook preInstall
36+
mkdir -p $out
37+
cp -r ./* $out/
38+
runHook postInstall
39+
'';
40+
41+
src = fetchGitHubReleaseAsset ({
42+
owner = "succinctlabs";
43+
repo = "rust";
44+
tag = "succinct-${version}";
45+
} // {
46+
"x86_64-linux" = {
47+
asset = "rust-toolchain-x86_64-unknown-linux-gnu.tar.gz";
48+
hash = "sha256-wXI2zVwfrVk28CR8PLq4xyepdlu65uamzt/+jER2M2k=";
49+
};
50+
"aarch64-linux" = {
51+
asset = "rust-toolchain-aarch64-unknown-linux-gnu.tar.gz";
52+
hash = "";
53+
};
54+
"x86_64-darwin" = {
55+
asset = "rust-toolchain-x86_64-apple-darwin.tar.gz";
56+
hash = "sha256-sPQW8eo+qItsmgK1uxRh1r73DBLUXUtmtVUvjacGzp0=";
57+
};
58+
"aarch64-darwin" = {
59+
asset = "rust-toolchain-aarch64-apple-darwin.tar.gz";
60+
hash = "sha256-R4D7hj2DcZ3vfCejvXwJ68YDOlgWGDPcb08GZNXz1Cg=";
61+
};
62+
}.${stdenv.system});
63+
}

packages/sp1.nix

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
lib,
3+
sp1-rust,
4+
rustPlatform,
5+
fetchFromGitHub,
6+
pkg-config,
7+
openssl,
8+
...
9+
}:
10+
rustPlatform.buildRustPackage {
11+
pname = "sp1";
12+
version = "unstable-2025-03-06";
13+
14+
nativeBuildInputs = [
15+
sp1-rust
16+
pkg-config
17+
openssl
18+
];
19+
cargoBuildFlags = [ "--package sp1-cli" ];
20+
cargoHash = "sha256-gI/N381IfIWnF4tfXM1eKLI93eCjEELg/a5gWQn/3EA=";
21+
22+
src = fetchFromGitHub {
23+
owner = "succinctlabs";
24+
repo = "sp1";
25+
rev = "9f202bf603b3cab5b7c9db0e8cf5524a3428fbee";
26+
hash = "sha256-RpllsIlrGyYw6dInN0tTs7K1y4FiFmrxFSyt3/Xelkg=";
27+
fetchSubmodules = true;
28+
};
29+
doCheck = false;
30+
}

templates/default.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
let
2+
commonWelcome = ''
3+
## More info
4+
- Zero.nix Docs: https://timewave.computer/zero.nix
5+
'';
6+
in
7+
{
8+
flake.templates = {
9+
zk-dev = {
10+
path = ./zk-development;
11+
description = "Simple ZK development environment";
12+
welcomeText = ''
13+
# Simple ZK development environment
14+
## Provided packages
15+
- sp1 (cargo prove)
16+
- rust-sp1
17+
18+
${commonWelcome}
19+
'';
20+
};
21+
};
22+
}

templates/zk-development/flake.nix

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
description = "Valence ZK development environment";
3+
4+
nixConfig.extra-experimental-features = "nix-command flakes";
5+
nixConfig.extra-substituters = "https://timewave.cachix.org";
6+
nixConfig.extra-trusted-public-keys = ''
7+
colmena.cachix.org-1:7BzpDnjjH8ki2CT3f6GdOk7QAzPOl+1t3LvTLXqYcSg=
8+
cosmos-nix.cachix.org-1:I9dmz4kn5+JExjPxOd9conCzQVHPl0Jo1Cdp6s+63d4=
9+
nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=
10+
'';
11+
12+
13+
inputs = {
14+
nixpkgs.url = "nixpkgs/nixos-24.11";
15+
16+
flake-parts.url = "github:hercules-ci/flake-parts";
17+
18+
devshell.url = "github:numtide/devshell";
19+
20+
zero-nix.url = "github:timewave-computer/zero.nix";
21+
};
22+
23+
outputs = {
24+
self,
25+
flake-parts,
26+
...
27+
} @ inputs:
28+
flake-parts.lib.mkFlake {inherit inputs;} {
29+
imports = [
30+
inputs.devshell.flakeModule
31+
];
32+
33+
systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
34+
35+
perSystem = {
36+
pkgs,
37+
inputs,
38+
...
39+
}: {
40+
devshells.workshop = {pkgs, ...}: {
41+
commands = [
42+
{package = pkgs.cargo;}
43+
{package = pkgs.rustc;}
44+
{package = inputs'.packages.sp1-rust;}
45+
{package = inputs'.packages.sp1;}
46+
];
47+
};
48+
};
49+
};
50+
}

0 commit comments

Comments
 (0)