Skip to content

Commit

Permalink
Merge pull request #14649 from MinaProtocol/feat/add-o1js-stubs-develop
Browse files Browse the repository at this point in the history
[develop] Add o1js-stub to Mina repo in place of SnarkyJS
  • Loading branch information
MartinMinkov authored Dec 19, 2023
2 parents 4abe31c + d22d685 commit 4934295
Show file tree
Hide file tree
Showing 74 changed files with 10,733 additions and 197 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@
[submodule "src/external/c-reference-signer"]
path = src/external/c-reference-signer
url = https://github.com/MinaProtocol/c-reference-signer.git
[submodule "src/lib/snarky_js_bindings/snarkyjs"]
path = src/lib/snarkyjs
url = https://github.com/o1-labs/snarkyjs.git
1 change: 0 additions & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
/src/lib/snarky_curves/ @MinaProtocol/crypto-eng-reviewers
/src/lib/snarky_field_extensions/ @MinaProtocol/crypto-eng-reviewers
/src/lib/snarky_group_map/ @MinaProtocol/crypto-eng-reviewers
/src/lib/snarkyjs @MinaProtocol/product-eng-reviewers
/src/lib/snarky_log/ @MinaProtocol/crypto-eng-reviewers
/src/lib/unsigned_extended/ @MinaProtocol/crypto-eng-reviewers

Expand Down
12 changes: 0 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,6 @@ build_intgtest: ocaml_checks
dune build --profile=$(DUNE_PROFILE) src/app/test_executive/test_executive.exe src/app/logproc/logproc.exe
$(info Build complete)

snarkyjs: ocaml_checks
$(info Starting Build)
((ulimit -s 65532) || true) && (ulimit -n 10240 || true) \
&& bash ./src/lib/snarkyjs/src/bindings/scripts/build-snarkyjs-node.sh
$(info Build complete)

snarkyjs_no_types: ocaml_checks
$(info Starting Build)
((ulimit -s 65532) || true) && (ulimit -n 10240 || true) \
&& bash ./src/lib/snarkyjs/src/bindings/scripts/build-snarkyjs-node-artifacts.sh
$(info Build complete)

rosetta_lib_encodings: ocaml_checks
$(info Starting Build)
(ulimit -s 65532 || true) && (ulimit -n 10240 || true) && dune build src/lib/rosetta_lib/test/test_encodings.exe --profile=mainnet
Expand Down
17 changes: 0 additions & 17 deletions buildkite/scripts/build-js-tests.sh

This file was deleted.

12 changes: 0 additions & 12 deletions buildkite/scripts/build-snarkyjs-bindings.sh

This file was deleted.

16 changes: 0 additions & 16 deletions buildkite/scripts/test-snarkyjs-bindings-minimal.sh

This file was deleted.

19 changes: 0 additions & 19 deletions buildkite/scripts/test-snarkyjs-bindings.sh

This file was deleted.

50 changes: 0 additions & 50 deletions buildkite/src/Jobs/Test/SnarkyJSTest.dhall

This file was deleted.

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/snarkyjs/src/bindings/kimchi/wasm/rust-toolchain.toml
# - src/lib/crypto/kimchi_bindings/wasm/rust-toolchain.toml
ARG RUST_NIGHTLY=2023-09-01
# wasm-pack version
ARG WASM_PACK_VERSION=v0.12.1
Expand Down
19 changes: 0 additions & 19 deletions nix/javascript.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,6 @@ in {
mv src/*.js $out/share/client_sdk
'';
};
snarky_js = nix-npm-buildPackage.buildNpmPackage {
src = ../src/lib/snarkyjs;
preBuild = ''
BINDINGS_PATH=./src/bindings/compiled/node_bindings
mkdir -p "$BINDINGS_PATH"
cp ${plonk_wasm}/nodejs/plonk_wasm* "$BINDINGS_PATH"
cp ${ocamlPackages_mina.mina_client_sdk}/share/snarkyjs_bindings/snarky_js_node*.js "$BINDINGS_PATH"
chmod -R 777 "$BINDINGS_PATH"
# TODO: deduplicate from ./scripts/build-snarkyjs-node.sh
# better error messages
# TODO: find a less hacky way to make adjustments to jsoo compiler output
# `s` is the jsoo representation of the error message string, and `s.c` is the actual JS string
sed -i 's/function failwith(s){throw \[0,Failure,s\]/function failwith(s){throw globalThis.Error(s.c)/' "$BINDINGS_PATH"/snarky_js_node.bc.js
sed -i 's/function invalid_arg(s){throw \[0,Invalid_argument,s\]/function invalid_arg(s){throw globalThis.Error(s.c)/' "$BINDINGS_PATH"/snarky_js_node.bc.js
sed -i 's/return \[0,Exn,t\]/return globalThis.Error(t.c)/' "$BINDINGS_PATH"/snarky_js_node.bc.js
'';
npmBuild = "npm run build";
};

# Jobs/Release/LeaderboardArtifact
leaderboard = nix-npm-buildPackage.buildYarnPackage {
Expand Down
40 changes: 0 additions & 40 deletions nix/ocaml.nix
Original file line number Diff line number Diff line change
Expand Up @@ -297,46 +297,6 @@ let
dune exec --profile=dev src/app/reformat/reformat.exe -- -path . -check
'';

# Javascript Client SDK
mina_client_sdk = self.mina-dev.overrideAttrs (_: {
pname = "mina_client_sdk";
version = "dev";
src = filtered-src;

outputs = [ "out" ];

checkInputs = [ pkgs.nodejs-16_x ];

MINA_VERSION_IMPLEMENTATION = "mina_version.dummy";

buildPhase = ''
dune build --display=short \
src/lib/crypto/kimchi_bindings/js/node_js \
src/app/client_sdk/client_sdk.bc.js \
src/lib/snarky_js_bindings/snarky_js_node.bc.js \
src/lib/snarky_js_bindings/snarky_js_web.bc.js
'';

doCheck = true;
checkPhase = ''
node src/app/client_sdk/tests/run_unit_tests.js
dune build src/app/client_sdk/tests/test_signatures.exe
./_build/default/src/app/client_sdk/tests/test_signatures.exe > nat.consensus.json
node src/app/client_sdk/tests/test_signatures.js > js.nonconsensus.json
if ! diff -q nat.consensus.json js.nonconsensus.json; then
echo "Consensus and JS code generate different signatures";
exit 1
fi
'';

installPhase = ''
mkdir -p $out/share/client_sdk $out/share/snarkyjs_bindings
mv _build/default/src/app/client_sdk/client_sdk.bc.js $out/share/client_sdk
mv _build/default/src/lib/snarky_js_bindings/snarky_js_*.js $out/share/snarkyjs_bindings
'';
});

# Integration test executive
test_executive-dev = self.mina-dev.overrideAttrs (oa: {
pname = "mina-test_executive";
Expand Down
8 changes: 4 additions & 4 deletions nix/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ in
};

kimchi-rust = rustChannelFromToolchainFileOf
../src/lib/snarkyjs/src/bindings/kimchi/wasm/rust-toolchain.toml;
../src/lib/crypto/kimchi_bindings/wasm/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 @@ -124,7 +124,7 @@ in
plonk_wasm =
let

lock = ../src/lib/snarkyjs/src/bindings/kimchi/wasm/Cargo.lock;
lock = ../src/lib/crypto/kimchi_bindings/wasm/Cargo.lock;

deps = builtins.listToAttrs (map
(pkg: {
Expand Down Expand Up @@ -165,10 +165,10 @@ in
pname = "plonk_wasm";
version = "0.1.0";
src = final.lib.sourceByRegex ../src [
"^lib(/snarkyjs(/src(/bindings(/kimchi(/wasm(/.*)?)?)?)?)?)?$"
"^lib(/crypto(/kimchi_bindings(/wasm(/.*)?)?)?)?$"
"^lib(/crypto(/proof-systems(/.*)?)?)?$"
];
sourceRoot = "source/lib/snarkyjs/src/bindings/kimchi/wasm";
sourceRoot = "source/lib/crypto/kimchi_bindings/wasm";
nativeBuildInputs = [ final.wasm-pack wasm-bindgen-cli ];
buildInputs = with final; lib.optional stdenv.isDarwin libiconv;
cargoLock.lockFile = lock;
Expand Down
1 change: 0 additions & 1 deletion scripts/build-snarkyjs-node.sh

This file was deleted.

1 change: 0 additions & 1 deletion scripts/update-snarkyjs-bindings.sh

This file was deleted.

1 change: 1 addition & 0 deletions src/dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
(package (name best_tip_merger))
(package (name best_tip_prover))
(package (name bignum_bigint))
(package (name bindings_js))
(package (name blake2))
(package (name blockchain_snark))
(package (name block_producer))
Expand Down
28 changes: 28 additions & 0 deletions src/lib/crypto/kimchi_bindings/js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
This library provides a wrapper around the WebAssembly prover code, which
allows `js_of_ocaml` to compile the mina project against the WebAssembly
backend.

The different versions of the backend are generated in subdirectories; e.g. the
NodeJS backend is generated in `node_js/` and the Web backend is generated
in `web/`. To use a backend, run `dune build backend/plonk_wasm.js` and copy
`backend/plonk_wasm*` to the project directory.

Note that the backend code is not automatically compiled while linking against
the backend library. You should always manually issue a build command for the
`plonk_wasm.js` for the desired backend to ensure that it has been generated.
For example, to run the nodejs tests in the `test/nodejs` directory you will
need to run

```
dune build src/lib/marlin_plonk_bindings/js/test/nodejs/nodejs_test.bc.js
src/lib/marlin_plonk_bindings/js/test/nodejs/copy_over.sh
```

Similarly, to run the web tests in `test/web`, you can run

```
dune build src/lib/marlin_plonk_bindings/js/test/web/web_test.bc.js
src/lib/marlin_plonk_bindings/js/test/web/copy_over.sh
```

and then visit `http://localhost:8000` from a browser.
50 changes: 50 additions & 0 deletions src/lib/crypto/kimchi_bindings/js/bindings-bigint256.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* global tsBindings
*/

// Provides: caml_bigint_256_of_numeral
// Requires: tsBindings
var caml_bigint_256_of_numeral = tsBindings.caml_bigint_256_of_numeral;

// Provides: caml_bigint_256_of_decimal_string
// Requires: tsBindings
var caml_bigint_256_of_decimal_string = tsBindings.caml_bigint_256_of_decimal_string;

// Provides: caml_bigint_256_num_limbs
// Requires: tsBindings
var caml_bigint_256_num_limbs = tsBindings.caml_bigint_256_num_limbs;

// Provides: caml_bigint_256_bytes_per_limb
// Requires: tsBindings
var caml_bigint_256_bytes_per_limb = tsBindings.caml_bigint_256_bytes_per_limb;

// Provides: caml_bigint_256_div
// Requires: tsBindings
var caml_bigint_256_div = tsBindings.caml_bigint_256_div;

// Provides: caml_bigint_256_compare
// Requires: tsBindings
var caml_bigint_256_compare = tsBindings.caml_bigint_256_compare;

// Provides: caml_bigint_256_print
// Requires: tsBindings
var caml_bigint_256_print = tsBindings.caml_bigint_256_print;

// Provides: caml_bigint_256_to_string
// Requires: tsBindings
var caml_bigint_256_to_string = tsBindings.caml_bigint_256_to_string;

// Provides: caml_bigint_256_test_bit
// Requires: tsBindings
var caml_bigint_256_test_bit = tsBindings.caml_bigint_256_test_bit;

// Provides: caml_bigint_256_to_bytes
// Requires: tsBindings
var caml_bigint_256_to_bytes = tsBindings.caml_bigint_256_to_bytes;

// Provides: caml_bigint_256_of_bytes
// Requires: tsBindings
var caml_bigint_256_of_bytes = tsBindings.caml_bigint_256_of_bytes;

// Provides: caml_bigint_256_deep_copy
// Requires: tsBindings
var caml_bigint_256_deep_copy = tsBindings.caml_bigint_256_deep_copy
Loading

0 comments on commit 4934295

Please sign in to comment.