Skip to content

Commit

Permalink
feat: add ZkVerificationProvider and allows for verification via zksy…
Browse files Browse the repository at this point in the history
…nc block explorer
  • Loading branch information
dutterbutter committed Oct 4, 2024
1 parent cc27c50 commit b8723d0
Show file tree
Hide file tree
Showing 6 changed files with 403 additions and 29 deletions.
4 changes: 2 additions & 2 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ impl CreateArgs {
config.get_etherscan_config_with_chain(Some(chain.into()))?.map(|c| c.key);

let context = if verify.zksync {
CompilerVerificationContext::Solc(verify.resolve_context().await?)
} else {
CompilerVerificationContext::ZkSolc(verify.zk_resolve_context().await?)
} else {
CompilerVerificationContext::Solc(verify.resolve_context().await?)
};

verify.verification_provider()?.preflight_check(verify, context).await?;
Expand Down
1 change: 1 addition & 0 deletions crates/verify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use provider::VerificationProvider;
pub mod bytecode;
pub mod retry;
mod sourcify;
mod zksync;

pub use retry::RetryArgs;

Expand Down
11 changes: 9 additions & 2 deletions crates/verify/src/provider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
etherscan::EtherscanVerificationProvider, sourcify::SourcifyVerificationProvider, VerifyArgs,
VerifyCheckArgs,
etherscan::EtherscanVerificationProvider, sourcify::SourcifyVerificationProvider,
zksync::ZkVerificationProvider, VerifyArgs, VerifyCheckArgs,
};
use crate::zk_provider::CompilerVerificationContext;
use alloy_json_abi::JsonAbi;
Expand Down Expand Up @@ -128,6 +128,7 @@ impl FromStr for VerificationProviderType {
"s" | "sourcify" => Ok(Self::Sourcify),
"b" | "blockscout" => Ok(Self::Blockscout),
"o" | "oklink" => Ok(Self::Oklink),
"z" | "zksync" => Ok(Self::ZKsync),
_ => Err(format!("Unknown provider: {s}")),
}
}
Expand All @@ -148,6 +149,9 @@ impl fmt::Display for VerificationProviderType {
Self::Oklink => {
write!(f, "oklink")?;
}
Self::ZKsync => {
write!(f, "zksync")?;
}
};
Ok(())
}
Expand All @@ -160,6 +164,8 @@ pub enum VerificationProviderType {
Sourcify,
Blockscout,
Oklink,
#[value(alias = "zksync")]
ZKsync,
}

impl VerificationProviderType {
Expand All @@ -175,6 +181,7 @@ impl VerificationProviderType {
Self::Sourcify => Ok(Box::<SourcifyVerificationProvider>::default()),
Self::Blockscout => Ok(Box::<EtherscanVerificationProvider>::default()),
Self::Oklink => Ok(Box::<EtherscanVerificationProvider>::default()),
Self::ZKsync => Ok(Box::<ZkVerificationProvider>::default()),
}
}
}
25 changes: 0 additions & 25 deletions crates/verify/src/zk_provider.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::provider::VerificationContext;

use super::{VerifyArgs, VerifyCheckArgs};
use alloy_json_abi::JsonAbi;
use async_trait::async_trait;
use eyre::{OptionExt, Result};
use foundry_common::compile::ProjectCompiler;
use foundry_compilers::{
Expand Down Expand Up @@ -124,29 +122,6 @@ impl ZkVerificationContext {
}
}

/// An abstraction for various verification providers such as etherscan, sourcify, blockscout
#[async_trait]
pub trait ZkVerificationProvider {
/// This should ensure the verify request can be prepared successfully.
///
/// Caution: Implementers must ensure that this _never_ sends the actual verify request
/// `[VerificationProvider::verify]`, instead this is supposed to evaluate whether the given
/// [`VerifyArgs`] are valid to begin with. This should prevent situations where there's a
/// contract deployment that's executed before the verify request and the subsequent verify task
/// fails due to misconfiguration.
async fn preflight_check(
&mut self,
args: VerifyArgs,
context: ZkVerificationContext,
) -> Result<()>;

/// Sends the actual verify request for the targeted contract.
async fn verify(&mut self, args: VerifyArgs, context: ZkVerificationContext) -> Result<()>;

/// Checks whether the contract is verified.
async fn check(&self, args: VerifyCheckArgs) -> Result<()>;
}

#[derive(Debug)]
pub enum CompilerVerificationContext {
Solc(VerificationContext),
Expand Down
Loading

0 comments on commit b8723d0

Please sign in to comment.