Skip to content

Commit adf2502

Browse files
Trivo25querolita
authored andcommitted
proxy for native conversion core (wip)
1 parent bd06311 commit adf2502

File tree

7 files changed

+56
-39
lines changed

7 files changed

+56
-39
lines changed

src/lib/crypto/kimchi_bindings/js/bindings/oracles.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* global plonk_wasm, tsRustConversion,
2-
3-
*/
1+
/* global plonk_wasm, tsRustConversion,*/
42

53
// Provides: fp_oracles_create
64
// Requires: plonk_wasm, tsRustConversion
@@ -75,31 +73,3 @@ function caml_pasta_fp_poseidon_params_create() {
7573
function caml_pasta_fq_poseidon_params_create() {
7674
return [0];
7775
}
78-
79-
// Provides: caml_pasta_fp_poseidon_block_cipher
80-
// Requires: plonk_wasm, tsRustConversion, tsRustConversion
81-
function caml_pasta_fp_poseidon_block_cipher(_fake_params, fp_vector) {
82-
// 1. get permuted field vector from rust
83-
var wasm_flat_vector = plonk_wasm.caml_pasta_fp_poseidon_block_cipher(
84-
tsRustConversion.fp.vectorToRust(fp_vector)
85-
);
86-
var new_fp_vector = tsRustConversion.fp.vectorFromRust(wasm_flat_vector);
87-
// 2. write back modified field vector to original one
88-
new_fp_vector.forEach(function (a, i) {
89-
fp_vector[i] = a;
90-
});
91-
}
92-
93-
// Provides: caml_pasta_fq_poseidon_block_cipher
94-
// Requires: plonk_wasm, tsRustConversion, tsRustConversion
95-
function caml_pasta_fq_poseidon_block_cipher(_fake_params, fq_vector) {
96-
// 1. get permuted field vector from rust
97-
var wasm_flat_vector = plonk_wasm.caml_pasta_fq_poseidon_block_cipher(
98-
tsRustConversion.fq.vectorToRust(fq_vector)
99-
);
100-
var new_fq_vector = tsRustConversion.fq.vectorFromRust(wasm_flat_vector);
101-
// 2. write back modified field vector to original one
102-
new_fq_vector.forEach(function (a, i) {
103-
fq_vector[i] = a;
104-
});
105-
}

src/lib/crypto/kimchi_bindings/js/bindings/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global UInt64, caml_int64_of_int32, caml_create_bytes,
22
caml_bytes_unsafe_set, caml_bytes_unsafe_get, caml_ml_bytes_length,
3-
plonk_wasm
3+
plonk_wasm, getTsBindings
44
*/
55

66
// Provides: tsBindings

src/lib/crypto/kimchi_bindings/js/dune

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
bindings/prover-index.js
1515
bindings/util.js
1616
bindings/srs.js
17-
bindings/verifier-index.js))
17+
bindings/verifier-index.js
18+
native/native-overrides/oracles.js
19+
native/native-overrides/util.js
20+
))
1821
(instrumentation
1922
(backend bisect_ppx))
2023
(preprocess
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* global plonk_wasm, tsRustConversionNative,*/
2+
3+
4+
// Provides: caml_pasta_fq_poseidon_block_cipher
5+
// Requires: plonk_wasm, tsRustConversionNative
6+
function caml_pasta_fq_poseidon_block_cipher(_fake_params, fq_vector) {
7+
8+
console.log("overriding the old wasm caml_pasta_fq_poseidon_block_cipher, now using the native one")
9+
10+
// 1. get permuted field vector from rust
11+
var wasm_flat_vector = plonk_wasm.caml_pasta_fq_poseidon_block_cipher(
12+
tsRustConversionNative.fq.vectorToRust(fq_vector)
13+
);
14+
var new_fq_vector = tsRustConversionNative.fq.vectorFromRust(wasm_flat_vector);
15+
// 2. write back modified field vector to original one
16+
new_fq_vector.forEach(function (a, i) {
17+
fq_vector[i] = a;
18+
});
19+
}
20+
21+
22+
// Provides: caml_pasta_fp_poseidon_block_cipher
23+
// Requires: plonk_wasm, tsRustConversionNative
24+
function caml_pasta_fp_poseidon_block_cipher(_fake_params, fp_vector) {
25+
26+
console.log("overriding the old wasm caml_pasta_fp_poseidon_block_cipher, now using the native one")
27+
28+
29+
// 1. get permuted field vector from rust
30+
var wasm_flat_vector = plonk_wasm.caml_pasta_fp_poseidon_block_cipher(
31+
tsRustConversionNative.fp.vectorToRust(fp_vector)
32+
);
33+
var new_fp_vector = tsRustConversionNative.fp.vectorFromRust(wasm_flat_vector);
34+
// 2. write back modified field vector to original one
35+
new_fp_vector.forEach(function (a, i) {
36+
fp_vector[i] = a;
37+
});
38+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* global plonk_wasm, tsRustConversionNative, getTsBindings, tsBindings */
2+
3+
4+
// Provides: tsRustConversionNative
5+
// Requires: tsBindings, plonk_wasm, getTsBindings
6+
var tsRustConversionNative = tsBindings.nativeRustConversion(plonk_wasm);

src/lib/crypto/kimchi_bindings/stubs/kimchi_bindings.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ module Protocol = struct
215215
-> SRS.Fp.t
216216
-> bool
217217
-> t
218-
= "caml_pasta_fp_plonk_index_create_bytecode" "caml_pasta_fp_plonk_index_create"
218+
= "caml_pasta_fp_plonk_index_create_bytecode"
219+
"caml_pasta_fp_plonk_index_create"
219220

220221
external max_degree : t -> int = "caml_pasta_fp_plonk_index_max_degree"
221222

@@ -250,7 +251,8 @@ module Protocol = struct
250251
-> SRS.Fq.t
251252
-> bool
252253
-> t
253-
= "caml_pasta_fq_plonk_index_create_bytecode" "caml_pasta_fq_plonk_index_create"
254+
= "caml_pasta_fq_plonk_index_create_bytecode"
255+
"caml_pasta_fq_plonk_index_create"
254256

255257
external max_degree : t -> int = "caml_pasta_fq_plonk_index_max_degree"
256258

src/lib/pickles/plonk_checks/scalars.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,8 +2831,7 @@ module Tick : S = struct
28312831
+ if_feature
28322832
( LookupPattern RangeCheck
28332833
, (fun () ->
2834-
cell (var (LookupKindIndex RangeCheck, Curr))
2835-
)
2834+
cell (var (LookupKindIndex RangeCheck, Curr)) )
28362835
, fun () ->
28372836
field
28382837
"0x0000000000000000000000000000000000000000000000000000000000000000"
@@ -2842,8 +2841,7 @@ module Tick : S = struct
28422841
, (fun () ->
28432842
cell
28442843
(var
2845-
(LookupKindIndex ForeignFieldMul, Curr) )
2846-
)
2844+
(LookupKindIndex ForeignFieldMul, Curr) ) )
28472845
, fun () ->
28482846
field
28492847
"0x0000000000000000000000000000000000000000000000000000000000000000"

0 commit comments

Comments
 (0)