Skip to content

Commit ec4f99b

Browse files
committed
Merge branch 'main' into shigoto/document-build-scripts
2 parents 1b6cf4a + 49a0181 commit ec4f99b

File tree

29 files changed

+256
-132
lines changed

29 files changed

+256
-132
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ This project adheres to
1818

1919
## [Unreleased](https://github.com/o1-labs/o1js/compare/3453d1e53...HEAD)
2020

21+
### Added
22+
23+
- Add `KimchiProof.toJSON()` and `KimchiProof.fromJSON()`
24+
https://github.com/o1-labs/o1js/pull/2594
25+
- Add `KimchiVerificationKey.toString()` and
26+
`KimchiVerificationKey.fromString()` https://github.com/o1-labs/o1js/pull/2594
27+
2128
### Internal
2229

2330
- Change cache harness to only allow writes when `dump` mode is active.

src/bindings.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ declare namespace Snarky {
7373
type Keypair = unknown;
7474
type VerificationKey = unknown;
7575
type Proof = unknown;
76+
type ProofWithEvals = unknown;
7677
}
7778

7879
/**
@@ -406,6 +407,11 @@ declare const Snarky: {
406407
verificationKey: Snarky.VerificationKey
407408
): boolean;
408409

410+
411+
proofToBackendProofEvals(publicInput: MlArray<FieldConst>, proof: Snarky.Proof): Snarky.ProofWithEvals;
412+
413+
proofFromBackendProofEvals(proof: Snarky.ProofWithEvals): Snarky.Proof;
414+
409415
keypair: {
410416
getVerificationKey(keypair: Snarky.Keypair): Snarky.VerificationKey;
411417
/**

src/bindings/ocaml/lib/snarky_bindings.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,12 @@ module Circuit = struct
406406
Backend.Field.Vector.emplace_back public_input_vec x ) ;
407407
Backend.Proof.verify proof vk public_input_vec |> Js.bool
408408

409+
let proof_to_backend_proof_evals xs (t : Backend.Proof.with_public_evals) =
410+
Backend.Proof.to_backend_with_public_evals' [] xs t
411+
412+
let proof_from_backend_proof_evals t =
413+
Backend.Proof.of_backend_with_public_evals t
414+
409415
module Keypair = struct
410416
let get_vk t = Impl.Keypair.vk t
411417

@@ -582,6 +588,11 @@ let snarky =
582588

583589
method verify = Circuit.verify
584590

591+
method proofToBackendProofEvals = Circuit.proof_to_backend_proof_evals
592+
593+
method proofFromBackendProofEvals =
594+
Circuit.proof_from_backend_proof_evals
595+
585596
val keypair =
586597
object%js
587598
method getVerificationKey = Circuit.Keypair.get_vk

src/bindings/ocaml/lib/snarky_bindings.mli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ val snarky :
273273
Kimchi_types.poly_comm )
274274
Kimchi_types.VerifierIndex.verifier_index
275275
-> bool Js.t )
276-
Js.meth >
276+
Js.meth
277+
; proofToBackendProofEvals :
278+
(field array -> Backend.Proof.with_public_evals -> Backend.Proof.Backend.with_public_evals) Js.meth
279+
; proofFromBackendProofEvals : (Backend.Proof.Backend.with_public_evals -> Backend.Proof.with_public_evals) Js.meth >
277280
Js.t
278281
Js.readonly_prop >
279282
Js.t

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.

0 commit comments

Comments
 (0)