Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds verification for zksync block explorer #599

Merged
merged 16 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?)
dutterbutter marked this conversation as resolved.
Show resolved Hide resolved
};

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