From 4919b7895645ff7e787c94b32535a1a0cbc17e75 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Wed, 2 Oct 2024 15:47:51 -0300 Subject: [PATCH 01/19] feat(sdk): FromStr trait for Networ enum --- batcher/aligned-sdk/src/core/types.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index 5ba32a3a8..37cac4093 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -1,3 +1,5 @@ +use std::str::FromStr; + use ethers::core::k256::ecdsa::SigningKey; use ethers::signers::Signer; use ethers::signers::Wallet; @@ -344,6 +346,19 @@ pub enum Network { HoleskyStage, } +impl FromStr for Network { + type Err = String; // The error type is a string + + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_str() { + "holesky" => Ok(Network::Holesky), + "holesky-stage" => Ok(Network::HoleskyStage), + "devnet" => Ok(Network::Devnet), + _ => Ok(Network::HoleskyStage), + } + } +} + #[cfg(test)] mod tests { use ethers::signers::LocalWallet; From c1b51e812b60a669e80c4a52869d9765abebb4c4 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Wed, 2 Oct 2024 15:49:11 -0300 Subject: [PATCH 02/19] feat(zkquiz): add batcher_url, network and chain_id args --- examples/zkquiz/quiz/script/src/main.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/zkquiz/quiz/script/src/main.rs b/examples/zkquiz/quiz/script/src/main.rs index 07e565f53..35a6380cb 100644 --- a/examples/zkquiz/quiz/script/src/main.rs +++ b/examples/zkquiz/quiz/script/src/main.rs @@ -1,5 +1,4 @@ #![feature(slice_flatten)] - use std::io; use std::sync::Arc; @@ -18,11 +17,8 @@ use sp1_sdk::{ProverClient, SP1Stdin}; abigen!(VerifierContract, "VerifierContract.json",); -const BATCHER_URL: &str = "wss://batcher.alignedlayer.com"; const ELF: &[u8] = include_bytes!("../../program/elf/riscv32im-succinct-zkvm-elf"); -const NETWORK: Network = Network::Holesky; - #[derive(Parser, Debug)] #[command(version, about, long_about = None)] struct Args { @@ -34,6 +30,12 @@ struct Args { default_value = "https://ethereum-holesky-rpc.publicnode.com" )] rpc_url: String, + #[arg(short, long, default_value = "wss://batcher.alignedlayer.com")] + batcher_url: String, + #[arg(short, long, default_value = "holesky")] + network: Network, + #[arg(short, long, default_value = "17000")] + chain_id: u64, #[arg(short, long)] verifier_contract_address: H160, } @@ -50,7 +52,7 @@ async fn main() { let wallet = LocalWallet::decrypt_keystore(args.keystore_path, &keystore_password) .expect("Failed to decrypt keystore") - .with_chain_id(17000u64); + .with_chain_id(args.chain_id); let provider = Provider::::try_from(rpc_url.as_str()).expect("Failed to connect to provider"); @@ -61,7 +63,7 @@ async fn main() { .with_prompt("Do you want to deposit 0.004eth in Aligned ?\nIf you already deposited Ethereum to Aligned before, this is not needed") .interact() .expect("Failed to read user input") { - deposit_to_batcher(wallet.address(), signer.clone()).await.expect("Failed to pay for proof submission"); + deposit_to_batcher(wallet.address(), signer.clone(), args.network).await.expect("Failed to pay for proof submission"); } // Generate proof. @@ -126,14 +128,14 @@ async fn main() { .expect("Failed to read user input") { return; } - let nonce = get_next_nonce(&rpc_url, wallet.address(), NETWORK) + let nonce = get_next_nonce(&rpc_url, wallet.address(), args.network) .await .expect("Failed to get next nonce"); let aligned_verification_data = submit_and_wait_verification( - BATCHER_URL, + &args.rpc_url, &rpc_url, - NETWORK, + args.network, &verification_data, max_fee, wallet.clone(), @@ -196,8 +198,9 @@ fn read_answer() -> char { async fn deposit_to_batcher( from: Address, signer: Arc, LocalWallet>>, + network: Network, ) -> anyhow::Result<()> { - let addr = get_payment_service_address(NETWORK); + let addr = get_payment_service_address(network); let tx = TransactionRequest::new() .from(from) From c057ce167d5b1734a486453a1b6eaeaa180c812b Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Wed, 2 Oct 2024 16:17:34 -0300 Subject: [PATCH 03/19] chore(zkquiz): add make commands to test locally --- examples/zkquiz/Makefile | 12 ++++++++++++ examples/zkquiz/contracts/.devnet.env | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 examples/zkquiz/contracts/.devnet.env diff --git a/examples/zkquiz/Makefile b/examples/zkquiz/Makefile index 45dfc5324..817e991a6 100644 --- a/examples/zkquiz/Makefile +++ b/examples/zkquiz/Makefile @@ -1,6 +1,9 @@ deploy_verifier: @. ./contracts/.env && . ./contracts/deploy.sh +deploy_verifier_devnet: + @. ./contracts/.devnet.env && . ./contracts/deploy.sh + CONTRACT_ADDRESS=0xA828f1463074d26FB761c662F80194f5dB2d31D0 RPC_URL=https://ethereum-holesky-rpc.publicnode.com VERIFICATION_DATA=./aligned_verification_data/0a1fab5df88a71e48633cbdeedc8d1a234b790d15a8a2fd04cd6a03c1e05b5ef_212.json @@ -10,3 +13,12 @@ answer_quiz: --keystore-path $(KEYSTORE_PATH) \ --rpc-url $(RPC_URL) \ --verifier-contract-address $(CONTRACT_ADDRESS) + +answer_quiz_local: + @cd quiz/script && cargo run -r -- \ + --keystore-path ../../../../config-files/devnet/keys/operator-3.ecdsa.key.json \ + --rpc-url http://localhost:8545 \ + --batcher-url ws://http://localhost:8545 \ + --network devnet \ + --chain-id 31337u64 \ + --verifier-contract-address $(CONTRACT_ADDRESS) \ No newline at end of file diff --git a/examples/zkquiz/contracts/.devnet.env b/examples/zkquiz/contracts/.devnet.env new file mode 100644 index 000000000..9b51f9caf --- /dev/null +++ b/examples/zkquiz/contracts/.devnet.env @@ -0,0 +1,4 @@ +RPC_URL=http://localhost:8545 +PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 # a rich anvil account +ALIGNED_SERVICE_MANAGER_ADDRESS=0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8 +BATCHER_PAYMENT_SERVICE_ADDRESS=0x7969c5eD335650692Bc04293B07F5BF2e7A673C0 From 862dbfd59d022dd16dcb433a89881de30df9d5b1 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Wed, 2 Oct 2024 16:25:02 -0300 Subject: [PATCH 04/19] docs(zkquiz): instructions to test locally --- examples/zkquiz/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/zkquiz/README.md b/examples/zkquiz/README.md index 1b32c390e..2dcb5d7d1 100644 --- a/examples/zkquiz/README.md +++ b/examples/zkquiz/README.md @@ -52,3 +52,12 @@ This will: 3. Pay & submit proof to aligned for verification 4. Wait for proof to be verified in aligned 5. Claim NFT if proof is verified + +## Testing locally + +If you want to test the zk quiz on a local network following this steps: + +1. From the root directory of the repo start anvil: `make anvil_start` +2. cd into the zkquiz example: `cd examples/zkquiz` +3. Deploy the verifier and locate the `CONTRACT_ADDRESS` from the output of: `make deploy_verifier_testnet` +4. Run the quiz: `CONTRACT_ADDRESS= make answer_quiz_local` \ No newline at end of file From 9e912fa45cefcf60d823da845786c267100c32c9 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Wed, 2 Oct 2024 16:40:34 -0300 Subject: [PATCH 05/19] fix(zkquiz): devnet chain id param --- examples/zkquiz/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/zkquiz/Makefile b/examples/zkquiz/Makefile index 817e991a6..4cf6682f7 100644 --- a/examples/zkquiz/Makefile +++ b/examples/zkquiz/Makefile @@ -20,5 +20,5 @@ answer_quiz_local: --rpc-url http://localhost:8545 \ --batcher-url ws://http://localhost:8545 \ --network devnet \ - --chain-id 31337u64 \ + --chain-id 31337 \ --verifier-contract-address $(CONTRACT_ADDRESS) \ No newline at end of file From c58cbbc8ac995db50b046154d6d624d4e340fc50 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Wed, 2 Oct 2024 16:43:06 -0300 Subject: [PATCH 06/19] fix(zkquiz): batcher ws url --- examples/zkquiz/Makefile | 2 +- examples/zkquiz/quiz/script/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/zkquiz/Makefile b/examples/zkquiz/Makefile index 4cf6682f7..2090ae06c 100644 --- a/examples/zkquiz/Makefile +++ b/examples/zkquiz/Makefile @@ -18,7 +18,7 @@ answer_quiz_local: @cd quiz/script && cargo run -r -- \ --keystore-path ../../../../config-files/devnet/keys/operator-3.ecdsa.key.json \ --rpc-url http://localhost:8545 \ - --batcher-url ws://http://localhost:8545 \ + --batcher-url ws://localhost:8545 \ --network devnet \ --chain-id 31337 \ --verifier-contract-address $(CONTRACT_ADDRESS) \ No newline at end of file diff --git a/examples/zkquiz/quiz/script/src/main.rs b/examples/zkquiz/quiz/script/src/main.rs index 35a6380cb..b416aac09 100644 --- a/examples/zkquiz/quiz/script/src/main.rs +++ b/examples/zkquiz/quiz/script/src/main.rs @@ -133,7 +133,7 @@ async fn main() { .expect("Failed to get next nonce"); let aligned_verification_data = submit_and_wait_verification( - &args.rpc_url, + &args.batcher_url, &rpc_url, args.network, &verification_data, From d533e93861ceee7546fb86f8a50eacab036bf8b8 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Wed, 2 Oct 2024 16:49:49 -0300 Subject: [PATCH 07/19] refactor(sdk): network from_str trait --- batcher/aligned-sdk/src/core/types.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index 37cac4093..c04c56f1c 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -347,14 +347,17 @@ pub enum Network { } impl FromStr for Network { - type Err = String; // The error type is a string + type Err = String; fn from_str(s: &str) -> Result { match s.to_lowercase().as_str() { "holesky" => Ok(Network::Holesky), "holesky-stage" => Ok(Network::HoleskyStage), "devnet" => Ok(Network::Devnet), - _ => Ok(Network::HoleskyStage), + _ => Err( + "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\"" + .to_string(), + ), } } } From bae15fb9da4ea1cffa3f66672b185a3c3b20b51f Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Wed, 2 Oct 2024 16:51:47 -0300 Subject: [PATCH 08/19] docs(zkquiz): updated instructions to test locally --- examples/zkquiz/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/zkquiz/README.md b/examples/zkquiz/README.md index 2dcb5d7d1..0a2f1a7df 100644 --- a/examples/zkquiz/README.md +++ b/examples/zkquiz/README.md @@ -57,7 +57,7 @@ This will: If you want to test the zk quiz on a local network following this steps: -1. From the root directory of the repo start anvil: `make anvil_start` +1. Setup Aligned locally following [this guide](../../docs/3_guides/6_setup_aligned.md) 2. cd into the zkquiz example: `cd examples/zkquiz` 3. Deploy the verifier and locate the `CONTRACT_ADDRESS` from the output of: `make deploy_verifier_testnet` 4. Run the quiz: `CONTRACT_ADDRESS= make answer_quiz_local` \ No newline at end of file From ff2f8706da18afafa0bec9982d6ac8f5d16f5041 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Wed, 2 Oct 2024 16:56:26 -0300 Subject: [PATCH 09/19] chore(zkquiz): eol for makefile --- examples/zkquiz/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/zkquiz/Makefile b/examples/zkquiz/Makefile index 2090ae06c..809778025 100644 --- a/examples/zkquiz/Makefile +++ b/examples/zkquiz/Makefile @@ -21,4 +21,4 @@ answer_quiz_local: --batcher-url ws://localhost:8545 \ --network devnet \ --chain-id 31337 \ - --verifier-contract-address $(CONTRACT_ADDRESS) \ No newline at end of file + --verifier-contract-address $(CONTRACT_ADDRESS) From 622e74889186c901471ad3f3b88c467a84da45de Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Wed, 2 Oct 2024 16:58:42 -0300 Subject: [PATCH 10/19] fix(zkquiz): batcher url --- examples/zkquiz/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/zkquiz/Makefile b/examples/zkquiz/Makefile index 809778025..8a2a33b85 100644 --- a/examples/zkquiz/Makefile +++ b/examples/zkquiz/Makefile @@ -18,7 +18,7 @@ answer_quiz_local: @cd quiz/script && cargo run -r -- \ --keystore-path ../../../../config-files/devnet/keys/operator-3.ecdsa.key.json \ --rpc-url http://localhost:8545 \ - --batcher-url ws://localhost:8545 \ + --batcher-url ws://localhost:8080 \ --network devnet \ --chain-id 31337 \ --verifier-contract-address $(CONTRACT_ADDRESS) From 0279066a70fcb31fabdbb01865767dcd78f1af2d Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Fri, 4 Oct 2024 12:02:55 -0300 Subject: [PATCH 11/19] docs(zkquiz): add note to local test --- examples/zkquiz/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/zkquiz/README.md b/examples/zkquiz/README.md index 0a2f1a7df..de0aacb59 100644 --- a/examples/zkquiz/README.md +++ b/examples/zkquiz/README.md @@ -60,4 +60,6 @@ If you want to test the zk quiz on a local network following this steps: 1. Setup Aligned locally following [this guide](../../docs/3_guides/6_setup_aligned.md) 2. cd into the zkquiz example: `cd examples/zkquiz` 3. Deploy the verifier and locate the `CONTRACT_ADDRESS` from the output of: `make deploy_verifier_testnet` -4. Run the quiz: `CONTRACT_ADDRESS= make answer_quiz_local` \ No newline at end of file +4. Run the quiz: `CONTRACT_ADDRESS= make answer_quiz_local` + +**Note** Make sure you send another proof alongside as the batcher will not create a task if it only has one proof in its queue. For example you could do: `make batcher_send_burst_groth16` From fa6605d97372ed707a7f7cecc9018a0a764b6711 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Fri, 4 Oct 2024 12:03:42 -0300 Subject: [PATCH 12/19] fix(zkquiz): remove chain_id arg --- examples/zkquiz/Makefile | 1 - examples/zkquiz/quiz/script/src/main.rs | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/zkquiz/Makefile b/examples/zkquiz/Makefile index 8a2a33b85..50fa6a0d8 100644 --- a/examples/zkquiz/Makefile +++ b/examples/zkquiz/Makefile @@ -20,5 +20,4 @@ answer_quiz_local: --rpc-url http://localhost:8545 \ --batcher-url ws://localhost:8080 \ --network devnet \ - --chain-id 31337 \ --verifier-contract-address $(CONTRACT_ADDRESS) diff --git a/examples/zkquiz/quiz/script/src/main.rs b/examples/zkquiz/quiz/script/src/main.rs index b416aac09..885b1dac2 100644 --- a/examples/zkquiz/quiz/script/src/main.rs +++ b/examples/zkquiz/quiz/script/src/main.rs @@ -34,8 +34,6 @@ struct Args { batcher_url: String, #[arg(short, long, default_value = "holesky")] network: Network, - #[arg(short, long, default_value = "17000")] - chain_id: u64, #[arg(short, long)] verifier_contract_address: H160, } @@ -51,8 +49,7 @@ async fn main() { .expect("Failed to read keystore password"); let wallet = LocalWallet::decrypt_keystore(args.keystore_path, &keystore_password) - .expect("Failed to decrypt keystore") - .with_chain_id(args.chain_id); + .expect("Failed to decrypt keystore"); let provider = Provider::::try_from(rpc_url.as_str()).expect("Failed to connect to provider"); @@ -63,6 +60,7 @@ async fn main() { .with_prompt("Do you want to deposit 0.004eth in Aligned ?\nIf you already deposited Ethereum to Aligned before, this is not needed") .interact() .expect("Failed to read user input") { + deposit_to_aligned(); deposit_to_batcher(wallet.address(), signer.clone(), args.network).await.expect("Failed to pay for proof submission"); } From 5242061a87b6a5e8b86aaf95ece160df77221149 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Fri, 4 Oct 2024 12:32:42 -0300 Subject: [PATCH 13/19] fix(zkquiz): get chain_id from rpc --- examples/zkquiz/quiz/script/src/main.rs | 57 +++++++------------------ 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/examples/zkquiz/quiz/script/src/main.rs b/examples/zkquiz/quiz/script/src/main.rs index 885b1dac2..4b83e3a1b 100644 --- a/examples/zkquiz/quiz/script/src/main.rs +++ b/examples/zkquiz/quiz/script/src/main.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use aligned_sdk::core::types::{ AlignedVerificationData, Network, PriceEstimate, ProvingSystemId, VerificationData, }; -use aligned_sdk::sdk::{estimate_fee, get_payment_service_address}; +use aligned_sdk::sdk::{deposit_to_aligned, estimate_fee, get_payment_service_address}; use aligned_sdk::sdk::{get_next_nonce, submit_and_wait_verification}; use clap::Parser; use dialoguer::Confirm; @@ -48,20 +48,27 @@ async fn main() { let keystore_password = rpassword::prompt_password("Enter keystore password: ") .expect("Failed to read keystore password"); - let wallet = LocalWallet::decrypt_keystore(args.keystore_path, &keystore_password) - .expect("Failed to decrypt keystore"); - let provider = Provider::::try_from(rpc_url.as_str()).expect("Failed to connect to provider"); - let signer = Arc::new(SignerMiddleware::new(provider.clone(), wallet.clone())); + let chain_id = provider + .get_chainid() + .await + .expect("Failed to get chain_id"); + + let wallet = LocalWallet::decrypt_keystore(args.keystore_path, &keystore_password) + .expect("Failed to decrypt keystore") + .with_chain_id(chain_id.as_u64()); + + let signer = SignerMiddleware::new(provider.clone(), wallet.clone()); if Confirm::with_theme(&dialoguer::theme::ColorfulTheme::default()) .with_prompt("Do you want to deposit 0.004eth in Aligned ?\nIf you already deposited Ethereum to Aligned before, this is not needed") .interact() .expect("Failed to read user input") { - deposit_to_aligned(); - deposit_to_batcher(wallet.address(), signer.clone(), args.network).await.expect("Failed to pay for proof submission"); + + deposit_to_aligned(U256::from(4000000000000000u128), signer.clone(), args.network).await + .expect("Failed to pay for proof submission"); } // Generate proof. @@ -193,44 +200,12 @@ fn read_answer() -> char { } } -async fn deposit_to_batcher( - from: Address, - signer: Arc, LocalWallet>>, - network: Network, -) -> anyhow::Result<()> { - let addr = get_payment_service_address(network); - - let tx = TransactionRequest::new() - .from(from) - .to(addr) - .value(4000000000000000u128); - - match signer - .send_transaction(tx, None) - .await - .map_err(|e| anyhow::anyhow!("Failed to send tx {}", e))? - .await - .map_err(|e| anyhow::anyhow!("Failed to submit tx {}", e))? - { - Some(receipt) => { - println!( - "Payment sent. Transaction hash: {:x}", - receipt.transaction_hash - ); - Ok(()) - } - None => { - anyhow::bail!("Payment failed"); - } - } -} - async fn claim_nft_with_verified_proof( aligned_verification_data: &AlignedVerificationData, - signer: Arc, LocalWallet>>, + signer: SignerMiddleware, LocalWallet>, verifier_contract_addr: &Address, ) -> anyhow::Result<()> { - let verifier_contract = VerifierContract::new(*verifier_contract_addr, signer); + let verifier_contract = VerifierContract::new(*verifier_contract_addr, signer.into()); let index_in_batch = U256::from(aligned_verification_data.index_in_batch); let merkle_path = Bytes::from( From 90c1d567c40fb810d2502a8dac5cee1db7ab44cf Mon Sep 17 00:00:00 2001 From: Marcos Nicolau <76252340+MarcosNicolau@users.noreply.github.com> Date: Fri, 4 Oct 2024 13:02:51 -0300 Subject: [PATCH 14/19] docs(zkquiz): local test typos --- examples/zkquiz/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/zkquiz/README.md b/examples/zkquiz/README.md index de0aacb59..6e93d773a 100644 --- a/examples/zkquiz/README.md +++ b/examples/zkquiz/README.md @@ -55,11 +55,11 @@ This will: ## Testing locally -If you want to test the zk quiz on a local network following this steps: +If you want to test the zk quiz on a local network follow these steps: 1. Setup Aligned locally following [this guide](../../docs/3_guides/6_setup_aligned.md) 2. cd into the zkquiz example: `cd examples/zkquiz` -3. Deploy the verifier and locate the `CONTRACT_ADDRESS` from the output of: `make deploy_verifier_testnet` +3. Deploy the verifier and locate the `CONTRACT_ADDRESS` from the output of: `make deploy_verifier_devnet` 4. Run the quiz: `CONTRACT_ADDRESS= make answer_quiz_local` **Note** Make sure you send another proof alongside as the batcher will not create a task if it only has one proof in its queue. For example you could do: `make batcher_send_burst_groth16` From 2846720345b82fd8c1a5e8c42b8b3348040ed534 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:01:38 -0300 Subject: [PATCH 15/19] feat: tidy the docs --- examples/zkquiz/README.md | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/examples/zkquiz/README.md b/examples/zkquiz/README.md index 6e93d773a..4a15bf53b 100644 --- a/examples/zkquiz/README.md +++ b/examples/zkquiz/README.md @@ -58,8 +58,28 @@ This will: If you want to test the zk quiz on a local network follow these steps: 1. Setup Aligned locally following [this guide](../../docs/3_guides/6_setup_aligned.md) -2. cd into the zkquiz example: `cd examples/zkquiz` -3. Deploy the verifier and locate the `CONTRACT_ADDRESS` from the output of: `make deploy_verifier_devnet` -4. Run the quiz: `CONTRACT_ADDRESS= make answer_quiz_local` -**Note** Make sure you send another proof alongside as the batcher will not create a task if it only has one proof in its queue. For example you could do: `make batcher_send_burst_groth16` +3. Move into the zkquiz example: + ``` + cd examples/zkquiz + ``` + +4. Deploy the ZKQuiz verifier contract, and locate the `CONTRACT_ADDRESS` from its output: + ``` + make deploy_verifier_devnet + ``` + + +5. Run the quiz: + ``` + CONTRACT_ADDRESS= make answer_quiz_local + ``` + +> [!NOTE] +> Make sure you send another proof alongside the ZKQuiz proof, as the batcher will not create a batch with only 1 proof. +> +> For example you could do: +> ``` +> make batcher_send_risc0_burst +> ``` + From 98a0869bec8304b6333119a43828e62a8f7bde97 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:16:02 -0300 Subject: [PATCH 16/19] feat: better prints and remove warnings --- examples/zkquiz/quiz/script/src/main.rs | 8 +++-- operator/merkle_tree/lib/Cargo.lock | 45 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/examples/zkquiz/quiz/script/src/main.rs b/examples/zkquiz/quiz/script/src/main.rs index 4b83e3a1b..1a2203d10 100644 --- a/examples/zkquiz/quiz/script/src/main.rs +++ b/examples/zkquiz/quiz/script/src/main.rs @@ -1,11 +1,10 @@ #![feature(slice_flatten)] use std::io; -use std::sync::Arc; use aligned_sdk::core::types::{ AlignedVerificationData, Network, PriceEstimate, ProvingSystemId, VerificationData, }; -use aligned_sdk::sdk::{deposit_to_aligned, estimate_fee, get_payment_service_address}; +use aligned_sdk::sdk::{deposit_to_aligned, estimate_fee}; use aligned_sdk::sdk::{get_next_nonce, submit_and_wait_verification}; use clap::Parser; use dialoguer::Confirm; @@ -137,6 +136,8 @@ async fn main() { .await .expect("Failed to get next nonce"); + println!("Submitting your proof..."); + let aligned_verification_data = submit_and_wait_verification( &args.batcher_url, &rpc_url, @@ -150,9 +151,10 @@ async fn main() { .unwrap(); println!( - "Proof submitted and verified successfully on batch {}, claiming prize...", + "Proof submitted and verified successfully on batch {}", hex::encode(aligned_verification_data.batch_merkle_root) ); + println!("Claiming NFT prize..."); claim_nft_with_verified_proof( &aligned_verification_data, diff --git a/operator/merkle_tree/lib/Cargo.lock b/operator/merkle_tree/lib/Cargo.lock index 079878cdb..bbae7f9b3 100644 --- a/operator/merkle_tree/lib/Cargo.lock +++ b/operator/merkle_tree/lib/Cargo.lock @@ -52,6 +52,7 @@ name = "aligned-sdk" version = "0.1.0" dependencies = [ "ciborium", + "dialoguer", "ethers", "futures-util", "hex", @@ -433,6 +434,19 @@ dependencies = [ "thiserror", ] +[[package]] +name = "console" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys 0.52.0", +] + [[package]] name = "const-hex" version = "1.11.4" @@ -590,6 +604,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "dialoguer" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658bce805d770f407bc62102fca7c2c64ceef2fbcb2b8bd19d2765ce093980de" +dependencies = [ + "console", + "shell-words", + "tempfile", + "thiserror", + "zeroize", +] + [[package]] name = "digest" version = "0.10.7" @@ -698,6 +725,12 @@ dependencies = [ "log", ] +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -2826,6 +2859,12 @@ dependencies = [ "keccak", ] +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + [[package]] name = "signature" version = "2.2.0" @@ -3407,6 +3446,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + [[package]] name = "unicode-xid" version = "0.2.4" From c859ac33453e075b2136afebe28f4fb60338aa41 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Mon, 7 Oct 2024 15:51:28 -0300 Subject: [PATCH 17/19] chore: add shell for linux --- examples/zkquiz/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/zkquiz/Makefile b/examples/zkquiz/Makefile index 50fa6a0d8..62812913c 100644 --- a/examples/zkquiz/Makefile +++ b/examples/zkquiz/Makefile @@ -1,3 +1,5 @@ +SHELL := /bin/bash + deploy_verifier: @. ./contracts/.env && . ./contracts/deploy.sh From 09577281fba5cba9ea6102c4525efa33351b6ac4 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:40:29 -0300 Subject: [PATCH 18/19] remove: deprecated note from docs --- examples/zkquiz/README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/examples/zkquiz/README.md b/examples/zkquiz/README.md index 4a15bf53b..14dc790c1 100644 --- a/examples/zkquiz/README.md +++ b/examples/zkquiz/README.md @@ -74,12 +74,3 @@ If you want to test the zk quiz on a local network follow these steps: ``` CONTRACT_ADDRESS= make answer_quiz_local ``` - -> [!NOTE] -> Make sure you send another proof alongside the ZKQuiz proof, as the batcher will not create a batch with only 1 proof. -> -> For example you could do: -> ``` -> make batcher_send_risc0_burst -> ``` - From f3800b5985849ca18cda8890e2b9be19838fc948 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:04:43 -0300 Subject: [PATCH 19/19] fix: bump fee to accept in a single batch --- examples/zkquiz/quiz/script/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/zkquiz/quiz/script/src/main.rs b/examples/zkquiz/quiz/script/src/main.rs index 1a2203d10..69d0092fb 100644 --- a/examples/zkquiz/quiz/script/src/main.rs +++ b/examples/zkquiz/quiz/script/src/main.rs @@ -120,7 +120,7 @@ async fn main() { pub_input: None, }; - let max_fee = estimate_fee(&rpc_url, PriceEstimate::Default) + let max_fee = estimate_fee(&rpc_url, PriceEstimate::Instant) .await .expect("failed to fetch gas price from the blockchain");