Skip to content

Commit c39f24e

Browse files
authored
Merge pull request #2243 from o1-labs/florian/prettier-for-bindings
Adjust prettier for bindings
2 parents edfd391 + b26d0db commit c39f24e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1284
-1868
lines changed

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ benchmark/
44
dist/
55
node_modules/
66
o1js-reference/
7-
src/bindings/
7+
src/bindings/mina-transaction/gen/
8+
src/bindings/compiled/
89
src/mina/
910
**/*.d.ts

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2222
### Added
2323

2424
- [PR! 1905](https://github.com/o1-labs/o1js/pull/1905) API support for circuit chunking
25-
- work in progress - still requires memory optimizations to be fully functional
25+
- still requires memory optimizations to be fully functional, and
26+
- proof-systems version still needs to be updated to include [this commit](https://github.com/o1-labs/proof-systems/pull/3222/commits/8c37c293f8159eed3676964ba47fc5dc0ae6ea1e)
2627
- [PR !1848](https://github.com/o1-labs/o1js/pull/1848) Dynamic array provable type
2728

2829
## [2.5.0](https://github.com/o1-labs/o1js/compare/6ff7f8470a...4e23a60)

README-nix.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ On macos the first time you run this command, you can expect it to take hours (o
9292
Then, you will observe that the current devshell becomes a Nix shell with the right
9393
configuration for `o1js` and `mina`.
9494
95-
9695
From within the shell, you can build o1js and update the bindings.
9796
9897
```console

src/bindings/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
This directory collects code required by o1js to bind to lower layers of the proof system and the Mina transaction logic, which are written in Rust and OCaml.
44

5-
65
**Directory structure**
76

87
- `/compiled` - compiled JS and Wasm artifacts produced by `js_of_ocaml` and `wasm-bindgen` from Rust and OCaml source code. We keep these artifacts in the source tree so that developing on o1js can be done with standard JS tooling and doesn't require setting up the full OCaml/Rust build pipeline.
@@ -12,4 +11,3 @@ This directory collects code required by o1js to bind to lower layers of the pro
1211
- `/mina-transaction` - TS types and modules that specialize the generic tooling in `/lib` to Mina's zkApp protocol; mostly auto-generated from OCaml.
1312
- `/ocaml` - OCaml library exposing Snarky, Pickles and parts of the Mina transaction logic to JS. Also, OCaml scripts that help auto-generate TypeScript for Mina- and crypto-related types and constants.
1413
- `/scripts` - scripts that build parts of o1js from their OCaml and Rust sources, including the contents of `/compiled` and other generated TS files.
15-

src/bindings/crypto/bigint.unit-test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ test(Random.field, (x) => testBigintRoundtrip(x, fieldSize));
3737
// failure cases
3838
expect(() => bigIntToBytes(256n, 1)).toThrow(/does not fit in 1 bytes/);
3939
expect(() => bigIntToBytes(100_000n, 2)).toThrow(/does not fit in 2 bytes/);
40-
expect(() => bigIntToBytes(4n * Fp.modulus, 32)).toThrow(
41-
/does not fit in 32 bytes/
42-
);
40+
expect(() => bigIntToBytes(4n * Fp.modulus, 32)).toThrow(/does not fit in 32 bytes/);
4341

4442
// parseHexString32
4543

src/bindings/crypto/bindings.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import { PallasBindings, VestaBindings } from './bindings/curve.js';
99
import { FpBindings, FqBindings } from './bindings/field.js';
1010
import { FpVectorBindings, FqVectorBindings } from './bindings/vector.js';
1111
import type * as wasmNamespace from '../compiled/node_bindings/plonk_wasm.cjs';
12-
import {
13-
fieldsFromRustFlat,
14-
fieldsToRustFlat,
15-
} from './bindings/conversion-base.js';
12+
import { fieldsFromRustFlat, fieldsToRustFlat } from './bindings/conversion-base.js';
1613
import { proofConversion } from './bindings/conversion-proof.js';
1714
import { conversionCore } from './bindings/conversion-core.js';
1815
import { verifierIndexConversion } from './bindings/conversion-verifier-index.js';

src/bindings/crypto/bindings/bindings.unit-test.ts

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ import {
1616
toMlStringAscii,
1717
} from './bigint256.js';
1818
import { wasm } from '../../js/node/node-backend.js';
19-
import {
20-
Spec,
21-
ToSpec,
22-
FromSpec,
23-
defaultAssertEqual,
24-
id,
25-
} from '../../../lib/testing/equivalent.js';
19+
import { Spec, ToSpec, FromSpec, defaultAssertEqual, id } from '../../../lib/testing/equivalent.js';
2620
import { Random } from '../../../lib/testing/property.js';
2721
import {
2822
WasmAffine,
@@ -35,18 +29,8 @@ import {
3529
import { equivalentRecord } from './test-utils.js';
3630
import { Field, FpBindings, FqBindings } from './field.js';
3731
import { MlBool, MlOption } from '../../../lib/ml/base.js';
38-
import {
39-
OrInfinity,
40-
PallasBindings,
41-
VestaBindings,
42-
toMlOrInfinity,
43-
} from './curve.js';
44-
import {
45-
GroupProjective,
46-
Pallas,
47-
ProjectiveCurve,
48-
Vesta,
49-
} from '../elliptic-curve.js';
32+
import { OrInfinity, PallasBindings, VestaBindings, toMlOrInfinity } from './curve.js';
33+
import { GroupProjective, Pallas, ProjectiveCurve, Vesta } from '../elliptic-curve.js';
5034
import {
5135
WasmGPallas,
5236
WasmGVesta,
@@ -189,13 +173,7 @@ function projective<WasmP extends WasmProjective, WasmA extends WasmAffine>(
189173
let randomScaled = Random(() => Curve.scale(Curve.one, Scalar.random()));
190174

191175
return {
192-
rng: Random.oneOf(
193-
Curve.zero,
194-
Curve.one,
195-
randomScaled,
196-
randomScaled,
197-
randomScaled
198-
),
176+
rng: Random.oneOf(Curve.zero, Curve.one, randomScaled, randomScaled, randomScaled),
199177
// excessively expensive to work around limited Rust API - only use for tests
200178
there(p: GroupProjective): WasmP {
201179
let { x, y, infinity } = Curve.toAffine(p);
@@ -233,13 +211,7 @@ function affine<WasmA extends WasmAffine>(
233211
affineOne: () => WasmA
234212
): Spec<OrInfinity, WasmA> {
235213
let randomScaled = Random(() => Curve.scale(Curve.one, Scalar.random()));
236-
let rngProjective = Random.oneOf(
237-
Curve.zero,
238-
Curve.one,
239-
randomScaled,
240-
randomScaled,
241-
randomScaled
242-
);
214+
let rngProjective = Random.oneOf(Curve.zero, Curve.one, randomScaled, randomScaled, randomScaled);
243215
let rng = Random.map(rngProjective, (p) => toMlOrInfinity(Curve.toAffine(p)));
244216

245217
return {

src/bindings/crypto/bindings/conversion-base.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ function affineFromRust<A extends WasmAffine>(pt: A): OrInfinity {
7878

7979
const tmpBytes = new Uint8Array(32);
8080

81-
function affineToRust<A extends WasmAffine>(
82-
pt: OrInfinity,
83-
makeAffine: () => A
84-
) {
81+
function affineToRust<A extends WasmAffine>(pt: OrInfinity, makeAffine: () => A) {
8582
let res = makeAffine();
8683
if (pt === Infinity) {
8784
res.infinity = true;

src/bindings/crypto/bindings/conversion-core.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ function conversionCorePerField(
8686

8787
gateToRust(gate: Gate) {
8888
let [, typ, [, ...wires], coeffs] = gate;
89-
let rustWires = new wasm.WasmGateWires(
90-
...mapTuple(wires, self.wireToRust)
91-
);
89+
let rustWires = new wasm.WasmGateWires(...mapTuple(wires, self.wireToRust));
9290
let rustCoeffs = fieldsToRustFlat(coeffs);
9391
return new Gate(typ, rustWires, rustCoeffs);
9492
},
@@ -104,14 +102,10 @@ function conversionCorePerField(
104102
pointFromRust: affineFromRust,
105103

106104
pointsToRust([, ...points]: MlArray<OrInfinity>): Uint32Array {
107-
return mapToUint32Array(points, (point) =>
108-
unwrap(self.pointToRust(point))
109-
);
105+
return mapToUint32Array(points, (point) => unwrap(self.pointToRust(point)));
110106
},
111107
pointsFromRust(points: Uint32Array): MlArray<OrInfinity> {
112-
let arr = mapFromUintArray(points, (ptr) =>
113-
affineFromRust(wrap(ptr, CommitmentCurve))
114-
);
108+
let arr = mapFromUintArray(points, (ptr) => affineFromRust(wrap(ptr, CommitmentCurve)));
115109
return [0, ...arr];
116110
},
117111

@@ -133,9 +127,7 @@ function conversionCorePerField(
133127
return mapToUint32Array(comms, (c) => unwrap(self.polyCommToRust(c)));
134128
},
135129
polyCommsFromRust(rustComms: Uint32Array): MlArray<PolyComm> {
136-
let comms = mapFromUintArray(rustComms, (ptr) =>
137-
self.polyCommFromRust(wrap(ptr, PolyComm))
138-
);
130+
let comms = mapFromUintArray(rustComms, (ptr) => self.polyCommFromRust(wrap(ptr, PolyComm)));
139131
return [0, ...comms];
140132
},
141133
};
@@ -176,18 +168,12 @@ function freeOnFinalize<T extends Freeable>(instance: T) {
176168
// directly, but unfortunately the destructor name is some mangled internal
177169
// string generated by wasm_bindgen. For now, this is the best,
178170
// least-brittle way to free once the original class instance gets collected.
179-
let instanceRepresentative = wrap<T>(
180-
(instance as any).__wbg_ptr,
181-
(instance as any).constructor
182-
);
171+
let instanceRepresentative = wrap<T>((instance as any).__wbg_ptr, (instance as any).constructor);
183172
registry.register(instance, instanceRepresentative, instance);
184173
return instance;
185174
}
186175

187-
function mapFromUintArray<T>(
188-
array: Uint32Array | Uint8Array,
189-
map: (i: number) => T
190-
) {
176+
function mapFromUintArray<T>(array: Uint32Array | Uint8Array, map: (i: number) => T) {
191177
let n = array.length;
192178
let result: T[] = Array(n);
193179
for (let i = 0; i < n; i++) {

src/bindings/crypto/bindings/conversion-oracles.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ import type {
66
} from '../../compiled/node_bindings/plonk_wasm.cjs';
77
import type * as wasmNamespace from '../../compiled/node_bindings/plonk_wasm.cjs';
88
import { MlOption } from '../../../lib/ml/base.js';
9-
import {
10-
Field,
11-
Oracles,
12-
RandomOracles,
13-
ScalarChallenge,
14-
} from './kimchi-types.js';
9+
import { Field, Oracles, RandomOracles, ScalarChallenge } from './kimchi-types.js';
1510
import {
1611
fieldFromRust,
1712
fieldToRust,
@@ -80,11 +75,7 @@ function oraclesConversionPerField({ RandomOracles, Oracles }: WasmClasses) {
8075
let jointCombiner = ro.joint_combiner;
8176
let jointCombinerOption = MlOption<[0, ScalarChallenge, Field]>(
8277
jointCombinerChal &&
83-
jointCombiner && [
84-
0,
85-
[0, fieldFromRust(jointCombinerChal)],
86-
fieldFromRust(jointCombiner),
87-
]
78+
jointCombiner && [0, [0, fieldFromRust(jointCombinerChal)], fieldFromRust(jointCombiner)]
8879
);
8980
let mlRo: RandomOracles = [
9081
0,

0 commit comments

Comments
 (0)