From 4693f6695198d6f81979c8a5d1cc9d481a89f257 Mon Sep 17 00:00:00 2001 From: barriebyron Date: Thu, 16 Nov 2023 14:05:40 -0500 Subject: [PATCH 1/3] new FAQs some are Mina --- docs/zkapps/faq.mdx | 63 +++++++++++++++++++++++++++++ docs/zkapps/how-to-test-a-zkapp.mdx | 47 ++++++++++++++++++++- 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/docs/zkapps/faq.mdx b/docs/zkapps/faq.mdx index c0ce96a3c..cb04c63cc 100644 --- a/docs/zkapps/faq.mdx +++ b/docs/zkapps/faq.mdx @@ -95,3 +95,66 @@ This example fails for two reasons: 1. `n.toString()` can't be used in circuit code at all. It throws an error during `SmartContract.compile()` because during `compile()`, variables like `n` don't have any JS values attached to them; they represent abstract variables used to build up an abstract arithmetic circuit. So, in general, you can't use any of the methods that read out the JS value of your Field elements: `Field.toString()`, `Field.toBigInt()`, `Bool.toBoolean()` etc. 2. More subtly, your methods must create the same constraints every time because a proof cannot be verified against a verification key for a differing set of constraints. The code above adds `x.equals(y).assertFalse()` _on condition of_ the value of `n` which leads to constraints varying between executions of the proof. + +### Why is the variable currentState set to a value retrieved from the blockchain and then immediately compared to that value? + +As represented in the tutorial example code: + +```TypeScript +const currentState = this.num.get(); + +this.num.assertEquals(currentState); +``` + +- The first line of code executes before the proof is generated. +- The second line of code creates a precondition that is checked when the proof is sent to the blockchain to be verified. + +This ensures that the transaction fails if the value of the field in question has changed. + +### Can I pass hex values into Fields? + +Yes, just pass in the appropriate BigInt literal. + +`Field(0x1337)` + +### Can I pass arguments to the SmartContract init method? + +The best practice is no. To test something with more than one initialization state, you can set the state by passing arguments to another user-defined method. + +### Can I use TypeScript enums? + +You can try! We experimented with this, so it might generate unconstrained functionality. + +### How can I use the Field type? + +Are there specific reasons I want to specify the `Field` type? + +All provable types are built using the type `Field`. For efficiency, use `Field` only when you do not need to take advantage of the properties of the other provable types in o1js. + +### What does the @method decorator do? + +It allows the method to be invoked by a user interacting with the smart contract. You can check out the compiled JavaScript in `./build/src` to see exactly what's going on. + +### How can you enforce that an account update must be signed by the account owner? + +Use the `requireSignature` command. See the [requireSignature](/zkapps/o1js-reference/classes/SmartContract#requiresignature) Method reference. + +### How do I configure who has the authority to interact and make changes to a specific part of an account? + +Permissions determine who has the authority to interact and make changes to a specific part of a smart contract. See [Permissions](https://docs.minaprotocol.com/zkapps/o1js/permissions). + +### How are proofs generated in the Mina Protocol? + +[Kimchi](https://minaprotocol.com/blog/kimchi-the-latest-update-to-minas-proof-system) is the main machinery that generates the recursive proofs that allow the Mina blockchain to remain of a fixed size of about 22 KB. See [Proof systems](https://o1-labs.github.io/proof-systems/). + +### Are there proof generation scenarios when recursive proofs are not needed? + +Yes. It is possible to use the Kimchi proof system without the Pickles recursion layer. See [Pickles](https://o1-labs.github.io/proof-systems/specs/pickles.html?highlight=pickl#pickles) in the Mina book. + +### Which curves are used by the Mina Protocol to generate proofs? + +Pasta curves (Pallas and Vesta). See [Pasta Curves](https://o1-labs.github.io/proof-systems/specs/pasta.html?highlight=curves#pasta-curves) in the Mina book. + +### When do I use Provable conditional logic? + +Are there situations in which I would not want to use the Provable versions? If the conditional logic is not part of your provable code, you do not need to use Provable conditional statements. \ No newline at end of file diff --git a/docs/zkapps/how-to-test-a-zkapp.mdx b/docs/zkapps/how-to-test-a-zkapp.mdx index 77a8802c7..5200620ce 100644 --- a/docs/zkapps/how-to-test-a-zkapp.mdx +++ b/docs/zkapps/how-to-test-a-zkapp.mdx @@ -28,9 +28,52 @@ A Docker image for Mina local networks provides a simple and efficient way to de - Genesis ledger with pre-funded accounts - Accounts manager service - Additional port served by reverse proxy to pass requests to the Mina daemon GraphQL endpoint so zkApps work without additional configuration -- Single commands to launch a single node or multi node network +- Single command to launch a single node or multi node network +- `zk lightnet` sub-commands to manage the local network + +### Installation + +See the specifications and usage at [o1labs/mina-local-network](https://hub.docker.com/r/o1labs/mina-local-network) on Docker Hub. + +Pull the image from Docker Hub. + +You must have Docker Engine installed on your host machine. + +Network readiness time depends on resources allocated for the Docker Engine. +- macOS and Windows: Configure resources +- Linux: Configuration is not required + +### Managing your local network + +Use the `zk lightnet` subcommands to manage your lightweight Mina blockchain. + +You can configure the local blockchain when you start it: + +```sh +zk lightnet start [mode] [type] [proof-level] [mina-branch] [archive] [sync] [pull] [debug] +``` + +Use `zk lightnet start --help` for optional configuration: + +- `mode`: The default 'single-node' mode makes the network fastest. +- `type`: + +To stop the lightweight Mina blockchain Docker container: + +```sh +zk lightnet stop +``` + +To zk lightnet status + +boolean options with default value of true can be negated by adding --no- prefix. +For example: + +The --archive option of zk lightnet start sub-command is true by default. And to set it to false you can do zk lightnet start --no-archive. + +protocol configuration. One of the expensive parts of the protocol is creating blockchain snark proofs, so mocking that is important for faster everything. The proof_level Mina constant can be used to disable proving (set it to be check) or disable block calculation altogether (set it to none). None is default because for zkApps development with o1js we don't really care about protocol proofs, assuming that it is well tested. Sometimes though one might want to run zkApps against network that has closer to "real world" properties (say, some of the Nightly CI tests). That is when zk lightnet start --mode multi-node --type real --proof-level full might be useful. + -Pull the [o1labs/mina-local-network](https://hub.docker.com/r/o1labs/mina-local-network) image from Docker Hub. ## Writing tests for your smart contract From 7d800c4a82179c98a030e6a78a93c12e9158b38c Mon Sep 17 00:00:00 2001 From: barriebyron Date: Thu, 16 Nov 2023 14:07:41 -0500 Subject: [PATCH 2/3] remove the testing doc from this PR --- docs/zkapps/how-to-test-a-zkapp.mdx | 47 ++--------------------------- 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/docs/zkapps/how-to-test-a-zkapp.mdx b/docs/zkapps/how-to-test-a-zkapp.mdx index 5200620ce..77a8802c7 100644 --- a/docs/zkapps/how-to-test-a-zkapp.mdx +++ b/docs/zkapps/how-to-test-a-zkapp.mdx @@ -28,52 +28,9 @@ A Docker image for Mina local networks provides a simple and efficient way to de - Genesis ledger with pre-funded accounts - Accounts manager service - Additional port served by reverse proxy to pass requests to the Mina daemon GraphQL endpoint so zkApps work without additional configuration -- Single command to launch a single node or multi node network -- `zk lightnet` sub-commands to manage the local network - -### Installation - -See the specifications and usage at [o1labs/mina-local-network](https://hub.docker.com/r/o1labs/mina-local-network) on Docker Hub. - -Pull the image from Docker Hub. - -You must have Docker Engine installed on your host machine. - -Network readiness time depends on resources allocated for the Docker Engine. -- macOS and Windows: Configure resources -- Linux: Configuration is not required - -### Managing your local network - -Use the `zk lightnet` subcommands to manage your lightweight Mina blockchain. - -You can configure the local blockchain when you start it: - -```sh -zk lightnet start [mode] [type] [proof-level] [mina-branch] [archive] [sync] [pull] [debug] -``` - -Use `zk lightnet start --help` for optional configuration: - -- `mode`: The default 'single-node' mode makes the network fastest. -- `type`: - -To stop the lightweight Mina blockchain Docker container: - -```sh -zk lightnet stop -``` - -To zk lightnet status - -boolean options with default value of true can be negated by adding --no- prefix. -For example: - -The --archive option of zk lightnet start sub-command is true by default. And to set it to false you can do zk lightnet start --no-archive. - -protocol configuration. One of the expensive parts of the protocol is creating blockchain snark proofs, so mocking that is important for faster everything. The proof_level Mina constant can be used to disable proving (set it to be check) or disable block calculation altogether (set it to none). None is default because for zkApps development with o1js we don't really care about protocol proofs, assuming that it is well tested. Sometimes though one might want to run zkApps against network that has closer to "real world" properties (say, some of the Nightly CI tests). That is when zk lightnet start --mode multi-node --type real --proof-level full might be useful. - +- Single commands to launch a single node or multi node network +Pull the [o1labs/mina-local-network](https://hub.docker.com/r/o1labs/mina-local-network) image from Docker Hub. ## Writing tests for your smart contract From 6897ecf98aa943219d409e7e0325265cd42edf7a Mon Sep 17 00:00:00 2001 From: Barrie Byron Date: Fri, 17 Nov 2023 09:55:42 -0500 Subject: [PATCH 3/3] Gar's update in a transaction --- docs/zkapps/faq.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zkapps/faq.mdx b/docs/zkapps/faq.mdx index cb04c63cc..734faf1e4 100644 --- a/docs/zkapps/faq.mdx +++ b/docs/zkapps/faq.mdx @@ -107,7 +107,7 @@ this.num.assertEquals(currentState); ``` - The first line of code executes before the proof is generated. -- The second line of code creates a precondition that is checked when the proof is sent to the blockchain to be verified. +- The second line of code creates a precondition that is checked when the proof is sent in a transaction to the blockchain to be verified. This ensures that the transaction fails if the value of the field in question has changed.