From 05cb9b4a72df452027f2220f2644fbc257bf68c6 Mon Sep 17 00:00:00 2001 From: Coby Date: Wed, 18 Sep 2024 17:12:34 -0400 Subject: [PATCH 1/3] minor fixes --- examples/zkapps/01-hello-world/src/main.ts | 2 ++ .../zkapps/02-private-inputs-and-hash-functions/src/main.ts | 2 ++ examples/zkapps/05-common-types-and-functions/src/main.ts | 2 ++ examples/zkapps/10-account-updates/src/ProofsOnlyZkApp.ts | 6 +----- examples/zkapps/anonymous-message-board/src/message.ts | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/zkapps/01-hello-world/src/main.ts b/examples/zkapps/01-hello-world/src/main.ts index c93b2d287..3e87cc9a2 100644 --- a/examples/zkapps/01-hello-world/src/main.ts +++ b/examples/zkapps/01-hello-world/src/main.ts @@ -19,6 +19,8 @@ const zkAppAddress = zkAppPrivateKey.toPublicKey(); // create an instance of Square - and deploy it to zkAppAddress const zkAppInstance = new Square(zkAppAddress); const deployTxn = await Mina.transaction(deployerAccount, async () => { + // 1 Mina fee is required to create a new account for the zkApp + // This line means the deployer account will pay the fee for any account created in this transaction AccountUpdate.fundNewAccount(deployerAccount); await zkAppInstance.deploy(); }); diff --git a/examples/zkapps/02-private-inputs-and-hash-functions/src/main.ts b/examples/zkapps/02-private-inputs-and-hash-functions/src/main.ts index 4a1c9decd..e1097c904 100644 --- a/examples/zkapps/02-private-inputs-and-hash-functions/src/main.ts +++ b/examples/zkapps/02-private-inputs-and-hash-functions/src/main.ts @@ -20,6 +20,8 @@ const zkAppAddress = zkAppPrivateKey.toPublicKey(); const zkAppInstance = new IncrementSecret(zkAppAddress); const deployTxn = await Mina.transaction(deployerAccount, async () => { + // 1 Mina fee is required to create a new account for the zkApp + // This line means the deployer account will pay the fee for any account created in this transaction AccountUpdate.fundNewAccount(deployerAccount); await zkAppInstance.deploy(); await zkAppInstance.initState(salt, Field(750)); diff --git a/examples/zkapps/05-common-types-and-functions/src/main.ts b/examples/zkapps/05-common-types-and-functions/src/main.ts index 7a5f85f7c..8a685c49b 100644 --- a/examples/zkapps/05-common-types-and-functions/src/main.ts +++ b/examples/zkapps/05-common-types-and-functions/src/main.ts @@ -179,6 +179,8 @@ const senderPrivateKey = senderPublicKey.key; // deploy the smart contract const deployTxn = await Mina.transaction(deployerAccount, async () => { + // 1 Mina fee is required to create a new account for the zkApp + // This line means the deployer account will pay the fee for any account created in this transaction AccountUpdate.fundNewAccount(deployerAccount); await zkApp.deploy(); // get the root of the new tree to use as the initial tree root diff --git a/examples/zkapps/10-account-updates/src/ProofsOnlyZkApp.ts b/examples/zkapps/10-account-updates/src/ProofsOnlyZkApp.ts index e60f9f22b..548a2a355 100644 --- a/examples/zkapps/10-account-updates/src/ProofsOnlyZkApp.ts +++ b/examples/zkapps/10-account-updates/src/ProofsOnlyZkApp.ts @@ -34,8 +34,7 @@ export class ProofsOnlyZkApp extends SmartContract { } @method async init() { - this.account.provedState.getAndRequireEquals(); - this.account.provedState.get().assertFalse(); + this.account.provedState.getAndRequireEquals().assertFalse(); super.init(); this.num.set(Field(1)); @@ -44,7 +43,6 @@ export class ProofsOnlyZkApp extends SmartContract { @method async add(incrementBy: Field) { this.account.provedState.getAndRequireEquals(); - this.account.provedState.get().assertTrue(); const num = this.num.getAndRequireEquals(); this.num.set(num.add(incrementBy)); @@ -54,7 +52,6 @@ export class ProofsOnlyZkApp extends SmartContract { @method async incrementCalls() { this.account.provedState.getAndRequireEquals(); - this.account.provedState.get().assertTrue(); const calls = this.calls.getAndRequireEquals(); this.calls.set(calls.add(Field(1))); @@ -62,7 +59,6 @@ export class ProofsOnlyZkApp extends SmartContract { @method async callSecondary(secondaryAddr: PublicKey) { this.account.provedState.getAndRequireEquals(); - this.account.provedState.get().assertTrue(); const secondaryContract = new SecondaryZkApp(secondaryAddr); const num = this.num.getAndRequireEquals(); diff --git a/examples/zkapps/anonymous-message-board/src/message.ts b/examples/zkapps/anonymous-message-board/src/message.ts index 56cf38d18..2f4b4518b 100644 --- a/examples/zkapps/anonymous-message-board/src/message.ts +++ b/examples/zkapps/anonymous-message-board/src/message.ts @@ -62,13 +62,13 @@ export class Message extends SmartContract { .equals(user1) .or(signerPublicKey.equals(user2)) .or(signerPublicKey.equals(user3)) - .assertEquals(true); + .assertTrue(); // Update on-chain message state this.message.set(message); // Compute new messageHistoryHash - const oldHash = this.messageHistoryHash.get(); + const oldHash = this.messageHistoryHash.getAndRequireEquals(); const newHash = Poseidon.hash([message, oldHash]); // Update on-chain messageHistoryHash From 70b1f24e602572a9c5fc33d37adc5d221463a143 Mon Sep 17 00:00:00 2001 From: Coby Date: Wed, 18 Sep 2024 17:20:52 -0400 Subject: [PATCH 2/3] fix reversion --- examples/zkapps/10-account-updates/src/ProofsOnlyZkApp.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/zkapps/10-account-updates/src/ProofsOnlyZkApp.ts b/examples/zkapps/10-account-updates/src/ProofsOnlyZkApp.ts index 548a2a355..48ac83ed4 100644 --- a/examples/zkapps/10-account-updates/src/ProofsOnlyZkApp.ts +++ b/examples/zkapps/10-account-updates/src/ProofsOnlyZkApp.ts @@ -42,7 +42,7 @@ export class ProofsOnlyZkApp extends SmartContract { } @method async add(incrementBy: Field) { - this.account.provedState.getAndRequireEquals(); + this.account.provedState.getAndRequireEquals().assertTrue(); const num = this.num.getAndRequireEquals(); this.num.set(num.add(incrementBy)); @@ -51,14 +51,14 @@ export class ProofsOnlyZkApp extends SmartContract { } @method async incrementCalls() { - this.account.provedState.getAndRequireEquals(); + this.account.provedState.getAndRequireEquals().assertTrue(); const calls = this.calls.getAndRequireEquals(); this.calls.set(calls.add(Field(1))); } @method async callSecondary(secondaryAddr: PublicKey) { - this.account.provedState.getAndRequireEquals(); + this.account.provedState.getAndRequireEquals().assertTrue(); const secondaryContract = new SecondaryZkApp(secondaryAddr); const num = this.num.getAndRequireEquals(); From c5758dad74b4616774e782706ce1fe4f41ee9a3a Mon Sep 17 00:00:00 2001 From: Coby Date: Wed, 18 Sep 2024 17:23:00 -0400 Subject: [PATCH 3/3] more getAndRequires --- examples/zkapps/anonymous-message-board/src/message.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/zkapps/anonymous-message-board/src/message.ts b/examples/zkapps/anonymous-message-board/src/message.ts index 2f4b4518b..42f67301a 100644 --- a/examples/zkapps/anonymous-message-board/src/message.ts +++ b/examples/zkapps/anonymous-message-board/src/message.ts @@ -53,9 +53,9 @@ export class Message extends SmartContract { const signerPublicKey = signerPrivateKey.toPublicKey(); // Get approved public keys - const user1 = this.user1.get(); - const user2 = this.user2.get(); - const user3 = this.user3.get(); + const user1 = this.user1.getAndRequireEquals(); + const user2 = this.user2.getAndRequireEquals(); + const user3 = this.user3.getAndRequireEquals(); // Assert that signerPublicKey is one of the approved public keys signerPublicKey