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

Support cast run quorum private txn #9058

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions crates/cast/bin/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use foundry_config::{
use foundry_evm::{
executors::{EvmError, TracingExecutor},
opts::EvmOpts,
utils::configure_tx_env,
utils::{configure_quorum, configure_tx_env},
};

/// CLI arguments for `cast run`.
Expand Down Expand Up @@ -109,7 +109,7 @@ impl RunArgs {
.build()?;

let tx_hash = self.tx_hash.parse().wrap_err("invalid tx hash")?;
let tx = provider
let mut tx = provider
.get_transaction_by_hash(tx_hash)
.await
.wrap_err_with(|| format!("tx not found: {tx_hash:?}"))?
Expand Down Expand Up @@ -188,10 +188,10 @@ impl RunArgs {
tx.transaction_type == Some(SYSTEM_TRANSACTION_TYPE)
{
pb.set_position((index + 1) as u64);
continue;
continue
}
if tx.hash == tx_hash {
break;
break
}

configure_tx_env(&mut env, &tx.inner);
Expand Down Expand Up @@ -231,6 +231,7 @@ impl RunArgs {
let result = {
executor.set_trace_printer(self.trace_printer);

configure_quorum(&mut tx, provider).await;
configure_tx_env(&mut env, &tx.inner);

if let Some(to) = tx.to {
Expand Down
47 changes: 44 additions & 3 deletions crates/evm/core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ use crate::{
InspectorExt,
};
use alloy_json_abi::{Function, JsonAbi};
use alloy_primitives::{Address, Selector, TxKind, U256};
use alloy_primitives::{Address, Bytes, Selector, TxKind, Uint, U256};
use alloy_provider::{
network::{BlockResponse, HeaderResponse},
Network,
network::{AnyNetwork, BlockResponse, HeaderResponse},
Network, Provider, RootProvider,
};
use alloy_rpc_types::{Transaction, TransactionRequest};
use alloy_serde::WithOtherFields;
use alloy_transport::layers::RetryBackoffService;
use foundry_common::provider::runtime_transport::RuntimeTransport;
use foundry_config::NamedChain;
use foundry_fork_db::DatabaseError;
use revm::{
Expand Down Expand Up @@ -142,6 +145,44 @@ pub fn configure_tx_req_env(
Ok(())
}

/// Configures the input to the raw payload for the given RPC transaction if it is a quorum private
/// transaction.
pub async fn configure_quorum(
tx: &mut WithOtherFields<Transaction>,
provider: RootProvider<RetryBackoffService<RuntimeTransport>, AnyNetwork>,
) {
if let Some(signature) = tx.inner.signature {
let v = signature.v;

let is_private_quorum_txn =
(v == Uint::from(37) || v == Uint::from(38)) && tx.input.len() == 64;

if is_private_quorum_txn {
println!("Private quorum transaction detected.");

let result: alloy_transport::TransportResult<Bytes> =
provider.client().request("eth_getQuorumPayload", (tx.input.clone(),)).await;

match result {
Ok(tessera_input) => {
println!(
"Executing private quorum transaction with quorum payload: {:?}",
tessera_input.to_string()
);
tx.input = tessera_input;
}
Err(e) => {
println!(
"eth_getQuorumPayload threw an error: {e}, cannot fetch transaction
input {:?}",
tx.hash
);
}
}
}
}
}

/// Get the gas used, accounting for refunds
pub fn gas_used(spec: SpecId, spent: u64, refunded: u64) -> u64 {
let refund_quotient = if SpecId::enabled(spec, SpecId::LONDON) { 5 } else { 2 };
Expand Down