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
Next Next commit
Add support for op-stack deposit transactions
  • Loading branch information
mdehoog authored and anikaraghu committed Nov 21, 2023
commit 655f109bf1ef8993cfa2da78bb41bf6efaa430d5
2 changes: 1 addition & 1 deletion crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ foundry-utils.workspace = true
bytes = "1.4.0"
# needed as documented in https://github.com/foundry-rs/foundry/pull/6358
k256 = "=0.13.1"
ethers = { workspace = true, features = ["rustls", "ws", "ipc"] }
ethers = { workspace = true, features = ["rustls", "ws", "ipc", "optimism"] }
trie-db = "0.23"
hash-db = "0.15"
memory-db = "0.29"
Expand Down
23 changes: 21 additions & 2 deletions crates/anvil/core/src/eth/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl Decodable for EIP658Receipt {
// same underlying data structure
pub type EIP2930Receipt = EIP658Receipt;
pub type EIP1559Receipt = EIP658Receipt;
pub type OpDepositReceipt = EIP658Receipt;

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand All @@ -104,6 +105,8 @@ pub enum TypedReceipt {
EIP2930(EIP2930Receipt),
/// EIP-1559 receipt
EIP1559(EIP1559Receipt),
/// op-stack deposit receipt
OpDeposit(OpDepositReceipt),
}

// == impl TypedReceipt ==
Expand All @@ -112,7 +115,7 @@ impl TypedReceipt {
/// Returns the gas used by the transactions
pub fn gas_used(&self) -> U256 {
match self {
TypedReceipt::Legacy(r) | TypedReceipt::EIP2930(r) | TypedReceipt::EIP1559(r) => {
TypedReceipt::Legacy(r) | TypedReceipt::EIP2930(r) | TypedReceipt::EIP1559(r) | TypedReceipt::OpDeposit(r) => {
r.gas_used
}
}
Expand All @@ -121,7 +124,7 @@ impl TypedReceipt {
/// Returns the gas used by the transactions
pub fn logs_bloom(&self) -> &Bloom {
match self {
TypedReceipt::Legacy(r) | TypedReceipt::EIP2930(r) | TypedReceipt::EIP1559(r) => {
TypedReceipt::Legacy(r) | TypedReceipt::EIP2930(r) | TypedReceipt::EIP1559(r) | TypedReceipt::OpDeposit(r) => {
&r.logs_bloom
}
}
Expand All @@ -134,6 +137,7 @@ impl Encodable for TypedReceipt {
TypedReceipt::Legacy(r) => r.rlp_append(s),
TypedReceipt::EIP2930(r) => enveloped(1, r, s),
TypedReceipt::EIP1559(r) => enveloped(2, r, s),
TypedReceipt::OpDeposit(r) => enveloped(0x7E, r, s),
}
}
}
Expand Down Expand Up @@ -171,6 +175,7 @@ impl open_fastrlp::Encodable for TypedReceipt {
let payload_len = match receipt {
TypedReceipt::EIP2930(r) => r.length() + 1,
TypedReceipt::EIP1559(r) => r.length() + 1,
TypedReceipt::OpDeposit(r) => r.length() + 1,
_ => unreachable!("receipt already matched"),
};

Expand All @@ -188,6 +193,7 @@ impl open_fastrlp::Encodable for TypedReceipt {
let payload_len = match receipt {
TypedReceipt::EIP2930(r) => r.length() + 1,
TypedReceipt::EIP1559(r) => r.length() + 1,
TypedReceipt::OpDeposit(r) => r.length() + 1,
_ => unreachable!("receipt already matched"),
};

Expand All @@ -208,6 +214,14 @@ impl open_fastrlp::Encodable for TypedReceipt {
out.put_u8(0x02);
r.encode(out);
}
TypedReceipt::OpDeposit(r) => {
let receipt_string_header =
Header { list: false, payload_length: payload_len };

receipt_string_header.encode(out);
out.put_u8(0x7E);
r.encode(out);
}
_ => unreachable!("receipt already matched"),
}
}
Expand Down Expand Up @@ -244,6 +258,10 @@ impl open_fastrlp::Decodable for TypedReceipt {
buf.advance(1);
<EIP1559Receipt as open_fastrlp::Decodable>::decode(buf)
.map(TypedReceipt::EIP1559)
} else if receipt_type == 0x7E {
buf.advance(1);
<OpDepositReceipt as open_fastrlp::Decodable>::decode(buf)
.map(TypedReceipt::OpDeposit)
} else {
Err(open_fastrlp::DecodeError::Custom("invalid receipt type"))
}
Expand All @@ -264,6 +282,7 @@ impl From<TypedReceipt> for EIP658Receipt {
TypedReceipt::Legacy(receipt) => receipt,
TypedReceipt::EIP2930(receipt) => receipt,
TypedReceipt::EIP1559(receipt) => receipt,
TypedReceipt::OpDeposit(receipt) => receipt,
}
}
}
Expand Down
69 changes: 65 additions & 4 deletions crates/anvil/core/src/eth/transaction/ethers_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use super::EthTransactionRequest;
use crate::eth::transaction::{
EIP1559TransactionRequest, EIP2930TransactionRequest, LegacyTransactionRequest,
MaybeImpersonatedTransaction, TypedTransaction, TypedTransactionRequest,
OpDepositTransactionRequest,
};
use ethers_core::types::{
transaction::eip2718::TypedTransaction as EthersTypedTransactionRequest, Address,
Eip1559TransactionRequest as EthersEip1559TransactionRequest,
Eip2930TransactionRequest as EthersEip2930TransactionRequest, NameOrAddress,
Transaction as EthersTransaction, TransactionRequest as EthersLegacyTransactionRequest,
TransactionRequest, H256, U256, U64,
TransactionRequest, H256, U256, U64, transaction::optimism::DepositTransaction,
};

impl From<TypedTransactionRequest> for EthersTypedTransactionRequest {
Expand Down Expand Up @@ -87,6 +88,33 @@ impl From<TypedTransactionRequest> for EthersTypedTransactionRequest {
chain_id: Some(chain_id.into()),
})
}
TypedTransactionRequest::OpDeposit(tx) => {
let OpDepositTransactionRequest {
source_hash,
from,
kind,
mint,
value,
gas_limit,
is_system_tx,
input,
} = tx;
EthersTypedTransactionRequest::DepositTransaction(DepositTransaction {
tx: TransactionRequest {
from: Some(from),
to: kind.as_call().cloned().map(Into::into),
gas: Some(gas_limit),
value: Some(value),
data: Some(input),
gas_price: Some(0.into()),
nonce: Some(0.into()),
chain_id: None,
},
source_hash: Some(source_hash),
mint: Some(mint),
is_system_tx: Some(is_system_tx),
})
}
}
}
}
Expand Down Expand Up @@ -117,7 +145,9 @@ fn to_ethers_transaction_with_hash_and_sender(
s: t.signature.s,
access_list: None,
transaction_type: None,
other: Default::default(),
source_hash: None,
mint: None,
is_system_tx: None,
},
TypedTransaction::EIP2930(t) => EthersTransaction {
hash,
Expand All @@ -139,7 +169,9 @@ fn to_ethers_transaction_with_hash_and_sender(
s: U256::from(t.s.as_bytes()),
access_list: Some(t.access_list),
transaction_type: Some(1u64.into()),
other: Default::default(),
source_hash: None,
mint: None,
is_system_tx: None,
},
TypedTransaction::EIP1559(t) => EthersTransaction {
hash,
Expand All @@ -161,7 +193,33 @@ fn to_ethers_transaction_with_hash_and_sender(
s: U256::from(t.s.as_bytes()),
access_list: Some(t.access_list),
transaction_type: Some(2u64.into()),
other: Default::default(),
source_hash: None,
mint: None,
is_system_tx: None,
},
TypedTransaction::OpDeposit(t) => EthersTransaction {
hash,
nonce: t.nonce(),
block_hash: None,
block_number: None,
transaction_index: None,
from,
to: None,
value: t.value,
gas_price: Some(0.into()),
max_fee_per_gas: Some(0.into()),
max_priority_fee_per_gas: Some(0.into()),
gas: t.gas_limit,
input: t.input.clone(),
chain_id: t.chain_id().map(Into::into),
v: 0.into(),
r: 0.into(),
s: 0.into(),
access_list: None,
transaction_type: Some(126u64.into()),
source_hash: Some(t.source_hash),
mint: Some(t.mint),
is_system_tx: Some(t.is_system_tx),
},
}
}
Expand Down Expand Up @@ -201,6 +259,9 @@ impl From<TransactionRequest> for EthTransactionRequest {
chain_id,
access_list: None,
transaction_type: None,
source_hash: None,
mint: None,
is_system_tx: None,
}
}
}
Expand Down
Loading