Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SnarkyJS to be compatible with new Berkeley #1021

Merged
merged 58 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
ac73fcb
fixup global slot binable / json
mitschabaude May 5, 2023
a51a84d
bindings
mitschabaude May 5, 2023
e6106e2
bindings
mitschabaude May 5, 2023
36627c5
bindings
mitschabaude May 5, 2023
147c36f
Merge pull request #893 from o1-labs/fix/use-fake-logger
mitschabaude May 7, 2023
9e06f9c
bindings
mitschabaude May 8, 2023
bc46083
Merge branch 'berkeley' into fix/global-slot-serialization
mitschabaude May 8, 2023
835c6fc
Remove duplicate user command fields
nholland94 May 1, 2023
1b5446f
Update bindings
nholland94 May 10, 2023
885e2fa
bindings
mitschabaude May 10, 2023
91eb907
bindings
mitschabaude May 10, 2023
310a89f
bindings
mitschabaude May 10, 2023
618b35a
delete uninteresting unit test which fails CI
mitschabaude May 11, 2023
80ed0c0
bindings
mitschabaude May 11, 2023
265c311
Merge pull request #884 from o1-labs/remove-duplicate-user-command-fi…
mitschabaude May 30, 2023
0a5a7a8
Merge branch 'berkeley' into fix/global-slot-serialization
mitschabaude Jun 1, 2023
4a2277b
bindings
mitschabaude Jun 1, 2023
c309fb1
bindings
mitschabaude Jun 1, 2023
6b14e2b
Merge pull request #892 from o1-labs/fix/global-slot-serialization
mitschabaude Jun 1, 2023
82485cd
Merge branch 'fix/wasm-build' into fix/wasm-build-berkeley
mitschabaude Jun 2, 2023
abe02dd
bindings
mitschabaude Jun 2, 2023
af0202f
Merge pull request #952 from o1-labs/fix/wasm-build-berkeley
mitschabaude Jun 5, 2023
0e60fa1
Merge branch 'berkeley' into make-ci-not-broken-too-2
mrmr1993 Jun 7, 2023
6914469
Merge pull request #978 from o1-labs/make-ci-not-broken-too-2
mrmr1993 Jun 7, 2023
63bd416
Merge branch 'main' into merge-main-berkeley
mitschabaude Jun 15, 2023
1b66620
bindings
mitschabaude Jun 15, 2023
0e51cfe
Merge pull request #991 from o1-labs/merge-main-berkeley-2
mitschabaude Jun 16, 2023
108cd2a
type import changes for no ts build
mitschabaude Jun 16, 2023
2e6df12
run examples without requiring ts build
mitschabaude Jun 16, 2023
f50d7e8
port inductive proofs example
mitschabaude Jun 16, 2023
fd3e197
add script to run minimal snarkyjs tests
mitschabaude Jun 20, 2023
d638b67
minor
mitschabaude Jun 20, 2023
ff69674
use smaller example in test
mitschabaude Jun 20, 2023
47a6034
add a script to copy files
mitschabaude Jun 20, 2023
4b99e4d
simplify
mitschabaude Jun 20, 2023
9179211
delete pointless file
mitschabaude Jun 22, 2023
0f95b8e
clean up some build logic
mitschabaude Jun 22, 2023
195697c
Merge pull request #996 from o1-labs/feature/revive-snarkyjs-ci-berkeley
mitschabaude Jun 23, 2023
676212b
Merge branch 'berkeley' into main
MartinMinkov Jul 10, 2023
50b05ea
feat(bindings): update bindings
MartinMinkov Jul 10, 2023
9b4805d
feat(vk_hash): update hardcoded vk hash to use new mina dummy
MartinMinkov Jul 10, 2023
1fc38c0
chore(vk_regression): update vk regression dumps
MartinMinkov Jul 10, 2023
c37c459
feat(tsconfig.mina-signer.json): fix building by enabling decorators
MartinMinkov Jul 10, 2023
a20d1f9
Revert "feat(tsconfig.mina-signer.json): fix building by enabling dec…
MartinMinkov Jul 10, 2023
b3b4cb1
feat(account_update): correctly create empty verification key hash
MartinMinkov Jul 11, 2023
6e624eb
refactor(sign-zkapp-command.ts, accountUpdate.ts): replace Pickles.du…
MartinMinkov Jul 11, 2023
5e1e10a
feat(sign-zkapp-command.unit-test.ts): use mocks for dummyVerificatio…
MartinMinkov Jul 11, 2023
4bc172d
fix(tsconfig.mina-signer.json): fix mina-signer building due to inclu…
MartinMinkov Jul 11, 2023
cf070a3
chore(bindings): update subproject commit hash to 988f7b8445a5d159730…
MartinMinkov Jul 11, 2023
eaea0d5
chore(package.json): bump version from 0.11.4 to 0.12.0 for the new r…
MartinMinkov Jul 11, 2023
8cec003
docs(CHANGELOG.md): update unreleased changes and add version 0.12.0 …
MartinMinkov Jul 11, 2023
e0af732
fix(zkapp.unit-test.ts): replace vk with with mocked version
MartinMinkov Jul 11, 2023
e157304
Revert "fix(tsconfig.mina-signer.json): fix mina-signer building due …
MartinMinkov Jul 11, 2023
38c12fb
fix(sign-zkapp-command.unit-test.ts): correct the import path for moc…
MartinMinkov Jul 11, 2023
89beca3
refactor(random.ts): replace Pickles.dummyVerificationKey() with mock…
MartinMinkov Jul 11, 2023
4a5cffa
feat(tsconfig.mina-signer.json): enable experimentalDecorators, emitD…
MartinMinkov Jul 11, 2023
bd477a7
refactor(tsconfig.mina-signer.json): remove unnecessary decorator-rel…
MartinMinkov Jul 11, 2023
97869a6
chore(bindings): update subproject commit hash to 2c4c71339073ffe1f03…
MartinMinkov Jul 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ 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/eaa39dca0...HEAD)
## [Unreleased](https://github.com/o1-labs/snarkyjs/compare/161b69d602...HEAD)

> No unreleased changes yet

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

### Breaking Changes

- Fix the default verification key hash that was generated for AccountUpdates. This change adopts the default mechanism provided by Mina Protocol https://github.com/o1-labs/snarkyjs/pull/1021
- Please be aware that this alteration results in a breaking change affecting the verification key of already deployed contracts.

## [0.11.4](https://github.com/o1-labs/snarkyjs/compare/544489609...eaa39dca0)

### Fixed
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.11.4",
"version": "0.12.0",
"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.

14 changes: 11 additions & 3 deletions src/lib/account_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ 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, Empty, Proof, Prover } from './proof_system.js';
import {
dummyBase64Proof,
dummyVerificationKeyHash,
Empty,
Proof,
Prover,
} from './proof_system.js';
import { Memo } from '../mina-signer/src/memo.js';
import {
Events,
Expand Down Expand Up @@ -1802,7 +1808,8 @@ const Authorization = {
signature ??= {};
accountUpdate.body.authorizationKind.isSigned = Bool(true);
accountUpdate.body.authorizationKind.isProved = Bool(false);
accountUpdate.body.authorizationKind.verificationKeyHash = Field(0);
accountUpdate.body.authorizationKind.verificationKeyHash =
dummyVerificationKeyHash();
accountUpdate.authorization = {};
accountUpdate.lazyAuthorization = { ...signature, kind: 'lazy-signature' };
},
Expand Down Expand Up @@ -1860,7 +1867,8 @@ const Authorization = {
setLazyNone(accountUpdate: AccountUpdate) {
accountUpdate.body.authorizationKind.isSigned = Bool(false);
accountUpdate.body.authorizationKind.isProved = Bool(false);
accountUpdate.body.authorizationKind.verificationKeyHash = Field(0);
accountUpdate.body.authorizationKind.verificationKeyHash =
dummyVerificationKeyHash();
accountUpdate.authorization = {};
accountUpdate.lazyAuthorization = { kind: 'lazy-none' };
},
Expand Down
9 changes: 9 additions & 0 deletions src/lib/account_update.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 @@ -97,6 +98,14 @@ function createAccountUpdate() {
);
}

// creates the right empty vk hash
{
let accountUpdate = createAccountUpdate();
expect(
accountUpdate.body.authorizationKind.verificationKeyHash.toString()
).toEqual(dummyVerificationKeyHash().toString());
}

// does not throw an error if private key is missing unless if .send is executed
{
let Local = Mina.LocalBlockchain({ proofsEnabled: false });
Expand Down
6 changes: 6 additions & 0 deletions src/lib/proof_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export {
isAsFields,
Prover,
dummyBase64Proof,
dummyVerificationKeyHash,
};

type Undefined = undefined;
Expand Down Expand Up @@ -808,6 +809,11 @@ 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
9 changes: 8 additions & 1 deletion src/lib/testing/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Field,
Actions,
ActionState,
VerificationKeyHash,
ReceiptChainHash,
Sign,
TokenId,
Expand All @@ -37,6 +38,7 @@ import { Memo } from '../../mina-signer/src/memo.js';
import { ProvableExtended } from '../../bindings/lib/provable-bigint.js';
import { tokenSymbolLength } from '../../bindings/mina-transaction/derived-leaves.js';
import { stringLengthInBytes } from '../../bindings/lib/binable.js';
import { mocks } from '../../bindings/crypto/constants.js';

export { Random, sample, withHardCoded };

Expand Down Expand Up @@ -103,6 +105,7 @@ const actions = mapWithInvalid(
Actions.fromList
);
const actionState = oneOf(ActionState.emptyValue(), field);
const verificationKeyHash = oneOf(VerificationKeyHash.emptyValue(), field);
const receiptChainHash = oneOf(ReceiptChainHash.emptyValue(), field);
const zkappUri = map(string(nat(50)), ZkappUri.fromJSON);

Expand All @@ -126,6 +129,7 @@ const Generators: Generators = {
Events: events,
Actions: actions,
ActionState: actionState,
VerificationKeyHash: verificationKeyHash,
ReceiptChainHash: receiptChainHash,
ZkappUri: zkappUri,
null: constant(null),
Expand Down Expand Up @@ -228,6 +232,7 @@ const JsonGenerators: JsonGenerators = {
Events: mapWithInvalid(events, Events.toJSON),
Actions: mapWithInvalid(actions, Actions.toJSON),
ActionState: mapWithInvalid(actionState, ActionState.toJSON),
VerificationKeyHash: mapWithInvalid(verificationKeyHash, Field.toJSON),
ReceiptChainHash: mapWithInvalid(receiptChainHash, ReceiptChainHash.toJSON),
ZkappUri: string(nat(50)),
null: constant(null),
Expand Down Expand Up @@ -255,8 +260,10 @@ const accountUpdateJson = mapWithInvalid(
if (isProved && isSigned) {
a.body.authorizationKind.isProved = false;
}

if (!a.body.authorizationKind.isProved) {
a.body.authorizationKind.verificationKeyHash = '0';
a.body.authorizationKind.verificationKeyHash =
mocks.dummyVerificationKeyHash;
}
// ensure mayUseToken is valid
let { inheritFromParent, parentsOwnToken } = a.body.mayUseToken;
Expand Down
12 changes: 6 additions & 6 deletions src/mina-signer/MinaSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class Client {
let signature = signPayment(
{
common: { fee, feePayer: from, nonce, validUntil, memo },
body: { source: from, receiver: to, amount },
body: { receiver: to, amount },
},
privateKey,
this.network
Expand Down Expand Up @@ -226,7 +226,7 @@ class Client {
return verifyPayment(
{
common: { fee, feePayer: from, nonce, validUntil, memo },
body: { source: from, receiver: to, amount },
body: { receiver: to, amount },
},
signature,
publicKey,
Expand Down Expand Up @@ -254,7 +254,7 @@ class Client {
let signature = signStakeDelegation(
{
common: { fee, feePayer: from, nonce, validUntil, memo },
body: { newDelegate: to, delegator: from },
body: { newDelegate: to },
},
privateKey,
this.network
Expand All @@ -281,7 +281,7 @@ class Client {
return verifyStakeDelegation(
{
common: { fee, feePayer: from, nonce, validUntil, memo },
body: { newDelegate: to, delegator: from },
body: { newDelegate: to },
},
signature,
publicKey,
Expand All @@ -306,7 +306,7 @@ class Client {
signature,
data: {
common: { fee, feePayer: from, nonce, validUntil, memo },
body: { source: from, receiver: to, amount },
body: { receiver: to, amount },
},
},
options
Expand All @@ -329,7 +329,7 @@ class Client {
signature,
data: {
common: { fee, feePayer: from, nonce, validUntil, memo },
body: { newDelegate: to, delegator: from },
body: { newDelegate: to },
},
},
options
Expand Down
2 changes: 0 additions & 2 deletions src/mina-signer/src/random-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const common = record({
const payment = record<PaymentJson>({
common,
body: record({
source: Random.json.publicKey,
receiver: Random.json.publicKey,
amount: Random.json.uint64,
}),
Expand All @@ -36,7 +35,6 @@ const signedPayment = record<SignedLegacy<PaymentJson>>({
const delegation = record<DelegationJson>({
common,
body: record({
delegator: Random.json.publicKey,
newDelegate: Random.json.publicKey,
}),
});
Expand Down
35 changes: 25 additions & 10 deletions src/mina-signer/src/sign-legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export {
delegationFromJson,
commonFromJson,
PaymentJson,
PaymentJsonV1,
DelegationJson,
DelegationJsonV1,
CommonJson,
Tag,
UserCommand,
Expand Down Expand Up @@ -146,7 +148,7 @@ function commonToInputLegacy({
HashInputLegacy.bits(legacyTokenId),
PublicKey.toInputLegacy(feePayer),
HashInputLegacy.bits(UInt32.toBits(nonce)),
HashInputLegacy.bits(UInt32.toBits(validUntil)),
HashInputLegacy.bits(UInt32.toBits(validUntil.value)),
HashInputLegacy.bits(Memo.toBits(memo)),
].reduce(HashInputLegacy.append);
}
Expand All @@ -160,13 +162,13 @@ const legacyTokenId = [true, ...Array<boolean>(63).fill(false)];

function paymentFromJson({
common,
body: { source, receiver, amount },
body: { receiver, amount },
}: PaymentJson): UserCommand {
return {
common: commonFromJson(common),
body: {
tag: 'Payment',
source: PublicKey.fromJSON(source),
source: PublicKey.fromJSON(common.feePayer),
receiver: PublicKey.fromJSON(receiver),
amount: UInt64.fromJSON(amount),
},
Expand All @@ -175,25 +177,25 @@ function paymentFromJson({

function delegationFromJson({
common,
body: { delegator, newDelegate },
body: { newDelegate },
}: DelegationJson): UserCommand {
return {
common: commonFromJson(common),
body: {
tag: 'StakeDelegation',
source: PublicKey.fromJSON(delegator),
source: PublicKey.fromJSON(common.feePayer),
receiver: PublicKey.fromJSON(newDelegate),
amount: UInt64(0),
},
};
}

function commonFromJson(c: CommonJson) {
function commonFromJson(c: CommonJson): Common {
return {
fee: UInt64.fromJSON(c.fee),
feePayer: PublicKey.fromJSON(c.feePayer),
nonce: UInt32.fromJSON(c.nonce),
validUntil: UInt32.fromJSON(c.validUntil),
validUntil: { type: 'SinceGenesis', value: UInt32.fromJSON(c.validUntil) },
// TODO: this might need to be fromBase58
memo: Memo.fromString(c.memo),
};
Expand Down Expand Up @@ -262,17 +264,15 @@ type Common = {
fee: UInt64;
feePayer: PublicKey;
nonce: UInt32;
validUntil: UInt32;
validUntil: { type: 'SinceGenesis'; value: UInt32 };
memo: string;
};

type Payment = {
source: PublicKey;
receiver: PublicKey;
amount: UInt64;
};
type Delegation = {
delegator: PublicKey;
newDelegate: PublicKey;
};

Expand All @@ -285,6 +285,14 @@ type CommonJson = {
};

type PaymentJson = {
common: CommonJson;
body: {
receiver: Json.PublicKey;
amount: Json.UInt64;
};
};

type PaymentJsonV1 = {
common: CommonJson;
body: {
source: Json.PublicKey;
Expand All @@ -294,6 +302,13 @@ type PaymentJson = {
};

type DelegationJson = {
common: CommonJson;
body: {
newDelegate: Json.PublicKey;
};
};

type DelegationJsonV1 = {
common: CommonJson;
body: {
delegator: Json.PublicKey;
Expand Down
14 changes: 0 additions & 14 deletions src/mina-signer/src/sign-legacy.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ let amountTooLarge = {
amount: (2n ** 64n).toString(),
},
};
let invalidPublicKey: PaymentJson = {
common: validPayment.common,
body: {
...validPayment.body,
source: PublicKey.toBase58({ x: 0n, isOdd: 0n }),
},
};
let signature = Signature.toJSON({ r: Field.random(), s: Scalar.random() });

expect(() => signPayment(amountTooLarge, privateKey, 'mainnet')).toThrow(
Expand All @@ -122,13 +115,6 @@ expect(verifyPayment(amountTooLarge, signature, publicKey, 'mainnet')).toEqual(
false
);

expect(() => signPayment(invalidPublicKey, privateKey, 'mainnet')).toThrow(
'not a valid group element'
);
expect(
verifyPayment(invalidPublicKey, signature, publicKey, 'mainnet')
).toEqual(false);

// negative tests with invalid signatures

let garbageSignature = { field: 'garbage', scalar: 'garbage' };
Expand Down
Loading
Loading