Skip to content

Commit

Permalink
Merge commit '8a51b89' into upstream-da77402
Browse files Browse the repository at this point in the history
  • Loading branch information
Karrq committed Oct 4, 2024
2 parents 24582d9 + 8a51b89 commit 8952c5f
Show file tree
Hide file tree
Showing 98 changed files with 2,616 additions and 1,349 deletions.
991 changes: 525 additions & 466 deletions Cargo.lock

Large diffs are not rendered by default.

133 changes: 69 additions & 64 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,57 +164,61 @@ foundry-zksync-compiler = { path = "crates/zksync/compiler" }
foundry-zksync-inspectors = { path = "crates/zksync/inspectors" }

# solc & compilation utilities
# foundry-block-explorers = { version = "0.5.1", default-features = false }
# foundry-compilers = { version = "0.10.2", default-features = false }
# foundry-fork-db = "0.2"
foundry-block-explorers = { git = "https://github.com/Moonsong-Labs/block-explorers", branch = "zksync-v0.5.2", default-features = false }
foundry-compilers = { git = "https://github.com/Moonsong-Labs/compilers", branch = "zksync-v0.10.3" }
foundry-fork-db = { git = "https://github.com/Moonsong-Labs/foundry-zksync-fork-db", branch = "zksync-v0.2.1" }
# foundry-block-explorers = { version = "0.7.1", default-features = false }
# foundry-compilers = { version = "0.11.0", default-features = false }
# foundry-fork-db = "0.3"
foundry-block-explorers = { git = "https://github.com/Moonsong-Labs/block-explorers", branch = "zksync-v0.7.1", default-features = false }
foundry-compilers = { git = "https://github.com/Moonsong-Labs/compilers", branch = "zksync-v0.11.0" }
foundry-fork-db = { git = "https://github.com/Moonsong-Labs/foundry-zksync-fork-db", branch = "zksync-v0.3.0" }
solang-parser = "=0.3.3"

## revm
# no default features to avoid c-kzg
revm = { version = "13.0.0", default-features = false }
revm-primitives = { version = "8.0.0", default-features = false }
revm-inspectors = { version = "0.5", features = ["serde"] }
revm = { version = "14.0.1", default-features = false }
revm-primitives = { version = "9.0.1", default-features = false }
revm-inspectors = { version = "0.6", features = ["serde"] }

## ethers
ethers-contract-abigen = { version = "2.0.14", default-features = false }

## alloy
alloy-consensus = { version = "0.2.1", default-features = false }
alloy-contract = { version = "0.2.1", default-features = false }
alloy-eips = { version = "0.2.1", default-features = false }
alloy-genesis = { version = "0.2.1", default-features = false }
alloy-json-rpc = { version = "0.2.1", default-features = false }
alloy-network = { version = "0.2.1", default-features = false }
alloy-provider = { version = "0.2.1", default-features = false }
alloy-pubsub = { version = "0.2.1", default-features = false }
alloy-rpc-client = { version = "0.2.1", default-features = false }
alloy-rpc-types = { version = "0.2.1", default-features = true }
alloy-serde = { version = "0.2.1", default-features = false }
alloy-signer = { version = "0.2.1", default-features = false }
alloy-signer-aws = { version = "0.2.1", default-features = false }
alloy-signer-gcp = { version = "0.2.1", default-features = false }
alloy-signer-ledger = { version = "0.2.1", default-features = false }
alloy-signer-local = { version = "0.2.1", default-features = false }
alloy-signer-trezor = { version = "0.2.1", default-features = false }
alloy-transport = { version = "0.2.1", default-features = false }
alloy-transport-http = { version = "0.2.1", default-features = false }
alloy-transport-ipc = { version = "0.2.1", default-features = false }
alloy-transport-ws = { version = "0.2.1", default-features = false }
alloy-consensus = { version = "0.3.1", default-features = false }
alloy-contract = { version = "0.3.1", default-features = false }
alloy-eips = { version = "0.3.1", default-features = false }
alloy-genesis = { version = "0.3.1", default-features = false }
alloy-json-rpc = { version = "0.3.1", default-features = false }
alloy-network = { version = "0.3.1", default-features = false }
alloy-provider = { version = "0.3.1", default-features = false }
alloy-pubsub = { version = "0.3.1", default-features = false }
alloy-rpc-client = { version = "0.3.1", default-features = false }
alloy-rpc-types = { version = "0.3.1", default-features = true }
alloy-serde = { version = "0.3.1", default-features = false }
alloy-signer = { version = "0.3.1", default-features = false }
alloy-signer-aws = { version = "0.3.1", default-features = false }
alloy-signer-gcp = { version = "0.3.1", default-features = false }
alloy-signer-ledger = { version = "0.3.1", default-features = false }
alloy-signer-local = { version = "0.3.1", default-features = false }
alloy-signer-trezor = { version = "0.3.1", default-features = false }
alloy-transport = { version = "0.3.1", default-features = false }
alloy-transport-http = { version = "0.3.1", default-features = false }
alloy-transport-ipc = { version = "0.3.1", default-features = false }
alloy-transport-ws = { version = "0.3.1", default-features = false }

alloy-dyn-abi = "0.7.7"
alloy-json-abi = "0.7.7"
alloy-primitives = { version = "0.7.7", features = ["getrandom", "rand"] }
alloy-sol-macro-expander = "0.7.7"
alloy-sol-macro-input = "0.7.7"
alloy-sol-types = "0.7.7"
syn-solidity = "0.7.7"
## alloy-core
alloy-dyn-abi = "0.8.1"
alloy-json-abi = "0.8.1"
alloy-primitives = { version = "0.8.1", features = ["getrandom", "rand"] }
alloy-sol-macro-expander = "0.8.1"
alloy-sol-macro-input = "0.8.1"
alloy-sol-types = "0.8.1"
syn-solidity = "0.8.1"

alloy-chains = "0.1"
alloy-rlp = "0.3.3"
alloy-trie = "0.4.1"
alloy-rlp = "0.3"
alloy-trie = "0.5.0"

## op-alloy for tests in anvil
op-alloy-rpc-types = "0.2.8"

## zksync
era_test_node = { git="https://github.com/matter-labs/era-test-node.git" , rev = "2041018903aa7e00e74c450f8c0baf799c056d86" }
Expand Down Expand Up @@ -273,41 +277,42 @@ yansi = { version = "1.0", features = ["detect-tty", "detect-env"] }
tempfile = "3.10"
tokio = "1"
rayon = "1"

evmole = "0.5"
axum = "0.7"
hyper = "1.0"
reqwest = { version = "0.12", default-features = false }
tower = "0.4"
tower-http = "0.5"
# soldeer
soldeer = "0.3.1"
soldeer = "=0.3.4"
proptest = "1"
comfy-table = "7"

[patch.crates-io]
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-contract = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-pubsub = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-serde = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-signer-aws = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-signer-gcp = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-signer-ledger = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-signer-local = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-signer-trezor = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-transport-ipc = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "511ae98" }
revm = { git = "https://github.com/bluealloy/revm", rev = "caadc71" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "caadc71" }
# https://github.com/alloy-rs/alloy/pull/1229 + https://github.com/alloy-rs/alloy/pull/1243
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-contract = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-network-primitives = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-pubsub = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-rpc-types-eth = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-serde = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-signer-aws = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-signer-gcp = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-signer-ledger = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-signer-local = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-signer-trezor = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-transport-ipc = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }
alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" }

[patch.'https://github.com/matter-labs/zksync-era.git']
# era-test-node uses the original ones
Expand Down
1 change: 1 addition & 0 deletions crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ alloy-pubsub.workspace = true
foundry-test-utils.workspace = true
similar-asserts.workspace = true
tokio = { workspace = true, features = ["full"] }
op-alloy-rpc-types.workspace = true

[features]
default = ["cli", "jemalloc"]
Expand Down
81 changes: 80 additions & 1 deletion crates/anvil/core/src/eth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::eth::subscription::SubscriptionId;
use crate::{eth::subscription::SubscriptionId, types::ReorgOptions};
use alloy_primitives::{Address, Bytes, TxHash, B256, B64, U256};
use alloy_rpc_types::{
anvil::{Forking, MineOptions},
Expand Down Expand Up @@ -768,6 +768,10 @@ pub enum EthRequest {
serde(rename = "anvil_removePoolTransactions", with = "sequence")
)]
RemovePoolTransactions(Address),

/// Reorg the chain
#[cfg_attr(feature = "serde", serde(rename = "anvil_reorg",))]
Reorg(ReorgOptions),
}

/// Represents ethereum JSON-RPC API
Expand Down Expand Up @@ -1595,4 +1599,79 @@ true}]}"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}

#[test]
fn test_serde_anvil_reorg() {
// TransactionData::JSON
let s = r#"
{
"method": "anvil_reorg",
"params": [
5,
[
[
{
"from": "0x976EA74026E726554dB657fA54763abd0C3a0aa9",
"to": "0x1199bc69f16FDD6690DC40339EC445FaE1b6DD11",
"value": 100
},
1
],
[
{
"from": "0x976EA74026E726554dB657fA54763abd0C3a0aa9",
"to": "0x1199bc69f16FDD6690DC40339EC445FaE1b6DD11",
"value": 200
},
2
]
]
]
}
"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
// TransactionData::Raw
let s = r#"
{
"method": "anvil_reorg",
"params": [
5,
[
[
"0x19d55c67e1ba8f1bbdfed75f8ad524ebf087e4ecb848a2d19881d7a5e3d2c54e1732cb1b462da3b3fdb05bdf4c4d3c8e3c9fcebdc2ab5fa5d59a3f752888f27e1b",
1
]
]
]
}
"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
// TransactionData::Raw and TransactionData::JSON
let s = r#"
{
"method": "anvil_reorg",
"params": [
5,
[
[
"0x19d55c67e1ba8f1bbdfed75f8ad524ebf087e4ecb848a2d19881d7a5e3d2c54e1732cb1b462da3b3fdb05bdf4c4d3c8e3c9fcebdc2ab5fa5d59a3f752888f27e1b",
1
],
[
{
"from": "0x976EA74026E726554dB657fA54763abd0C3a0aa9",
"to": "0x1199bc69f16FDD6690DC40339EC445FaE1b6DD11",
"value": 200
},
2
]
]
]
}
"#;
let value: serde_json::Value = serde_json::from_str(s).unwrap();
let _req = serde_json::from_value::<EthRequest>(value).unwrap();
}
}
35 changes: 30 additions & 5 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ pub fn to_alloy_transaction_with_hash_and_sender(
transaction_type: None,
max_fee_per_blob_gas: None,
blob_versioned_hashes: None,
other: Default::default(),
authorization_list: None,
},
TypedTransaction::EIP2930(t) => RpcTransaction {
Expand Down Expand Up @@ -328,7 +327,6 @@ pub fn to_alloy_transaction_with_hash_and_sender(
transaction_type: Some(1),
max_fee_per_blob_gas: None,
blob_versioned_hashes: None,
other: Default::default(),
authorization_list: None,
},
TypedTransaction::EIP1559(t) => RpcTransaction {
Expand Down Expand Up @@ -356,7 +354,6 @@ pub fn to_alloy_transaction_with_hash_and_sender(
transaction_type: Some(2),
max_fee_per_blob_gas: None,
blob_versioned_hashes: None,
other: Default::default(),
authorization_list: None,
},
TypedTransaction::EIP4844(t) => RpcTransaction {
Expand Down Expand Up @@ -384,7 +381,6 @@ pub fn to_alloy_transaction_with_hash_and_sender(
transaction_type: Some(3),
max_fee_per_blob_gas: Some(t.tx().tx().max_fee_per_blob_gas),
blob_versioned_hashes: Some(t.tx().tx().blob_versioned_hashes.clone()),
other: Default::default(),
authorization_list: None,
},
TypedTransaction::EIP7702(t) => RpcTransaction {
Expand Down Expand Up @@ -433,7 +429,6 @@ pub fn to_alloy_transaction_with_hash_and_sender(
transaction_type: None,
max_fee_per_blob_gas: None,
blob_versioned_hashes: None,
other: Default::default(),
authorization_list: None,
},
}
Expand Down Expand Up @@ -674,6 +669,36 @@ pub enum TypedTransaction {
Deposit(DepositTransaction),
}

/// This is a function that demotes TypedTransaction to TransactionRequest for greater flexibility
/// over the type.
///
/// This function is purely for convience and specific use cases, e.g. RLP encoded transactions
/// decode to TypedTransactions where the API over TypedTransctions is quite strict.
impl TryFrom<TypedTransaction> for TransactionRequest {
type Error = ConversionError;

fn try_from(value: TypedTransaction) -> Result<Self, Self::Error> {
let from = value.recover().map_err(|_| ConversionError::InvalidSignature)?;
let essentials = value.essentials();
let tx_type = value.r#type();
Ok(Self {
from: Some(from),
to: Some(value.kind()),
gas_price: essentials.gas_price,
max_fee_per_gas: essentials.max_fee_per_gas,
max_priority_fee_per_gas: essentials.max_priority_fee_per_gas,
max_fee_per_blob_gas: essentials.max_fee_per_blob_gas,
gas: Some(essentials.gas_limit),
value: Some(essentials.value),
input: essentials.input.into(),
nonce: Some(essentials.nonce),
chain_id: essentials.chain_id,
transaction_type: tx_type,
..Default::default()
})
}
}

impl TypedTransaction {
/// Returns true if the transaction uses dynamic fees: EIP1559 or EIP4844
pub fn is_dynamic_fee(&self) -> bool {
Expand Down
38 changes: 38 additions & 0 deletions crates/anvil/core/src/eth/transaction/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,44 @@ impl Transaction for DepositTransactionRequest {
fn gas_price(&self) -> Option<u128> {
None
}

fn ty(&self) -> u8 {
0x7E
}

// Below fields are not found in a `DepositTransactionRequest`

fn access_list(&self) -> Option<&alloy_rpc_types::AccessList> {
None
}

fn authorization_list(&self) -> Option<&[revm::primitives::SignedAuthorization]> {
None
}

fn blob_versioned_hashes(&self) -> Option<&[B256]> {
None
}

fn effective_tip_per_gas(&self, _base_fee: u64) -> Option<u128> {
None
}

fn max_fee_per_blob_gas(&self) -> Option<u128> {
None
}

fn max_fee_per_gas(&self) -> u128 {
0
}

fn max_priority_fee_per_gas(&self) -> Option<u128> {
None
}

fn priority_fee_or_price(&self) -> u128 {
0
}
}

impl SignableTransaction<Signature> for DepositTransactionRequest {
Expand Down
Loading

0 comments on commit 8952c5f

Please sign in to comment.