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 silent deploy fail with no verification key #885

Merged
merged 3 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Support for fallback endpoints when making network requests, allowing users to provide an array of endpoints for GraphQL network requests. https://github.com/o1-labs/snarkyjs/pull/871
- Endpoints are checked for validity, and a "waterfall" approach is used to loop through fallback endpoints if needed.

### Fixed

- `SmartContract.deploy()` throws an error when no verification key is found https://github.com/o1-labs/snarkyjs/pull/885
- The old, confusing behaviour was to silently not update the verification key (but still update some permissions to "proof", breaking the zkApp)

## [0.9.8](https://github.com/o1-labs/snarkyjs/compare/1a984089...97e393ed)

### Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion src/lib/precondition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let feePayerKey: PrivateKey;
beforeAll(async () => {
// set up local blockchain, create zkapp keys, deploy the contract
await isReady;
let Local = Mina.LocalBlockchain();
let Local = Mina.LocalBlockchain({ proofsEnabled: false });
Mina.setActiveInstance(Local);
feePayerKey = Local.testAccounts[0].privateKey;
feePayer = Local.testAccounts[0].publicKey;
Expand Down
19 changes: 12 additions & 7 deletions src/lib/zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,14 +728,19 @@ class SmartContract {
} = {}) {
let accountUpdate = this.newSelf();
verificationKey ??= (this.constructor as any)._verificationKey;
if (verificationKey === undefined && !Mina.getProofsEnabled()) {
verificationKey = Pickles.dummyVerificationKey();
}
if (verificationKey !== undefined) {
let { hash: hash_, data } = verificationKey;
let hash = typeof hash_ === 'string' ? Field(hash_) : hash_;
accountUpdate.account.verificationKey.set({ hash, data });
if (verificationKey === undefined) {
if (!Mina.getProofsEnabled()) {
verificationKey = Pickles.dummyVerificationKey();
} else {
throw Error(
`\`${this.constructor.name}.deploy()\` was called but no verification key was found.\n` +
`Try calling \`await ${this.constructor.name}.compile()\` first, this will cache the verification key in the background.`
);
}
}
let { hash: hash_, data } = verificationKey;
let hash = typeof hash_ === 'string' ? Field(hash_) : hash_;
accountUpdate.account.verificationKey.set({ hash, data });
accountUpdate.account.permissions.set(Permissions.default());
accountUpdate.sign(zkappKey);
AccountUpdate.attachToTransaction(accountUpdate);
Expand Down