Skip to content

Commit

Permalink
fix: wrong gas parameters while broadcasting tx in script (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
HermanObst authored Jul 16, 2024
1 parent 33b81ac commit 825ca04
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions crates/forge/bin/cmd/script/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ impl ScriptArgs {
}
}
}

Ok((tx, zk, kind, is_fixed_gas_limit))
})
.collect::<Result<Vec<_>>>()?;
Expand Down Expand Up @@ -652,33 +651,38 @@ impl ScriptArgs {

let signed_tx = if let Some(zk) = zk {
let custom_data = Eip712Meta::new().factory_deps(zk.factory_deps);
let gas_price = provider.get_gas_price().await?;

let mut deploy_request = Eip712TransactionRequest::new()
.r#type(EIP712_TX_TYPE)
.from(*legacy_or_1559.from().unwrap())
.to(*legacy_or_1559.to().and_then(|to| to.as_address()).unwrap())
.chain_id(legacy_or_1559.chain_id().unwrap().as_u64())
.nonce(legacy_or_1559.nonce().unwrap())
.gas_price(legacy_or_1559.gas_price().unwrap())
.gas_price(gas_price)
.max_fee_per_gas(legacy_or_1559.max_cost().unwrap())
.data(legacy_or_1559.data().cloned().unwrap_or_default())
.custom_data(custom_data);

let gas_price = provider.get_gas_price().await?;
let fee: zksync_web3_rs::zks_provider::types::Fee =
provider.request("zks_estimateFee", [deploy_request.clone()]).await.unwrap();

deploy_request = deploy_request
.gas_limit(fee.gas_limit)
.max_fee_per_gas(fee.max_fee_per_gas)
.max_priority_fee_per_gas(fee.max_priority_fee_per_gas)
.gas_price(gas_price);
.max_priority_fee_per_gas(fee.max_priority_fee_per_gas);
deploy_request.custom_data.gas_per_pubdata = fee.gas_per_pubdata_limit;

let signable: Eip712Transaction =
// TODO: This is a work around as try_into is not propagating
// gas_per_pubdata_byte_limit. It always set the default We would need to
// fix that library or add EIP712 to alloy with correct implementation.
let mut signable: Eip712Transaction =
deploy_request.clone().try_into().expect("converting deploy request");
debug!("sending transaction: {:?}", signable);
signable.gas_per_pubdata_byte_limit = deploy_request.custom_data.gas_per_pubdata;

let signature =
signer.sign_typed_data(&signable).await.wrap_err("Failed to sign typed data")?;
debug!("sending transaction: {:?}", signable);

let encoded_rlp =
&*deploy_request.rlp_signed(signature).expect("able to rlp encode deploy request");
Expand Down

0 comments on commit 825ca04

Please sign in to comment.