Skip to content

Commit

Permalink
Merge pull request #1032 from o1-labs/fix/premature-vk-hash
Browse files Browse the repository at this point in the history
Fix: Revert vk hash to make snarkyjs compatible
  • Loading branch information
mitschabaude authored Jul 14, 2023
2 parents 4790cb6 + 2fbd74e commit aed64f2
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 62 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
_Security_ in case of vulnerabilities.
-->

## [Unreleased](https://github.com/o1-labs/snarkyjs/compare/161b69d602...HEAD)
## [Unreleased](https://github.com/o1-labs/snarkyjs/compare/b1d8d5910...HEAD)

> No unreleased changes yet
## [0.12.1](https://github.com/o1-labs/snarkyjs/compare/161b69d602...b1d8d5910)

### Added

- Added a method `createTestNullifier` to the Nullifier class for testing purposes. It is recommended to use mina-signer to create Nullifiers in production, since it does not leak the private key of the user. The `Nullifier.createTestNullifier` method requires the private key as an input _outside of the users wallet_. https://github.com/o1-labs/snarkyjs/pull/1026
- Added `field.isEven` to check if a Field element is odd or even. https://github.com/o1-labs/snarkyjs/pull/1026

### Fixed

- Revert verification key hash change from previous release to stay compatible with the current testnet https://github.com/o1-labs/snarkyjs/pull/1032

## [0.12.0](https://github.com/o1-labs/snarkyjs/compare/eaa39dca0...161b69d602)

### Breaking Changes
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "snarkyjs",
"description": "TypeScript framework for zk-SNARKs and zkApps",
"version": "0.12.0",
"version": "0.12.1",
"license": "Apache-2.0",
"homepage": "https://github.com/o1-labs/snarkyjs/",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/bindings
68 changes: 34 additions & 34 deletions src/examples/regression_test.json

Large diffs are not rendered by default.

20 changes: 8 additions & 12 deletions src/lib/account_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@ import { UInt64, UInt32, Int64, Sign } from './int.js';
import * as Mina from './mina.js';
import { SmartContract } from './zkapp.js';
import * as Precondition from './precondition.js';
import {
dummyBase64Proof,
dummyVerificationKeyHash,
Empty,
Proof,
Prover,
} from './proof_system.js';
import { dummyBase64Proof, Empty, Proof, Prover } from './proof_system.js';
import { Memo } from '../mina-signer/src/memo.js';
import {
Events,
Actions,
} from '../bindings/mina-transaction/transaction-leaves.js';
import { TokenId as Base58TokenId } from './base58-encodings.js';
import { hashWithPrefix, packToFields } from './hash.js';
import { prefixes } from '../bindings/crypto/constants.js';
import { mocks, prefixes } from '../bindings/crypto/constants.js';
import { Context } from './global-context.js';
import { assert } from './errors.js';
import { MlArray } from './ml/base.js';
Expand Down Expand Up @@ -1808,8 +1802,9 @@ const Authorization = {
signature ??= {};
accountUpdate.body.authorizationKind.isSigned = Bool(true);
accountUpdate.body.authorizationKind.isProved = Bool(false);
accountUpdate.body.authorizationKind.verificationKeyHash =
dummyVerificationKeyHash();
accountUpdate.body.authorizationKind.verificationKeyHash = Field(
mocks.dummyVerificationKeyHash
);
accountUpdate.authorization = {};
accountUpdate.lazyAuthorization = { ...signature, kind: 'lazy-signature' };
},
Expand Down Expand Up @@ -1867,8 +1862,9 @@ const Authorization = {
setLazyNone(accountUpdate: AccountUpdate) {
accountUpdate.body.authorizationKind.isSigned = Bool(false);
accountUpdate.body.authorizationKind.isProved = Bool(false);
accountUpdate.body.authorizationKind.verificationKeyHash =
dummyVerificationKeyHash();
accountUpdate.body.authorizationKind.verificationKeyHash = Field(
mocks.dummyVerificationKeyHash
);
accountUpdate.authorization = {};
accountUpdate.lazyAuthorization = { kind: 'lazy-none' };
},
Expand Down
3 changes: 1 addition & 2 deletions src/lib/account_update.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '../index.js';
import { Test } from '../snarky.js';
import { expect } from 'expect';
import { dummyVerificationKeyHash } from './proof_system.js';

let address = PrivateKey.random().toPublicKey();

Expand Down Expand Up @@ -103,7 +102,7 @@ function createAccountUpdate() {
let accountUpdate = createAccountUpdate();
expect(
accountUpdate.body.authorizationKind.verificationKeyHash.toString()
).toEqual(dummyVerificationKeyHash().toString());
).toEqual('0');
}

// does not throw an error if private key is missing unless if .send is executed
Expand Down
2 changes: 1 addition & 1 deletion src/lib/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class Field {
// check composition
xDiv2.mul(2).add(isOdd).assertEquals(this);

return new Bool(isOddVar);
return new Bool(isOddVar).not();
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/lib/field.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ equivalentVoid1(
(x) => x.assertBool(),
(x) => x === 0n || x === 1n || throwError('not boolean')
);
equivalent1(
(x) => x.isEven().toField(),
(x) => BigInt((x & 1n) === 0n),
SmallField
);

// non-constant field vars
test(Random.field, (x0, assert) => {
Expand Down
6 changes: 0 additions & 6 deletions src/lib/proof_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export {
isAsFields,
Prover,
dummyBase64Proof,
dummyVerificationKeyHash,
};

type Undefined = undefined;
Expand Down Expand Up @@ -809,11 +808,6 @@ function dummyBase64Proof() {
return withThreadPool(async () => Pickles.dummyBase64Proof());
}

function dummyVerificationKeyHash() {
let [, , hash] = Pickles.dummyVerificationKey();
return Field.fromBytes([...hash]);
}

// helpers for circuit context

function Prover<ProverData>() {
Expand Down
4 changes: 2 additions & 2 deletions src/mina-signer/src/sign-zkapp-command.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ console.log('to/from json, hashes & signatures are consistent! 🎉');
function fixVerificationKey(a: AccountUpdate) {
// ensure verification key is valid
if (a.body.update.verificationKey.isSome === 1n) {
let [, data] = Pickles.dummyVerificationKey();
let [, data, hash] = Pickles.dummyVerificationKey();
a.body.update.verificationKey.value = {
data,
hash: Field(mocks.dummyVerificationKeyHash),
hash: Field.fromBytes([...hash]),
};
} else {
a.body.update.verificationKey.value = {
Expand Down

0 comments on commit aed64f2

Please sign in to comment.