Skip to content

Commit

Permalink
fix: update sdk in zkquiz
Browse files Browse the repository at this point in the history
  • Loading branch information
JuArce committed Feb 10, 2025
1 parent 31019a9 commit ad664bc
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 13 deletions.
8 changes: 8 additions & 0 deletions examples/zkquiz/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ deploy_verifier_devnet:
. ./contracts/.devnet.env && . ./contracts/deploy.sh

CONTRACT_ADDRESS=0x1adFb00CC74Ff26bB05419953006c66B1abFCD45
STAGE_CONTRACT_ADDRESS=0xc4da6fcfa317eaf166b09ef276c0bdf43648a65f
RPC_URL=https://ethereum-holesky-rpc.publicnode.com

answer_quiz:
Expand All @@ -15,6 +16,13 @@ answer_quiz:
--rpc-url $(RPC_URL) \
--verifier-contract-address $(CONTRACT_ADDRESS)

answer_quiz_stage:
@cd quiz/script && cargo run -r -- \
--keystore-path $(KEYSTORE_PATH) \
--rpc-url $(RPC_URL) \
--network holesky-stage \
--verifier-contract-address $(STAGE_CONTRACT_ADDRESS)

answer_quiz_local:
@cd quiz/script && cargo run -r -- \
--keystore-path ../../../../config-files/devnet/keys/operator-3.ecdsa.key.json \
Expand Down
2 changes: 2 additions & 0 deletions examples/zkquiz/contracts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ forge script script/Deployer.s.sol \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--broadcast \
--verify \
--etherscan-api-key $ETHERSCAN_API_KEY \
--sig "run(address _alignedServiceManager, address _paymentService)"
110 changes: 97 additions & 13 deletions examples/zkquiz/quiz/script/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![feature(slice_flatten)]
use std::io;
use std::str::FromStr;

use aligned_sdk::core::types::{
AlignedVerificationData, Network, PriceEstimate, ProvingSystemId, VerificationData,
};
use aligned_sdk::core::types::{AlignedVerificationData, FeeEstimationType, Network, ProvingSystemId, VerificationData};
use aligned_sdk::sdk::{deposit_to_aligned, estimate_fee};
use aligned_sdk::sdk::{get_nonce_from_ethereum, submit_and_wait_verification};
use clap::Parser;
Expand All @@ -29,14 +28,99 @@ 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,
#[clap(flatten)]
network: NetworkArg,
#[arg(short, long)]
verifier_contract_address: H160,
}

#[derive(Debug, Clone, Copy)]
enum NetworkNameArg {
Devnet,
Holesky,
HoleskyStage,
Mainnet,
}

impl FromStr for NetworkNameArg {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"devnet" => Ok(NetworkNameArg::Devnet),
"holesky" => Ok(NetworkNameArg::Holesky),
"holesky-stage" => Ok(NetworkNameArg::HoleskyStage),
"mainnet" => Ok(NetworkNameArg::Mainnet),
_ => Err(
"Unknown network. Possible values: devnet, holesky, holesky-stage, mainnet"
.to_string(),
),
}
}
}

#[derive(Debug, clap::Args, Clone)]
struct NetworkArg {
#[arg(
name = "The working network's name",
long = "network",
default_value = "devnet",
help = "[possible values: devnet, holesky, holesky-stage, mainnet]"
)]
network: Option<NetworkNameArg>,
#[arg(
name = "Aligned Service Manager Contract Address",
long = "aligned_service_manager",
conflicts_with("The working network's name"),
requires("Batcher Payment Service Contract Address"),
requires("Batcher URL")
)]
aligned_service_manager_address: Option<String>,

#[arg(
name = "Batcher Payment Service Contract Address",
long = "batcher_payment_service",
conflicts_with("The working network's name"),
requires("Aligned Service Manager Contract Address"),
requires("Batcher URL")
)]
batcher_payment_service_address: Option<String>,

#[arg(
name = "Batcher URL",
long = "batcher_url",
conflicts_with("The working network's name"),
requires("Aligned Service Manager Contract Address"),
requires("Batcher Payment Service Contract Address")
)]
batcher_url: Option<String>,
}

impl From<NetworkArg> for Network {
fn from(network_arg: NetworkArg) -> Self {
let mut processed_network_argument = network_arg.clone();

if network_arg.batcher_url.is_some()
|| network_arg.aligned_service_manager_address.is_some()
|| network_arg.batcher_payment_service_address.is_some()
{
processed_network_argument.network = None; // We need this because network is Devnet as default, which is not true for a Custom network
}

match processed_network_argument.network {
None => Network::Custom(
network_arg.aligned_service_manager_address.unwrap(),
network_arg.batcher_payment_service_address.unwrap(),
network_arg.batcher_url.unwrap(),
),
Some(NetworkNameArg::Devnet) => Network::Devnet,
Some(NetworkNameArg::Holesky) => Network::Holesky,
Some(NetworkNameArg::HoleskyStage) => Network::HoleskyStage,
Some(NetworkNameArg::Mainnet) => Network::Mainnet,
}
}
}

#[tokio::main]
async fn main() {
println!("Welcome to the zkQuiz! Answer questions, generate a zkProof, and claim your NFT!");
Expand Down Expand Up @@ -66,7 +150,7 @@ async fn main() {
.interact()
.expect("Failed to read user input") {

deposit_to_aligned(U256::from(4000000000000000u128), signer.clone(), args.network).await
deposit_to_aligned(U256::from(4000000000000000u128), signer.clone(), args.network.clone().into()).await
.expect("Failed to pay for proof submission");
}

Expand Down Expand Up @@ -120,7 +204,7 @@ async fn main() {
pub_input: None,
};

let max_fee = estimate_fee(&rpc_url, PriceEstimate::Instant)
let max_fee = estimate_fee(&rpc_url, FeeEstimationType::Instant)
.await
.expect("failed to fetch gas price from the blockchain");

Expand All @@ -132,16 +216,15 @@ async fn main() {
.expect("Failed to read user input")
{ return; }

let nonce = get_nonce_from_ethereum(&rpc_url, wallet.address(), args.network)
let nonce = get_nonce_from_ethereum(&rpc_url, wallet.address(), args.network.clone().into())
.await
.expect("Failed to get next nonce");

println!("Submitting your proof...");
println!("Submitting your proof...");

let aligned_verification_data = submit_and_wait_verification(
&args.batcher_url,
&rpc_url,
args.network,
args.network.clone().into(),
&verification_data,
max_fee,
wallet.clone(),
Expand Down Expand Up @@ -207,6 +290,7 @@ async fn claim_nft_with_verified_proof(
signer: SignerMiddleware<Provider<Http>, LocalWallet>,
verifier_contract_addr: &Address,
) -> anyhow::Result<()> {
println!("Verifier contract address: {}", verifier_contract_addr);
let verifier_contract = VerifierContract::new(*verifier_contract_addr, signer.into());

let index_in_batch = U256::from(aligned_verification_data.index_in_batch);
Expand Down

0 comments on commit ad664bc

Please sign in to comment.