Skip to content

Commit

Permalink
Merge pull request #740 from matter-labs/elfedy-fd-non-zero
Browse files Browse the repository at this point in the history
fix: insert transaction type into EIP-712 transactions
  • Loading branch information
elfedy authored Nov 22, 2024
2 parents f75d7bf + 13a11f3 commit 438920a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
25 changes: 9 additions & 16 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ use std::{
collections::{HashSet, VecDeque},
marker::PhantomData,
path::PathBuf,
str::FromStr,
sync::Arc,
};
use zksync_types::H256;

merge_impl_figment_convert!(CreateArgs, opts, eth);

Expand Down Expand Up @@ -114,7 +112,6 @@ pub struct CreateArgs {
pub struct ZkSyncData {
#[allow(dead_code)]
bytecode: Vec<u8>,
bytecode_hash: H256,
factory_deps: Vec<Vec<u8>>,
paymaster_params: Option<PaymasterParams>,
}
Expand Down Expand Up @@ -157,7 +154,7 @@ impl CreateArgs {

let artifact = remove_zk_contract(&mut zk_output, &target_path, &self.contract.name)?;

let ZkContractArtifact { bytecode, hash, factory_dependencies, abi, .. } = artifact;
let ZkContractArtifact { bytecode, factory_dependencies, abi, .. } = artifact;

let abi = abi.expect("Abi not found");
let bin = bytecode.expect("Bytecode not found");
Expand All @@ -181,7 +178,6 @@ impl CreateArgs {
eyre::bail!("Dynamic linking not supported in `create` command - deploy the following library contracts first, then provide the address to link at compile time\n{}", link_refs)
}
};
let bytecode_hash = H256::from_str(&hash.expect("Contract hash not found"))?;

// Add arguments to constructor
let config = self.eth.try_load_config_emit_warnings()?;
Expand Down Expand Up @@ -256,7 +252,7 @@ impl CreateArgs {
visited_bytecodes.insert(bytecode.clone());
visited_bytecodes.into_iter().collect()
};
let zk_data = ZkSyncData { bytecode, bytecode_hash, factory_deps, paymaster_params };
let zk_data = ZkSyncData { bytecode, factory_deps, paymaster_params };

return if self.unlocked {
// Deploy with unlocked account
Expand Down Expand Up @@ -1077,21 +1073,16 @@ where
None => Default::default(),
Some(constructor) => constructor.abi_encode_input(&params).unwrap_or_default(),
};
let data: Bytes = foundry_zksync_core::encode_create_params(
&forge::revm::primitives::CreateScheme::Create,
zk_data.bytecode_hash,
constructor_args,
)
.into();

// create the tx object. Since we're deploying a contract, `to` is
// `CONTRACT_DEPLOYER_ADDRESS`
let tx: alloy_zksync::network::transaction_request::TransactionRequest =
let mut tx: alloy_zksync::network::transaction_request::TransactionRequest =
TransactionRequest::default()
.to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address())
.input(data.into())
.into();

tx = tx
.zksync_deploy(zk_data.bytecode.clone(), constructor_args, zk_data.factory_deps.clone())
.map_err(|_| ContractDeploymentError::TransactionBuildError)?;

Ok(ZkDeployer {
client: self.client.clone(),
abi: self.abi,
Expand All @@ -1116,6 +1107,8 @@ pub enum ContractDeploymentError {
ContractNotDeployed,
#[error(transparent)]
RpcError(#[from] TransportError),
#[error("failed building transaction")]
TransactionBuildError,
}

impl From<PendingTransactionError> for ContractDeploymentError {
Expand Down
6 changes: 4 additions & 2 deletions crates/script/src/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use alloy_rpc_types::TransactionRequest;
use alloy_serde::WithOtherFields;
use alloy_transport::Transport;
use alloy_zksync::network::{
transaction_request::TransactionRequest as ZkTransactionRequest, Zksync,
transaction_request::TransactionRequest as ZkTransactionRequest, tx_type::TxType, Zksync,
};
use eyre::{bail, Context, Result};
use forge_verify::provider::VerificationProviderType;
Expand Down Expand Up @@ -119,7 +119,9 @@ pub async fn send_transaction(
debug!("sending transaction: {:?}", tx);

if let Some(zk) = zk {
let mut zk_tx: ZkTransactionRequest = tx.inner.clone().into();
let mut inner = tx.inner.clone();
inner.transaction_type = Some(TxType::Eip712 as u8);
let mut zk_tx: ZkTransactionRequest = inner.into();
if !zk.factory_deps.is_empty() {
zk_tx.set_factory_deps(zk.factory_deps.iter().map(Bytes::from_iter).collect());
}
Expand Down

0 comments on commit 438920a

Please sign in to comment.