Skip to content

Commit

Permalink
Merge pull request #700 from qwadratic/tutorial-9-fix
Browse files Browse the repository at this point in the history
fix tutorial 9 typing errors added void type as a second param (where methods don’t return anything, and Field (where a method returns Field)
  • Loading branch information
barriebyron authored Nov 8, 2023
2 parents 23f8069 + adb55d1 commit b482165
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
6 changes: 3 additions & 3 deletions examples/zkapps/09-recursion/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const Add = ZkProgram({
addNumber: {
privateInputs: [SelfProof, Field ],

method(newState: Field, earlierProof: SelfProof<Field>, numberToAdd: Field) {
method(newState: Field, earlierProof: SelfProof<Field, void>, numberToAdd: Field) {
earlierProof.verify();
newState.assertEquals(earlierProof.publicInput.add(numberToAdd));
},
Expand All @@ -79,8 +79,8 @@ const Add = ZkProgram({

method(
newState: Field,
earlierProof1: SelfProof<Field>,
earlierProof2: SelfProof<Field>,
earlierProof1: SelfProof<Field, void>,
earlierProof2: SelfProof<Field, void>,
) {
earlierProof1.verify();
earlierProof2.verify();
Expand Down
22 changes: 6 additions & 16 deletions examples/zkapps/09-recursion/src/rollup.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import {
isReady,
shutdown,
Field,
Mina,
PrivateKey,
AccountUpdate,
SelfProof,
ZkProgram,
Struct,
Bool,
Circuit,
Poseidon,
MerkleMap,
MerkleTree,
MerkleWitness,
MerkleMapWitness,
verify,
Expand All @@ -23,14 +14,14 @@ import {
DeployArgs,
Proof,
Permissions,
ZkProgram
} from 'o1js';

class MerkleWitness20 extends MerkleWitness(20) {}

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

async function main() {
await isReady;

console.log('o1js loaded');

Expand Down Expand Up @@ -82,7 +73,7 @@ async function main() {
// const proof = await Rollup.oneStep(rollup, initialRoot, latestRoot, key, currentValue, increment, witness);
// return proof;
// });
const rollupProofs: Proof<RollupState>[] = [];
const rollupProofs: Proof<RollupState, void>[] = [];
for (var { initialRoot, latestRoot, key, currentValue, increment, witness } of rollupStepInfo) {
const rollup = RollupState.createOneStep(initialRoot, latestRoot, key, currentValue, increment, witness);
const proof = await Rollup.oneStep(rollup, initialRoot, latestRoot, key, currentValue, increment, witness);
Expand All @@ -97,7 +88,7 @@ async function main() {
// const rollup = RollupState.createMerged((await a).publicInput, (await b).publicInput);
// return await Rollup.merge(rollup, (await a), (await b));
// });
var proof: Proof<RollupState> = rollupProofs[0];
var proof: Proof<RollupState, void> = rollupProofs[0];
for (let i=1; i<rollupProofs.length; i++) {
const rollup = RollupState.createMerged(proof.publicInput, rollupProofs[i].publicInput);
let mergedProof = await Rollup.merge(rollup, proof, rollupProofs[i]);
Expand All @@ -111,8 +102,6 @@ async function main() {
console.log('ok', ok);

console.log('Shutting down');

await shutdown();
};

// ===============================================================
Expand Down Expand Up @@ -158,6 +147,7 @@ class RollupState extends Struct({
// ===============================================================

const Rollup = ZkProgram({
name: 'rollup',
publicInput: RollupState,

methods: {
Expand Down Expand Up @@ -190,8 +180,8 @@ const Rollup = ZkProgram({

method(
newState: RollupState,
rollup1proof: SelfProof<RollupState>,
rollup2proof: SelfProof<RollupState>,
rollup1proof: SelfProof<RollupState, void>,
rollup2proof: SelfProof<RollupState, void>,
) {
rollup1proof.verify();
rollup2proof.verify();
Expand Down
2 changes: 1 addition & 1 deletion examples/zkapps/09-recursion/src/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const Vote = ZkProgram({
privateInputs: [SelfProof, Bool, PrivateKey, MerkleWitness20, MerkleMapWitness],

method(newState: VoteState,
earlierProof: SelfProof<VoteState>,
earlierProof: SelfProof<VoteState, void>,
voteFor: Bool,
voter: PrivateKey,
voterWitness: MerkleWitness20,
Expand Down
2 changes: 1 addition & 1 deletion examples/zkapps/09-recursion/src/zkProgram_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const main = () => {
step: {
privateInputs: [ SelfProof ],

method(earlierProof: SelfProof<Field>) {
method(earlierProof: SelfProof<Field, Field>) {
earlierProof.verify();
return earlierProof.publicInput.add(1);
},
Expand Down

2 comments on commit b482165

@vercel
Copy link

@vercel vercel bot commented on b482165 Nov 8, 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-minadocs.vercel.app
07-oracles.vercel.app
07-oracles-git-main-minadocs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on b482165 Nov 8, 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

Please sign in to comment.