-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add ZK (sp1) development tools #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Guides | ||
- [Build Valence Contracts](./build-valence-contracts.md) | ||
- [Upload Contracts](./upload-contracts.md) | ||
- [ZK Development](./zk-development.md) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# ZK Development | ||
|
||
Zero.nix provides the `sp1` and `sp1-rust` packages to make it | ||
easy to setup a nix development shell with sp1 tooling. | ||
|
||
To use them create a flake.nix with the following contents: | ||
```nix | ||
{{#include ../../templates/zk-development/flake.nix}} | ||
``` | ||
You can also run the following command to initialize the template. | ||
```bash | ||
nix flake init -t github:timewave-computer/zero.nix#zk-dev | ||
|
||
``` | ||
|
||
Then run `nix develop` to enter a devshell with the packages. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
stdenv, | ||
autoPatchelfHook, | ||
fixDarwinDylibNames, | ||
fetchzip, | ||
zlib, | ||
... | ||
}: | ||
let | ||
fetchGitHubReleaseAsset = | ||
{ | ||
owner, | ||
repo, | ||
tag, | ||
asset, | ||
hash, | ||
}: | ||
fetchzip { | ||
url = "https://github.com/${owner}/${repo}/releases/download/${tag}/${asset}"; | ||
inherit hash; | ||
stripRoot = false; | ||
}; | ||
|
||
in | ||
stdenv.mkDerivation rec { | ||
name = "sp1-rust"; | ||
version = "1.82.0"; | ||
|
||
nativeBuildInputs = [ | ||
stdenv.cc.cc.lib | ||
zlib | ||
] ++ (if stdenv.isDarwin then [ fixDarwinDylibNames ] else [ autoPatchelfHook ]); | ||
|
||
installPhase = '' | ||
runHook preInstall | ||
mkdir -p $out | ||
cp -r ./* $out/ | ||
runHook postInstall | ||
''; | ||
|
||
src = fetchGitHubReleaseAsset ({ | ||
owner = "succinctlabs"; | ||
repo = "rust"; | ||
tag = "succinct-${version}"; | ||
} // { | ||
"x86_64-linux" = { | ||
asset = "rust-toolchain-x86_64-unknown-linux-gnu.tar.gz"; | ||
hash = "sha256-wXI2zVwfrVk28CR8PLq4xyepdlu65uamzt/+jER2M2k="; | ||
}; | ||
"aarch64-linux" = { | ||
asset = "rust-toolchain-aarch64-unknown-linux-gnu.tar.gz"; | ||
hash = ""; | ||
}; | ||
"x86_64-darwin" = { | ||
asset = "rust-toolchain-x86_64-apple-darwin.tar.gz"; | ||
hash = "sha256-sPQW8eo+qItsmgK1uxRh1r73DBLUXUtmtVUvjacGzp0="; | ||
}; | ||
"aarch64-darwin" = { | ||
asset = "rust-toolchain-aarch64-apple-darwin.tar.gz"; | ||
hash = "sha256-R4D7hj2DcZ3vfCejvXwJ68YDOlgWGDPcb08GZNXz1Cg="; | ||
}; | ||
}.${stdenv.system}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
lib, | ||
sp1-rust, | ||
rustPlatform, | ||
fetchFromGitHub, | ||
pkg-config, | ||
openssl, | ||
... | ||
}: | ||
rustPlatform.buildRustPackage { | ||
pname = "sp1"; | ||
version = "unstable-2025-03-06"; | ||
|
||
nativeBuildInputs = [ | ||
sp1-rust | ||
pkg-config | ||
openssl | ||
]; | ||
cargoBuildFlags = [ "--package sp1-cli" ]; | ||
cargoHash = "sha256-gI/N381IfIWnF4tfXM1eKLI93eCjEELg/a5gWQn/3EA="; | ||
|
||
src = fetchFromGitHub { | ||
owner = "succinctlabs"; | ||
repo = "sp1"; | ||
rev = "9f202bf603b3cab5b7c9db0e8cf5524a3428fbee"; | ||
hash = "sha256-RpllsIlrGyYw6dInN0tTs7K1y4FiFmrxFSyt3/Xelkg="; | ||
fetchSubmodules = true; | ||
}; | ||
doCheck = false; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
let | ||
commonWelcome = '' | ||
## More info | ||
- Zero.nix Docs: https://timewave.computer/zero.nix | ||
''; | ||
in | ||
{ | ||
flake.templates = { | ||
zk-dev = { | ||
path = ./zk-development; | ||
description = "Simple ZK development environment"; | ||
welcomeText = '' | ||
# Simple ZK development environment | ||
## Provided packages | ||
- sp1 (cargo prove) | ||
- rust-sp1 | ||
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Inconsistent package naming in welcome text In the welcome text, you refer to "rust-sp1", but the actual package name in packages/default.nix is "sp1-rust". This inconsistency might confuse users. - - sp1 (cargo prove)
- - rust-sp1
+ - sp1 (cargo prove)
+ - sp1-rust |
||
|
||
${commonWelcome} | ||
''; | ||
}; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,50 @@ | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
description = "Valence ZK development environment"; | ||||||||||||||||||||||
|
||||||||||||||||||||||
nixConfig.extra-experimental-features = "nix-command flakes"; | ||||||||||||||||||||||
nixConfig.extra-substituters = "https://timewave.cachix.org"; | ||||||||||||||||||||||
nixConfig.extra-trusted-public-keys = '' | ||||||||||||||||||||||
colmena.cachix.org-1:7BzpDnjjH8ki2CT3f6GdOk7QAzPOl+1t3LvTLXqYcSg= | ||||||||||||||||||||||
cosmos-nix.cachix.org-1:I9dmz4kn5+JExjPxOd9conCzQVHPl0Jo1Cdp6s+63d4= | ||||||||||||||||||||||
nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= | ||||||||||||||||||||||
''; | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
inputs = { | ||||||||||||||||||||||
nixpkgs.url = "nixpkgs/nixos-24.11"; | ||||||||||||||||||||||
|
||||||||||||||||||||||
flake-parts.url = "github:hercules-ci/flake-parts"; | ||||||||||||||||||||||
|
||||||||||||||||||||||
devshell.url = "github:numtide/devshell"; | ||||||||||||||||||||||
|
||||||||||||||||||||||
zero-nix.url = "github:timewave-computer/zero.nix"; | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
|
||||||||||||||||||||||
outputs = { | ||||||||||||||||||||||
self, | ||||||||||||||||||||||
flake-parts, | ||||||||||||||||||||||
... | ||||||||||||||||||||||
} @ inputs: | ||||||||||||||||||||||
flake-parts.lib.mkFlake {inherit inputs;} { | ||||||||||||||||||||||
imports = [ | ||||||||||||||||||||||
inputs.devshell.flakeModule | ||||||||||||||||||||||
]; | ||||||||||||||||||||||
|
||||||||||||||||||||||
systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; | ||||||||||||||||||||||
|
||||||||||||||||||||||
perSystem = { | ||||||||||||||||||||||
pkgs, | ||||||||||||||||||||||
inputs, | ||||||||||||||||||||||
... | ||||||||||||||||||||||
}: { | ||||||||||||||||||||||
devshells.workshop = {pkgs, ...}: { | ||||||||||||||||||||||
commands = [ | ||||||||||||||||||||||
{package = pkgs.cargo;} | ||||||||||||||||||||||
{package = pkgs.rustc;} | ||||||||||||||||||||||
{package = inputs'.packages.sp1-rust;} | ||||||||||||||||||||||
{package = inputs'.packages.sp1;} | ||||||||||||||||||||||
Comment on lines
+44
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Undefined variable There's a reference to Fix this by updating the perSystem function to include perSystem = {
pkgs,
inputs,
+ inputs',
...
}: { 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
]; | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty hash for aarch64-linux platform
The hash value for aarch64-linux platform is empty. Without a hash, Nix cannot verify the integrity of the downloaded file, which is a security risk and may also cause build issues. Please provide a valid SHA256 hash for this platform.