Skip to content

Commit

Permalink
Merge branch 'main' into 640-docs-create-example-that-checks-public-i…
Browse files Browse the repository at this point in the history
…nput
  • Loading branch information
NicolasRampoldi authored Jul 25, 2024
2 parents 6f35a5c + 0cb4b14 commit bb1fcd1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 64 deletions.
2 changes: 1 addition & 1 deletion examples/zkquiz/quiz/script/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/zkquiz/quiz/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"

[dependencies]
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", rev = "v1.0.8-testnet" }
aligned-sdk = { git = "https://github.com/yetanotherco/aligned_layer" }
aligned-sdk = { git = "https://github.com/yetanotherco/aligned_layer", tag="v0.3.0" }
ethers = { tag = "v2.0.15-fix-reconnections", features = ["ws", "rustls"], git = "https://github.com/yetanotherco/ethers-rs.git" }
rpassword = "7.3.1"
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] }
Expand Down
92 changes: 30 additions & 62 deletions examples/zkquiz/quiz/script/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ use std::io;
use std::str::FromStr;
use std::sync::Arc;

use aligned_sdk::sdk::{submit, verify_proof_onchain};
use aligned_sdk::types::{AlignedVerificationData, Chain, ProvingSystemId, VerificationData};
use aligned_sdk::core::types::{AlignedVerificationData, Chain, ProvingSystemId, VerificationData};
use aligned_sdk::sdk::submit_and_wait;
use clap::Parser;
use dialoguer::Confirm;
use ethers::core::k256::ecdsa::SigningKey;
use ethers::prelude::*;
use ethers::providers::{Http, Provider};
use ethers::signers::{LocalWallet, Signer};
use ethers::types::{Address, Bytes, H160, U256};
use sp1_sdk::{ProverClient, SP1Stdin};

abigen!(
VerifierContract,
"VerifierContract.json",
);
abigen!(VerifierContract, "VerifierContract.json",);

const BATCHER_URL: &str = "wss://batcher.alignedlayer.com";
const BATCHER_PAYMENTS_ADDRESS: &str = "0x815aeCA64a974297942D2Bbf034ABEe22a38A003";
Expand Down Expand Up @@ -112,24 +108,36 @@ async fn main() {
pub_input: None,
};

match submit_proof_and_wait_for_verification(
verification_data,
match submit_and_wait(
BATCHER_URL,
&rpc_url,
Chain::Holesky,
&verification_data,
wallet.clone(),
rpc_url.clone(),
).await {
Ok(aligned_verification_data) => {
println!("Proof verified in Aligned, claiming prize...");

if let Err(e) = verify_batch_inclusion(
aligned_verification_data.clone(),
signer.clone(),
args.verifier_contract_address,
)
)
.await
{
Ok(maybe_aligned_verification_data) => match maybe_aligned_verification_data {
Some(aligned_verification_data) => {
println!(
"Proof submitted and verified successfully on batch {}, claiming prize...",
hex::encode(aligned_verification_data.batch_merkle_root)
);

if let Err(e) = verify_batch_inclusion(
aligned_verification_data.clone(),
signer.clone(),
args.verifier_contract_address,
)
.await
{
println!("Failed to claim prize: {:?}", e);
{
println!("Failed to claim prize: {:?}", e);
}
}
}
None => {
println!("Proof submission failed. No verification data");
}
},
Err(e) => {
println!("Proof verification failed: {:?}", e);
}
Expand Down Expand Up @@ -178,46 +186,6 @@ fn read_answer() -> char {
}
}

async fn submit_proof_and_wait_for_verification(
verification_data: VerificationData,
wallet: Wallet<SigningKey>,
rpc_url: String,
) -> anyhow::Result<AlignedVerificationData> {
let res = submit(BATCHER_URL, &verification_data, wallet.clone())
.await
.map_err(|e| anyhow::anyhow!("Failed to submit proof for verification: {:?}", e))?;

match res {
Some(aligned_verification_data) => {
println!(
"Proof submitted successfully on batch {}, waiting for verification...",
hex::encode(aligned_verification_data.batch_merkle_root)
);

for _ in 0..10 {
if verify_proof_onchain(
aligned_verification_data.clone(),
Chain::Holesky,
rpc_url.as_str(),
)
.await
.is_ok_and(|r| r)
{
return Ok(aligned_verification_data);
}

println!("Proof not verified yet. Waiting 10 seconds before checking again...");
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
}

anyhow::bail!("Proof verification failed");
}
None => {
anyhow::bail!("Proof submission failed, no verification data");
}
}
}

async fn pay_batcher(
from: Address,
signer: Arc<SignerMiddleware<Provider<Http>, LocalWallet>>,
Expand Down

0 comments on commit bb1fcd1

Please sign in to comment.