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 init() by removing optional key argument #908

Merged
merged 5 commits into from
May 10, 2023

Conversation

mitschabaude
Copy link
Member

@mitschabaude mitschabaude commented May 10, 2023

fixes o1-labs/zkapp-cli#406

This removes the optional zkappKey argument to smartContract.init()

For context, this argument was originally added for the case that you make init() a @method, to prove that it was called and to get the provedState = true property on the zkapp account.

If init() is a @method, it means everybody can call it after deploy (since it doesn't require a signature!). That's bad of course, because we want init() to only be callable once; we don't want everyone to be able to reset the state.

The solution to this is to add a precondition on provedState: to call init(), provedState must be false. Since init() causes provedState to become true, and assuming that the state is henceforth only updated with proofs, nobody will ever be able to call it again.

At the time of introducing init(), the proved state precondition was not available. Therefore, as a workaround, we added an optional privateKey argument to init(), and made it prove that privateKey.toPublicKey() equals the account's address. With this workaround, only the owner of the zkapp private key could call init() (but they could do so as often as they wanted). We no longer need this workaround since the provedState precondition is available now.

Removing the optional argument also solves a bug that occured when you didn't annotate the optional argument as a @method argument, but still passed in the private key. It's not supported to leave out a @method argument, but the previous deploy() behaviour made it extremely easy to accidentally cause such a bug. (see o1-labs/zkapp-cli#406, where the Sudoku zkApp didn't specify the zkappKey argument). In general, optional arguments to a zkApp method are an absolute anti-pattern

@mitschabaude mitschabaude changed the title Fix init() Fix init() by removing optional key argument May 10, 2023
@mitschabaude mitschabaude changed the title Fix init() by removing optional key argument Fix init() by removing optional key argument May 10, 2023
Comment on lines +30 to +33
### Fixes

- Fix running SnarkyJS in Node.js on Windows https://github.com/o1-labs/snarkyjs-bindings/pull/19 (@wizicer)[https://github.com/wizicer]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated: this points to latest snarkyjs-bindings with a fix for windows o1-labs/o1js-bindings#19

@mitschabaude mitschabaude merged commit 2bc5ddf into main May 10, 2023
9 checks passed
@mitschabaude mitschabaude deleted the feature/init-assert-proved-state branch May 10, 2023 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deploying example Sudoku contract fails
2 participants