Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [Guides](./guides/index.md)
- [Build Valence Contracts](./guides/build-valence-contracts.md)
- [Upload Contracts](./guides/upload-contracts.md)
- [ZK Development](./guides/zk-development.md)
- [Flake Modules Reference](./reference/flake-modules/index.md)
- [Upload Contracts Options](./reference/flake-modules/upload-contracts.md)
- [Valence Contracts Options](./reference/flake-modules/valence-contracts.md)
1 change: 1 addition & 0 deletions docs/guides/index.md
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)

18 changes: 18 additions & 0 deletions docs/guides/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.


1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
./packages/default.nix
./tools/default.nix
./docs/default.nix
./templates/default.nix
./flakeModules/valence-contracts.nix
];
};
Expand Down
5 changes: 4 additions & 1 deletion packages/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{ inputs, lib, ... }:
{
imports = [
./valence-contracts.nix
Expand All @@ -7,6 +6,10 @@
packages = {
upload-contract = pkgs.callPackage ./upload-contract {};
local-ic = pkgs.callPackage ./local-ic.nix {};
sp1-rust = pkgs.callPackage ./sp1-rust.nix {};
sp1 = pkgs.callPackage ./sp1.nix {
inherit (config.packages) sp1-rust;
};
};
};
}
63 changes: 63 additions & 0 deletions packages/sp1-rust.nix
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 = "";
};
Comment on lines +52 to +53
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

#!/bin/bash
# Fetch the tarball and calculate its SHA256 hash
curl -sL "https://github.com/succinctlabs/rust/releases/download/succinct-1.82.0/rust-toolchain-aarch64-unknown-linux-gnu.tar.gz" | sha256sum

"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});
}
30 changes: 30 additions & 0 deletions packages/sp1.nix
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;
}
22 changes: 22 additions & 0 deletions templates/default.nix
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
Copy link

Choose a reason for hiding this comment

The 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}
'';
};
};
}
50 changes: 50 additions & 0 deletions templates/zk-development/flake.nix
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Undefined variable inputs' in workshop devshell

There's a reference to inputs' which doesn't appear to be defined. In flake-parts, the per-system inputs should be passed as a parameter to the function, but it's missing from the function arguments.

Fix this by updating the perSystem function to include inputs' in its parameters:

      perSystem = {
        pkgs,
        inputs,
+       inputs',
        ...
      }: {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{package = inputs'.packages.sp1-rust;}
{package = inputs'.packages.sp1;}
perSystem = {
pkgs,
inputs,
inputs',
...
}: {
# … rest of function body …
}

];
};
};
};
}
Loading