Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Comments and final TODOs
  • Loading branch information
anikaraghu committed Nov 21, 2023
commit e8ae0ddaa84695648d67dd38e6b89b9b7450b9f5
22 changes: 11 additions & 11 deletions Cargo.lock

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

36 changes: 18 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ revm = { version = "3", default-features = false }
revm-primitives = { version = "1", default-features = false }

## ethers
ethers = { git = "https://github.com/gakonst/ethers-rs", version = "2.0.11", default-features = false }
ethers-core = { git = "https://github.com/gakonst/ethers-rs", version = "2.0.11", default-features = false }
ethers-contract = { git = "https://github.com/gakonst/ethers-rs", version = "2.0.11", default-features = false }
ethers-contract-abigen = { git = "https://github.com/gakonst/ethers-rs", version = "2.0.11", default-features = false }
ethers-providers = { git = "https://github.com/gakonst/ethers-rs", version = "2.0.11", default-features = false }
ethers-signers = { git = "https://github.com/gakonst/ethers-rs", version = "2.0.11", default-features = false }
ethers-middleware = { git = "https://github.com/gakonst/ethers-rs", version = "2.0.11", default-features = false }
ethers-solc = { git = "https://github.com/gakonst/ethers-rs", version = "2.0.11", default-features = false }
ethers = { version = "2.0.11", default-features = false }
ethers-core = { version = "2.0.11", default-features = false }
ethers-contract = { version = "2.0.11", default-features = false }
ethers-contract-abigen = { version = "2.0.11", default-features = false }
ethers-providers = { version = "2.0.11", default-features = false }
ethers-signers = { version = "2.0.11", default-features = false }
ethers-middleware = { version = "2.0.11", default-features = false }
ethers-solc = { version = "2.0.11", default-features = false }

## alloy
alloy-primitives = "0.4.1"
Expand Down Expand Up @@ -196,16 +196,16 @@ tower-http = "0.4"
#ethers-solc = { path = "../ethers-rs/ethers-solc" }

[patch.crates-io]
ethers = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-addressbook = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-core = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-contract = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-contract-abigen = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-providers = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-signers = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-middleware = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-etherscan = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers-solc = { git = "https://github.com/gakonst/ethers-rs", rev = "4e09be88730045dd6c4ed8a4e198a9956931e7bd" }
ethers = { git = "https://github.com/gakonst/ethers-rs", rev = "2d2599f90237376e443163e3f05b887c6141dc78" }
ethers-core = { git = "https://github.com/gakonst/ethers-rs", rev = "2d2599f90237376e443163e3f05b887c6141dc78" }
ethers-contract = { git = "https://github.com/gakonst/ethers-rs", rev = "2d2599f90237376e443163e3f05b887c6141dc78" }
ethers-contract-abigen = { git = "https://github.com/gakonst/ethers-rs", rev = "2d2599f90237376e443163e3f05b887c6141dc78" }
ethers-providers = { git = "https://github.com/gakonst/ethers-rs", rev = "2d2599f90237376e443163e3f05b887c6141dc78" }
ethers-signers = { git = "https://github.com/gakonst/ethers-rs", rev = "2d2599f90237376e443163e3f05b887c6141dc78" }
ethers-middleware = { git = "https://github.com/gakonst/ethers-rs", rev = "2d2599f90237376e443163e3f05b887c6141dc78" }
ethers-solc = { git = "https://github.com/gakonst/ethers-rs", rev = "2d2599f90237376e443163e3f05b887c6141dc78" }

foundry-block-explorers = { git = "https://github.com/foundry-rs/block-explorers" }

alloy-dyn-abi = { git = "https://github.com/alloy-rs/core/" }
alloy-json-abi = { git = "https://github.com/alloy-rs/core/" }
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ default = ["serde","optimism"]
impersonated-tx = []
fastrlp = ["dep:open-fastrlp"]
serde = ["dep:serde"]
optimism = ["dep:ethers-core", "dep:ethers-contract", "dep:ethers-providers", "dep:ethers-middleware"]
optimism = ["ethers-core/optimism", "ethers-contract/optimism", "ethers-providers/optimism", "ethers-middleware/optimism"]
25 changes: 12 additions & 13 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ pub enum TypedTransactionRequest {
/// Represents _all_ transaction requests received from RPC
#[derive(Clone, Debug, PartialEq, Eq, Default, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
// #[cfg_attr(feature = "serde", serde(deny_unknown_fields))] // TODO: had to disable this to get
// tests passing
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct EthTransactionRequest {
/// from address
Expand Down Expand Up @@ -156,7 +155,6 @@ impl EthTransactionRequest {
}
// op-stack deposit
(Some(126), _, None, None, None) => {
// TODO: gas price should be zero, enforce this here?
Some(TypedTransactionRequest::Deposit(DepositTransactionRequest {
source_hash: source_hash.unwrap_or_default(),
from: from.unwrap_or_default(),
Expand Down Expand Up @@ -1247,6 +1245,7 @@ impl Decodable for EIP1559Transaction {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "fastrlp", derive(open_fastrlp::RlpEncodable, open_fastrlp::RlpDecodable))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

pub struct DepositTransaction {
pub nonce: U256,
pub source_hash: H256,
Expand Down Expand Up @@ -1295,20 +1294,20 @@ impl Encodable for DepositTransaction {

impl Decodable for DepositTransaction {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
if rlp.item_count()? != 9 {
if rlp.item_count()? != 8 {
return Err(DecoderError::RlpIncorrectListLen)
}

Ok(Self {
nonce: rlp.val_at(0)?,
source_hash: rlp.val_at(1)?,
from: rlp.val_at(2)?,
kind: rlp.val_at(3)?,
mint: rlp.val_at(4)?,
value: rlp.val_at(5)?,
gas_limit: rlp.val_at(6)?,
is_system_tx: rlp.val_at(7)?,
input: rlp.val_at::<Vec<u8>>(8)?.into(),
source_hash: rlp.val_at(0)?,
from: rlp.val_at(1)?,
kind: rlp.val_at(2)?,
mint: rlp.val_at(3)?,
value: rlp.val_at(4)?,
gas_limit: rlp.val_at(5)?,
is_system_tx: rlp.val_at(6)?,
input: rlp.val_at::<Vec<u8>>(7)?.into(),
nonce: U256::from(0),
})
}
}
Expand Down
7 changes: 3 additions & 4 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,9 @@ impl EthApi {
) -> Result<TypedTransaction> {
match request {
TypedTransactionRequest::Deposit(_) => {
return build_typed_transaction(
request,
Signature { r: U256::zero(), s: U256::zero(), v: 0 },
)
const NIL_SIGNATURE: ethers::types::Signature =
Signature { r: U256::zero(), s: U256::zero(), v: 0 };
return build_typed_transaction(request, NIL_SIGNATURE)
}
_ => {
for signer in self.signers.iter() {
Expand Down
9 changes: 3 additions & 6 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ impl Backend {
}

/// Returns true if op-stack deposits are active
pub fn is_op_deposits(&self) -> bool {
pub fn is_optimism(&self) -> bool {
self.env.read().cfg.optimism
}

Expand All @@ -576,7 +576,7 @@ impl Backend {

/// Returns an error if op-stack deposits are not active
pub fn ensure_op_deposits_active(&self) -> Result<(), BlockchainError> {
if self.is_op_deposits() {
if self.is_optimism() {
return Ok(())
}
Err(BlockchainError::DepositTransactionUnsupported)
Expand Down Expand Up @@ -1929,10 +1929,7 @@ impl Backend {
TypedTransaction::Deposit(_) => U256::from(0),
};

let mut deposit_nonce: Option<u64> = None;
if transaction_type.unwrap_or_default() == 0x7E {
deposit_nonce = Some(info.nonce);
}
let deposit_nonce = transaction_type.and_then(|x| (x == 0x7E).then_some(info.nonce));

let inner = TransactionReceipt {
transaction_hash: info.transaction_hash,
Expand Down
83 changes: 42 additions & 41 deletions crates/anvil/tests/it/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,44 +88,45 @@ async fn test_send_value_deposit_transaction() {
assert_eq!(balance, send_value);
}

// // TODO: get this working - it tests eth_sendRawTransaction
// #[tokio::test(flavor = "multi_thread")]
// async fn test_send_value_raw_deposit_transaction() {
// // enable the Optimism flag
// let (api, handle) = spawn(NodeConfig::test().with_optimism(true)).await;
// let provider = handle.http_provider();

// let send_value: U256 = "1234".parse().unwrap();
// let from_addr: Address = "cf7f9e66af820a19257a2108375b180b0ec49167".parse().unwrap();
// let to_addr: Address = "71562b71999873db5b286df957af199ec94617f7".parse().unwrap();

// // fund the sender
// api.anvil_set_balance(from_addr, send_value).await.unwrap();

// let deposit_tx: TypedTransaction = TypedTransaction::DepositTransaction(DepositTransaction {
// tx: TransactionRequest {
// chain_id: None,
// from: Some(from_addr),
// to: Some(ethers::types::NameOrAddress::Address(to_addr)),
// value: Some(send_value),
// gas: Some(U256::from(21000)),
// gas_price: None,
// data: Some(Bytes::default()),
// nonce: None,
// },
// source_hash:
// H256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap(),
// mint: Some(U256::zero()),
// is_system_tx: true,
// });

// let rlpbytes = deposit_tx.rlp();
// provider.send_raw_transaction(rlpbytes).await.unwrap().await.unwrap().unwrap();

// // mine block
// api.evm_mine(None).await.unwrap();

// // the recipient should have received the value
// let balance = provider.get_balance(to_addr, None).await.unwrap();
// assert_eq!(balance, send_value);
// }
#[tokio::test(flavor = "multi_thread")]
async fn test_send_value_raw_deposit_transaction() {
// enable the Optimism flag
let (api, handle) = spawn(NodeConfig::test().with_optimism(true)).await;
let provider = handle.http_provider();

let send_value: U256 = "1234".parse().unwrap();
let from_addr: Address = "cf7f9e66af820a19257a2108375b180b0ec49167".parse().unwrap();
let to_addr: Address = "71562b71999873db5b286df957af199ec94617f7".parse().unwrap();

// fund the sender
api.anvil_set_balance(from_addr, send_value).await.unwrap();

let deposit_tx: TypedTransaction = TypedTransaction::DepositTransaction(DepositTransaction {
tx: TransactionRequest {
chain_id: None,
from: Some(from_addr),
to: Some(ethers::types::NameOrAddress::Address(to_addr)),
value: Some(send_value),
gas: Some(U256::from(21000)),
gas_price: None,
data: Some(Bytes::default()),
nonce: None,
},
source_hash: H256::from_str(
"0000000000000000000000000000000000000000000000000000000000000000",
)
.unwrap(),
mint: Some(U256::zero()),
is_system_tx: true,
});

let rlpbytes = deposit_tx.rlp();
provider.send_raw_transaction(rlpbytes).await.unwrap().await.unwrap().unwrap();

// mine block
api.evm_mine(None).await.unwrap();

// the recipient should have received the value
let balance = provider.get_balance(to_addr, None).await.unwrap();
assert_eq!(balance, send_value);
}