Skip to content

Commit

Permalink
Merge pull request #714 from o1-labs/zkprogram
Browse files Browse the repository at this point in the history
docs: ZkProgram docs and code, remove experimental, add name argument
  • Loading branch information
barriebyron authored Nov 2, 2023
2 parents 944d189 + 1aaae98 commit 7a2f690
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
1 change: 0 additions & 1 deletion docs/zkapps/o1js-reference/modules/Experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ This module exposes APIs that are unstable, in the sense that the API surface is

### Functions

- [ZkProgram](Experimental.md#zkprogram)
- [createChildAccountUpdate](Experimental.md#createchildaccountupdate)
- [memoizeWitness](Experimental.md#memoizewitness)

Expand Down
33 changes: 17 additions & 16 deletions docs/zkapps/o1js/recursion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ Kimchi, the proof system that backs o1js, supports arbitrary infinite recursive

More generally, you can use recursion to verify any zero-knowledge program as part of your zkApp.

:::experimental
## ZkProgram Overview

The use of the ZkProgram API with recursion is experimental. This API may change. To learn more, see [Experimental Features](/zkapps/experimental).

Specifically, ZkProgram methods could be refactored to explicitly return values rather than requiring them to be passed as further inputs.
:::note
zkProgram has been moved out of the Experimental namespace and is available as a top-level import directly. `Experimental.ZkProgram` is deprecated.

If you are experiencing issues with zkProgram, be sure to update o1js to the latest version.
:::

## Overview

In o1js, you can use `ZkProgram()` to define the steps of our recursive program. Just like `SmartContract()` methods, `ZkProgram()` methods have any number of methods and execute off-chain.
In o1js, you can use `ZkProgram()` to define the steps of a recursive program. Just like `SmartContract()` methods, `ZkProgram()` methods have any number of methods and execute off-chain.

After performing your desired recursive steps, you can settle the interaction on Mina's blockchain and by embedding the `ZkProgram` within a `SmartContract` method that verifies the underlying proof of execution and extracts the output that can be used elsewhere in the method (like storing the output in app-state, for example).

Expand All @@ -53,10 +51,11 @@ Similar to methods within the `SmartContract` class, inputs to `ZkProgram` are _
This simple example has only one method that proves the public input it received is zero.

```typescript
import { Field, Experimental } from 'o1js';
import { Field, ZkProgram } from 'o1js';

const SimpleProgram = Experimental.ZkProgram({
publicInput: Field,
const SimpleProgram = ZkProgram({
name: "simple-program-example",
publicInputType: Field,

methods: {
run: {
Expand Down Expand Up @@ -103,10 +102,11 @@ This example shows a recursive `ZkProgram` that you can use to create recursive
This program describes a recursive operation of adding one repeatedly to a number. Note that you recursively depend on the older proof as a private argument to your method.

```typescript
import { SelfProof, Field, Experimental, verify } from 'o1js';
import { SelfProof, Field, ZkProgram, verify } from 'o1js';

const AddOne = Experimental.ZkProgram({
publicInput: Field,
const AddOne = ZkProgram({
name: "add-one-example",
publicInputType: Field,

methods: {
baseCase: {
Expand Down Expand Up @@ -166,10 +166,11 @@ Tree recursion is even more rarely seen in other proof systems and zk toolkits.
This example program describes a very simple rollup for adding numbers:

```typescript
import { SelfProof, Field, Experimental, verify } from 'o1js';
import { SelfProof, Field, ZkProgram, verify } from 'o1js';

let RollupAdd = Experimental.ZkProgram({
publicInput: Field,
let RollupAdd = ZkProgram({
name: "rollup-add-example",
publicInputType: Field,

methods: {
baseCase: {
Expand Down
10 changes: 6 additions & 4 deletions docs/zkapps/tutorials/09-recursion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ To create a ZkProgram, start with the `init()` method.
- The first argument of a ZkProgram method is always the state of the ZkProgram, named `publicInput` since it is public.

```typescript
const Add = Experimental.ZkProgram({
publicInput: Field,
const Add = ZkProgram({
name: 'add-example',
publicInputType: Field,

methods: {
init: {
Expand Down Expand Up @@ -263,8 +264,9 @@ class RollupState extends Struct({
...
}

const Rollup = Experimental.ZkProgram({
publicInput: RollupState,
const Rollup = ZkProgram({
name: "rollup-example",
publicInputType: Field,

methods: {
oneStep: {
Expand Down
4 changes: 2 additions & 2 deletions examples/zkapps/09-recursion/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PrivateKey,
AccountUpdate,
SelfProof,
Experimental,
ZkProgram,
Struct,
Bool,
Circuit,
Expand Down Expand Up @@ -53,7 +53,7 @@ async function main() {
await shutdown();
}

const Add = Experimental.ZkProgram({
const Add = ZkProgram({
publicInput: Field,

methods: {
Expand Down
6 changes: 3 additions & 3 deletions examples/zkapps/09-recursion/src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
PrivateKey,
AccountUpdate,
SelfProof,
Experimental,
ZkProgram,
Struct,
Bool,
Circuit,
Expand Down Expand Up @@ -157,7 +157,7 @@ class RollupState extends Struct({

// ===============================================================

const Rollup = Experimental.ZkProgram({
const Rollup = ZkProgram({
publicInput: RollupState,

methods: {
Expand Down Expand Up @@ -205,7 +205,7 @@ const Rollup = Experimental.ZkProgram({
},
});

export let RollupProof_ = Experimental.ZkProgram.Proof(Rollup);
export let RollupProof_ = ZkProgram.Proof(Rollup);
export class RollupProof extends RollupProof_ {}

// ===============================================================
Expand Down
4 changes: 2 additions & 2 deletions examples/zkapps/09-recursion/src/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PrivateKey,
AccountUpdate,
SelfProof,
Experimental,
ZkProgram,
Struct,
Bool,
Circuit,
Expand Down Expand Up @@ -144,7 +144,7 @@ class VoteState extends Struct({

// ===============================================================

const Vote = Experimental.ZkProgram({
const Vote = ZkProgram({
publicInput: VoteState,

methods: {
Expand Down
4 changes: 2 additions & 2 deletions examples/zkapps/09-recursion/src/zkProgram_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
PrivateKey,
AccountUpdate,
SelfProof,
Experimental,
ZkProgram,
Struct,
Bool,
Circuit,
Expand Down Expand Up @@ -63,7 +63,7 @@ const ZkProgram = (config : any) => {
}
});

const originalZkProgram = Experimental.ZkProgram(zkProgramConfig);
const originalZkProgram = ZkProgram(zkProgramConfig);

const zkProgram: any = {};

Expand Down

2 comments on commit 7a2f690

@vercel
Copy link

@vercel vercel bot commented on 7a2f690 Nov 2, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

docs2 – ./

docs2-git-main-minadocs.vercel.app
docs2-minadocs.vercel.app
docs.minaprotocol.com

@vercel
Copy link

@vercel vercel bot commented on 7a2f690 Nov 2, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

07-oracles – ./examples/zkapps/07-oracles/oracle

07-oracles.vercel.app
07-oracles-git-main-minadocs.vercel.app
07-oracles-minadocs.vercel.app

Please sign in to comment.