Skip to content
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

use proof-systems plonk-wasm #16418

Draft
wants to merge 1 commit into
base: dw/use-latest-master-proof-systems
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion dockerfiles/stages/1-build-deps
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ARG GO_CAPNP_VERSION=v3.0.0-alpha.5
# - src/lib/crypto/proof-systems/rust-toolchain.toml
ARG RUST_VERSION=1.72
# Nightly Rust Version used for WebAssembly builds
# - src/lib/crypto/kimchi_bindings/wasm/rust-toolchain.toml
# - src/lib/crypto/proof-systems/plonk-wasm/rust-toolchain.toml
ARG RUST_NIGHTLY=2023-09-01
# wasm-pack version
ARG WASM_PACK_VERSION=v0.12.1
Expand Down
16 changes: 7 additions & 9 deletions nix/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ let
};
toolchainHashes = {
"1.72" = "sha256-dxE7lmCFWlq0nl/wKcmYvpP9zqQbBitAQgZ1zx9Ooik=";
"nightly-2023-09-01" =
"sha256-zek9JAnRaoX8V0U2Y5ssXVe9tvoQ0ERGXfUCUGYdrMA=";
# copy the placeholder line with the correct toolchain name when adding a new toolchain
# That is,
# 1. Put the correct version name;
Expand Down Expand Up @@ -89,7 +87,7 @@ in {
};

kimchi-rust = rustChannelFromToolchainFileOf
../src/lib/crypto/kimchi_bindings/wasm/rust-toolchain.toml;
../src/lib/crypto/proof-systems/rust-toolchain.toml;

# TODO: raise issue on nixpkgs and remove workaround when fix is applied
kimchi-rust-wasm = (final.kimchi-rust.rust.override {
Expand All @@ -111,7 +109,7 @@ in {
};

plonk_wasm = let
lock = ../src/lib/crypto/kimchi_bindings/wasm/Cargo.lock;
lock = ../src/lib/crypto/proof-systems/Cargo.lock;

deps = builtins.listToAttrs (map (pkg: {
inherit (pkg) name;
Expand All @@ -120,7 +118,7 @@ in {

rustPlatform = rustPlatformFor final.kimchi-rust-wasm;

wasm-bindgen-cli = rustPlatform.buildRustPackage rec {
wasm-bindgen-cli = final.rustPlatform.buildRustPackage rec {
pname = "wasm-bindgen-cli";
version = deps.wasm-bindgen.version;
src = final.fetchCrate {
Expand Down Expand Up @@ -148,10 +146,10 @@ in {
pname = "plonk_wasm";
version = "0.1.0";
src = final.lib.sourceByRegex ../src [
"^lib(/crypto(/kimchi_bindings(/wasm(/.*)?)?)?)?$"
"^lib(/crypto(/proof-systems(/.*)?)?)?$"
];
sourceRoot = "source/lib/crypto/kimchi_bindings/wasm";
buildAndTestSubdir = "plonk-wasm";
sourceRoot = "source/lib/crypto/proof-systems";
nativeBuildInputs = [ final.wasm-pack wasm-bindgen-cli ];
buildInputs = with final; lib.optional stdenv.isDarwin libiconv;
cargoLock.lockFile = lock;
Expand All @@ -178,8 +176,8 @@ in {
(
set -x
export RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--no-check-features -C link-arg=--max-memory=4294967296"
wasm-pack build --mode no-install --target nodejs --out-dir $out/nodejs ./. -- --features nodejs
wasm-pack build --mode no-install --target web --out-dir $out/web ./.
wasm-pack build --mode no-install --target nodejs --out-dir $out/nodejs ./plonk-wasm -- --features nodejs
wasm-pack build --mode no-install --target web --out-dir $out/web ./plonk-wasm
)
runHook postBuild
'';
Expand Down
2 changes: 1 addition & 1 deletion src/dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
(package (name heap_usage))
(package (name hex))
(package (name immutable_array))
(package (name inline_test_quiet_logs))
(package (name inline_test_quiet_logs) (allow_empty))
(package (name integers_stubs_js))
(package (name integration_test_local_engine))
(package (name integration_test_lib))
Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto/kimchi_bindings/js/bindings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This way, when calling the function `FunnyLittleModule.do_cool_thingies`, we tel

We use this for many things. Many things in the code base rely of implementations in Rust. For example, we use Kimchi to generate proofs! So in order to tell OCaml to generate a Kimchi proof, we need to point it to the correct function that's living in the Rust proof-systems repository.

The other side of the `external` keyword is somewhere in the Rust bindings layer, more specifically somewhere in `src/lib/crypto/kimchi_bindings/wasm/src` - in our case where we want to establish bindings between OCaml that has been compiled to JavaScript using JSOO and Rust (compiled to WASM).
The other side of the `external` keyword is somewhere in the Rust bindings layer, more specifically somewhere in `src/lib/crypto/proof-systems/plonk-wasm/src` - in our case where we want to establish bindings between OCaml that has been compiled to JavaScript using JSOO and Rust (compiled to WASM).

For example, the implementation of `caml_do_cool_thingies` could look like this:

Expand Down
6 changes: 4 additions & 2 deletions src/lib/crypto/kimchi_bindings/js/node_js/build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail

# When using nix this is already cached
if [[ -z "${PLONK_WASM_NODEJS-}" ]]; then
export RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--no-check-features -C link-arg=--max-memory=4294967296"
# The version should stay in line with the one in kimchi_bindings/wasm/rust-toolchain.toml
rustup run nightly-2023-09-01 wasm-pack build --target nodejs --out-dir ../js/node_js ../../wasm -- -Z build-std=panic_abort,std --features nodejs
# The rust version should stay in line with the one in kimchi_bindings/wasm/rust-toolchain.toml
# TODO: change out-dir to be relative to PWD when we upgrade to wasm-pack 0.13 (see https://github.com/rustwasm/wasm-pack/issues/704)
rustup run 1.72 wasm-pack build --target nodejs --out-dir ../../kimchi_bindings/js/node_js ../../../proof-systems/plonk-wasm -- --features nodejs
else
cp "$PLONK_WASM_NODEJS"/* -R .
fi
10 changes: 5 additions & 5 deletions src/lib/crypto/kimchi_bindings/js/node_js/dune
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
(deps
build.sh
../../dune-build-root
../../wasm/Cargo.toml
../../wasm/Cargo.lock
(source_tree ../../wasm/src)
(source_tree ../../wasm/.cargo/config)
../../../proof-systems/Cargo.toml
../../../proof-systems/Cargo.lock
(source_tree ../../../proof-systems/plonk-wasm/src)
(source_tree ../../proof-systems/plonk-wasm/.cargo/config)
(source_tree ../../../proof-systems))
(locks /cargo-lock) ; lock for rustup
(action
(progn
(run chmod -R +w ../../wasm .)
(run chmod -R +w ../../../proof-systems/plonk-wasm .)
(setenv
CARGO_TARGET_DIR
"%{read:../../dune-build-root}/cargo_kimchi_wasm"
Expand Down
4 changes: 3 additions & 1 deletion src/lib/crypto/kimchi_bindings/js/web/build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail

# When using nix this is already cached
if [[ -z "${PLONK_WASM_WEB-}" ]]; then
export RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--no-check-features -C link-arg=--max-memory=4294967296"
# The version should stay in line with the one in kimchi_bindings/wasm/rust-toolchain.toml
rustup run nightly-2023-09-01 wasm-pack build --target web --out-dir ../js/web ../../wasm -- -Z build-std=panic_abort,std
# TODO: change out-dir to be relative to PWD when we upgrade to wasm-pack 0.13 (see https://github.com/rustwasm/wasm-pack/issues/704)
rustup run 1.72 wasm-pack build --target web --out-dir ../../kimchi_bindings/js/web ../../../proof-systems/plonk-wasm
else
cp "$PLONK_WASM_WEB"/* -R .
fi
10 changes: 5 additions & 5 deletions src/lib/crypto/kimchi_bindings/js/web/dune
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
flags.sexp)
(deps
build.sh
../../wasm/Cargo.toml
../../wasm/Cargo.lock
../../../proof-systems/plonk-wasm/Cargo.toml
../../../proof-systems/Cargo.lock
../../dune-build-root
(source_tree ../../wasm/src)
(source_tree ../../wasm/.cargo/config)
(source_tree ../../../proof-systems/plonk-wasm/src)
(source_tree ../../../proof-systems/plonk-wasm/.cargo/config)
(source_tree ../../../proof-systems))
(locks /cargo-lock) ; lock for rustup
(action
(progn
(run chmod -R +w ../../wasm .)
(run chmod -R +w ../../../proof-systems/plonk-wasm .)
(setenv
CARGO_TARGET_DIR
"%{read:../../dune-build-root}/cargo_kimchi_wasm"
Expand Down
8 changes: 0 additions & 8 deletions src/lib/crypto/kimchi_bindings/wasm/.cargo/config

This file was deleted.

1 change: 0 additions & 1 deletion src/lib/crypto/kimchi_bindings/wasm/.gitignore

This file was deleted.

Loading