Skip to content

Commit

Permalink
chore: rewrite shanghai support check (#6356)
Browse files Browse the repository at this point in the history
* chore: rewrite shanghai support check

* bump chains
  • Loading branch information
DaniPopes authored Nov 21, 2023
1 parent c0a9975 commit e38d8c6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ alloy-json-abi = "0.4.1"
alloy-sol-types = "0.4.1"
syn-solidity = "0.4.1"

alloy-chains = "0.1.2"
alloy-chains = "0.1.3"
alloy-rlp = "0.3.3"
solang-parser = "=0.3.3"

Expand Down
67 changes: 23 additions & 44 deletions crates/forge/bin/cmd/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use alloy_primitives::{Address, Bytes, U256};
use clap::{Parser, ValueHint};
use dialoguer::Confirm;
use ethers_core::types::{
transaction::eip2718::TypedTransaction, Chain, Log, NameOrAddress, TransactionRequest,
transaction::eip2718::TypedTransaction, Log, NameOrAddress, TransactionRequest,
};
use ethers_providers::{Http, Middleware};
use ethers_signers::LocalWallet;
Expand Down Expand Up @@ -42,7 +42,7 @@ use foundry_config::{
value::{Dict, Map},
Metadata, Profile, Provider,
},
Config,
Config, NamedChain,
};
use foundry_evm::{
constants::DEFAULT_CREATE2_DEPLOYER,
Expand All @@ -51,6 +51,7 @@ use foundry_evm::{
};
use foundry_utils::types::{ToAlloy, ToEthers};
use futures::future;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
use yansi::Paint;
Expand All @@ -68,16 +69,6 @@ mod sequence;
pub mod transaction;
mod verify;

/// List of Chains that support Shanghai.
static SHANGHAI_ENABLED_CHAINS: &[Chain] = &[
Chain::Mainnet,
Chain::Goerli,
Chain::Sepolia,
Chain::OptimismGoerli,
Chain::OptimismSepolia,
Chain::BaseGoerli,
];

// Loads project's figment and merges the build cli arguments into it
foundry_config::merge_impl_figment_convert!(ScriptArgs, opts, evm_opts);

Expand Down Expand Up @@ -212,7 +203,7 @@ pub struct ScriptArgs {
// === impl ScriptArgs ===

impl ScriptArgs {
pub fn decode_traces(
fn decode_traces(
&self,
script_config: &ScriptConfig,
result: &mut ScriptResult,
Expand Down Expand Up @@ -288,7 +279,7 @@ impl ScriptArgs {
Ok(returns)
}

pub async fn show_traces(
async fn show_traces(
&self,
script_config: &ScriptConfig,
decoder: &CallTraceDecoder,
Expand Down Expand Up @@ -373,7 +364,7 @@ impl ScriptArgs {
Ok(())
}

pub fn show_json(&self, script_config: &ScriptConfig, result: &ScriptResult) -> Result<()> {
fn show_json(&self, script_config: &ScriptConfig, result: &ScriptResult) -> Result<()> {
let returns = self.get_returns(script_config, &result.returned)?;

let console_logs = decode_console_logs(&result.logs);
Expand Down Expand Up @@ -452,7 +443,7 @@ impl ScriptArgs {
/// corresponding function by matching the selector, first 4 bytes in the calldata.
///
/// Note: We assume that the `sig` is already stripped of its prefix, See [`ScriptArgs`]
pub fn get_method_and_calldata(&self, abi: &Abi) -> Result<(Function, Bytes)> {
fn get_method_and_calldata(&self, abi: &Abi) -> Result<(Function, Bytes)> {
let (func, data) = if let Ok(func) = Function::parse(&self.sig) {
(
abi.functions().find(|&abi_func| abi_func.selector() == func.selector()).wrap_err(
Expand Down Expand Up @@ -622,10 +613,10 @@ pub struct ScriptResult {
}

#[derive(Serialize, Deserialize)]
pub struct JsonResult {
pub logs: Vec<String>,
pub gas_used: u64,
pub returns: HashMap<String, NestedValue>,
struct JsonResult {
logs: Vec<String>,
gas_used: u64,
returns: HashMap<String, NestedValue>,
}

#[derive(Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -697,36 +688,24 @@ impl ScriptConfig {
/// If not, warns the user.
async fn check_shanghai_support(&self) -> Result<()> {
let chain_ids = self.total_rpcs.iter().map(|rpc| async move {
if let Ok(provider) = ethers_providers::Provider::<Http>::try_from(rpc) {
match provider.get_chainid().await {
Ok(chain_id) => match TryInto::<Chain>::try_into(chain_id) {
Ok(chain) => return Some((SHANGHAI_ENABLED_CHAINS.contains(&chain), chain)),
Err(_) => return None,
},
Err(_) => return None,
}
}
None
let provider = ethers_providers::Provider::<Http>::try_from(rpc).ok()?;
let id = provider.get_chainid().await.ok()?;
let id_u64: u64 = id.try_into().ok()?;
NamedChain::try_from(id_u64).ok()
});

let chain_ids: Vec<_> = future::join_all(chain_ids).await.into_iter().flatten().collect();

let chain_id_unsupported = chain_ids.iter().any(|(supported, _)| !supported);

// At least one chain ID is unsupported, therefore we print the message.
if chain_id_unsupported {
let chains = future::join_all(chain_ids).await;
let iter = chains.iter().flatten().map(|c| (c.supports_shanghai(), c));
if iter.clone().any(|(s, _)| !s) {
let msg = format!(
r#"
"\
EIP-3855 is not supported in one or more of the RPCs used.
Unsupported Chain IDs: {}.
Contracts deployed with a Solidity version equal or higher than 0.8.20 might not work properly.
For more information, please see https://eips.ethereum.org/EIPS/eip-3855"#,
chain_ids
.iter()
.filter(|(supported, _)| !supported)
.map(|(_, chain)| format!("{}", *chain as u64))
.collect::<Vec<_>>()
.join(", ")
For more information, please see https://eips.ethereum.org/EIPS/eip-3855",
iter.filter(|(supported, _)| !supported)
.map(|(_, chain)| *chain as u64)
.format(", ")
);
shell::println(Paint::yellow(msg))?;
}
Expand Down

0 comments on commit e38d8c6

Please sign in to comment.