Skip to content

Commit

Permalink
Minor fixes - Dev feedback
Browse files Browse the repository at this point in the history
Minor fixes - Dev feedback
  • Loading branch information
45930 authored Sep 19, 2024
2 parents e184aee + c5758da commit ece2e8b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions examples/zkapps/01-hello-world/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions examples/zkapps/05-common-types-and-functions/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions examples/zkapps/10-account-updates/src/ProofsOnlyZkApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ 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));
this.calls.set(Field(0));
}

@method async add(incrementBy: Field) {
this.account.provedState.getAndRequireEquals();
this.account.provedState.get().assertTrue();
this.account.provedState.getAndRequireEquals().assertTrue();

const num = this.num.getAndRequireEquals();
this.num.set(num.add(incrementBy));
Expand All @@ -53,16 +51,14 @@ export class ProofsOnlyZkApp extends SmartContract {
}

@method async incrementCalls() {
this.account.provedState.getAndRequireEquals();
this.account.provedState.get().assertTrue();
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.get().assertTrue();
this.account.provedState.getAndRequireEquals().assertTrue();

const secondaryContract = new SecondaryZkApp(secondaryAddr);
const num = this.num.getAndRequireEquals();
Expand Down
10 changes: 5 additions & 5 deletions examples/zkapps/anonymous-message-board/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ 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
.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
Expand Down

0 comments on commit ece2e8b

Please sign in to comment.