Skip to content

Commit

Permalink
new FAQs some are Mina
Browse files Browse the repository at this point in the history
  • Loading branch information
barriebyron committed Nov 16, 2023
1 parent 78a3054 commit 4693f66
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 2 deletions.
63 changes: 63 additions & 0 deletions docs/zkapps/faq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
47 changes: 45 additions & 2 deletions docs/zkapps/how-to-test-a-zkapp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4693f66

Please sign in to comment.