Skip to content

Commit 85d507f

Browse files
Added a linter, and moving towards a better standard
1 parent 7bbb7c9 commit 85d507f

File tree

9 files changed

+65
-128
lines changed

9 files changed

+65
-128
lines changed

src/lib/.oxlintrc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": [
3+
"oxlint/recommended"
4+
],
5+
"rules": {
6+
"erasing-op": "off",
7+
"no-new-array": "off",
8+
"no-this-alias": "off",
9+
"no-unsafe-finally": "off",
10+
"no-unused-labels": "off",
11+
"no-useless-escape": "off",
12+
"no-wrapper-object-types": "off"
13+
}
14+
}

src/lib/proof-system/lazy-mode.unit-test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import { Field } from '../provable/field.js';
1+
import { spawn } from 'child_process';
2+
import { basename, dirname, join } from 'path';
3+
import { fileURLToPath } from 'url';
4+
import { wasm } from '../../bindings.js';
25
import { Cache } from '../proof-system/cache.js';
36
import { ZkProgram } from '../proof-system/zkprogram.js';
4-
import { Spec, fieldWithRng } from '../testing/equivalent.js';
5-
import { Random } from '../testing/property.js';
7+
import { Field } from '../provable/field.js';
68
import { assert } from '../provable/gadgets/common.js';
79
import { Gadgets } from '../provable/gadgets/gadgets.js';
8-
import { wasm } from '../../bindings.js';
9-
import { spawn } from 'child_process';
10-
import { fileURLToPath } from 'url';
11-
import { dirname, join, basename } from 'path';
1210

1311
// Path resolution for subprocess execution
1412
const __filename = fileURLToPath(import.meta.url);
@@ -22,10 +20,6 @@ function getMemory() {
2220
};
2321
}
2422

25-
let uint = (n: number | bigint): Spec<bigint, Field> => {
26-
return fieldWithRng(Random.bignat((1n << BigInt(n)) - 1n));
27-
};
28-
2923
// Dummy circuit
3024
let LazyMode = ZkProgram({
3125
name: 'lazy-mode',
@@ -82,7 +76,11 @@ function runSubprocess(lazyMode: boolean): Promise<void> {
8276
});
8377
child.on('exit', (code) => {
8478
console.log(`(Parent) Process lazyMode=${lazyMode} exited with code ${code}`);
85-
code === 0 ? resolve() : reject(new Error(`Test failed for lazyMode=${lazyMode}`));
79+
if (code === 0) {
80+
resolve()
81+
} else {
82+
reject(new Error(`Test failed for lazyMode=${lazyMode}`))
83+
}
8684
});
8785
});
8886
}

src/lib/proof-system/recursive.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { InferProvable } from '../provable/types/struct.js';
1+
import { From } from '../../bindings/lib/provable-generic.js';
2+
import { Bool } from '../provable/bool.js';
23
import { Provable } from '../provable/provable.js';
34
import { ProvableType } from '../provable/types/provable-intf.js';
5+
import { InferProvable } from '../provable/types/struct.js';
6+
import { mapObject, mapToObject, zip } from '../util/arrays.js';
47
import { Tuple } from '../util/types.js';
58
import { Proof } from './proof.js';
6-
import { mapObject, mapToObject, zip } from '../util/arrays.js';
79
import { Undefined, Void } from './zkprogram.js';
8-
import { Bool } from '../provable/bool.js';
9-
import { From } from '../../bindings/lib/provable-generic.js';
1010

1111
export { Recursive };
1212

@@ -34,20 +34,20 @@ function Recursive<
3434
}>;
3535
}
3636
): {
37-
[Key in keyof PrivateInputs]: RecursiveProver<
38-
InferProvable<PublicInputType>,
39-
PublicInputType,
40-
InferProvable<PublicOutputType>,
41-
PrivateInputs[Key]
42-
> & {
43-
if: ConditionalRecursiveProver<
37+
[Key in keyof PrivateInputs]: RecursiveProver<
4438
InferProvable<PublicInputType>,
4539
PublicInputType,
4640
InferProvable<PublicOutputType>,
4741
PrivateInputs[Key]
48-
>;
49-
};
50-
} {
42+
> & {
43+
if: ConditionalRecursiveProver<
44+
InferProvable<PublicInputType>,
45+
PublicInputType,
46+
InferProvable<PublicOutputType>,
47+
PrivateInputs[Key]
48+
>;
49+
};
50+
} {
5151
type PublicInput = InferProvable<PublicInputType>;
5252
type PublicOutput = InferProvable<PublicOutputType>;
5353
type MethodKey = keyof PrivateInputs;
@@ -69,7 +69,7 @@ function Recursive<
6969

7070
let methodKeys: MethodKey[] = Object.keys(methods);
7171

72-
let regularRecursiveProvers = mapToObject(methodKeys, (key, i) => {
72+
let regularRecursiveProvers = mapToObject(methodKeys, (key) => {
7373
return async function proveRecursively_(
7474
conditionAndConfig: Bool | { condition: Bool; domainLog2?: number },
7575
publicInput: PublicInput,
@@ -175,14 +175,14 @@ type ConditionalRecursiveProver<
175175
Args extends Tuple<ProvableType>,
176176
> = PublicInput extends undefined
177177
? (
178-
condition: Bool | { condition: Bool; domainLog2?: number },
179-
...args: TupleFrom<Args>
180-
) => Promise<PublicOutput>
178+
condition: Bool | { condition: Bool; domainLog2?: number },
179+
...args: TupleFrom<Args>
180+
) => Promise<PublicOutput>
181181
: (
182-
condition: Bool | { condition: Bool; domainLog2?: number },
183-
publicInput: From<PublicInputType>,
184-
...args: TupleFrom<Args>
185-
) => Promise<PublicOutput>;
182+
condition: Bool | { condition: Bool; domainLog2?: number },
183+
publicInput: From<PublicInputType>,
184+
...args: TupleFrom<Args>
185+
) => Promise<PublicOutput>;
186186

187187
type TupleFrom<T> = {
188188
[I in keyof T]: From<T[I]>;

src/lib/provable/gadgets/blake2b.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { FlexibleBytes } from '../bytes.js';
44
import { Bytes } from '../wrapped-classes.js';
55
import { Gadgets } from './gadgets.js';
66
import { assert } from '../../util/errors.js';
7-
import { Provable } from '../provable.js';
87
import { wordToBytes } from './bit-slices.js';
98

109
export { BLAKE2B };

src/lib/provable/group.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { Field } from './field.js';
2-
import { FieldVar } from './core/fieldvar.js';
3-
import { Scalar } from './scalar.js';
4-
import { Fp } from '../../bindings/crypto/finite-field.js';
51
import { GroupAffine, Pallas, PallasAffine } from '../../bindings/crypto/elliptic-curve.js';
6-
import { Provable } from './provable.js';
7-
import { Bool } from './bool.js';
2+
import { Fp } from '../../bindings/crypto/finite-field.js';
83
import { assert } from '../util/assert.js';
4+
import { FieldVar } from './core/fieldvar.js';
5+
import { Field } from './field.js';
96
import { add, scaleField, scaleShifted } from './gadgets/native-curve.js';
7+
import { Provable } from './provable.js';
8+
import { Scalar } from './scalar.js';
109

1110
export { Group };
1211

@@ -265,7 +264,7 @@ class Group {
265264
*
266265
* Returns an empty array.
267266
*/
268-
static toAuxiliary(g?: Group) {
267+
static toAuxiliary(_?: Group) {
269268
return [];
270269
}
271270

src/lib/provable/packed.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { mapValue, provableFromClass } from './types/provable-derivers.js';
2-
import { HashInput, ProvableExtended } from './types/struct.js';
3-
import { Unconstrained } from './types/unconstrained.js';
1+
import { Poseidon, ProvableHashable, packToFields } from './crypto/poseidon.js';
42
import { Field } from './field.js';
53
import { assert } from './gadgets/common.js';
6-
import { Poseidon, ProvableHashable, packToFields } from './crypto/poseidon.js';
74
import { Provable } from './provable.js';
85
import { fields, modifiedField } from './types/fields.js';
6+
import { mapValue, provableFromClass } from './types/provable-derivers.js';
97
import { ProvableType, WithProvable } from './types/provable-intf.js';
8+
import { HashInput } from './types/struct.js';
9+
import { Unconstrained } from './types/unconstrained.js';
1010

11-
export { Packed, Hashed };
11+
export { Hashed, Packed };
1212

1313
/**
1414
* `Packed<T>` is a "packed" representation of any type `T`.

src/lib/provable/test/blake2b.unit-test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { ZkProgram } from '../../proof-system/zkprogram.js';
2-
import { Bytes } from '../wrapped-classes.js';
3-
import { Gadgets } from '../gadgets/gadgets.js';
41
import { blake2b as nobleBlake2b } from '@noble/hashes/blake2b';
5-
import { bytes } from './test-utils.js';
2+
import { ZkProgram } from '../../proof-system/zkprogram.js';
63
import { equivalentAsync, equivalentProvable } from '../../testing/equivalent.js';
74
import { Random, sample } from '../../testing/random.js';
8-
import { expect } from 'expect';
5+
import { Gadgets } from '../gadgets/gadgets.js';
6+
import { Bytes } from '../wrapped-classes.js';
7+
import { bytes } from './test-utils.js';
98

109
sample(Random.nat(400), 5).forEach((preimageLength) => {
1110
let inputBytes = bytes(preimageLength);
@@ -23,7 +22,7 @@ for (let { digest_length, preimage, hash } of testVectors()) {
2322
let outputBytes = bytes(digest_length);
2423
equivalentProvable({ from: [inputBytes], to: outputBytes, verbose: true })(
2524
() => Bytes.fromHex(hash).toBytes(),
26-
(x) => Gadgets.BLAKE2B.hash(Bytes.fromString(preimage), digest_length),
25+
() => Gadgets.BLAKE2B.hash(Bytes.fromString(preimage), digest_length),
2726
`provable: blake2b preimage length ${preimage.length}`
2827
);
2928
}

src/lib/provable/test/group.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Bool, Group, Scalar, Provable } from 'o1js';
1+
import { Bool, Group, Provable, Scalar } from 'o1js';
22

33
describe('group', () => {
44
let g = Group({ x: -1, y: 2 });
@@ -359,7 +359,7 @@ describe('group', () => {
359359
});
360360

361361
it('sub', () => {
362-
let y = Provable.witness(Group, () => g).assertEquals(Provable.witness(Group, () => g));
362+
Provable.witness(Group, () => g).assertEquals(Provable.witness(Group, () => g));
363363
g.assertEquals(g);
364364
});
365365
});

src/lib/provable/test/string.unit-test.ts

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -40,66 +40,6 @@ describe('Circuit String', () => {
4040
});
4141
});
4242

43-
/* describe('#contains', () => {
44-
test('returns true when str contains other str', () => {
45-
const str = CircuitString.fromString(
46-
'Everything we hear is an opinion, not a fact. Everything we see is a perspective, not the truth'
47-
);
48-
const contained_str = CircuitString.fromString(
49-
'Everything we hear is an opinion, not a fact.'
50-
);
51-
expect(str.contains(contained_str)).toEqual(new Bool(true));
52-
53-
await Provable.runAndCheck(() => {
54-
const str = CircuitString.fromString(
55-
'Everything we hear is an opinion, not a fact. Everything we see is a perspective, not the truth'
56-
);
57-
const contained_str = CircuitString.fromString(
58-
'Everything we hear is an opinion, not a fact.'
59-
);
60-
expect(str.contains(contained_str)).toEqual(new Bool(true));
61-
});
62-
});
63-
64-
test('returns false when str does not contain other str', () => {
65-
const str = CircuitString.fromString('abcdefghijklmnop');
66-
const not_contained_str = CircuitString.fromString('defhij');
67-
expect(str.contains(not_contained_str)).toEqual(new Bool(false));
68-
69-
await Provable.runAndCheck(() => {
70-
const str = CircuitString.fromString('abcdefghijklmnop');
71-
const not_contained_str = CircuitString.fromString('defhij');
72-
expect(str.contains(not_contained_str)).toEqual(new Bool(false));
73-
});
74-
});
75-
76-
describe('compatibility with implementing classes', () => {
77-
test('string8 may contain string', () => {
78-
const str = CircuitString8.fromString('abcd');
79-
const contained_str = CircuitString.fromString('ab');
80-
expect(str.contains(contained_str)).toEqual(new Bool(true));
81-
82-
await Provable.runAndCheck(() => {
83-
const str = CircuitString8.fromString('abcd');
84-
const contained_str = CircuitString.fromString('ab');
85-
expect(str.contains(contained_str)).toEqual(new Bool(true));
86-
});
87-
});
88-
89-
test('string may contain string8', () => {
90-
const str = CircuitString.fromString('abcd');
91-
const contained_str = CircuitString8.fromString('ab');
92-
expect(str.contains(contained_str)).toEqual(new Bool(true));
93-
94-
await Provable.runAndCheck(() => {
95-
const str = CircuitString.fromString('abcd');
96-
const contained_str = CircuitString8.fromString('ab');
97-
expect(str.contains(contained_str)).toEqual(new Bool(true));
98-
});
99-
});
100-
});
101-
}); */
102-
10343
describe('#toString', () => {
10444
test('serializes to string', async () => {
10545
const js_str =
@@ -158,23 +98,11 @@ describe('Circuit String', () => {
15898
});
15999
});
160100

161-
/* describe('CircuitString8', async () => {
162-
test('cannot create more than 8 chars', () => {
163-
expect(() => {
164-
await Provable.runAndCheck(() => {
165-
Provable.witness(CircuitString8, () => {
166-
return CircuitString8.fromString('More than eight chars');
167-
});
168-
});
169-
}).toThrow();
170-
});
171-
}); */
172-
173101
describe.skip('with invalid input', () => {
174102
test('cannot use a character out of range', () => {
175103
expect(() => {
176104
Provable.runAndCheck(() => {
177-
const str = Provable.witness(CircuitString, () => {
105+
Provable.witness(CircuitString, () => {
178106
return CircuitString.fromCharacters([
179107
new Character(Field(100)),
180108
new Character(Field(10000)),

0 commit comments

Comments
 (0)