Skip to content
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
32 changes: 1 addition & 31 deletions src/lib/crypto/kimchi_bindings/js/bindings/oracles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* global plonk_wasm, tsRustConversion,

*/
/* global plonk_wasm, tsRustConversion,*/

// Provides: fp_oracles_create
// Requires: plonk_wasm, tsRustConversion
Expand Down Expand Up @@ -75,31 +73,3 @@ function caml_pasta_fp_poseidon_params_create() {
function caml_pasta_fq_poseidon_params_create() {
return [0];
}

// Provides: caml_pasta_fp_poseidon_block_cipher
// Requires: plonk_wasm, tsRustConversion, tsRustConversion
function caml_pasta_fp_poseidon_block_cipher(_fake_params, fp_vector) {
// 1. get permuted field vector from rust
var wasm_flat_vector = plonk_wasm.caml_pasta_fp_poseidon_block_cipher(
tsRustConversion.fp.vectorToRust(fp_vector)
);
var new_fp_vector = tsRustConversion.fp.vectorFromRust(wasm_flat_vector);
// 2. write back modified field vector to original one
new_fp_vector.forEach(function (a, i) {
fp_vector[i] = a;
});
}

// Provides: caml_pasta_fq_poseidon_block_cipher
// Requires: plonk_wasm, tsRustConversion, tsRustConversion
function caml_pasta_fq_poseidon_block_cipher(_fake_params, fq_vector) {
// 1. get permuted field vector from rust
var wasm_flat_vector = plonk_wasm.caml_pasta_fq_poseidon_block_cipher(
tsRustConversion.fq.vectorToRust(fq_vector)
);
var new_fq_vector = tsRustConversion.fq.vectorFromRust(wasm_flat_vector);
// 2. write back modified field vector to original one
new_fq_vector.forEach(function (a, i) {
fq_vector[i] = a;
});
}
2 changes: 1 addition & 1 deletion src/lib/crypto/kimchi_bindings/js/bindings/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global UInt64, caml_int64_of_int32, caml_create_bytes,
caml_bytes_unsafe_set, caml_bytes_unsafe_get, caml_ml_bytes_length,
plonk_wasm
plonk_wasm, getTsBindings
*/

// Provides: tsBindings
Expand Down
5 changes: 4 additions & 1 deletion src/lib/crypto/kimchi_bindings/js/dune
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
bindings/prover-index.js
bindings/util.js
bindings/srs.js
bindings/verifier-index.js))
bindings/verifier-index.js
native/native-overrides/oracles.js
native/native-overrides/util.js
))
(instrumentation
(backend bisect_ppx))
(preprocess
Expand Down
30 changes: 30 additions & 0 deletions src/lib/crypto/kimchi_bindings/js/native/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
CURRENT_DIRECTORY="${SCRIPT_DIR}"
PROOF_SYSTEMS_ROOT=$(cd "${SCRIPT_DIR}/../../../proof-systems" && pwd)
PLONK_NAPI_ROOT="${PROOF_SYSTEMS_ROOT}/plonk-napi"

TARGET_ROOT="${CARGO_TARGET_DIR:-"${PROOF_SYSTEMS_ROOT}/target"}"
export CARGO_TARGET_DIR="${TARGET_ROOT}"

cargo build \
--manifest-path "${PLONK_NAPI_ROOT}/Cargo.toml" \
--release

case "$(uname -s)" in
Darwin*) LIB_NAME="libplonk_napi.dylib" ;;
MINGW*|MSYS*|CYGWIN*) LIB_NAME="plonk_napi.dll" ;;
*) LIB_NAME="libplonk_napi.so" ;;
esac

ARTIFACT="${TARGET_ROOT}/release/${LIB_NAME}"

if [[ ! -f "${ARTIFACT}" ]]; then
echo "Failed to locate plonk-napi artifact at ${ARTIFACT}" >&2
exit 1
fi

rm -f "${CURRENT_DIRECTORY}/plonk_napi.node"
cp "${ARTIFACT}" "${CURRENT_DIRECTORY}/plonk_napi.node"
29 changes: 29 additions & 0 deletions src/lib/crypto/kimchi_bindings/js/native/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(library
(name native_backend)
(public_name bindings_js.native_backend)
(js_of_ocaml
(flags
(:include flags.sexp))
(javascript_files native_backend.js))
(instrumentation
(backend bisect_ppx))
(preprocess
(pps ppx_version js_of_ocaml-ppx)))

(rule
(targets
plonk_napi.node
flags.sexp)
(deps
build.sh
../../dune-build-root
(source_tree ../../../proof-systems))
(locks /cargo-lock)
(action
(progn
(setenv
CARGO_TARGET_DIR
"%{read:../../dune-build-root}/cargo_kimchi_native"
(run bash build.sh))
(write-file flags.sexp "()"))))

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* global plonk_wasm, tsRustConversionNative,*/


// Provides: caml_pasta_fq_poseidon_block_cipher
// Requires: plonk_wasm, tsRustConversionNative
function caml_pasta_fq_poseidon_block_cipher(_fake_params, fq_vector) {

console.log("overriding the old wasm caml_pasta_fq_poseidon_block_cipher, now using the native one")

// 1. get permuted field vector from rust
var wasm_flat_vector = plonk_wasm.caml_pasta_fq_poseidon_block_cipher(
tsRustConversionNative.fq.vectorToRust(fq_vector)
);
var new_fq_vector = tsRustConversionNative.fq.vectorFromRust(wasm_flat_vector);
// 2. write back modified field vector to original one
new_fq_vector.forEach(function (a, i) {
fq_vector[i] = a;
});
}


// Provides: caml_pasta_fp_poseidon_block_cipher
// Requires: plonk_wasm, tsRustConversionNative
function caml_pasta_fp_poseidon_block_cipher(_fake_params, fp_vector) {

console.log("overriding the old wasm caml_pasta_fp_poseidon_block_cipher, now using the native one")


// 1. get permuted field vector from rust
var wasm_flat_vector = plonk_wasm.caml_pasta_fp_poseidon_block_cipher(
tsRustConversionNative.fp.vectorToRust(fp_vector)
);
var new_fp_vector = tsRustConversionNative.fp.vectorFromRust(wasm_flat_vector);
// 2. write back modified field vector to original one
new_fp_vector.forEach(function (a, i) {
fp_vector[i] = a;
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* global plonk_wasm, tsRustConversionNative, getTsBindings, tsBindings */


// Provides: tsRustConversionNative
// Requires: tsBindings, plonk_wasm, getTsBindings
var tsRustConversionNative = tsBindings.nativeRustConversion(plonk_wasm);
4 changes: 4 additions & 0 deletions src/lib/crypto/kimchi_bindings/js/native/native_backend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Provides: plonk_napi
var plonk_napi = require('./plonk_napi.node');

module.exports = plonk_napi;
25 changes: 25 additions & 0 deletions src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
// Provides: plonk_wasm
var plonk_wasm = require('./plonk_wasm.js');
var native = null;
try {
native = require('../native/plonk_napi.node');
} catch (e) {
// native not available, keep WASM
}

function snakeToCamel(name) {
return name.replace(/_([a-z])/g, function (_match, ch) {
return ch.toUpperCase();
});
}

function override(functionName) {
if (!native) return;
var camel = snakeToCamel(functionName);
var impl = native[functionName] || native[camel];
if (typeof impl === 'function') {
plonk_wasm[functionName] = impl;
}
}

// Overwrite only the functions that are already available in native
override('caml_pasta_fp_poseidon_block_cipher');
override('caml_pasta_fq_poseidon_block_cipher');
6 changes: 4 additions & 2 deletions src/lib/crypto/kimchi_bindings/stubs/kimchi_bindings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ module Protocol = struct
-> SRS.Fp.t
-> bool
-> t
= "caml_pasta_fp_plonk_index_create_bytecode" "caml_pasta_fp_plonk_index_create"
= "caml_pasta_fp_plonk_index_create_bytecode"
"caml_pasta_fp_plonk_index_create"

external max_degree : t -> int = "caml_pasta_fp_plonk_index_max_degree"

Expand Down Expand Up @@ -250,7 +251,8 @@ module Protocol = struct
-> SRS.Fq.t
-> bool
-> t
= "caml_pasta_fq_plonk_index_create_bytecode" "caml_pasta_fq_plonk_index_create"
= "caml_pasta_fq_plonk_index_create_bytecode"
"caml_pasta_fq_plonk_index_create"

external max_degree : t -> int = "caml_pasta_fq_plonk_index_max_degree"

Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto/proof-systems
Submodule proof-systems updated 84 files
+1 −1 .github/actions/ocaml-shared/action.yml
+4 −1 .github/actions/toolchain-shared/action.yml
+8 −1 .github/workflows/benches-mina-prover-set-baseline.yml
+2 −2 .github/workflows/benches-mina-prover.yml
+1 −1 .github/workflows/benches.yml
+2 −2 .github/workflows/ci-nightly.yml
+2 −2 .github/workflows/ci.yml
+1 −1 .github/workflows/o1vm-ci.yml
+3 −3 .github/workflows/saffron.yml
+137 −0 .github/workflows/test-export-vectors.yml
+1 −1 CONTRIBUTING.md
+122 −16 Cargo.lock
+11 −7 Cargo.toml
+2 −2 arrabbiata/src/interpreter.rs
+2 −2 arrabbiata/src/witness.rs
+16 −0 crates/arkworks/src/group_affine.rs
+1 −1 folding/src/instance_witness.rs
+260 −1 hasher/src/roinput.rs
+4 −0 kimchi-stubs/src/pasta_fp_plonk_proof.rs
+4 −0 kimchi-stubs/src/pasta_fq_plonk_proof.rs
+3 −2 kimchi/Cargo.toml
+0 −1 kimchi/src/circuits/constraints.rs
+2 −2 kimchi/src/tests/framework.rs
+2 −2 kimchi/src/tests/lazy_mode.rs
+40 −0 kimchi/tests/test_constraints.rs
+2 −2 msm/src/logup.rs
+1 −1 msm/src/serialization/interpreter.rs
+18 −0 o1vm/LICENSE-APACHE
+21 −0 o1vm/LICENSE-MIT
+11 −0 o1vm/README.md
+1 −1 o1vm/src/interpreters/mips/tests.rs
+1 −1 o1vm/src/interpreters/mips/witness.rs
+1 −1 o1vm/src/interpreters/riscv32im/tests.rs
+1 −1 o1vm/src/interpreters/riscv32im/witness.rs
+43 −0 plonk-napi/Cargo.toml
+3 −0 plonk-napi/build.rs
+6 −0 plonk-napi/src/lib.rs
+56 −0 plonk-napi/src/poseidon.rs
+1 −1 plonk-wasm/Cargo.toml
+3 −2 plonk-wasm/src/lib.rs
+3 −3 plonk-wasm/src/wasm_ocaml_serde/mod.rs
+34 −0 plonk-wasm/src/wasm_vector.rs
+7 −6 poly-commitment/src/combine.rs
+15 −12 poly-commitment/src/commitment.rs
+3 −2 poly-commitment/src/hash_map_cache.rs
+50 −36 poly-commitment/src/ipa.rs
+15 −10 poly-commitment/src/kzg.rs
+6 −5 poly-commitment/src/pbt_srs.rs
+1 −1 poly-commitment/src/precomputed_srs.rs
+0 −172 poly-commitment/tests/batch_15_wires.rs
+155 −2 poly-commitment/tests/ipa_commitment.rs
+4 −4 poseidon/export_test_vectors/Cargo.toml
+74 −0 poseidon/export_test_vectors/README.md
+134 −71 poseidon/export_test_vectors/src/main.rs
+204 −4 poseidon/export_test_vectors/src/vectors.rs
+36 −0 poseidon/export_test_vectors/test_vectors/b10_kimchi.js
+49 −0 poseidon/export_test_vectors/test_vectors/b10_kimchi.json
+36 −0 poseidon/export_test_vectors/test_vectors/b10_legacy.js
+49 −0 poseidon/export_test_vectors/test_vectors/b10_legacy.json
+36 −0 poseidon/export_test_vectors/test_vectors/hex_kimchi.js
+49 −0 poseidon/export_test_vectors/test_vectors/hex_kimchi.json
+36 −0 poseidon/export_test_vectors/test_vectors/hex_legacy.js
+49 −0 poseidon/export_test_vectors/test_vectors/hex_legacy.json
+0 −1 rust-toolchain
+2 −0 rust-toolchain.toml
+1 −3 saffron/Cargo.toml
+1 −1 saffron/README.md
+8 −9 saffron/benches/folding_bench.rs
+44 −54 saffron/benches/read_proof_bench.rs
+1 −1 saffron/og-flow/main.rs
+10 −48 saffron/src/blob.rs
+78 −9 saffron/src/commitment.rs
+15 −13 saffron/src/diff.rs
+169 −0 saffron/src/encoding.rs
+50 −54 saffron/src/folding.rs
+11 −10 saffron/src/lib.rs
+11 −12 saffron/src/main.rs
+216 −100 saffron/src/read_proof.rs
+237 −0 saffron/src/storage.rs
+31 −34 saffron/src/storage_proof.rs
+27 −109 saffron/src/utils.rs
+9 −0 scripts/bench-criterion-mina-circuits.sh
+5 −2 utils/Cargo.toml
+2 −2 utils/src/lazy_cache.rs
6 changes: 2 additions & 4 deletions src/lib/pickles/plonk_checks/scalars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2831,8 +2831,7 @@ module Tick : S = struct
+ if_feature
( LookupPattern RangeCheck
, (fun () ->
cell (var (LookupKindIndex RangeCheck, Curr))
)
cell (var (LookupKindIndex RangeCheck, Curr)) )
, fun () ->
field
"0x0000000000000000000000000000000000000000000000000000000000000000"
Expand All @@ -2842,8 +2841,7 @@ module Tick : S = struct
, (fun () ->
cell
(var
(LookupKindIndex ForeignFieldMul, Curr) )
)
(LookupKindIndex ForeignFieldMul, Curr) ) )
, fun () ->
field
"0x0000000000000000000000000000000000000000000000000000000000000000"
Expand Down