Skip to content

Commit fd8c65b

Browse files
committed
Improve verify assertions in zkprogram crypto examples
1 parent 1735760 commit fd8c65b

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/examples/crypto/ecdsa/run.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ perfKeccakEcdsa.start('prove', 'verifyEcdsa');
3434
let { proof } = await keccakAndEcdsa.verifyEcdsa(message, signature, publicKey);
3535
perfKeccakEcdsa.end();
3636

37-
proof.publicOutput.assertTrue('signature verifies');
37+
proof.publicOutput.assertTrue('signature verification failed!');
3838

3939
perfKeccakEcdsa.start('verify', 'verifyEcdsa');
4040
const isValid = await keccakAndEcdsa.verify(proof);
4141
perfKeccakEcdsa.end();
4242

43-
assert(isValid, 'proof verifies');
43+
assert(isValid, 'proof verification failed!');
4444

4545
// Hardcoded ethers.js signature and inputs for verification in o1js
4646

@@ -78,10 +78,10 @@ perfEcdsaEthers.start('prove', 'verifyEthers');
7878
let { proof: proofE } = await ecdsaEthers.verifyEthers(msgBytes, signatureE, publicKeyE);
7979
perfEcdsaEthers.end();
8080

81-
proofE.publicOutput.assertTrue('signature verifies');
81+
proofE.publicOutput.assertTrue('signature verification failed!');
8282

8383
perfEcdsaEthers.start('verify', 'verifyEthers');
8484
const isValidE = await ecdsaEthers.verify(proofE);
8585
perfEcdsaEthers.end();
8686

87-
assert(isValidE, 'proof verifies');
87+
assert(isValidE, 'proof verification failed!');

src/examples/crypto/rsa/run.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ let { proof } = await rsaZkProgram.verifyRsa65537(message, signature, modulus);
2828
perfRsa.end();
2929

3030
perfRsa.start('verify', 'verifyRsa65537');
31-
await rsaZkProgram.verify(proof);
31+
let isValid = await rsaZkProgram.verify(proof);
3232
perfRsa.end();
33+
34+
if (!isValid) throw Error('proof verification failed!');

src/examples/crypto/sha256/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ if (
2626
proof.publicOutput.toHex() !== '7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9'
2727
)
2828
throw new Error('Invalid sha256 digest!');
29-
if (!isValid) throw new Error('Invalid proof');
29+
if (!isValid) throw new Error('Invalid proof!');

src/examples/crypto/sha256/sha256.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Bytes, Gadgets, ZkProgram } from 'o1js';
1+
import { Bytes, Hash, ZkProgram } from 'o1js';
22

3-
export { SHA256Program, Bytes12 };
3+
export { Bytes12, SHA256Program };
44

55
class Bytes12 extends Bytes(12) {}
66

@@ -12,7 +12,7 @@ let SHA256Program = ZkProgram({
1212
privateInputs: [Bytes12],
1313
async method(xs: Bytes12) {
1414
return {
15-
publicOutput: Gadgets.SHA256.hash(xs),
15+
publicOutput: Hash.SHA2_256.hash(xs),
1616
};
1717
},
1818
},

0 commit comments

Comments
 (0)