Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(anvil): support for op-stack deposit transactions #6073

Merged
merged 21 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 16 additions & 13 deletions Cargo.lock

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

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,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 = "546ea029362a7502365667c6f99fac92ad0aeb9f" }
ethers-core = { git = "https://github.com/gakonst/ethers-rs", rev = "546ea029362a7502365667c6f99fac92ad0aeb9f" }
ethers-contract = { git = "https://github.com/gakonst/ethers-rs", rev = "546ea029362a7502365667c6f99fac92ad0aeb9f" }
ethers-contract-abigen = { git = "https://github.com/gakonst/ethers-rs", rev = "546ea029362a7502365667c6f99fac92ad0aeb9f" }
ethers-providers = { git = "https://github.com/gakonst/ethers-rs", rev = "546ea029362a7502365667c6f99fac92ad0aeb9f" }
ethers-signers = { git = "https://github.com/gakonst/ethers-rs", rev = "546ea029362a7502365667c6f99fac92ad0aeb9f" }
ethers-middleware = { git = "https://github.com/gakonst/ethers-rs", rev = "546ea029362a7502365667c6f99fac92ad0aeb9f" }
ethers-solc = { git = "https://github.com/gakonst/ethers-rs", rev = "546ea029362a7502365667c6f99fac92ad0aeb9f" }

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
3 changes: 2 additions & 1 deletion crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ foundry-evm.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 Expand Up @@ -75,6 +75,7 @@ ethereum-forkid = "0.12"

[dev-dependencies]
ethers = { workspace = true, features = ["abigen"] }
ethers-core = { workspace = true, features = ["optimism"] }
ethers-solc = { workspace = true, features = ["project-util", "full"] }
pretty_assertions = "1.3.0"
tokio = { version = "1", features = ["full"] }
Expand Down
10 changes: 7 additions & 3 deletions crates/anvil/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ repository.workspace = true
foundry-common.workspace = true
foundry-evm.workspace = true

alloy-primitives = { workspace = true, features = ["serde"] }
revm = { workspace = true, default-features = false, features = ["std", "serde", "memory_limit"] }
ethers-core = { workspace = true, features = ["optimism"] }
# theses are not used by anvil-core, but are required by ethers, because pulled in via foundry-common
ethers-contract = { workspace = true, features = ["optimism"] }
ethers-providers = { workspace = true, features = ["optimism"] }
ethers-middleware = { workspace = true, features = ["optimism"] }

alloy-primitives = { workspace = true, features = ["serde"] }
ethers-core.workspace = true
serde = { workspace = true, optional = true }
serde_json.workspace = true
bytes = { version = "1.4" }
Expand All @@ -36,4 +40,4 @@ anvil-core = { path = ".", features = ["serde"] }
default = ["serde"]
impersonated-tx = []
fastrlp = ["dep:open-fastrlp"]
serde = ["dep:serde"]
serde = ["dep:serde"]
37 changes: 31 additions & 6 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 DepositReceipt = 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
Deposit(DepositReceipt),
}

// == impl TypedReceipt ==
Expand All @@ -112,18 +115,20 @@ 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) => {
r.gas_used
}
TypedReceipt::Legacy(r) |
TypedReceipt::EIP2930(r) |
TypedReceipt::EIP1559(r) |
TypedReceipt::Deposit(r) => r.gas_used,
}
}

/// Returns the gas used by the transactions
pub fn logs_bloom(&self) -> &Bloom {
match self {
TypedReceipt::Legacy(r) | TypedReceipt::EIP2930(r) | TypedReceipt::EIP1559(r) => {
&r.logs_bloom
}
TypedReceipt::Legacy(r) |
TypedReceipt::EIP2930(r) |
TypedReceipt::EIP1559(r) |
TypedReceipt::Deposit(r) => &r.logs_bloom,
}
}
}
Expand All @@ -134,6 +139,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::Deposit(r) => enveloped(0x7E, r, s),
}
}
}
Expand All @@ -158,6 +164,10 @@ impl Decodable for TypedReceipt {
return rlp::decode(s).map(TypedReceipt::EIP1559)
}

if first == 0x7E {
return rlp::decode(s).map(TypedReceipt::Deposit)
}

Err(DecoderError::Custom("unknown receipt type"))
}
}
Expand All @@ -171,6 +181,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::Deposit(r) => r.length() + 1,
_ => unreachable!("receipt already matched"),
};

Expand All @@ -188,6 +199,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::Deposit(r) => r.length() + 1,
_ => unreachable!("receipt already matched"),
};

Expand All @@ -208,6 +220,14 @@ impl open_fastrlp::Encodable for TypedReceipt {
out.put_u8(0x02);
r.encode(out);
}
TypedReceipt::Deposit(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 +264,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);
<DepositReceipt as open_fastrlp::Decodable>::decode(buf)
.map(TypedReceipt::Deposit)
} else {
Err(open_fastrlp::DecodeError::Custom("invalid receipt type"))
}
Expand All @@ -264,6 +288,7 @@ impl From<TypedReceipt> for EIP658Receipt {
TypedReceipt::Legacy(receipt) => receipt,
TypedReceipt::EIP2930(receipt) => receipt,
TypedReceipt::EIP1559(receipt) => receipt,
TypedReceipt::Deposit(receipt) => receipt,
}
}
}
Expand Down
Loading