From e9afbf027145cbe5630e2ee736c4109d55af20c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Est=C3=A9fano=20Bargas?= Date: Fri, 27 Sep 2024 16:14:03 -0300 Subject: [PATCH] Fix zkapp address --- .env.template | 3 ++ core/src/utils/constants.rs | 2 -- example/app/src/main.rs | 2 +- example/mina_zkapp/package-lock.json | 15 ++++++++ example/mina_zkapp/package.json | 3 ++ example/mina_zkapp/src/run.ts | 51 ++++++++-------------------- 6 files changed, 36 insertions(+), 40 deletions(-) diff --git a/.env.template b/.env.template index 396301cc..1012d199 100644 --- a/.env.template +++ b/.env.template @@ -2,6 +2,9 @@ ETH_CHAIN= MINA_RPC_URL= SAVE_PROOF=true/false # also false if other than "true" or variable were to be not defined +## A Mina fee payer account is needed for running the Sudoku example +#FEEPAYER_KEY= + ## These can be skipped if using devnet with Anvil. # BATCHER_ADDR= # BATCHER_ETH_ADDR= diff --git a/core/src/utils/constants.rs b/core/src/utils/constants.rs index 67844030..392da9f3 100644 --- a/core/src/utils/constants.rs +++ b/core/src/utils/constants.rs @@ -18,10 +18,8 @@ pub const MINA_HASH_SIZE: usize = 32; // Bridge related constants pub const BRIDGE_DEVNET_ETH_ADDR: &str = "0x700b6A60ce7EaaEA56F065753d8dcB9653dbAD35"; -pub const BRIDGE_HOLESKY_ETH_ADDR: &str = "0x4Eb39dB24B0E89D49dD082EA68d6aab6514C613B"; pub const BRIDGE_TRANSITION_FRONTIER_LEN: usize = 16; pub const BRIDGE_ACCOUNT_DEVNET_ETH_ADDR: &str = "0xA15BB66138824a1c7167f5E85b957d04Dd34E468"; -pub const BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR: &str = "0x148Ff17B5142B85Bf387baF48b8681ccc014A3c9"; // Aligned related constants pub const PROOF_GENERATOR_ADDR: &str = "0x66f9664f97F2b50F62D13eA064982f936dE76657"; diff --git a/example/app/src/main.rs b/example/app/src/main.rs index ebe37cfe..f8c6a090 100644 --- a/example/app/src/main.rs +++ b/example/app/src/main.rs @@ -19,7 +19,7 @@ use mina_bridge_core::{ }; use std::{process, str::FromStr, time::SystemTime}; -const MINA_ZKAPP_ADDRESS: &str = "B62qkAgG7MFhpemxLsveJC7Xr5G1RmkbttJjASAxeQR3sGGHQWQN3HP"; +const MINA_ZKAPP_ADDRESS: &str = "B62qmpq1JBejZYDQrZwASPRM5oLXW346WoXgbApVf5HJZXMWFPWFPuA"; const SUDOKU_VALIDITY_DEVNET_ADDRESS: &str = "0xb19b36b1456E65E3A6D514D3F715f204BD59f431"; const SUDOKU_VALIDITY_HOLESKY_ADDRESS: &str = "0xeAB6068E1e06941A9d47734FB49C3B9dD69E054d"; diff --git a/example/mina_zkapp/package-lock.json b/example/mina_zkapp/package-lock.json index 406342ee..14104ebe 100644 --- a/example/mina_zkapp/package-lock.json +++ b/example/mina_zkapp/package-lock.json @@ -8,6 +8,9 @@ "name": "sudoku", "version": "0.1.0", "license": "Apache-2.0", + "dependencies": { + "dotenv": "^16.4.5" + }, "devDependencies": { "@babel/preset-env": "^7.16.4", "@babel/preset-typescript": "^7.16.0", @@ -4073,6 +4076,18 @@ "node": ">=6.0.0" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/electron-to-chromium": { "version": "1.5.24", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.24.tgz", diff --git a/example/mina_zkapp/package.json b/example/mina_zkapp/package.json index a06651b9..a3942228 100644 --- a/example/mina_zkapp/package.json +++ b/example/mina_zkapp/package.json @@ -41,5 +41,8 @@ }, "engines": { "node": ">=18.14.0" + }, + "dependencies": { + "dotenv": "^16.4.5" } } diff --git a/example/mina_zkapp/src/run.ts b/example/mina_zkapp/src/run.ts index 9d50d5b3..f4ed07cc 100644 --- a/example/mina_zkapp/src/run.ts +++ b/example/mina_zkapp/src/run.ts @@ -1,48 +1,25 @@ -import fs from 'fs/promises'; +import path from 'path'; import { Sudoku, SudokuZkApp } from './sudoku.js'; import { generateSudoku, solveSudoku } from './sudoku-lib.js'; -import { Mina, PrivateKey, NetworkId, fetchAccount } from 'o1js'; +import { Mina, PrivateKey, NetworkId, fetchAccount, PublicKey } from 'o1js'; +import dotenv from 'dotenv'; -const TX_MAX_TRIES = 5; -const DEPLOY_ALIAS = "devnet"; - -type Config = { - deployAliases: Record< - string, - { - networkId?: string; - url: string; - keyPath: string; - fee: string; - feepayerKeyPath: string; - feepayerAlias: string; - } - >; -}; +dotenv.config({ path: '../../.env' }); -let configJson: Config = JSON.parse(await fs.readFile('config.json', 'utf8')); -let config = configJson.deployAliases[DEPLOY_ALIAS]; - -let feepayerKeysBase58: { privateKey: string; publicKey: string } = JSON.parse( - await fs.readFile(config.feepayerKeyPath, 'utf8') -); -let zkAppKeysBase58: { privateKey: string; publicKey: string } = JSON.parse( - await fs.readFile(config.keyPath, 'utf8') -); -let feepayerKey = PrivateKey.fromBase58(feepayerKeysBase58.privateKey); -let zkAppKey = PrivateKey.fromBase58(zkAppKeysBase58.privateKey); +const TX_MAX_TRIES = 5; +const FEE = 0.1; // in MINA +let feepayerKey = PrivateKey.fromBase58(process.env.FEEPAYER_KEY as string); let feepayerAddress = feepayerKey.toPublicKey(); -let zkAppAddress = zkAppKey.toPublicKey(); + +let zkAppAddress = PublicKey.fromBase58("B62qmKCv2HaPwVRHBKrDFGUpjSh3PPY9VqSa6ZweGAmj9hBQL4pfewn"); // define network (devnet) const Network = Mina.Network({ - // We need to default to the testnet networkId if none is specified for this deploy alias in config.json - // This is to ensure the backward compatibility. - networkId: config.networkId as NetworkId, - mina: config.url, + networkId: "testnet" as NetworkId, + mina: "https://api.minascan.io/node/devnet/v1/graphql", }); -const fee = Number(config.fee) * 1e9; // in nanomina (1 billion = 1.0 mina) +const fee = Number(FEE) * 1e9; // in nanomina (1 billion = 1.0 mina) Mina.setActiveInstance(Network); // define zkapp and create sudoku to upload @@ -55,7 +32,7 @@ const sudoku = generateSudoku(0.5); console.log('Compiling Sudoku'); await SudokuZkApp.compile(); -console.log("Sending update transaction and waiting until it's included in a block"); +console.log("Sending update transaction"); await trySendTx( { sender: feepayerAddress, fee }, async () => { @@ -77,7 +54,7 @@ console.log('Is the sudoku solved?', zkApp.isSolved.get().toBoolean()); async function trySendTx(sender: Mina.FeePayerSpec, f: () => Promise) { for (let i = 1; i <= TX_MAX_TRIES; i++) { try { - console.log("Defining transaction"); + console.log("Define new transaction"); const tx = await Mina.transaction(sender, f); console.log("Proving transaction");