Skip to content

Commit

Permalink
12-12
Browse files Browse the repository at this point in the history
  • Loading branch information
MBerguer committed Jan 15, 2025
2 parents b24a80f + e22a9ec commit 91dceba
Show file tree
Hide file tree
Showing 36 changed files with 391 additions and 18 deletions.
24 changes: 20 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release:
permissions:
id-token: write
contents: read
attestations: write
name: ${{ matrix.target }} (${{ matrix.runner }})
runs-on: ${{ matrix.runner }}
timeout-minutes: 240
Expand Down Expand Up @@ -151,12 +155,24 @@ jobs:
bins=(cast forge)
for name in "${bins[@]}"; do
bin=./target/$target/release/$name
file "$bin" || true
ldd "$bin" || true
$bin --version || true
bin=$OUT_DIR/$name$ext
echo ""
file "$bin" || true
du -h "$bin" || true
ldd "$bin" || true
$bin --version || true
echo "${name}_bin_path=${bin}" >> $GITHUB_ENV
done
- name: Binaries attestation
uses: actions/attest-build-provenance@v2
with:
subject-path: |
${{ env.anvil_bin_path }}
${{ env.cast_bin_path }}
${{ env.chisel_bin_path }}
${{ env.forge_bin_path }}
- name: Archive binaries
id: artifacts
env:
Expand Down
8 changes: 2 additions & 6 deletions Cargo.lock

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

26 changes: 22 additions & 4 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,10 +922,28 @@ impl Backend {
let fork_num_and_hash = self.get_fork().map(|f| (f.block_number(), f.block_hash()));

if let Some((number, hash)) = fork_num_and_hash {
// If loading state file on a fork, set best number to the fork block number.
// Ref: https://github.com/foundry-rs/foundry/pull/9215#issue-2618681838
self.blockchain.storage.write().best_number = U64::from(number);
self.blockchain.storage.write().best_hash = hash;
let best_number = state.best_block_number.unwrap_or(block.number.to::<U64>());
trace!(target: "backend", state_block_number=?best_number, fork_block_number=?number);
// If the state.block_number is greater than the fork block number, set best number
// to the state block number.
// Ref: https://github.com/foundry-rs/foundry/issues/9539
if best_number.to::<u64>() > number {
self.blockchain.storage.write().best_number = best_number;
let best_hash =
self.blockchain.storage.read().hash(best_number.into()).ok_or_else(
|| {
BlockchainError::RpcError(RpcError::internal_error_with(format!(
"Best hash not found for best number {best_number}",
)))
},
)?;
self.blockchain.storage.write().best_hash = best_hash;
} else {
// If loading state file on a fork, set best number to the fork block number.
// Ref: https://github.com/foundry-rs/foundry/pull/9215#issue-2618681838
self.blockchain.storage.write().best_number = U64::from(number);
self.blockchain.storage.write().best_hash = hash;
}
} else {
let best_number = state.best_block_number.unwrap_or(block.number.to::<U64>());
self.blockchain.storage.write().best_number = best_number;
Expand Down
33 changes: 32 additions & 1 deletion crates/anvil/tests/it/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::abi::Greeter;
use alloy_network::{ReceiptResponse, TransactionBuilder};
use alloy_primitives::{address, utils::Unit, Bytes, Uint, U256};
use alloy_primitives::{address, utils::Unit, Bytes, Uint, U256, U64};
use alloy_provider::Provider;
use alloy_rpc_types::{BlockId, TransactionRequest};
use alloy_serde::WithOtherFields;
Expand Down Expand Up @@ -245,3 +245,34 @@ async fn test_fork_load_state() {

assert_eq!(balance_alice + value, latest_balance_alice);
}

// <https://github.com/foundry-rs/foundry/issues/9539>
#[tokio::test(flavor = "multi_thread")]
async fn test_fork_load_state_with_greater_state_block() {
let (api, _handle) = spawn(
NodeConfig::test()
.with_eth_rpc_url(Some(next_http_rpc_endpoint()))
.with_fork_block_number(Some(21070682u64)),
)
.await;

api.mine_one().await;

let block_number = api.block_number().unwrap();

let serialized_state = api.serialized_state(false).await.unwrap();

assert_eq!(serialized_state.best_block_number, Some(block_number.to::<U64>()));

let (api, _handle) = spawn(
NodeConfig::test()
.with_eth_rpc_url(Some(next_http_rpc_endpoint()))
.with_fork_block_number(Some(21070682u64)) // Forked chain has moved forward
.with_init_state(Some(serialized_state)),
)
.await;

let new_block_number = api.block_number().unwrap();

assert_eq!(new_block_number, block_number);
}
14 changes: 13 additions & 1 deletion crates/cast/bin/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use foundry_cli::{
opts::{EtherscanOpts, RpcOpts},
utils::{self, handle_traces, init_progress, TraceResult},
};
use foundry_common::{is_known_system_sender, shell, SYSTEM_TRANSACTION_TYPE};
use foundry_common::{is_impersonated_tx, is_known_system_sender, shell, SYSTEM_TRANSACTION_TYPE};
use foundry_compilers::artifacts::EvmVersion;
use foundry_config::{
figment::{
Expand Down Expand Up @@ -214,6 +214,12 @@ impl RunArgs {

configure_tx_env(&mut env, &tx.inner);

if is_impersonated_tx(&tx.inner.inner) {
// If the transaction is impersonated, we need to set the caller to the from
// address Ref: https://github.com/foundry-rs/foundry/issues/9541
env.tx.caller = tx.from;
}

if let Some(to) = Transaction::to(tx) {
trace!(tx=?tx.tx_hash(),?to, "executing previous call transaction");
executor.transact_with_env(env.clone()).wrap_err_with(|| {
Expand Down Expand Up @@ -253,6 +259,12 @@ impl RunArgs {

configure_tx_env(&mut env, &tx.inner);

if is_impersonated_tx(&tx.inner.inner) {
// If the transaction is impersonated, we need to set the caller to the from address
// Ref: https://github.com/foundry-rs/foundry/issues/9541
env.tx.caller = tx.from;
}

if let Some(to) = Transaction::to(&tx) {
trace!(tx=?tx.tx_hash(), to=?to, "executing call transaction");
TraceResult::try_from(executor.transact_with_env(env))?
Expand Down
44 changes: 44 additions & 0 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
//! Contains various tests for checking cast commands
use alloy_chains::NamedChain;
<<<<<<< HEAD
use alloy_network::TransactionResponse;
use alloy_primitives::{b256, B256};
use alloy_rpc_types::{BlockNumberOrTag, Index};
=======
use alloy_network::{TransactionBuilder, TransactionResponse};
use alloy_primitives::{address, b256, Bytes, B256};
use alloy_provider::{Provider, ProviderBuilder};
use alloy_rpc_types::{BlockNumberOrTag, Index, TransactionRequest};
>>>>>>> e22a9ec
use anvil::{EthereumHardfork, NodeConfig};
use foundry_test_utils::{
casttest, file, forgetest, forgetest_async,
Expand Down Expand Up @@ -1996,3 +2003,40 @@ forgetest_async!(cast_call_custom_chain_id, |_prj, cmd| {
])
.assert_success();
});
<<<<<<< HEAD
=======

// https://github.com/foundry-rs/foundry/issues/9541
forgetest_async!(cast_run_impersonated_tx, |_prj, cmd| {
let (_api, handle) = anvil::spawn(
NodeConfig::test()
.with_auto_impersonate(true)
.with_eth_rpc_url(Some("https://sepolia.base.org")),
)
.await;

let http_endpoint = handle.http_endpoint();

let provider = ProviderBuilder::new().on_http(http_endpoint.parse().unwrap());

// send impersonated tx
let tx = TransactionRequest::default()
.with_from(address!("041563c07028Fc89106788185763Fc73028e8511"))
.with_to(address!("F38aA5909D89F5d98fCeA857e708F6a6033f6CF8"))
.with_input(
Bytes::from_str(
"0x60fe47b1000000000000000000000000000000000000000000000000000000000000000c",
)
.unwrap(),
);

let receipt = provider.send_transaction(tx).await.unwrap().get_receipt().await.unwrap();

assert!(receipt.status());

// run impersonated tx
cmd.cast_fuse()
.args(["run", &receipt.transaction_hash.to_string(), "--rpc-url", &http_endpoint])
.assert_success();
});
>>>>>>> e22a9ec
4 changes: 4 additions & 0 deletions crates/cheatcodes/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ use std::{
fmt::Display,
path::Path,
};
<<<<<<< HEAD
=======

>>>>>>> e22a9ec
mod record_debug_step;
use record_debug_step::{convert_call_trace_to_debug_step, flatten_call_trace};
use serde::Serialize;
Expand Down
3 changes: 3 additions & 0 deletions crates/cli/src/utils/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,12 @@ pub fn has_different_gas_calc(chain_id: u64) -> bool {
/// True if it supports broadcasting in batches.
pub fn has_batch_support(chain_id: u64) -> bool {
if let Some(chain) = Chain::from(chain_id).named() {
<<<<<<< HEAD
if matches!(chain, NamedChain::ZkSync | NamedChain::ZkSyncTestnet) {
return false
};
=======
>>>>>>> e22a9ec
return !chain.is_arbitrum();
}
true
Expand Down
3 changes: 3 additions & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ alloy-transport-ws.workspace = true
alloy-transport.workspace = true
alloy-consensus = { workspace = true, features = ["k256"] }
alloy-network.workspace = true
<<<<<<< HEAD

alloy-zksync.workspace = true
=======
>>>>>>> e22a9ec

tower.workspace = true

Expand Down
23 changes: 22 additions & 1 deletion crates/common/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Commonly used constants.
use alloy_primitives::{address, Address};
use alloy_consensus::Typed2718;
use alloy_network::AnyTxEnvelope;
use alloy_primitives::{address, Address, PrimitiveSignature, B256};
use std::time::Duration;

/// The dev chain-id, inherited from hardhat
Expand Down Expand Up @@ -53,6 +55,25 @@ pub fn is_known_system_sender(sender: Address) -> bool {
[ARBITRUM_SENDER, OPTIMISM_SYSTEM_ADDRESS].contains(&sender)
}

pub fn is_impersonated_tx(tx: &AnyTxEnvelope) -> bool {
if let AnyTxEnvelope::Ethereum(tx) = tx {
return is_impersonated_sig(tx.signature(), tx.ty());
}
false
}

pub fn is_impersonated_sig(sig: &PrimitiveSignature, ty: u8) -> bool {
let impersonated_sig = PrimitiveSignature::from_scalars_and_parity(
B256::with_last_byte(1),
B256::with_last_byte(1),
false,
);
if ty != SYSTEM_TRANSACTION_TYPE && sig == &impersonated_sig {
return true;
}
false
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ use_literal_content = false
# use ipfs method to generate the metadata hash, solc's default.
# To not include the metadata hash, to allow for deterministic code: https://docs.soliditylang.org/en/latest/metadata.html, use "none"
bytecode_hash = "ipfs"
# Whether to append the metadata hash to the bytecode
# Whether to append the CBOR-encoded metadata file.
cbor_metadata = true
# How to treat revert (and require) reason strings.
# Possible values are: "default", "strip", "debug" and "verboseDebug".
Expand Down
3 changes: 3 additions & 0 deletions crates/config/src/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ impl FuzzConfig {
Self {
failure_persist_dir: Some(cache_dir),
failure_persist_file: Some("failures".to_string()),
<<<<<<< HEAD
no_zksync_reserved_addresses: false,
=======
>>>>>>> e22a9ec
..Default::default()
}
}
Expand Down
9 changes: 9 additions & 0 deletions crates/config/src/invariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ pub struct InvariantConfig {
pub show_metrics: bool,
/// Optional timeout (in seconds) for each invariant test.
pub timeout: Option<u32>,
<<<<<<< HEAD
/// When enabled, filters all addresses below 2^16, as they are reserved in zkSync.
pub no_zksync_reserved_addresses: bool,
=======
>>>>>>> e22a9ec
}

impl Default for InvariantConfig {
Expand All @@ -50,7 +53,10 @@ impl Default for InvariantConfig {
failure_persist_dir: None,
show_metrics: false,
timeout: None,
<<<<<<< HEAD
no_zksync_reserved_addresses: false,
=======
>>>>>>> e22a9ec
}
}
}
Expand All @@ -70,7 +76,10 @@ impl InvariantConfig {
failure_persist_dir: Some(cache_dir),
show_metrics: false,
timeout: None,
<<<<<<< HEAD
no_zksync_reserved_addresses: false,
=======
>>>>>>> e22a9ec
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@ impl Config {
/// Returns the path to the `foundry.toml` of this `Config`.
pub fn get_config_path(&self) -> PathBuf {
self.root.join(Self::FILE_NAME)
<<<<<<< HEAD
}

/// Sets the non-inlinable libraries inside a `foundry.toml` file but only if it exists the
Expand All @@ -1793,6 +1794,8 @@ impl Config {
doc[Self::PROFILE_SECTION][profile]["libraries"] = libraries;
true
})
=======
>>>>>>> e22a9ec
}

/// Returns the selected profile.
Expand Down
Loading

0 comments on commit 91dceba

Please sign in to comment.