Skip to content

Commit ce1b5f2

Browse files
committed
Merge branch 'main' into florian/kimchi-proof-rust
2 parents 1d8af2e + a583a9c commit ce1b5f2

File tree

21 files changed

+57
-50
lines changed

21 files changed

+57
-50
lines changed

src/examples/crypto/ecdsa/ecdsa.ts

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

3-
export { keccakAndEcdsa, ecdsa, Secp256k1, Ecdsa, Bytes32, ecdsaEthers };
3+
export { Bytes32, Ecdsa, Secp256k1, ecdsa, ecdsaEthers, keccakAndEcdsa };
44

55
class Secp256k1 extends createForeignCurve(Crypto.CurveParams.Secp256k1) {}
66
class Scalar extends Secp256k1.Scalar {}

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/foreign-field.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
*/
77
import assert from 'assert';
88
import {
9-
createForeignField,
109
AlmostForeignField,
1110
CanonicalForeignField,
11+
Provable,
1212
Scalar,
1313
SmartContract,
14+
State,
15+
createForeignField,
1416
method,
15-
Provable,
1617
state,
17-
State,
1818
} from 'o1js';
1919

2020
// Let's create a small finite field: F_17

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/rsa/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Bigint2048, rsaVerify65537 } from './rsa.js';
2-
import { sha256Bigint, generateRsaParams, rsaSign, randomPrime } from './utils.js';
31
import { expect } from 'expect';
4-
import { it, describe } from 'node:test';
2+
import { describe, it } from 'node:test';
3+
import { Bigint2048, rsaVerify65537 } from './rsa.js';
4+
import { generateRsaParams, randomPrime, rsaSign, sha256Bigint } from './utils.js';
55

66
describe('RSA65537 verification tests', () => {
77
it('should accept a simple RSA signature', () => {

src/examples/crypto/rsa/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { sha256Bigint, generateRsaParams, rsaSign, randomPrime };
1+
export { generateRsaParams, randomPrime, rsaSign, sha256Bigint };
22

33
/**
44
* Generates an RSA signature for the given message using the private key and modulus.

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
},

src/examples/zkfunction/ecdsa.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Experimental, Crypto, createForeignCurve, Bytes, assert, createEcdsa } from 'o1js';
1+
import { Bytes, Crypto, Experimental, createEcdsa, createForeignCurve } from 'o1js';
22
const { ZkFunction } = Experimental;
33

4-
export { Secp256k1, Ecdsa, Bytes32, reserves };
4+
export { Bytes32, Ecdsa, Secp256k1, reserves };
55

66
class Secp256k1 extends createForeignCurve(Crypto.CurveParams.Secp256k1) {}
77
class Ecdsa extends createEcdsa(Secp256k1) {}
@@ -12,7 +12,7 @@ const reserves = ZkFunction({
1212
publicInputType: Bytes32,
1313
privateInputTypes: [Ecdsa, Secp256k1],
1414
main: (message: Bytes32, signature: Ecdsa, publicKey: Secp256k1) => {
15-
assert(signature.verify(message, publicKey));
15+
signature.verify(message, publicKey).assertTrue();
1616
},
1717
});
1818

@@ -31,5 +31,6 @@ console.timeEnd('prove');
3131

3232
console.time('verify');
3333
let isValid = await reserves.verify(proof, verificationKey);
34-
assert(isValid, 'verifies');
3534
console.timeEnd('verify');
35+
36+
if (!isValid) throw Error('verification failed!');

src/examples/zkfunction/preimage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Poseidon, Field, Experimental } from 'o1js';
1+
import { Experimental, Field, Poseidon } from 'o1js';
22
const { ZkFunction } = Experimental;
33

44
/**
@@ -26,7 +26,7 @@ console.log('prove...');
2626
const pi = await main.prove(hash, preimage);
2727

2828
console.log('verify...');
29-
let ok = await main.verify(pi, verificationKey);
30-
console.log('ok?', ok);
29+
let isValid = await main.verify(pi, verificationKey);
30+
console.log('isValid?', isValid);
3131

32-
if (!ok) throw Error('verification failed');
32+
if (!isValid) throw Error('verification failed!');

0 commit comments

Comments
 (0)