Skip to content

Commit a8bd45a

Browse files
committed
Lint main src directory files
1 parent 32a8af8 commit a8bd45a

File tree

6 files changed

+50
-43
lines changed

6 files changed

+50
-43
lines changed

src/bitwise.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ describe('Bitwise Operation Tests', () => {
3030
specific = false,
3131
rotrExpected?: bigint
3232
) => {
33-
const rotrActual = rotateRight32(UInt32.from(input), rotationBits).value.toBigInt();
33+
const rotrActual = rotateRight32(
34+
UInt32.from(input),
35+
rotationBits
36+
).value.toBigInt();
3437
if (specific) {
3538
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3639
expect(rotrActual).toBe(rotrExpected!);
@@ -113,7 +116,10 @@ describe('Bitwise Operation Tests', () => {
113116
specific = false,
114117
shrExpected?: bigint
115118
) => {
116-
const shrActual = shiftRight32(UInt32.from(input), shiftBits).value.toBigInt();
119+
const shrActual = shiftRight32(
120+
UInt32.from(input),
121+
shiftBits
122+
).value.toBigInt();
117123
if (specific) {
118124
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
119125
expect(shrActual).toBe(shrExpected!);

src/sha256-class.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ class SHA256 {
268268
}
269269

270270
//TODO Update code documentation
271+
//TODO? add the released sha256 in benchmarks -> released, direct, class.
272+
271273
//TODO Omit unnecessary files
272274
//TODO? point to the fact that the o1js used custom sigma functions
273-
//TODO? add the released sha256 in benchmarks -> released, direct, class.
275+
274276
//TODO? Update the readme and repo description

src/sha256.test.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('Testing o1js SHA256 hash function against to node-js implementation',
131131
}
132132
});
133133

134-
// !This test takes extremely long time to finish
134+
// !This test takes extremely long time to finish
135135
test.skip('should have passing sliding window tests - 4096', () => {
136136
const testWindow4096 = new Array<string>(4096);
137137
for (let i = 0; i < testWindow4096.length; i++)
@@ -150,11 +150,14 @@ describe('Testing o1js SHA256 hash function against to node-js implementation',
150150
*/
151151
test.skip('should pass sliding window tests - 3/256', () => {
152152
let BUF_768 = new Uint8Array(256 * 3);
153-
153+
154154
// Fill with random data
155155
for (let i = 0; i < (256 * 3) / 32; i++)
156-
BUF_768.set(crypto.createHash('sha256').update(new Uint8Array(i)).digest(), i * 32);
157-
156+
BUF_768.set(
157+
crypto.createHash('sha256').update(new Uint8Array(i)).digest(),
158+
i * 32
159+
);
160+
158161
let BYTES_768 = Bytes.from(BUF_768);
159162
const digest768 = sha256O1js(BYTES_768);
160163
for (let i = 0; i < 256; i++) {
@@ -163,14 +166,20 @@ describe('Testing o1js SHA256 hash function against to node-js implementation',
163166
for (let j = 0; j < 256; j++) {
164167
let b2 = BUF_768.subarray(i, i + j);
165168
let b2Bytes = Bytes.from(b2);
166-
169+
167170
let b3 = BUF_768.subarray(i + j);
168171
let b3Bytes = Bytes.from(b3);
169-
172+
170173
expect(concatBytes(b1, b2, b3)).toStrictEqual(BUF_768);
171-
expect(new SHA256().update(b1Bytes).update(b2Bytes).update(b3Bytes).digest().toHex())
172-
.toEqual(digest768.toHex());
174+
expect(
175+
new SHA256()
176+
.update(b1Bytes)
177+
.update(b2Bytes)
178+
.update(b3Bytes)
179+
.digest()
180+
.toHex()
181+
).toEqual(digest768.toHex());
173182
}
174183
}
175184
});
176-
});
185+
});

src/sha256.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import {
1717
} from './preprocessing.js';
1818
import { wordToBytes } from './binary-utils.js';
1919

20-
export {
21-
sha256O1js,
22-
}
20+
export { sha256O1js };
2321

2422
function sha256O1js(input: Bytes): Bytes {
2523
const H = [...initialHashWords];
@@ -69,4 +67,4 @@ function sha256O1js(input: Bytes): Bytes {
6967
// the message schedule is converted to big endian bytes
7068
// wordToBytes expects little endian, so we reverse the bytes
7169
return Bytes.from(H.map((x) => wordToBytes(x.value, 4).reverse()).flat());
72-
}
70+
}

src/test-utils.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,6 @@ function nodeHash(input: string | Uint8Array): string {
153153
return crypto.createHash('sha256').update(input).digest('hex');
154154
}
155155

156-
// function o1jsHashField(input: Field): string {
157-
// const digest = sha256O1js(Bytes.from(Field.toBytes(input)));
158-
// const digestBinary = digest.map(uint32ToBinary).join('');
159-
// const digestHex = binaryToHex(digestBinary);
160-
161-
// return digestHex;
162-
// }
163-
164156
function nobleHash(input: string | Uint8Array): string {
165157
return bytesToHex(nobleSha256(input));
166158
}

src/zkprogram.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
import { ZkProgram, Bytes } from "o1js";
2-
import { sha256O1js } from "./sha256.js";
3-
import { Timer } from "./test-utils.js";
4-
1+
import { ZkProgram, Bytes } from 'o1js';
2+
import { sha256O1js } from './sha256.js';
3+
import { Timer } from './test-utils.js';
54

65
class Bytes32 extends Bytes(32) {}
76
class Bytes3 extends Bytes(3) {}
87

98
// Define SHA256 ZkProgram
109
let sha256ZkProgram = ZkProgram({
11-
name: 'sha256',
12-
publicOutput: Bytes32.provable,
13-
methods: {
14-
hash: {
15-
privateInputs: [Bytes3.provable],
16-
method(input: Bytes3) {
17-
return sha256O1js(input);
18-
}
19-
}
20-
}
10+
name: 'sha256',
11+
publicOutput: Bytes32.provable,
12+
methods: {
13+
hash: {
14+
privateInputs: [Bytes3.provable],
15+
method(input: Bytes3) {
16+
return sha256O1js(input);
17+
},
18+
},
19+
},
2120
});
2221

23-
// Print SHA256 ZkProgram summary
22+
// Print SHA256 ZkProgram summary
2423
console.log('sha256 summary:', sha256ZkProgram.analyzeMethods().hash.summary());
2524

2625
// Compile SHA256 ZkProgram
@@ -40,12 +39,13 @@ const verifyTimer = new Timer('Verification Time');
4039
const res = await sha256ZkProgram.verify(proof);
4140
verifyTimer.end();
4241
if (res === true) {
43-
console.log("\nProof Verification OK!");
42+
console.log('\nProof Verification OK!');
4443
} else {
45-
console.log("Invalid proof");
44+
console.log('Invalid proof');
4645
}
4746

4847
// Verify Compliance to Expected Digest
4948
const digest = await proof.publicOutput.toHex();
50-
const integrityCheck = digest === 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad';
51-
console.log("Digest Integrity Check: ", integrityCheck);
49+
const integrityCheck =
50+
digest === 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad';
51+
console.log('Digest Integrity Check: ', integrityCheck);

0 commit comments

Comments
 (0)