Skip to content

Commit 4c083b0

Browse files
fixed build and overrides
1 parent 1769fde commit 4c083b0

File tree

9 files changed

+49
-63
lines changed

9 files changed

+49
-63
lines changed

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -69,34 +69,6 @@ var caml_pasta_fp_plonk_proof_deep_copy = function (proof) {
6969
);
7070
};
7171

72-
// Provides: caml_pasta_fq_plonk_proof_create
73-
// Requires: plonk_wasm, tsRustConversion
74-
var caml_pasta_fq_plonk_proof_create = function (
75-
index,
76-
witness_cols,
77-
caml_runtime_tables,
78-
prev_challenges,
79-
prev_sgs
80-
) {
81-
var w = new plonk_wasm.WasmVecVecFq(witness_cols.length - 1);
82-
for (var i = 1; i < witness_cols.length; i++) {
83-
w.push(tsRustConversion.fq.vectorToRust(witness_cols[i]));
84-
}
85-
witness_cols = w;
86-
prev_challenges = tsRustConversion.fq.vectorToRust(prev_challenges);
87-
var wasm_runtime_tables =
88-
tsRustConversion.fq.runtimeTablesToRust(caml_runtime_tables);
89-
prev_sgs = tsRustConversion.fq.pointsToRust(prev_sgs);
90-
var proof = plonk_wasm.caml_pasta_fq_plonk_proof_create(
91-
index,
92-
witness_cols,
93-
wasm_runtime_tables,
94-
prev_challenges,
95-
prev_sgs
96-
);
97-
return tsRustConversion.fq.proofFromRust(proof);
98-
};
99-
10072
// Provides: caml_pasta_fq_plonk_proof_verify
10173
// Requires: plonk_wasm, tsRustConversion
10274
var caml_pasta_fq_plonk_proof_verify = function (index, proof) {

src/lib/crypto/kimchi_bindings/js/dune

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
bindings/verifier-index.js
1818
native/native-overrides/oracles.js
1919
native/native-overrides/util.js
20-
native/native-overrides/circuit.js))
20+
native/native-overrides/circuit.js
21+
native/native-overrides/pasta-plonk-proof.js))
2122
(instrumentation
2223
(backend bisect_ppx))
2324
(preprocess
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* global plonk_wasm, tsRustConversionNative,*/
2+
3+
// Provides: caml_pasta_fq_plonk_proof_create
4+
// Requires: plonk_napi, tsRustConversionNative
5+
var caml_pasta_fq_plonk_proof_create = function (
6+
index,
7+
witness_cols,
8+
caml_runtime_tables,
9+
prev_challenges,
10+
prev_sgs
11+
) {
12+
console.log("overriding wasm caml_pasta_fq_plonk_proof_create with native")
13+
14+
var proof = plonk_napi.caml_pasta_fq_plonk_proof_create(
15+
index,
16+
witness_cols,
17+
caml_runtime_tables,
18+
prev_challenges,
19+
prev_sgs
20+
);
21+
22+
return tsRustConversion.fq.proofFromRust(proof);
23+
};
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
// Provides: plonk_napi
2-
var plonk_napi = require('@o1labs/o1js-darwin-arm64');
3-
4-
module.exports = plonk_napi;
2+
var plonk_napi = require('@o1js/native-' + process.platform + '-' + process.arch)
Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
11
// Provides: plonk_wasm
2-
var plonk_wasm = require('./plonk_wasm.js');
3-
var native = null;
4-
try {
5-
native = require(`@o1labs/o1js-${process.platform}-${process.arch}`);
6-
} catch (e) {
7-
// native not available, keep WASM
8-
}
2+
var plonk_wasm = (function() {
3+
var wasm = require('./plonk_wasm.js');
94

10-
function snakeToCamel(name) {
11-
return name.replace(/_([a-z])/g, function (_match, ch) {
12-
return ch.toUpperCase();
13-
});
14-
}
5+
try {
6+
var native = require('@o1js/native-' + process.platform + '-' + process.arch)
157

16-
function override(functionName) {
17-
if (!native) return;
18-
var camel = snakeToCamel(functionName);
19-
var impl = native[functionName] || native[camel];
20-
if (typeof impl === 'function') {
21-
plonk_wasm[functionName] = impl;
8+
wasm["caml_pasta_fp_poseidon_block_cipher"] = native["caml_pasta_fp_poseidon_block_cipher"]
9+
wasm["caml_pasta_fq_poseidon_block_cipher"] = native["caml_pasta_fq_poseidon_block_cipher"]
10+
} catch (e) {
11+
console.error(e)
12+
console.log("native didn't load")
13+
process.exit(1);
2214
}
23-
}
2415

25-
// Overwrite only the functions that are already available in native
26-
override('caml_pasta_fp_poseidon_block_cipher');
27-
override('caml_pasta_fq_poseidon_block_cipher');
28-
override('prover_to_json');
29-
override('prover_index_from_bytes');
16+
return wasm
17+
})()
18+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
// Provides: plonk_wasm
22
var plonk_wasm = globalThis.plonk_wasm;
3+
4+
// Provides: plonk_napi
5+
var plonk_napi = globalThis.plonk_wasm

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

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

221220
external max_degree : t -> int = "caml_pasta_fp_plonk_index_max_degree"
222221

@@ -251,8 +250,7 @@ module Protocol = struct
251250
-> SRS.Fq.t
252251
-> bool
253252
-> t
254-
= "caml_pasta_fq_plonk_index_create_bytecode"
255-
"caml_pasta_fq_plonk_index_create"
253+
= "caml_pasta_fq_plonk_index_create_bytecode" "caml_pasta_fq_plonk_index_create"
256254

257255
external max_degree : t -> int = "caml_pasta_fq_plonk_index_max_degree"
258256

src/lib/pickles/plonk_checks/scalars.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,7 +2831,8 @@ module Tick : S = struct
28312831
+ if_feature
28322832
( LookupPattern RangeCheck
28332833
, (fun () ->
2834-
cell (var (LookupKindIndex RangeCheck, Curr)) )
2834+
cell (var (LookupKindIndex RangeCheck, Curr))
2835+
)
28352836
, fun () ->
28362837
field
28372838
"0x0000000000000000000000000000000000000000000000000000000000000000"
@@ -2841,7 +2842,8 @@ module Tick : S = struct
28412842
, (fun () ->
28422843
cell
28432844
(var
2844-
(LookupKindIndex ForeignFieldMul, Curr) ) )
2845+
(LookupKindIndex ForeignFieldMul, Curr) )
2846+
)
28452847
, fun () ->
28462848
field
28472849
"0x0000000000000000000000000000000000000000000000000000000000000000"

0 commit comments

Comments
 (0)